switch from event subscription to status watch (https://github.com/woocommerce/woocommerce-blocks/pull/2119)
This commit is contained in:
parent
e54e08bccf
commit
4f990fd475
|
@ -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 />;
|
||||||
|
|
Loading…
Reference in New Issue