Merge pull request #1904 from woocommerce/PCP-2389-block-checkout-reloads-when-submitting-order-with-empty-fields

Block Checkout reloads when submitting order with empty fields (2389)
This commit is contained in:
Niklas Gutberlet 2023-12-15 09:57:16 +01:00 committed by GitHub
commit ebc2dc4f70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,6 +31,7 @@ const PayPalComponent = ({
const {responseTypes} = emitResponse;
const [paypalOrder, setPaypalOrder] = useState(null);
const [gotoContinuationOnError, setGotoContinuationOnError] = useState(false);
const methodId = fundingSource ? `${config.id}-${fundingSource}` : config.id;
@ -152,6 +153,7 @@ const PayPalComponent = ({
if (config.finalReviewEnabled) {
location.href = getCheckoutRedirectUrl();
} else {
setGotoContinuationOnError(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 (gotoContinuationOnError && 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, gotoContinuationOnError] );
const handleClick = (data, actions) => {
if (isEditing) {