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