diff --git a/src/components/hooks/order/useSetCustomerForOrder.tsx b/src/components/hooks/order/useSetCustomerForOrder.tsx index 521c72be2..a209c107e 100644 --- a/src/components/hooks/order/useSetCustomerForOrder.tsx +++ b/src/components/hooks/order/useSetCustomerForOrder.tsx @@ -18,18 +18,13 @@ const useSetCustomerForOrder = () => { setLoading(true) rawFetcher({ 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) } diff --git a/src/components/modules/checkout/CheckoutInfo/components/ShippingInfoForm/ShippingInfoForm.tsx b/src/components/modules/checkout/CheckoutInfo/components/ShippingInfoForm/ShippingInfoForm.tsx index 04217d706..64fe3ce6e 100644 --- a/src/components/modules/checkout/CheckoutInfo/components/ShippingInfoForm/ShippingInfoForm.tsx +++ b/src/components/modules/checkout/CheckoutInfo/components/ShippingInfoForm/ShippingInfoForm.tsx @@ -14,9 +14,11 @@ interface ShippingInfoFormProps { const option = [ { name: 'Hồ Chí Minh', + value: 'Hồ Chí Minh', }, { name: 'Hà Nội', + value: 'Hà Nội', }, ] diff --git a/src/utils/fetcher.ts b/src/utils/fetcher.ts index a86367398..a0c5222cc 100644 --- a/src/utils/fetcher.ts +++ b/src/utils/fetcher.ts @@ -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 (options: QueryOptions): Promise => { const { query, variables } = options const token = localStorage.getItem(LOCAL_STORAGE_KEY.TOKEN) - const res = await request( - 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( query, variables, - token ? { Authorization: 'Bearer ' + token } : {} ) return res diff --git a/src/utils/rawFetcher.ts b/src/utils/rawFetcher.ts index c26b2ab20..6c87dc4a9 100644 --- a/src/utils/rawFetcher.ts +++ b/src/utils/rawFetcher.ts @@ -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 = ({ }: QueryOptions): Promise<{ data: T; headers: any }> => { onLoad(true) const token = localStorage.getItem(LOCAL_STORAGE_KEY.TOKEN) - return rawRequest( - 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( query as string, variables, - token ? { Authorization: 'Bearer ' + token } : {} - ) - .then(({ data, headers }) => { - return { data, headers } - }) + ) + .then(({ data, headers }) => { + return { data, headers } + }) .finally(() => onLoad(false)) }