mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 12:24:18 +00:00
🔨 refactor: using query and mutation from framework vendure
:%s
This commit is contained in:
parent
4a9c36bf0a
commit
b752b0f7a4
@ -1,8 +1,5 @@
|
||||
import { gql } from 'graphql-request'
|
||||
|
||||
|
||||
export const VERIFY_CUSTOMER_ACCOUNT = gql`
|
||||
mutation verifyCustomerAccount($token: String!, $password: String) {
|
||||
export const verifyCustomerAccountMutaton = /* GraphQL */ `
|
||||
mutation verifyCustomerAccount($token: String!, $password: String) {
|
||||
verifyCustomerAccount( token: $token, password: $password) {
|
||||
__typename
|
||||
...on CurrentUser {
|
||||
@ -16,5 +13,3 @@ mutation verifyCustomerAccount($token: String!, $password: String) {
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
|
@ -1,21 +1,10 @@
|
||||
import { ActiveCustomerQuery } from '@framework/schema'
|
||||
import { gql } from 'graphql-request'
|
||||
import { activeCustomerQuery } from '@framework/utils/queries/active-customer-query'
|
||||
import gglFetcher from 'src/utils/gglFetcher'
|
||||
import useSWR from 'swr'
|
||||
|
||||
const query = gql`
|
||||
query activeCustomer {
|
||||
activeCustomer {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
emailAddress
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const useActiveCustomer = () => {
|
||||
const { data, ...rest } = useSWR<ActiveCustomerQuery>([query], gglFetcher)
|
||||
const { data, ...rest } = useSWR<ActiveCustomerQuery>([activeCustomerQuery], gglFetcher)
|
||||
return { customer: data?.activeCustomer, ...rest }
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { gql } from 'graphql-request'
|
||||
import { useState } from 'react'
|
||||
import useActiveCustomer from './useActiveCustomer'
|
||||
import { CommonError } from 'src/domains/interfaces/CommonError'
|
||||
@ -6,21 +5,7 @@ import rawFetcher from 'src/utils/rawFetcher'
|
||||
import { LoginMutation } from '@framework/schema'
|
||||
import { LOCAL_STORAGE_KEY } from 'src/utils/constanst.utils'
|
||||
import { errorMapping } from 'src/utils/errrorMapping'
|
||||
|
||||
const query = gql`
|
||||
mutation login($username: String!, $password: String!) {
|
||||
login(username: $username, password: $password) {
|
||||
__typename
|
||||
... on CurrentUser {
|
||||
id
|
||||
}
|
||||
... on ErrorResult {
|
||||
errorCode
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
import { loginMutation } from '@framework/utils/mutations/log-in-mutation'
|
||||
|
||||
interface LoginInput {
|
||||
username: string
|
||||
@ -38,7 +23,7 @@ const useLogin = () => {
|
||||
setError(null)
|
||||
setLoading(true)
|
||||
rawFetcher<LoginMutation>({
|
||||
query,
|
||||
query: loginMutation,
|
||||
variables: options,
|
||||
})
|
||||
.then(({ data, headers }) => {
|
||||
|
@ -1,24 +1,9 @@
|
||||
import { gql } from 'graphql-request'
|
||||
import { useState } from 'react'
|
||||
import useActiveCustomer from './useActiveCustomer'
|
||||
import { SignupMutation } from '@framework/schema'
|
||||
import fetcher from 'src/utils/fetcher'
|
||||
import { CommonError } from 'src/domains/interfaces/CommonError'
|
||||
|
||||
const query = gql`
|
||||
mutation signup($input: RegisterCustomerInput!) {
|
||||
registerCustomerAccount(input: $input) {
|
||||
__typename
|
||||
... on Success {
|
||||
success
|
||||
}
|
||||
... on ErrorResult {
|
||||
errorCode
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
import { signupMutation } from '@framework/utils/mutations/sign-up-mutation'
|
||||
|
||||
interface SignupInput {
|
||||
email: string
|
||||
@ -39,7 +24,7 @@ const useSignup = () => {
|
||||
setError(null)
|
||||
setLoading(true)
|
||||
fetcher<SignupMutation>({
|
||||
query,
|
||||
query: signupMutation,
|
||||
variables: {
|
||||
input: {
|
||||
firstName,
|
||||
|
@ -2,8 +2,8 @@ import { VerifyCustomerAccountMutation } from '@framework/schema'
|
||||
import { useState } from 'react'
|
||||
import { CommonError } from 'src/domains/interfaces/CommonError'
|
||||
import rawFetcher from 'src/utils/rawFetcher'
|
||||
import { VERIFY_CUSTOMER_ACCOUNT } from '../../../graphql/mutation'
|
||||
import useActiveCustomer from './useActiveCustomer'
|
||||
import { verifyCustomerAccountMutaton } from '@framework/utils/mutations/verify-customer-account-mutation'
|
||||
|
||||
interface VerifyInput {
|
||||
token: string
|
||||
@ -22,7 +22,7 @@ const useVerifyCustomer = () => {
|
||||
setError(null)
|
||||
setLoading(true)
|
||||
rawFetcher<VerifyCustomerAccountMutation>({
|
||||
query: VERIFY_CUSTOMER_ACCOUNT,
|
||||
query: verifyCustomerAccountMutaton,
|
||||
variables: options,
|
||||
})
|
||||
.then(({ data }) => {
|
||||
|
@ -2,7 +2,8 @@ import { useRouter } from 'next/router'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { ButtonCommon } from 'src/components/common'
|
||||
import LoadingCommon from 'src/components/common/LoadingCommon/LoadingCommon'
|
||||
import { useModalCommon, useVerifyCustomer } from 'src/components/hooks'
|
||||
import { useModalCommon } from 'src/components/hooks'
|
||||
import { useVerifyCustomer } from 'src/components/hooks/auth'
|
||||
import { ROUTE } from 'src/utils/constanst.utils'
|
||||
import s from './VerifyCustomerAccount.module.scss'
|
||||
import Link from 'next/link'
|
||||
|
@ -1 +0,0 @@
|
||||
export * from './user.mutation'
|
@ -1 +0,0 @@
|
||||
// export * from './user.mutation'
|
@ -1 +0,0 @@
|
||||
// query here
|
Loading…
x
Reference in New Issue
Block a user