Skip to content

Commit

Permalink
feat: orders Page Testing Feedback BUN-425
Browse files Browse the repository at this point in the history
  • Loading branch information
kris liu authored and kris-liu-smile committed Nov 22, 2022
1 parent 796a62c commit be823dc
Show file tree
Hide file tree
Showing 25 changed files with 52 additions and 89 deletions.
2 changes: 0 additions & 2 deletions apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {

import {
HashRouter,
useLocation,
// useNavigate,
} from 'react-router-dom'
import {
useB3AppOpen,
Expand Down
3 changes: 2 additions & 1 deletion apps/storefront/src/components/filter/B3Filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ const B3Filter:<T> (props: B3FilterProps<T>) => ReactElement = (props) => {
>
<Box
sx={{
width: '40%',
maxWidth: '24rem',
flexBasis: '100%',
display: 'flex',
alignItems: 'center',
}}
Expand Down
3 changes: 3 additions & 0 deletions apps/storefront/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare interface CustomFieldItems {
[key: string]: any
}
9 changes: 4 additions & 5 deletions apps/storefront/src/pages/order/Order.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ interface SortByListProps {
const sortByList: Array<SortByListProps> = [
{
name: 'Created on',
id: 'createdAt',
id: '-createdAt',
},
{
name: 'Lowest Price',
Expand All @@ -110,7 +110,7 @@ const sortByConfigData = {
sortByList,
sortByItemName,
sortByLabel: 'Sort by',
defaultValue: 'createdAt',
defaultValue: '-createdAt',
isFirstSelect: false,
w: 150,
}
Expand Down Expand Up @@ -175,7 +175,7 @@ const Order = ({
const initFilter = async () => {
const fn = isB2BUser ? getOrderStatusType : getBcOrderStatusType
const orderStatusesName = isB2BUser ? 'orderStatuses' : 'bcOrderStatuses'
const orderStatuses: any = await fn()
const orderStatuses: CustomFieldItems = await fn()
const filterInfo = getFilterMoreData(isB2BUser, isCompanyOrder, orderStatuses[orderStatusesName])
setOrderStatuses(orderStatuses[orderStatusesName])
setFilterInfo(filterInfo)
Expand All @@ -196,7 +196,7 @@ const Order = ({
edges: orderList = [],
totalCount,
},
}: any = await fn(filterData)
}: CustomFieldItems = await fn(filterData)
const page = {
...pagination,
count: totalCount,
Expand Down Expand Up @@ -356,7 +356,6 @@ const Order = ({
sx={{
display: 'flex',
flexDirection: 'column',
overflow: 'auto',
flex: 1,
}}
>
Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/src/pages/order/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const b2bFilterSearch:FilterSearchProps = {
beginDateAt: distanceDay(30),
endDateAt: distanceDay(),
companyName: '',
orderBy: 'createdAt',
orderBy: '-createdAt',
createdBy: '',
orderNumber: '',
poNumber: '',
Expand All @@ -48,7 +48,7 @@ const bcFilterSearch = {
first: 10,
beginDateAt: distanceDay(30),
endDateAt: distanceDay(),
orderBy: 'createdAt',
orderBy: '-createdAt',
createdBy: '',
q: '',
}
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/pages/registered/RegisterComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
} from '@/shared/service/b2b'

import {
RegisterFields, CustomFieldItems, deCodeField, toHump,
RegisterFields, deCodeField, toHump,
} from './config'

import {
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/pages/registered/RegisteredAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
} from './context/RegisteredContext'

import {
RegisterFields, CustomFieldItems,
RegisterFields,
} from './config'

import {
Expand Down
1 change: 0 additions & 1 deletion apps/storefront/src/pages/registered/RegisteredBCToB2B.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ import {
getRegisterLogo,
Country,
State,
CustomFieldItems,
getAccountFormFields,
RegisterFieldsItems,
deCodeField,
Expand Down
1 change: 0 additions & 1 deletion apps/storefront/src/pages/registered/RegisteredDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
} from './context/RegisteredContext'

import {
CustomFieldItems,
RegisterFields,
Country,
State,
Expand Down
6 changes: 3 additions & 3 deletions apps/storefront/src/pages/registered/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {

const inputFormat = 'yyyy-MM-dd'

export interface CustomFieldItems {
[key: string]: any
}
// export interface CustomFieldItems {
// [key: string]: any
// }
export interface QuoteConfig {
[key: string]: string
}
Expand Down
4 changes: 0 additions & 4 deletions apps/storefront/src/shared/service/b2b/api/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ import {
RequestType,
} from '../../request/base'

interface CustomFieldItems {
[key: string]: any
}

export const getBCToken = (data: CustomFieldItems): CustomFieldItems => B3Request.post('/api/v2/proxy', RequestType.B2BRest, data)
4 changes: 0 additions & 4 deletions apps/storefront/src/shared/service/b2b/api/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ import {
RequestType,
} from '../../request/base'

interface CustomFieldItems {
[key: string]: any
}

export const getBCOrders = (data: CustomFieldItems): CustomFieldItems => B3Request.post('/api/v2/proxy', RequestType.B2BRest, data)
4 changes: 0 additions & 4 deletions apps/storefront/src/shared/service/b2b/api/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import {
storeHash,
} from '../../../../utils/basicConfig'

interface CustomFieldItems {
[key: string]: any
}

export const createBCCompanyUser = (data: CustomFieldItems): CustomFieldItems => B3Request.post('/api/v2/proxy', RequestType.B2BRest, data)

export const validateBCCompanyExtraFields = (data: CustomFieldItems): CustomFieldItems => B3Request.post('/api/v2/extra-fields/company/validate', RequestType.B2BRest, {
Expand Down
12 changes: 6 additions & 6 deletions apps/storefront/src/shared/service/b2b/graphql/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,26 @@ const userCompanyQl = (userId: number) => `{
}
}`

export const getB2BToken = (bcJwtToken: string) => B3Request.graphqlB2B({
export const getB2BToken = (bcJwtToken: string): CustomFieldItems => B3Request.graphqlB2B({
query: getB2BTokenQl(bcJwtToken),
})

export const getAgentInfo = (customerId: string | number) => B3Request.graphqlB2B({
export const getAgentInfo = (customerId: string | number): CustomFieldItems => B3Request.graphqlB2B({
query: getAgentInfoQl(customerId),
})

export const superAdminCompanies = (id: number) => B3Request.graphqlB2B({
export const superAdminCompanies = (id: number): CustomFieldItems => B3Request.graphqlB2B({
query: superAdminCompaniesQl(id),
})

export const superAdminBeginMasquerade = (companyId: number, userId: number) => B3Request.graphqlB2B({
export const superAdminBeginMasquerade = (companyId: number, userId: number): CustomFieldItems => B3Request.graphqlB2B({
query: superAdminBeginMasqueradeQl(companyId, userId),
})

export const superAdminEndMasquerade = (companyId: number, userId: number) => B3Request.graphqlB2B({
export const superAdminEndMasquerade = (companyId: number, userId: number): CustomFieldItems => B3Request.graphqlB2B({
query: superAdminEndMasqueradeQl(companyId, userId),
})

export const getUserCompany = (userId: number) => B3Request.graphqlB2B({
export const getUserCompany = (userId: number): CustomFieldItems => B3Request.graphqlB2B({
query: userCompanyQl(userId),
})
16 changes: 6 additions & 10 deletions apps/storefront/src/shared/service/b2b/graphql/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import {
// storeHash,
// } from '../../../../utils'

interface CustomFieldItems {
[key: string]: any
}

const allOrders = (data: CustomFieldItems, fn: string) => `{
${fn}(
search: "${data.q || ''}"
Expand Down Expand Up @@ -200,26 +196,26 @@ const getOrderStatusTypeQl = (fn: string) => `{
}
}`

export const getB2BAllOrders = (data: CustomFieldItems) => B3Request.graphqlB2B({
export const getB2BAllOrders = (data: CustomFieldItems): CustomFieldItems => B3Request.graphqlB2B({
query: allOrders(data, 'allOrders'),
})

export const getBCAllOrders = (data: CustomFieldItems) => B3Request.graphqlProxyBC({
export const getBCAllOrders = (data: CustomFieldItems): CustomFieldItems => B3Request.graphqlProxyBC({
query: allOrders(data, 'customerOrders'),
})

export const getB2BOrderDetails = (id: number) => B3Request.graphqlB2B({
export const getB2BOrderDetails = (id: number): CustomFieldItems => B3Request.graphqlB2B({
query: orderDetail(id, 'order'),
})

export const getBCOrderDetails = (id: number) => B3Request.graphqlProxyBC({
export const getBCOrderDetails = (id: number): CustomFieldItems => B3Request.graphqlProxyBC({
query: orderDetail(id, 'customerOrder'),
})

export const getOrderStatusType = () => B3Request.graphqlB2B({
export const getOrderStatusType = (): CustomFieldItems => B3Request.graphqlB2B({
query: getOrderStatusTypeQl('orderStatuses'),
})

export const getBcOrderStatusType = () => B3Request.graphqlProxyBC({
export const getBcOrderStatusType = (): CustomFieldItems => B3Request.graphqlProxyBC({
query: getOrderStatusTypeQl('bcOrderStatuses'),
})
10 changes: 3 additions & 7 deletions apps/storefront/src/shared/service/b2b/graphql/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ import {
B3Request,
} from '../../request/b3Fetch'

interface CustomFieldItems {
[key: string]: any
}

const getVariantInfoBySkus = ({
skus = [],
}: CustomFieldItems) => `{
}) => `{
variantSku (
variantSkus: "${skus}"
){
Expand Down Expand Up @@ -42,10 +38,10 @@ const getVariantSkuByProductId = (productId: string) => `{
}
}`

export const getB2BVariantInfoBySkus = (data: CustomFieldItems = {}) => B3Request.graphqlB2B({
export const getB2BVariantInfoBySkus = (data: CustomFieldItems = {}): CustomFieldItems => B3Request.graphqlB2B({
query: getVariantInfoBySkus(data),
})

export const getB2BVariantSkuByProductId = (productId: string) => B3Request.graphqlB2B({
export const getB2BVariantSkuByProductId = (productId: string): CustomFieldItems => B3Request.graphqlB2B({
query: getVariantSkuByProductId(productId),
})
6 changes: 1 addition & 5 deletions apps/storefront/src/shared/service/b2b/graphql/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import {
storeHash,
} from '../../../../utils'

interface CustomFieldItems {
[key: string]: any
}

const getAccountFormFields = (type: number) => `{
accountFormFields(storeHash: "${storeHash}", formType: ${type}){
id
Expand Down Expand Up @@ -193,6 +189,6 @@ export const getBCForcePasswordReset = (email:string): CustomFieldItems => B3Req
query: getForcePasswordReset(email),
})

export const getBCStoreChannelId = () => B3Request.graphqlB2B({
export const getBCStoreChannelId = (): CustomFieldItems => B3Request.graphqlB2B({
query: getStoreChannelId(),
})
10 changes: 3 additions & 7 deletions apps/storefront/src/shared/service/b2b/graphql/shoppingList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ import {
B3Request,
} from '../../request/b3Fetch'

interface CustomFieldItems {
[key: string]: any
}

const getShoppingList = ({
offset = 0,
first = 50,
}: CustomFieldItems) => `{
}) => `{
shoppingLists (
offset: ${offset}
first: ${first}
Expand Down Expand Up @@ -67,10 +63,10 @@ const createShoppingList = (data: CustomFieldItems) => `mutation{
}
}`

export const getB2BShoppingList = (data: CustomFieldItems = {}) => B3Request.graphqlB2B({
export const getB2BShoppingList = (data: CustomFieldItems = {}): CustomFieldItems => B3Request.graphqlB2B({
query: getShoppingList(data),
})

export const createB2BShoppingList = (data: CustomFieldItems = {}) => B3Request.graphqlB2B({
export const createB2BShoppingList = (data: CustomFieldItems = {}): CustomFieldItems => B3Request.graphqlB2B({
query: createShoppingList(data),
})
4 changes: 2 additions & 2 deletions apps/storefront/src/shared/service/bc/api/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import {
bcBaseUrl,
} from '../../../../utils/basicConfig'

export const getBCForgotPassword = (data: any): any => B3Request.post(`${bcBaseUrl}/login.php?action=send_password_email`, RequestType.BCRest, data)
export const getBCForgotPassword = (data: CustomFieldItems): CustomFieldItems => B3Request.post(`${bcBaseUrl}/login.php?action=send_password_email`, RequestType.BCRest, data)

export const getBcCurrentJWT = (data: any): any => B3Request.get(`${bcBaseUrl}/customer/current.jwt`, RequestType.BCRest, data)
export const getBcCurrentJWT = (data: CustomFieldItems): CustomFieldItems => B3Request.get(`${bcBaseUrl}/customer/current.jwt`, RequestType.BCRest, data)
2 changes: 1 addition & 1 deletion apps/storefront/src/shared/service/bc/api/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ import {
bcBaseUrl,
} from '../../../../utils/basicConfig'

export const getBCRegisterCustomFields = (): any => B3Request.get(`${bcBaseUrl}/api/storefront/form-fields`, RequestType.BCRest)
export const getBCRegisterCustomFields = (): CustomFieldItems => B3Request.get(`${bcBaseUrl}/api/storefront/form-fields`, RequestType.BCRest)
6 changes: 1 addition & 5 deletions apps/storefront/src/shared/service/bc/graphql/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import {
B3Request,
} from '../../request/b3Fetch'

interface CustomFieldItems {
[key: string]: any
}

const getbcLogin = () => `mutation Login($email: String!, $pass: String!) {
login(email: $email, password: $pass) {
result
Expand All @@ -23,6 +19,6 @@ export const bcLogin = (data: CustomFieldItems): CustomFieldItems => B3Request.g
variables: data,
})

export const bcLogoutLogin = () => B3Request.graphqlBC({
export const bcLogoutLogin = (): CustomFieldItems => B3Request.graphqlBC({
query: logoutLogin(),
})
4 changes: 0 additions & 4 deletions apps/storefront/src/shared/service/bc/graphql/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import {
B3Request,
} from '../../request/b3Fetch'

interface CustomFieldItems {
[key: string]: any
}

const getCustomer = () => `query customer {
customer{
entityId,
Expand Down
14 changes: 5 additions & 9 deletions apps/storefront/src/shared/service/request/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ import {

const originFetch = window.fetch

function b3Fetch(path: string, init: any, type?: string) {
function b3Fetch<T>(path: string, init: any, type?: string) {
return new Promise((resolve, reject) => {
originFetch(path, init).then((res: Response) => {
if (path.includes('current.jwt')) {
return res.text()
}
return res.json()
}).then(async (res) => {
originFetch(path, init).then((res: Response) => (path.includes('current.jwt') ? res.text() : res.json())).then(async (res) => {
if (res?.code === 500) {
reject(res.message)
return
}
// jwt 15 minutes expected
if (res?.errors?.length && res.errors[0].message === 'JWT token is expired') {
try {
await getCurrentJwt()
Expand All @@ -43,8 +39,8 @@ function b3Fetch(path: string, init: any, type?: string) {
}
}
if (type === RequestType.B2BGraphql) {
if (res?.errors && res?.errors.length) {
reject(res.errors[0])
if (res?.errors?.length && res.errors[0].message) {
reject(res.errors[0].message)
} else {
resolve(res.data)
}
Expand Down
4 changes: 0 additions & 4 deletions apps/storefront/src/utils/graphqlDataConvert.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
interface CustomFieldItems {
[key: string]: any
}

export const convertObjectToGraphql = (data: CustomFieldItems) => {
if (typeof data === 'string' || typeof data === 'number') {
return data
Expand Down
Loading

0 comments on commit be823dc

Please sign in to comment.