-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add register customer mutation (#641)
- Loading branch information
1 parent
5af0e66
commit 43b1afd
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": patch | ||
--- | ||
|
||
add register customer mutation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |