switch from event subscription to status watch (https://github.com/woocommerce/woocommerce-blocks/pull/2119)

This commit is contained in:
Darren Ethier 2020-04-04 13:36:46 -04:00 committed by GitHub
parent e54e08bccf
commit 4f990fd475
1 changed files with 8 additions and 7 deletions

View File

@ -61,7 +61,11 @@ const Checkout = ( {
shippingRates = [],
} ) => {
const { isEditor } = useEditorContext();
const { hasOrder, onCheckoutCompleteError } = useCheckoutContext();
const {
hasOrder,
hasError: checkoutHasError,
isComplete: checkoutIsComplete,
} = useCheckoutContext();
const { showAllValidationErrors } = useValidationContext();
const {
shippingRatesLoading,
@ -121,14 +125,11 @@ const Checkout = ( {
}, [ shippingAsBilling, setBillingData ] );
useEffect( () => {
const unsubscribeCompleteError = onCheckoutCompleteError( () => {
if ( checkoutIsComplete && checkoutHasError ) {
showAllValidationErrors();
scrollToTop( { focusableSelector: 'input:invalid' } );
} );
return () => {
unsubscribeCompleteError();
};
}, [ onCheckoutCompleteError ] );
}
}, [ checkoutIsComplete, checkoutHasError ] );
if ( ! isEditor && ! hasOrder ) {
return <CheckoutOrderError />;