Skip to content

Commit

Permalink
feat(core): add register customer mutation (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurytut1993 committed Mar 19, 2024
1 parent 5af0e66 commit 43b1afd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-penguins-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

add register customer mutation
51 changes: 51 additions & 0 deletions apps/core/client/mutations/register-customer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { client } from '..';
import { graphql } from '../generated';
import { RegisterCustomerInput } from '../generated/graphql';

interface RegisterCustomer {
formFields: RegisterCustomerInput;
reCaptchaToken?: string;
}

export const REGISTER_CUSTOMER_MUTATION = /* GraphQL */ `
mutation registerCustomer($input: RegisterCustomerInput!, $reCaptchaV2: ReCaptchaV2Input) {
customer {
registerCustomer(input: $input, reCaptchaV2: $reCaptchaV2) {
customer {
firstName
lastName
}
errors {
... on EmailAlreadyInUseError {
message
}
... on AccountCreationDisabledError {
message
}
... on CustomerRegistrationError {
message
}
... on ValidationError {
message
}
}
}
}
}
`;

export const registerCustomer = async ({ formFields, reCaptchaToken }: RegisterCustomer) => {
const mutation = graphql(REGISTER_CUSTOMER_MUTATION);

const variables = {
input: formFields,
...(reCaptchaToken && { reCaptchaV2: { token: reCaptchaToken } }),
};

const response = await client.fetch({
document: mutation,
variables,
});

return response.data.customer.registerCustomer;
};

0 comments on commit 43b1afd

Please sign in to comment.