Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-pets-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Add delete customer address mutation
47 changes: 47 additions & 0 deletions apps/core/client/mutations/delete-customer-address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { getSessionCustomerId } from '~/auth';

import { client } from '..';
import { graphql, VariablesOf } from '../graphql';

const DELETE_CUSTOMER_ADDRESS_MUTATION = graphql(`
mutation DeleteCustomerAddress(
$reCaptcha: ReCaptchaV2Input
$input: DeleteCustomerAddressInput!
) {
customer {
deleteCustomerAddress(reCaptchaV2: $reCaptcha, input: $input) {
errors {
__typename
... on CustomerAddressDeletionError {
__typename
message
}
... on CustomerNotLoggedInError {
__typename
message
}
}
}
}
}
`);

type AddressId = VariablesOf<typeof DELETE_CUSTOMER_ADDRESS_MUTATION>['input']['addressEntityId'];

export const deleteCustomerAddress = async (addressId: AddressId, reCaptchaToken?: string) => {
const customerId = await getSessionCustomerId();

const response = await client.fetch({
document: DELETE_CUSTOMER_ADDRESS_MUTATION,
customerId,
fetchOptions: { cache: 'no-store' },
variables: {
input: {
addressEntityId: addressId,
},
...(reCaptchaToken && { reCaptcha: { token: reCaptchaToken } }),
},
});

return response.data;
};