Fix block checkout page reloading on form errors.

This commit is contained in:
Pedro Silva 2023-12-13 16:42:16 +00:00
parent be28f81758
commit 2f0f0a7e0f
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3

View file

@ -31,6 +31,7 @@ const PayPalComponent = ({
const {responseTypes} = emitResponse;
const [paypalOrder, setPaypalOrder] = useState(null);
const [gotoContinuation, setGotoContinuation] = useState(false);
const methodId = fundingSource ? `${config.id}-${fundingSource}` : config.id;
@ -152,6 +153,7 @@ const PayPalComponent = ({
if (config.finalReviewEnabled) {
location.href = getCheckoutRedirectUrl();
} else {
setGotoContinuation(true);
onSubmit();
}
} catch (err) {
@ -170,7 +172,7 @@ const PayPalComponent = ({
if (config.scriptData.continuation) {
return true;
}
if (wp.data.select('wc/store/validation').hasValidationErrors()) {
if (gotoContinuation && wp.data.select('wc/store/validation').hasValidationErrors()) {
location.href = getCheckoutRedirectUrl();
return { type: responseTypes.ERROR };
}
@ -178,7 +180,7 @@ const PayPalComponent = ({
return true;
});
return unsubscribe;
}, [onCheckoutValidation] );
}, [onCheckoutValidation, gotoContinuation] );
const handleClick = (data, actions) => {
if (isEditing) {