Skip to content

Commit

Permalink
fix: quick order pad keep the entered product quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 authored and libruce committed Feb 22, 2024
1 parent 648b860 commit 75122c9
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions apps/storefront/src/pages/quickorder/components/QuickorderTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,26 @@ function QuickorderTable({
})
}

const handleSetCheckedQty = (row: CustomFieldItems) => {
const cacheProductList: CustomFieldItems =
paginationTableRef.current?.getCacheList() || []

let qty = row.quantity
if (cacheProductList.length > 0) {
const currentProduct = cacheProductList.find(
(item: CustomFieldItems) =>
item.node.variantId === row.variantId &&
item.node.productId === row.productId
)

if (currentProduct && currentProduct.node) {
qty = currentProduct.node.quantity || qty
}
}

return qty
}

const columnItems: TableColumnItem<ListItem>[] = [
{
key: 'product',
Expand Down Expand Up @@ -374,16 +394,16 @@ function QuickorderTable({
productsSearch: { variants },
variantId,
basePrice,
quantity,
} = row
let priceIncTax = +basePrice
if (variants?.length) {
priceIncTax =
getProductPriceIncTax(variants, +variantId) || +basePrice
}

const qty = handleSetCheckedQty(row)
const withTaxPrice = priceIncTax || +basePrice
const price = withTaxPrice * +quantity
const price = withTaxPrice * +qty

return (
<Typography
Expand All @@ -403,21 +423,25 @@ function QuickorderTable({
{
key: 'qty',
title: b3Lang('purchasedProducts.qty'),
render: (row) => (
<StyledTextField
size="small"
type="number"
variant="filled"
value={row.quantity}
inputProps={{
inputMode: 'numeric',
pattern: '[0-9]*',
}}
onChange={(e) => {
handleUpdateProductQty(row.id, e.target.value)
}}
/>
),
render: (row) => {
const qty = handleSetCheckedQty(row)

return (
<StyledTextField
size="small"
type="number"
variant="filled"
value={qty}
inputProps={{
inputMode: 'numeric',
pattern: '[0-9]*',
}}
onChange={(e) => {
handleUpdateProductQty(row.id, e.target.value)
}}
/>
)
},
width: '15%',
style: {
textAlign: 'right',
Expand Down

0 comments on commit 75122c9

Please sign in to comment.