mirror of
https://github.com/vercel/commerce.git
synced 2025-07-27 04:01:23 +00:00
✨ feat: VerifyCustomerAccountMutation
:%s
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
import React from "react";
|
||||
import React from 'react'
|
||||
import s from './LoadingCommon.module.scss'
|
||||
|
||||
const LoadingCommon = () => {
|
||||
|
||||
return (
|
||||
<div className={s.wrapper}>
|
||||
<div className={s.loadingCommon}>
|
||||
</div>
|
||||
<p className={s.text}>Loading...</p>
|
||||
</div>
|
||||
)
|
||||
interface Props {
|
||||
description?: string
|
||||
}
|
||||
|
||||
export default LoadingCommon
|
||||
const LoadingCommon = ({ description = 'Loading...' }: Props) => {
|
||||
return (
|
||||
<div className={s.wrapper}>
|
||||
<div className={s.loadingCommon}></div>
|
||||
<p className={s.text}>{description}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default LoadingCommon
|
||||
|
1
src/components/hooks/useProduct.tsx
Normal file
1
src/components/hooks/useProduct.tsx
Normal file
@@ -0,0 +1 @@
|
||||
// here
|
@@ -1,4 +1,4 @@
|
||||
import { LoginMutation } from '@framework/schema'
|
||||
import { VerifyCustomerAccountMutation } from '@framework/schema'
|
||||
import { useState } from 'react'
|
||||
import { CommonError } from 'src/domains/interfaces/CommonError'
|
||||
import rawFetcher from 'src/utils/rawFetcher'
|
||||
@@ -13,28 +13,40 @@ interface VerifyInput {
|
||||
const useVerifyCustomer = () => {
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState<CommonError | null>(null)
|
||||
// const { mutate } = useActiveCustomer()
|
||||
const { mutate } = useActiveCustomer()
|
||||
|
||||
const verify = (options: VerifyInput) => {
|
||||
const verify = (
|
||||
options: VerifyInput,
|
||||
fCallBack?: (isSuccess: boolean) => void
|
||||
) => {
|
||||
setError(null)
|
||||
setLoading(true)
|
||||
rawFetcher<LoginMutation>({
|
||||
rawFetcher<VerifyCustomerAccountMutation>({
|
||||
query: VERIFY_CUSTOMER_ACCOUNT,
|
||||
variables: options,
|
||||
})
|
||||
.then(({ data, headers }) => {
|
||||
console.log("data: ", data)
|
||||
// if (data.login.__typename !== 'CurrentUser') {
|
||||
// throw CommonError.create(data.login.message, data.login.errorCode)
|
||||
// }
|
||||
// const authToken = headers.get('vendure-auth-token')
|
||||
// if (authToken != null) {
|
||||
// localStorage.setItem('token', authToken)
|
||||
// return mutate()
|
||||
// }
|
||||
if (data.verifyCustomerAccount.__typename !== 'CurrentUser') {
|
||||
throw CommonError.create(
|
||||
data.verifyCustomerAccount.message,
|
||||
data.verifyCustomerAccount.errorCode
|
||||
)
|
||||
}
|
||||
fCallBack && fCallBack(true)
|
||||
|
||||
const authToken = headers.get('vendure-auth-token')
|
||||
if (authToken != null) {
|
||||
localStorage.setItem('token', authToken)
|
||||
return mutate()
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
setError(err)
|
||||
fCallBack && fCallBack(false)
|
||||
})
|
||||
.finally(() => {
|
||||
setLoading(false)
|
||||
})
|
||||
.catch(setError)
|
||||
.finally(() => setLoading(false))
|
||||
}
|
||||
|
||||
return { loading, verify, error }
|
||||
|
2
src/components/modules/verify-customer/index.tsx
Normal file
2
src/components/modules/verify-customer/index.tsx
Normal file
@@ -0,0 +1,2 @@
|
||||
export { default as VerifyCustomerAccount } from './VerifyCustomerAccount/VerifyCustomerAccount'
|
||||
|
@@ -2,15 +2,19 @@ import { gql } from 'graphql-request'
|
||||
|
||||
|
||||
export const VERIFY_CUSTOMER_ACCOUNT = gql`
|
||||
mutation verifyCustomerAccount(token: String!, password: String) {
|
||||
mutation verifyCustomerAccount($token: String!, $password: String) {
|
||||
verifyCustomerAccount( token: $token, password: $password) {
|
||||
__typename
|
||||
...on CurrentUser {
|
||||
id
|
||||
identifier
|
||||
}
|
||||
...ErrorResult
|
||||
... on ErrorResult {
|
||||
errorCode
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
|
||||
|
@@ -10,11 +10,11 @@ interface QueryOptions {
|
||||
|
||||
const fetcher = async <T>(options: QueryOptions): Promise<T> => {
|
||||
const { query, variables } = options
|
||||
console.log('query')
|
||||
console.log(options)
|
||||
// console.log('query')
|
||||
// console.log(options)
|
||||
const token = localStorage.getItem('token')
|
||||
console.log('token')
|
||||
console.log(token)
|
||||
// console.log('token')
|
||||
// console.log(token)
|
||||
const res = await request<T>(
|
||||
process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL as string,
|
||||
query,
|
||||
|
Reference in New Issue
Block a user