mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 19:51:23 +00:00
Merge branch 'release-stable' of github.com:KieIO/grocery-vercel-commerce into feature/m1-product-collection
This commit is contained in:
@@ -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',
|
||||
|
14
src/utils/errrorMapping.ts
Normal file
14
src/utils/errrorMapping.ts
Normal 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
|
||||
}
|
||||
}
|
@@ -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,
|
||||
|
@@ -9,5 +9,8 @@ export const LANGUAGE = {
|
||||
},
|
||||
PLACE_HOLDER: {
|
||||
SEARCH: 'Search',
|
||||
},
|
||||
MESSAGE: {
|
||||
ERROR: 'Something went wrong! Please try again!'
|
||||
}
|
||||
}
|
@@ -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 }
|
||||
|
Reference in New Issue
Block a user