Skip to content

Commit

Permalink
fix: fix shoppingList bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 committed Jan 31, 2023
1 parent bc215ca commit 765e651
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 33 deletions.
3 changes: 3 additions & 0 deletions apps/storefront/src/components/table/B3PaginationTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ interface B3PaginationTableProps<Y> {
hover?: boolean,
labelRowsPerPage?: string,
itemIsMobileSpacing?: number,
disableCheckbox?: boolean,
}

const PaginationTable:<Y>(props: B3PaginationTableProps<Y>) => ReactElement = ({
Expand Down Expand Up @@ -81,6 +82,7 @@ const PaginationTable:<Y>(props: B3PaginationTableProps<Y>) => ReactElement = ({
hover = false,
labelRowsPerPage = '',
itemIsMobileSpacing = 2,
disableCheckbox = false,
}, ref?: Ref<unknown>) => {
const initPagination = {
offset: 0,
Expand Down Expand Up @@ -212,6 +214,7 @@ const PaginationTable:<Y>(props: B3PaginationTableProps<Y>) => ReactElement = ({
infiniteScrollLoader={infiniteScrollLoader}
infiniteScrollHeight={infiniteScrollHeight}
showCheckbox={showCheckbox}
disableCheckbox={disableCheckbox}
selectedSymbol={selectedSymbol}
selectCheckbox={selectCheckbox}
handleSelectAllItems={handleSelectAllItems}
Expand Down
6 changes: 6 additions & 0 deletions apps/storefront/src/components/table/B3Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface TableProps<T> {
selectedSymbol?: string,
selectCheckbox?: Array<number | string>,
labelRowsPerPage?: string,
disableCheckbox?: boolean,
}

export const B3Table:<T>(props: TableProps<T>) => ReactElement = ({
Expand Down Expand Up @@ -99,6 +100,7 @@ export const B3Table:<T>(props: TableProps<T>) => ReactElement = ({
selectedSymbol = 'id',
selectCheckbox = [],
labelRowsPerPage = '',
disableCheckbox = false,
}) => {
const {
offset,
Expand Down Expand Up @@ -145,6 +147,7 @@ export const B3Table:<T>(props: TableProps<T>) => ReactElement = ({
<Checkbox
checked={selectCheckbox.length === listItems.length}
onChange={handleSelectAllItems}
disabled={disableCheckbox}
/>
Select all
</Box>
Expand All @@ -163,6 +166,7 @@ export const B3Table:<T>(props: TableProps<T>) => ReactElement = ({
onChange={() => {
if (handleSelectOneItem) handleSelectOneItem(row.node[selectedSymbol])
}}
disabled={disableCheckbox}
/>
)
return (
Expand Down Expand Up @@ -263,6 +267,7 @@ export const B3Table:<T>(props: TableProps<T>) => ReactElement = ({
<Checkbox
checked={selectCheckbox.length === listItems.length}
onChange={handleSelectAllItems}
disabled={disableCheckbox}
/>
</TableCell>
)
Expand Down Expand Up @@ -305,6 +310,7 @@ export const B3Table:<T>(props: TableProps<T>) => ReactElement = ({
onChange={() => {
if (handleSelectOneItem) handleSelectOneItem(node[selectedSymbol])
}}
disabled={disableCheckbox}
/>
</TableCell>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const ShoppingDetailFooter = (props: ShoppingDetailFooterProps) => {
padding: '1rem',
height: isMobile ? '8rem' : 'auto',
display: 'flex',
zIndex: '10',
zIndex: '999',
...containerStyle,
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const ShoppingDetailHeader = (props: ShoppingDetailHeaderProps) => {
variant="h4"
sx={{
marginRight: '1rem',
wordBreak: 'break-all',
}}
>
{`${shoppingListInfo?.name || ''}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
styled,
Typography,
TextField,
Grid,
} from '@mui/material'

import {
Expand Down Expand Up @@ -166,6 +167,7 @@ const ShoppingDetailTable = (props: ShoppingDetailTableProps, ref: Ref<unknown>)
const [search, setSearch] = useState<SearchProps>({
search: '',
})
const [qtyNotChangeFlag, setQtyNotChangeFlag] = useState<boolean>(true)

const handleUpdateProductQty = (id: number | string, value: number | string) => {
const listItems = paginationTableRef.current?.getList() || []
Expand All @@ -174,6 +176,7 @@ const ShoppingDetailTable = (props: ShoppingDetailTableProps, ref: Ref<unknown>)
node,
} = item
if (node?.id === id) {
setQtyNotChangeFlag(node.quantity === +value)
node.quantity = +value || ''
}

Expand Down Expand Up @@ -237,6 +240,7 @@ const ShoppingDetailTable = (props: ShoppingDetailTableProps, ref: Ref<unknown>)
}

const handleUpdateShoppingListItem = async (itemId: number | string) => {
if (qtyNotChangeFlag) return
setIsRequestLoading(true)
const listItems: ListItemProps[] = paginationTableRef.current?.getList() || []
const currentItem = listItems.find((item: ListItemProps) => {
Expand Down Expand Up @@ -277,6 +281,7 @@ const ShoppingDetailTable = (props: ShoppingDetailTableProps, ref: Ref<unknown>)

await updateB2BShoppingListsItem(data)
snackbar.success('Product quantity updated successfully')
setQtyNotChangeFlag(true)
initSearch()
} finally {
setIsRequestLoading(false)
Expand Down Expand Up @@ -437,48 +442,57 @@ const ShoppingDetailTable = (props: ShoppingDetailTableProps, ref: Ref<unknown>)
marginTop: '1rem',
opacity: 0,
textAlign: isMobile ? 'end' : 'start',
display: 'flex',
}}
id="shoppingList-actionList"
>
{
optionList.length > 0 && !isReadForApprove && (
<Edit
<Grid
item
sx={{
marginRight: '0.5rem',
minWidth: '32px',
}}
>
{
optionList.length > 0 && !isReadForApprove && (
<Edit
sx={{
cursor: 'pointer',
color: 'rgba(0, 0, 0, 0.54)',
}}
onClick={() => {
const {
productsSearch,
variantId,
itemId,
optionList,
} = row

handleOpenProductEdit({
...productsSearch,
selectOptions: optionList,
}, variantId, itemId)
}}
/>
)
}
</Grid>
<Grid item>
{
!isReadForApprove && (
<Delete
sx={{
marginRight: '0.5rem',
cursor: 'pointer',
color: 'rgba(0, 0, 0, 0.54)',
}}
onClick={() => {
const {
productsSearch,
variantId,
itemId,
optionList,
} = row

handleOpenProductEdit({
...productsSearch,
selectOptions: optionList,
}, variantId, itemId)
setDeleteOpen(true)
setDeleteItemId(+itemId)
}}
/>
)
}
{
!isReadForApprove && (
<Delete
sx={{
cursor: 'pointer',
color: 'rgba(0, 0, 0, 0.54)',
}}
onClick={() => {
setDeleteOpen(true)
setDeleteItemId(+itemId)
}}
/>
)
}

)
}
</Grid>
</Box>
</Box>
)
Expand Down Expand Up @@ -533,6 +547,7 @@ const ShoppingDetailTable = (props: ShoppingDetailTableProps, ref: Ref<unknown>)
searchParams={search}
isCustomRender={false}
showCheckbox
disableCheckbox={isReadForApprove}
hover
labelRowsPerPage="Items per page:"
showBorder={false}
Expand Down

0 comments on commit 765e651

Please sign in to comment.