Merge branch 'release-stable' of github.com:KieIO/grocery-vercel-commerce into feature/m1-product-collection

This commit is contained in:
DatNguyen
2021-10-04 09:47:16 +07:00
61 changed files with 1559 additions and 643 deletions

View File

@@ -38,6 +38,10 @@ export const ACCOUNT_TAB = {
FAVOURITE: 'wishlist',
}
export const LOCAL_STORAGE_KEY = {
TOKEN: 'token'
}
export const QUERY_KEY = {
TAB: 'tab',
CATEGORY: 'category',

View File

@@ -0,0 +1,14 @@
import { LANGUAGE } from "./language.utils";
export function errorMapping(message?: string) {
if (!message) {
return LANGUAGE.MESSAGE.ERROR
}
switch (message) {
case 'The provided credentials are invalid':
return 'The email address or password is incorrect!'
default:
return LANGUAGE.MESSAGE.ERROR
}
}

View File

@@ -1,5 +1,6 @@
import { request } from 'graphql-request'
import { RequestDocument, Variables } from 'graphql-request/dist/types'
import { LOCAL_STORAGE_KEY } from './constanst.utils'
interface QueryOptions {
query: RequestDocument
@@ -10,11 +11,7 @@ interface QueryOptions {
const fetcher = async <T>(options: QueryOptions): Promise<T> => {
const { query, variables } = options
console.log('query')
console.log(options)
const token = localStorage.getItem('token')
console.log('token')
console.log(token)
const token = localStorage.getItem(LOCAL_STORAGE_KEY.TOKEN)
const res = await request<T>(
process.env.NEXT_PUBLIC_VENDURE_SHOP_API_URL as string,
query,

View File

@@ -9,5 +9,8 @@ export const LANGUAGE = {
},
PLACE_HOLDER: {
SEARCH: 'Search',
},
MESSAGE: {
ERROR: 'Something went wrong! Please try again!'
}
}

View File

@@ -1,5 +1,6 @@
import { rawRequest } from 'graphql-request'
import { RequestDocument, Variables } from 'graphql-request/dist/types'
import { LOCAL_STORAGE_KEY } from './constanst.utils'
interface QueryOptions {
query: RequestDocument
@@ -14,10 +15,12 @@ const rawFetcher = <T>({
onLoad = () => true,
}: 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,
query as string,
variables
variables,
token ? { Authorization: 'Bearer ' + token } : {}
)
.then(({ data, headers }) => {
return { data, headers }