Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
switch from event subscription to status watch (#2119)
Browse files Browse the repository at this point in the history
  • Loading branch information
nerrad authored Apr 4, 2020
1 parent e6757ab commit d0b182c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions assets/js/blocks/cart-checkout/checkout/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 />;
Expand Down

0 comments on commit d0b182c

Please sign in to comment.