diff --git a/.changeset/khaki-pianos-cry.md b/.changeset/khaki-pianos-cry.md new file mode 100644 index 0000000000..6b8a1c336e --- /dev/null +++ b/.changeset/khaki-pianos-cry.md @@ -0,0 +1,5 @@ +--- +"@graphcommerce/magento-cart-shipping-address": patch +--- + +Fixed CustomerAddressForm resetting to a saved address when trying to use a new address diff --git a/packages/magento-cart-shipping-address/components/CustomerAddressForm/CustomerAddressForm.tsx b/packages/magento-cart-shipping-address/components/CustomerAddressForm/CustomerAddressForm.tsx index f205e013bf..af71866ea4 100644 --- a/packages/magento-cart-shipping-address/components/CustomerAddressForm/CustomerAddressForm.tsx +++ b/packages/magento-cart-shipping-address/components/CustomerAddressForm/CustomerAddressForm.tsx @@ -107,18 +107,24 @@ export function CustomerAddressForm(props: CustomerAddressListProps) { useEffect(() => { if (mode === 'both' || mode === 'shipping') { - if (!cartAddressId && defaultShippingId) { - // console.log('shippingAddress.customer_address_id', defaultShippingId) + if (!cartAddressId && !cartShipping && defaultShippingId) { setValue('customer_address_id', defaultShippingId, { shouldValidate: true }) } } if (mode === 'billing') { - if (!cartAddressId && defaultBillingId) { - // console.log('billingAddress.customer_address_id', defaultBillingId) + if (!cartAddressId && !cartBilling && defaultBillingId) { setValue('customer_address_id', defaultBillingId, { shouldValidate: true }) } } - }, [cartAddressId, defaultBillingId, defaultShippingId, mode, setValue]) + }, [ + cartAddressId, + cartBilling, + cartShipping, + defaultBillingId, + defaultShippingId, + mode, + setValue, + ]) const submit = handleSubmit(() => {})