Skip to content

Commit

Permalink
fix: duplicate name issues
Browse files Browse the repository at this point in the history
  • Loading branch information
b3aton committed Mar 22, 2023
1 parent 82203b9 commit 302b496
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
22 changes: 18 additions & 4 deletions apps/storefront/src/components/table/B3PaginationTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface TablePagination {
// render?: (item: CustomFieldItems, index: number) => ReactNode,
// }

interface B3PaginationTableProps<T> {
interface B3PaginationTableProps {
tableFixed?: boolean,
tableHeaderHide?: boolean,
columnItems?: TableColumnItem<any>[],
Expand All @@ -46,7 +46,7 @@ interface B3PaginationTableProps<T> {
noDataText?: string,
tableKey?: string,
getRequestList: any,
searchParams?: T,
searchParams?: any,
requestLoading?: (bool: boolean) => void,
showCheckbox?: boolean,
selectedSymbol?: string,
Expand All @@ -60,7 +60,7 @@ interface B3PaginationTableProps<T> {
showRowsPerPageOptions?: boolean,
}

const PaginationTable:<T>(props: B3PaginationTableProps<T>) => ReactElement = ({
const PaginationTable:(props: B3PaginationTableProps) => ReactElement = ({
columnItems,
isCustomRender = false,
tableKey,
Expand Down Expand Up @@ -111,8 +111,22 @@ const PaginationTable:<T>(props: B3PaginationTableProps<T>) => ReactElement = ({
try {
setLoading(true)
if (requestLoading) requestLoading(true)
const params = {
const {
createdBy,
} = searchParams

const getEmailReg: RegExp = /\((.+)\)/g
const getCreatedByReg: RegExp = /^[^(]+/
const emailRegArr = getEmailReg.exec(createdBy)
const createdByUserRegArr = getCreatedByReg.exec(createdBy)
const createdByUser = createdByUserRegArr?.length ? createdByUserRegArr[0].trim() : ''
const newSearchParams = {
...searchParams,
createdBy: emailRegArr?.length ? '' : createdByUser,
email: emailRegArr?.length ? emailRegArr[1] : '',
}
const params = {
...newSearchParams,
first: b3Pagination?.first || pagination.first,
offset: b3Pagination?.offset || 0,
}
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 @@ -50,8 +50,8 @@ const bcFilterSearch = {
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}`,
})) || {}
createdBy: `${item.firstName} ${item.lastName} (${item.email})`,
})) || []
const filterMoreList = [
{
name: 'company',
Expand Down
21 changes: 10 additions & 11 deletions apps/storefront/src/pages/quote/QuotesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,13 @@ const quotesStatuses = [
},
]

const getFilterMoreList = (isB2BUser: boolean, createdByUsers: any, createdBySalesReps: any) => {
const getFilterMoreList = (isB2BUser: boolean, createdByUsers: any) => {
const newCreatedByUsers = createdByUsers?.createdByUser?.results?.createdBy.map((item: any) => ({
createdBy: item.email ? `${item.name} (${item.email})` : `${item.name}`,
})) || []
const newCreatedBySalesReps = createdByUsers?.createdByUser?.results?.salesRep.map((item: any) => ({
salesRep: `${item.salesRep || item.salesRepEmail}`,
})) || []
const filterMoreList = [
{
name: 'status',
Expand All @@ -156,7 +162,7 @@ const getFilterMoreList = (isB2BUser: boolean, createdByUsers: any, createdBySal
required: false,
default: '',
fieldType: 'dropdown',
options: createdByUsers,
options: newCreatedByUsers,
replaceOptions: {
label: 'createdBy',
value: 'createdBy',
Expand All @@ -171,7 +177,7 @@ const getFilterMoreList = (isB2BUser: boolean, createdByUsers: any, createdBySal
required: false,
default: '',
fieldType: 'dropdown',
options: createdBySalesReps,
options: newCreatedBySalesReps,
replaceOptions: {
label: 'salesRep',
value: 'salesRep',
Expand Down Expand Up @@ -227,14 +233,7 @@ const QuotesList = () => {
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)
const filterInfos = getFilterMoreList(isB2BUser, createdByUsers)
setFilterMoreInfo(filterInfos)
}

Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/src/pages/shoppingLists/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export const getFilterShoppingListStatus = (role?: number | string): Array<Shopp

export const getFilterMoreList = (createdByUsers: any, role: number | string): GetFilterMoreListProps[] => {
const newCreatedByUsers = createdByUsers?.createdByUser?.results.map((item: any) => ({
createdBy: `${item.firstName} ${item.lastName}`,
})) || {}
createdBy: `${item.firstName} ${item.lastName} (${item.email})`,
})) || []
const filterMoreList = [
{
name: 'createdBy',
Expand Down
1 change: 1 addition & 0 deletions apps/storefront/src/shared/service/b2b/graphql/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const allOrders = (data: CustomFieldItems, fn: string) => `{
createdBy: "${data?.createdBy || ''}"
isShowMy: "${data?.isShowMy || 0}"
orderBy: "${data.orderBy}"
email: "${data?.email || ''}"
){
totalCount,
pageInfo{
Expand Down
1 change: 1 addition & 0 deletions apps/storefront/src/shared/service/b2b/graphql/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const getQuotesList = (data: CustomFieldItems, type: string) => `{
search: "${data.q || ''}"
orderBy: "${data?.orderBy || ''}"
createdBy: "${data?.createdBy || ''}"
email: "${data?.email || ''}"
salesRep: "${data?.salesRep || ''}"
${data?.status ? `status: "${data.status}"` : ''}
${data?.dateCreatedBeginAt ? `dateCreatedBeginAt: "${data.dateCreatedBeginAt}"` : ''}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const getShoppingList = ({
first = 50,
status = '',
createdBy = '',
email = '',
search = '',
isDefault = true,
}) => `{
Expand All @@ -30,6 +31,7 @@ const getShoppingList = ({
first: ${first}
search: "${search}"
createdBy: "${createdBy}"
email: "${email}"
${getStatus(status)}
isDefault: ${isDefault}
){
Expand Down

0 comments on commit 302b496

Please sign in to comment.