Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add customer address mutation #777

Merged
merged 2 commits into from
Apr 18, 2024
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/many-parrots-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

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

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

const ADD_CUSTOMER_ADDRESS_MUTATION = graphql(`
mutation addCustomerAddress($input: AddCustomerAddressInput!, $reCaptchaV2: ReCaptchaV2Input) {
customer {
addCustomerAddress(input: $input, reCaptchaV2: $reCaptchaV2) {
errors {
... on CustomerAddressCreationError {
message
}
... on CustomerNotLoggedInError {
message
}
... on ValidationError {
message
path
}
}
address {
entityId
firstName
lastName
}
}
}
}
`);

type AddCustomerAddressInput = VariablesOf<typeof ADD_CUSTOMER_ADDRESS_MUTATION>['input'];

interface AddCustomerAddress {
input: AddCustomerAddressInput;
reCaptchaToken?: string;
}

export const addCustomerAddress = async ({ input, reCaptchaToken }: AddCustomerAddress) => {
const customerId = await getSessionCustomerId();

const response = await client.fetch({
bc-alexsaiannyi marked this conversation as resolved.
Show resolved Hide resolved
document: ADD_CUSTOMER_ADDRESS_MUTATION,
customerId,
fetchOptions: { cache: 'no-store' },
variables: {
input,
...(reCaptchaToken && { reCaptchaV2: { token: reCaptchaToken } }),
},
});

return response.data.customer.addCustomerAddress;
};
Loading