File tree Expand file tree Collapse file tree 2 files changed +11
-19
lines changed
free-listings/setup-free-listings Expand file tree Collapse file tree 2 files changed +11
-19
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import AppSpinner from '.~/components/app-spinner';
12
12
import Hero from '.~/components/free-listings/configure-product-listings/hero' ;
13
13
import checkErrors from '.~/components/free-listings/configure-product-listings/checkErrors' ;
14
14
import getOfferFreeShippingInitialValue from '.~/utils/getOfferFreeShippingInitialValue' ;
15
+ import isNonFreeShippingRate from '.~/utils/isNonFreeShippingRate' ;
15
16
import FormContent from './form-content' ;
16
17
17
18
/**
@@ -112,6 +113,16 @@ const SetupFreeListings = ( {
112
113
const handleChange = ( change , values ) => {
113
114
if ( change . name === 'shipping_country_rates' ) {
114
115
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
+ }
115
126
} else if ( change . name === 'shipping_country_times' ) {
116
127
onShippingTimesChange ( values . shipping_country_times ) ;
117
128
} else if ( settingsFieldNames . includes ( change . name ) ) {
Original file line number Diff line number Diff line change @@ -13,22 +13,6 @@ const FlatShippingRatesInputCards = ( props ) => {
13
13
isNonFreeShippingRate
14
14
) ;
15
15
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
-
32
16
const getOfferFreeShippingChangeHandler = ( onChange ) => (
33
17
newOfferFreeShippingValue
34
18
) => {
@@ -58,9 +42,6 @@ const FlatShippingRatesInputCards = ( props ) => {
58
42
< EstimatedShippingRatesCard
59
43
audienceCountries = { audienceCountries }
60
44
{ ...getInputProps ( 'shipping_country_rates' ) }
61
- onChange = { getShippingRatesChangeHandler (
62
- getInputProps ( 'shipping_country_rates' ) . onChange
63
- ) }
64
45
/>
65
46
{ displayFreeShippingCards && (
66
47
< >
You can’t perform that action at this time.
0 commit comments