mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 12:24:18 +00:00
🔧 config: cookie
:%s
This commit is contained in:
@@ -18,18 +18,13 @@ const useSetCustomerForOrder = () => {
|
||||
setLoading(true)
|
||||
rawFetcher<SetCustomerForOrderMutation>({
|
||||
query: setCustomerForOrderMutation,
|
||||
variables: {input},
|
||||
variables: { input },
|
||||
})
|
||||
.then(({ data, headers }) => {
|
||||
console.log("data here: ", data)
|
||||
.then(({ data }) => {
|
||||
if (data.setCustomerForOrder.__typename === 'ActiveOrderCustomerFragment') {
|
||||
console.log("success: ")
|
||||
|
||||
fCallBack(true)
|
||||
mutate()
|
||||
} else {
|
||||
console.log("fail ")
|
||||
|
||||
fCallBack(false, data.setCustomerForOrder.message)
|
||||
}
|
||||
|
||||
|
@@ -14,9 +14,11 @@ interface ShippingInfoFormProps {
|
||||
const option = [
|
||||
{
|
||||
name: 'Hồ Chí Minh',
|
||||
value: 'Hồ Chí Minh',
|
||||
},
|
||||
{
|
||||
name: 'Hà Nội',
|
||||
value: 'Hà Nội',
|
||||
},
|
||||
]
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { request } from 'graphql-request'
|
||||
import { GraphQLClient } from 'graphql-request'
|
||||
import { RequestDocument, Variables } from 'graphql-request/dist/types'
|
||||
import { LOCAL_STORAGE_KEY } from './constanst.utils'
|
||||
|
||||
@@ -12,11 +12,15 @@ interface QueryOptions {
|
||||
const fetcher = async <T>(options: QueryOptions): Promise<T> => {
|
||||
const { query, variables } = options
|
||||
const token = localStorage.getItem(LOCAL_STORAGE_KEY.TOKEN)
|
||||
const res = await request<T>(
|
||||
process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL as string,
|
||||
const graphQLClient = new GraphQLClient(process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL as string, {
|
||||
credentials: 'include',
|
||||
mode: 'cors',
|
||||
headers: token ? { Authorization: 'Bearer ' + token } : {},
|
||||
})
|
||||
|
||||
const res = await graphQLClient.request<T>(
|
||||
query,
|
||||
variables,
|
||||
token ? { Authorization: 'Bearer ' + token } : {}
|
||||
)
|
||||
|
||||
return res
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import { rawRequest } from 'graphql-request'
|
||||
import { GraphQLClient } from 'graphql-request'
|
||||
import { RequestDocument, Variables } from 'graphql-request/dist/types'
|
||||
import { LOCAL_STORAGE_KEY } from './constanst.utils'
|
||||
|
||||
interface QueryOptions {
|
||||
query: RequestDocument
|
||||
variables?: Variables
|
||||
@@ -16,15 +15,20 @@ const rawFetcher = <T>({
|
||||
}: QueryOptions): Promise<{ data: T; headers: any }> => {
|
||||
onLoad(true)
|
||||
const token = localStorage.getItem(LOCAL_STORAGE_KEY.TOKEN)
|
||||
return rawRequest<T>(
|
||||
process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL as string,
|
||||
|
||||
const graphQLClient = new GraphQLClient(process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL as string, {
|
||||
credentials: 'include',
|
||||
mode: 'cors',
|
||||
headers: token ? { Authorization: 'Bearer ' + token } : {},
|
||||
})
|
||||
|
||||
return graphQLClient.rawRequest<T>(
|
||||
query as string,
|
||||
variables,
|
||||
token ? { Authorization: 'Bearer ' + token } : {}
|
||||
)
|
||||
.then(({ data, headers }) => {
|
||||
return { data, headers }
|
||||
})
|
||||
)
|
||||
.then(({ data, headers }) => {
|
||||
return { data, headers }
|
||||
})
|
||||
.finally(() => onLoad(false))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user