mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
task: prettier
This commit is contained in:
@@ -3,42 +3,25 @@ import type { MutationHook } from '@commerce/utils/types'
|
||||
import { CommerceError } from '@commerce/utils/errors'
|
||||
import useSignup, { UseSignup } from '@commerce/auth/use-signup'
|
||||
import useCustomer from '../customer/use-customer'
|
||||
import {
|
||||
AccountRegisterInput,
|
||||
Mutation,
|
||||
MutationAccountRegisterArgs
|
||||
} from '../schema'
|
||||
import { AccountRegisterInput, Mutation, MutationAccountRegisterArgs } from '../schema'
|
||||
|
||||
import * as mutation from '../utils/mutations'
|
||||
import { handleAutomaticLogin, throwUserErrors } from '../utils'
|
||||
|
||||
export default useSignup as UseSignup<typeof handler>
|
||||
|
||||
export const handler: MutationHook<
|
||||
null,
|
||||
{},
|
||||
AccountRegisterInput,
|
||||
AccountRegisterInput
|
||||
> = {
|
||||
export const handler: MutationHook<null, {}, AccountRegisterInput, AccountRegisterInput> = {
|
||||
fetchOptions: {
|
||||
query: mutation.AccountCreate
|
||||
query: mutation.AccountCreate,
|
||||
},
|
||||
async fetcher({
|
||||
input: { email, password },
|
||||
options,
|
||||
fetch,
|
||||
}) {
|
||||
async fetcher({ input: { email, password }, options, fetch }) {
|
||||
if (!(email && password)) {
|
||||
throw new CommerceError({
|
||||
message:
|
||||
'A first name, last name, email and password are required to signup',
|
||||
message: 'A first name, last name, email and password are required to signup',
|
||||
})
|
||||
}
|
||||
|
||||
const { customerCreate } = await fetch<
|
||||
Mutation,
|
||||
MutationAccountRegisterArgs
|
||||
>({
|
||||
const { customerCreate } = await fetch<Mutation, MutationAccountRegisterArgs>({
|
||||
...options,
|
||||
variables: {
|
||||
input: {
|
||||
@@ -53,16 +36,18 @@ export const handler: MutationHook<
|
||||
|
||||
return null
|
||||
},
|
||||
useHook: ({ fetch }) => () => {
|
||||
const { revalidate } = useCustomer()
|
||||
useHook:
|
||||
({ fetch }) =>
|
||||
() => {
|
||||
const { revalidate } = useCustomer()
|
||||
|
||||
return useCallback(
|
||||
async function signup(input) {
|
||||
const data = await fetch({ input })
|
||||
await revalidate()
|
||||
return data
|
||||
},
|
||||
[fetch, revalidate]
|
||||
)
|
||||
},
|
||||
return useCallback(
|
||||
async function signup(input) {
|
||||
const data = await fetch({ input })
|
||||
await revalidate()
|
||||
return data
|
||||
},
|
||||
[fetch, revalidate]
|
||||
)
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user