Skip to content

Commit

Permalink
fix: number limit
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 authored and CarlLiu2023 committed May 10, 2023
1 parent f88be7f commit 59a6419
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
6 changes: 5 additions & 1 deletion apps/storefront/src/components/B3ProductList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,14 @@ export default function B3ProductList<T>(props: ProductProps<T>) {
}
}

const handleNumberInputBlur = (product: any) => () => {
const handleNumberInputBlur = (product: CustomFieldItems) => () => {
if (!product[quantityKey]) {
onProductQuantityChange(product.id, 1)
}

if (+product[quantityKey] > 1000000) {
onProductQuantityChange(product.id, 1000000)
}
}

const handleSelectAllChange = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export default function QuickAdd(props: AddToListContentProps) {

return (
<B3Sping isSpinning={isLoading} spinningHeight="auto">
<Box>
<Box sx={{ width: '100%' }}>
<Grid
container
sx={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ export default function ChooseOptionsDialog(props: ChooseOptionsDialogProps) {
if (!quantity) {
setQuantity(1)
}

if (+quantity > 1000000) {
setQuantity(1000000)
}
}

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export default function QuickAdd(props: AddToListContentProps) {
const productItems: CustomFieldItems[] = []
const passSku: string[] = []
const notAddAble: string[] = []
const numberLimit: string[] = []

skus.forEach((sku) => {
const variantInfo: CustomFieldItems | null = (variantInfoList || []).find(
Expand Down Expand Up @@ -177,6 +178,11 @@ export default function QuickAdd(props: AddToListContentProps) {
return
}

if (+quantity < 1 || +quantity > 1000000) {
numberLimit.push(sku)
return
}

const optionList = (options || []).reduce(
(arr: ShoppingListAddProductOption[], optionStr: string) => {
try {
Expand Down Expand Up @@ -230,6 +236,7 @@ export default function QuickAdd(props: AddToListContentProps) {
productItems,
passSku,
notAddAble,
numberLimit,
}
}

Expand Down Expand Up @@ -301,6 +308,7 @@ export default function QuickAdd(props: AddToListContentProps) {
productItems,
notAddAble,
passSku,
numberLimit,
} = getProductItems(variantInfoList, skuValue, skus)

if (notFoundSku.length > 0) {
Expand All @@ -327,6 +335,19 @@ export default function QuickAdd(props: AddToListContentProps) {
})
}

if (numberLimit.length > 0) {
numberLimit.forEach((sku) => {
showErrors(value, [sku], 'qty', '')
})

snackbar.error(
`SKU ${numberLimit} add quantity is limited from 1 to 1,000,000`,
{
isClose: true,
}
)
}

if (productItems.length > 0) {
await quickAddToList(productItems)
clearInputValue(value, passSku)
Expand All @@ -347,7 +368,7 @@ export default function QuickAdd(props: AddToListContentProps) {

return (
<B3Sping isSpinning={isLoading} spinningHeight="auto">
<Box>
<Box sx={{ width: '100%' }}>
<Grid
container
sx={{
Expand Down
2 changes: 2 additions & 0 deletions apps/storefront/src/utils/b3Product/shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,8 @@ export const getQuickAddRowFields = (name: string | number) => [
fieldType: 'number',
default: '',
allowArrow: true,
min: 1,
max: 1000000,
},
]

Expand Down

0 comments on commit 59a6419

Please sign in to comment.