Skip to content

Commit

Permalink
Avoid errors caused by automatically saving invalid shipping times du…
Browse files Browse the repository at this point in the history
…ring onboarding.
  • Loading branch information
eason9487 committed Dec 3, 2024
1 parent 4fab9f0 commit 2b00666
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion js/src/components/free-listings/setup-free-listings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,17 @@ const SetupFreeListings = ( {
setValue( 'shipping_country_rates', nextValue );
}
} else if ( change.name === 'shipping_country_times' ) {
// Skip the call of `onShippingTimesChange` if any shipping times are invalid.
const error = handleValidate( values );
const isValid = ! error.hasOwnProperty( change.name );

Check warning on line 141 in js/src/components/free-listings/setup-free-listings/index.js

View check run for this annotation

Codecov / codecov/patch

js/src/components/free-listings/setup-free-listings/index.js#L140-L141

Added lines #L140 - L141 were not covered by tests

// Skip the call of `onShippingTimesChange` if there are incomplete shipping times.
// This should only happen during onboarding when the shipping times haven't been stored yet.
const shippingIsIncomplete = values.shipping_country_times.some(
( item ) => item.time === null || item.maxTime === null
);
if ( ! shippingIsIncomplete ) {

if ( ! shippingIsIncomplete && isValid ) {
onShippingTimesChange( values.shipping_country_times );
}
} else if ( settingsFieldNames.includes( change.name ) ) {
Expand Down

0 comments on commit 2b00666

Please sign in to comment.