Skip to content

Commit

Permalink
fix: createdby change to dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
b3aton committed Mar 17, 2023
1 parent 179a018 commit 8d02166
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 54 deletions.
11 changes: 10 additions & 1 deletion apps/storefront/src/pages/order/Order.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
getBCAllOrders,
getOrderStatusType,
getBcOrderStatusType,
getOrdersCreatedByUser,
} from '@/shared/service/b2b'

import {
Expand Down Expand Up @@ -115,6 +116,10 @@ const Order = ({
isB2BUser,
isAgenting,
role,
companyInfo: {
id: companyB2BId,
},
salesRepCompanyId,
},
} = useContext(GlobaledContext)

Expand All @@ -132,11 +137,15 @@ const Order = ({
const search = getInitFilter(isCompanyOrder, isB2BUser)
setFilterData(search)
const initFilter = async () => {
const companyId = companyB2BId || salesRepCompanyId
let createdByUsers: CustomFieldItems = {}
if (isB2BUser && isCompanyOrder) createdByUsers = await getOrdersCreatedByUser(+companyId, 0)

const fn = isB2BUser ? getOrderStatusType : getBcOrderStatusType
const orderStatusesName = isB2BUser ? 'orderStatuses' : 'bcOrderStatuses'
const orderStatuses: CustomFieldItems = await fn()

const filterInfo = getFilterMoreData(isB2BUser, role, isCompanyOrder, isAgenting, orderStatuses[orderStatusesName])
const filterInfo = getFilterMoreData(isB2BUser, role, isCompanyOrder, isAgenting, createdByUsers, orderStatuses[orderStatusesName])
setOrderStatuses(orderStatuses[orderStatusesName])
setFilterInfo(filterInfo)
}
Expand Down
12 changes: 10 additions & 2 deletions apps/storefront/src/pages/order/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ const bcFilterSearch = {
q: '',
}

export const getFilterMoreData = (isB2BUser:boolean, role: string | number, isCompanyOrder: boolean, isAgenting: boolean, orderStatuses = []) => {
export const getFilterMoreData = (isB2BUser:boolean, role: string | number, isCompanyOrder: boolean, isAgenting: boolean, createdByUsers: any, orderStatuses = []) => {
const newOrderStatuses = orderStatuses.filter((item: CustomFieldStringItems) => item.statusCode !== '0' && item.statusCode !== '1')
const newCreatedByUsers = createdByUsers?.createdByUser?.results.map((item: any) => ({
createdBy: `${item.firstName} ${item.lastName}`,
})) || {}
const filterMoreList = [
{
name: 'company',
Expand Down Expand Up @@ -80,7 +83,12 @@ export const getFilterMoreData = (isB2BUser:boolean, role: string | number, isCo
label: 'Placed by',
required: false,
default: '',
fieldType: 'text',
fieldType: 'dropdown',
options: newCreatedByUsers,
replaceOptions: {
label: 'createdBy',
value: 'createdBy',
},
xs: 12,
variant: 'filled',
size: 'small',
Expand Down
133 changes: 86 additions & 47 deletions apps/storefront/src/pages/quote/QuotesList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
useContext,
useEffect,
useState,
} from 'react'
import {
Expand Down Expand Up @@ -30,6 +31,7 @@ import {
import {
getB2BQuotesList,
getBCQuotesList,
getShoppingListsCreatedByUser,
} from '@/shared/service/b2b'

import {
Expand Down Expand Up @@ -130,53 +132,63 @@ const quotesStatuses = [
statusCode: 5,
},
]
const filterMoreList = [
{
name: 'status',
label: 'Order status',
required: false,
default: '',
fieldType: 'dropdown',
options: quotesStatuses,
replaceOptions: {
label: 'customLabel',
value: 'statusCode',

const getFilterMoreList = (isB2BUser: boolean, createdByUsers: any, createdBySalesReps: any) => {
const filterMoreList = [
{
name: 'status',
label: 'Quote status',
required: false,
default: '',
fieldType: 'dropdown',
options: quotesStatuses,
replaceOptions: {
label: 'customLabel',
value: 'statusCode',
},
xs: 12,
variant: 'filled',
size: 'small',
},
xs: 12,
variant: 'filled',
size: 'small',
},
{
name: 'createdBy',
label: 'Created by',
required: false,
default: '',
fieldType: 'text',
xs: 12,
variant: 'filled',
size: 'small',
},
{
name: 'salesRep',
label: 'Sales rep',
required: false,
default: '',
fieldType: 'text',
xs: 12,
variant: 'filled',
size: 'small',
},
// {
// name: 'dateCreatedBeginAt',
// label: 'Date created',
// required: false,
// default: '',
// fieldType: 'date',
// xs: 12,
// variant: 'filled',
// size: 'small',
// },
]
{
name: 'createdBy',
label: 'Created by',
required: false,
default: '',
fieldType: 'dropdown',
options: createdByUsers,
replaceOptions: {
label: 'createdBy',
value: 'createdBy',
},
xs: 12,
variant: 'filled',
size: 'small',
},
{
name: 'salesRep',
label: 'Sales rep',
required: false,
default: '',
fieldType: 'dropdown',
options: createdBySalesReps,
replaceOptions: {
label: 'salesRep',
value: 'salesRep',
},
xs: 12,
variant: 'filled',
size: 'small',
},
]

const filterCurrentMoreList = filterMoreList.filter((item) => {
if (!isB2BUser && (item.name === 'createdBy' || item.name === 'salesRep')) return false
return true
})

return filterCurrentMoreList
}

const QuotesList = () => {
const initSearch = {
Expand All @@ -192,6 +204,8 @@ const QuotesList = () => {

const [isRequestLoading, setIsRequestLoading] = useState(false)

const [filterMoreInfo, setFilterMoreInfo] = useState<Array<any>>([])

const navigate = useNavigate()

const [isMobile] = useMobile()
Expand All @@ -200,9 +214,33 @@ const QuotesList = () => {
state: {
isB2BUser,
customer,
companyInfo: {
id: companyB2BId,
},
salesRepCompanyId,
},
} = useContext(GlobaledContext)

useEffect(() => {
const initFilter = async () => {
const companyId = companyB2BId || salesRepCompanyId
let createdByUsers: CustomFieldItems = {}
if (isB2BUser) createdByUsers = await getShoppingListsCreatedByUser(+companyId, 2)

const newCreatedByUsers = createdByUsers?.createdByUser?.results?.createdBy.map((item: any) => ({
createdBy: `${item}`,
})) || {}
const newCreatedBySalesReps = createdByUsers?.createdByUser?.results?.salesRep.map((item: any) => ({
salesRep: `${item.salesRep || item.salesRepEmail}`,
})) || {}

const filterInfos = getFilterMoreList(isB2BUser, newCreatedByUsers, newCreatedBySalesReps)
setFilterMoreInfo(filterInfos)
}

initFilter()
}, [])

const goToDetail = (item: ListItem, status: number) => {
if (+status === 0) {
navigate('/quoteDraft')
Expand Down Expand Up @@ -308,6 +346,7 @@ const QuotesList = () => {
render: (item: ListItem) => (<QuoteStatus code={item.status} />),
},
]

const handleChange = (key:string, value: string) => {
if (key === 'search') {
setFilterData({
Expand Down Expand Up @@ -351,7 +390,7 @@ const QuotesList = () => {
>
<B3Filter
sortByConfig={sortByConfigData}
fiterMoreInfo={filterMoreList}
fiterMoreInfo={filterMoreInfo}
startPicker={{
isEnabled: true,
label: 'From',
Expand Down
23 changes: 21 additions & 2 deletions apps/storefront/src/pages/shoppingLists/ShoppingLists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
useState,
useContext,
useRef,
useEffect,
} from 'react'

import {
Expand All @@ -16,6 +17,7 @@ import {
getBcShoppingList,
deleteB2BShoppingList,
deleteBcShoppingList,
getShoppingListsCreatedByUser,
} from '@/shared/service/b2b'

import {
Expand Down Expand Up @@ -60,16 +62,35 @@ const shoppingLists = () => {

const [deleteItem, setDeleteItem] = useState<null | ShoppingListsItemsProps>(null)

const [fiterMoreInfo, setFiterMoreinfo] = useState<Array<any>>([])

const [isMobile] = useMobile()

const {
state: {
role,
isB2BUser,
currentChannelId,
companyInfo: {
id: companyB2BId,
},
salesRepCompanyId,
},
} = useContext(GlobaledContext)

useEffect(() => {
const initFilter = async () => {
const companyId = companyB2BId || salesRepCompanyId
let createdByUsers: CustomFieldItems = {}
if (isB2BUser) createdByUsers = await getShoppingListsCreatedByUser(+companyId, 1)

const filterInfo = getFilterMoreList(createdByUsers, role)
setFiterMoreinfo(filterInfo)
}

initFilter()
}, [])

const isExtraLarge = useCardListColumn()

const isEnableBtnPermissions = true
Expand Down Expand Up @@ -102,8 +123,6 @@ const shoppingLists = () => {
})
}

const fiterMoreInfo = getFilterMoreList(role)

const handleChange = (key:string, value: string) => {
if (key === 'search') {
const search = {
Expand Down
12 changes: 10 additions & 2 deletions apps/storefront/src/pages/shoppingLists/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,22 @@ export const getFilterShoppingListStatus = (role?: number | string): Array<Shopp
return getShoppingListStatus
}

export const getFilterMoreList = (role: number | string): GetFilterMoreListProps[] => {
export const getFilterMoreList = (createdByUsers: any, role: number | string): GetFilterMoreListProps[] => {
const newCreatedByUsers = createdByUsers?.createdByUser?.results.map((item: any) => ({
createdBy: `${item.firstName} ${item.lastName}`,
})) || {}
const filterMoreList = [
{
name: 'createdBy',
label: 'Created by',
required: false,
default: '',
fieldType: 'text',
fieldType: 'dropdown',
options: newCreatedByUsers,
replaceOptions: {
label: 'createdBy',
value: 'createdBy',
},
xs: 12,
variant: 'filled',
size: 'small',
Expand Down
13 changes: 13 additions & 0 deletions apps/storefront/src/shared/service/b2b/graphql/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ const getOrderStatusTypeQl = (fn: string) => `{
}
}`

const getCreatedByUser = (companyId: number, module: number, fn: string) => `{
${fn}(
companyId: ${companyId},
module: ${module},
){
results,
}
}`

export const getB2BAllOrders = (data: CustomFieldItems): CustomFieldItems => B3Request.graphqlB2B({
query: allOrders(data, 'allOrders'),
})
Expand All @@ -207,3 +216,7 @@ export const getOrderStatusType = (): CustomFieldItems => B3Request.graphqlB2B({
export const getBcOrderStatusType = (): CustomFieldItems => B3Request.graphqlProxyBC({
query: getOrderStatusTypeQl('bcOrderStatuses'),
})

export const getOrdersCreatedByUser = (companyId: number, module: number) => B3Request.graphqlB2B({
query: getCreatedByUser(companyId, module, 'createdByUser'),
})
13 changes: 13 additions & 0 deletions apps/storefront/src/shared/service/b2b/graphql/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,15 @@ const quoteAttachFileDelete = (data: CustomFieldItems) => `mutation{
}
}`

const getCreatedByUser = (companyId: number, module: number, fn: string) => `{
${fn}(
companyId: ${companyId},
module: ${module},
){
results,
}
}`

export const getBCCustomerAddresses = (): CustomFieldItems => B3Request.graphqlProxyBC({
query: getCustomerAddresses(),
})
Expand Down Expand Up @@ -398,3 +407,7 @@ export const quoteDetailAttachFileCreate = (data: CustomFieldItems): CustomField
export const quoteDetailAttachFileDelete = (data: CustomFieldItems): CustomFieldItems => B3Request.graphqlProxyBC({
query: quoteAttachFileDelete(data),
})

export const getQuoteCreatedByUsers = (companyId: number, module: number) => B3Request.graphqlB2B({
query: getCreatedByUser(companyId, module, 'createdByUser'),
})
Loading

0 comments on commit 8d02166

Please sign in to comment.