Skip to content

Commit 415bb91

Browse files
committed
Fix the incorrect form state offer_free_shipping for the shipping settings
1 parent e464c76 commit 415bb91

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

js/src/components/free-listings/setup-free-listings/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import AppSpinner from '.~/components/app-spinner';
1212
import Hero from '.~/components/free-listings/configure-product-listings/hero';
1313
import checkErrors from '.~/components/free-listings/configure-product-listings/checkErrors';
1414
import getOfferFreeShippingInitialValue from '.~/utils/getOfferFreeShippingInitialValue';
15+
import isNonFreeShippingRate from '.~/utils/isNonFreeShippingRate';
1516
import FormContent from './form-content';
1617

1718
/**
@@ -112,6 +113,16 @@ const SetupFreeListings = ( {
112113
const handleChange = ( change, values ) => {
113114
if ( change.name === 'shipping_country_rates' ) {
114115
onShippingRatesChange( values.shipping_country_rates );
116+
117+
// If all the shipping rates are free shipping,
118+
// we set the offer_free_shipping to undefined,
119+
// so that when users add a non-free shipping rate,
120+
// they would need to choose "yes" / "no" for offer_free_shipping.
121+
if ( ! change.value.some( isNonFreeShippingRate ) ) {
122+
formPropsDelegateeRef.current.push( ( formProps ) => {
123+
formProps.setValue( 'offer_free_shipping', undefined );
124+
} );
125+
}
115126
} else if ( change.name === 'shipping_country_times' ) {
116127
onShippingTimesChange( values.shipping_country_times );
117128
} else if ( settingsFieldNames.includes( change.name ) ) {

js/src/components/shipping-rate-section/flat-shipping-rates-input-cards.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,6 @@ const FlatShippingRatesInputCards = ( props ) => {
1313
isNonFreeShippingRate
1414
);
1515

16-
const getShippingRatesChangeHandler = ( onChange ) => (
17-
newShippingRates
18-
) => {
19-
/**
20-
* If all the shipping rates are free shipping,
21-
* we set the offer_free_shipping to undefined,
22-
* so that when users add a non-free shipping rate,
23-
* they would need to choose "yes" / "no" for offer_free_shipping.
24-
*/
25-
if ( ! newShippingRates.some( isNonFreeShippingRate ) ) {
26-
setValue( 'offer_free_shipping', undefined );
27-
}
28-
29-
onChange( newShippingRates );
30-
};
31-
3216
const getOfferFreeShippingChangeHandler = ( onChange ) => (
3317
newOfferFreeShippingValue
3418
) => {
@@ -58,9 +42,6 @@ const FlatShippingRatesInputCards = ( props ) => {
5842
<EstimatedShippingRatesCard
5943
audienceCountries={ audienceCountries }
6044
{ ...getInputProps( 'shipping_country_rates' ) }
61-
onChange={ getShippingRatesChangeHandler(
62-
getInputProps( 'shipping_country_rates' ).onChange
63-
) }
6445
/>
6546
{ displayFreeShippingCards && (
6647
<>

0 commit comments

Comments
 (0)