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