Ensure email and phone are persisted through `setBillingData` (https://github.com/woocommerce/woocommerce-blocks/pull/2477)
* Force inclusion of email and phone * Update deps * update deps
This commit is contained in:
parent
9e4755ad04
commit
2395137790
|
@ -29,15 +29,12 @@ export const useBillingDataContext = () => {
|
|||
export const BillingDataProvider = ( { children } ) => {
|
||||
const [ billingData, setBillingDataState ] = useState( DEFAULT_STATE );
|
||||
|
||||
const setBillingData = useCallback(
|
||||
( newData ) => {
|
||||
setBillingDataState( ( prevState ) => ( {
|
||||
...prevState,
|
||||
...newData,
|
||||
} ) );
|
||||
},
|
||||
[ setBillingDataState ]
|
||||
);
|
||||
const setBillingData = useCallback( ( newData ) => {
|
||||
setBillingDataState( ( prevState ) => ( {
|
||||
...prevState,
|
||||
...newData,
|
||||
} ) );
|
||||
}, [] );
|
||||
|
||||
/**
|
||||
* @type {BillingDataContext}
|
||||
|
|
|
@ -58,14 +58,26 @@ export const useCheckoutAddress = () => {
|
|||
setShippingAddress( shippingFields );
|
||||
}
|
||||
|
||||
const newBillingData = shippingAsBilling
|
||||
? shippingFields
|
||||
: billingFields;
|
||||
// Uses shipping or billing fields depending on shippingAsBilling checkbox, but ensures
|
||||
// billing only fields are also included.
|
||||
const newBillingData = {
|
||||
...( shippingAsBilling ? shippingFields : billingFields ),
|
||||
email: billingFields.email,
|
||||
phone: billingFields.phone,
|
||||
};
|
||||
|
||||
if ( ! isEqual( newBillingData, billingData ) ) {
|
||||
setBillingData( newBillingData );
|
||||
}
|
||||
}, [ shippingFields, billingFields, shippingAsBilling ] );
|
||||
}, [
|
||||
shippingFields,
|
||||
billingFields,
|
||||
shippingAsBilling,
|
||||
billingData,
|
||||
shippingAddress,
|
||||
setBillingData,
|
||||
setShippingAddress,
|
||||
] );
|
||||
|
||||
/**
|
||||
* Wrapper for updateBillingFields (from useState) which handles merging.
|
||||
|
|
Loading…
Reference in New Issue