Skip to content

Commit

Permalink
fix: Duplicate customer addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
acasazza committed Dec 9, 2021
1 parent 89049cd commit 10d03a7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/components/BillingAddressForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { AddressCountrySelectName, AddressInputName } from '#typings'
import components from '#config/components'
import OrderContext from '#context/OrderContext'
import { Address } from '@commercelayer/sdk'
import { getSaveBillingAddressToAddressBook } from '#utils/localStorage'

const propTypes = components.BillingAddressForm.propTypes

Expand Down Expand Up @@ -97,7 +98,12 @@ const BillingAddressForm: FunctionComponent<BillingAddressFormProps> = (
}
setAddress({ values: values as Address, resource: 'billing_address' })
}
if (reset && (!isEmpty(values) || !isEmpty(errors))) {
const checkboxChecked =
ref.current?.querySelector(
'[name="billing_address_save_to_customer_book"]'
// @ts-ignore
)?.checked || getSaveBillingAddressToAddressBook()
if (reset && (!isEmpty(values) || !isEmpty(errors) || checkboxChecked)) {
saveAddressToCustomerAddressBook &&
saveAddressToCustomerAddressBook({
type: 'billing_address',
Expand Down
1 change: 0 additions & 1 deletion src/components/PricesContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import getCurrentItemKey from '#utils/getCurrentItemKey'
import ItemContext from '#context/ItemContext'
import components from '#config/components'
import { LoaderType } from '#typings'
import { Price } from '@commercelayer/sdk'

const propTypes = components.PricesContainer.propTypes
const defaultProps = components.PricesContainer.defaultProps
Expand Down
8 changes: 7 additions & 1 deletion src/components/ShippingAddressForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { AddressCountrySelectName, AddressInputName } from '#typings'
import components from '#config/components'
import OrderContext from '#context/OrderContext'
import { Address } from '@commercelayer/sdk'
import { getSaveShippingAddressToAddressBook } from '#utils/localStorage'

const propTypes = components.ShippingAddressForm.propTypes

Expand Down Expand Up @@ -97,7 +98,12 @@ const ShippingAddressForm: FunctionComponent<ShippingAddressFormProps> = (
}
setAddress({ values: values as Address, resource: 'shipping_address' })
}
if (reset && (!isEmpty(values) || !isEmpty(errors))) {
const checkboxChecked =
ref.current?.querySelector(
'[name="shipping_address_save_to_customer_book"]'
// @ts-ignore
)?.checked || getSaveShippingAddressToAddressBook()
if (reset && (!isEmpty(values) || !isEmpty(errors) || checkboxChecked)) {
saveAddressToCustomerAddressBook &&
saveAddressToCustomerAddressBook({
type: 'shipping_address',
Expand Down
1 change: 1 addition & 0 deletions src/config/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ const components = {
'SaveCustomerButton',
'AddressesContainer',
'PaymentMethodsContainer',
'ShipmentsContainer',
'ReactNode',
],
propTypes: {
Expand Down

0 comments on commit 10d03a7

Please sign in to comment.