Merge pull request #45 from beatz174-bit/codex/remove-quantity-field-and-carton-checkbox
Remove redundant quantity controls from active pick list
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
Autocomplete,
|
Autocomplete,
|
||||||
Button,
|
Button,
|
||||||
Checkbox,
|
|
||||||
Container,
|
Container,
|
||||||
FormControlLabel,
|
|
||||||
InputAdornment,
|
InputAdornment,
|
||||||
Stack,
|
Stack,
|
||||||
TextField,
|
TextField,
|
||||||
@@ -29,8 +27,6 @@ export const ActivePickListScreen = () => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [selectedProduct, setSelectedProduct] = useState<Product | null>(null);
|
const [selectedProduct, setSelectedProduct] = useState<Product | null>(null);
|
||||||
const [query, setQuery] = useState('');
|
const [query, setQuery] = useState('');
|
||||||
const [quantity, setQuantity] = useState(1);
|
|
||||||
const [isCarton, setIsCarton] = useState(false);
|
|
||||||
|
|
||||||
const areaName = useMemo(
|
const areaName = useMemo(
|
||||||
() => areas.find((area) => area.id === pickList?.area_id)?.name ?? 'Area',
|
() => areas.find((area) => area.id === pickList?.area_id)?.name ?? 'Area',
|
||||||
@@ -54,11 +50,6 @@ export const ActivePickListScreen = () => {
|
|||||||
}
|
}
|
||||||
}, [filteredProducts, selectedProduct]);
|
}, [filteredProducts, selectedProduct]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setQuantity(1);
|
|
||||||
setIsCarton(false);
|
|
||||||
}, [selectedProduct]);
|
|
||||||
|
|
||||||
const handleIncrementQuantity = async (itemId: string) => {
|
const handleIncrementQuantity = async (itemId: string) => {
|
||||||
const existing = await db.pickItems.get(itemId);
|
const existing = await db.pickItems.get(itemId);
|
||||||
if (!existing) return;
|
if (!existing) return;
|
||||||
@@ -101,15 +92,15 @@ export const ActivePickListScreen = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const addOrUpdateItem = async (product: Product) => {
|
const addOrUpdateItem = async (product: Product) => {
|
||||||
if (!id || quantity <= 0) return;
|
if (!id) return;
|
||||||
|
|
||||||
const existing = items.find(
|
const existing = items.find(
|
||||||
(item) => item.product_id === product.id && item.is_carton === isCarton,
|
(item) => item.product_id === product.id && item.is_carton === false,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (existing) {
|
if (existing) {
|
||||||
await db.pickItems.update(existing.id, {
|
await db.pickItems.update(existing.id, {
|
||||||
quantity: existing.quantity + quantity,
|
quantity: existing.quantity + 1,
|
||||||
updated_at: Date.now(),
|
updated_at: Date.now(),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -117,8 +108,8 @@ export const ActivePickListScreen = () => {
|
|||||||
id: uuidv4(),
|
id: uuidv4(),
|
||||||
pick_list_id: id,
|
pick_list_id: id,
|
||||||
product_id: product.id,
|
product_id: product.id,
|
||||||
quantity,
|
quantity: 1,
|
||||||
is_carton: isCarton,
|
is_carton: false,
|
||||||
status: 'pending',
|
status: 'pending',
|
||||||
created_at: Date.now(),
|
created_at: Date.now(),
|
||||||
updated_at: Date.now(),
|
updated_at: Date.now(),
|
||||||
@@ -127,24 +118,12 @@ export const ActivePickListScreen = () => {
|
|||||||
|
|
||||||
setSelectedProduct(null);
|
setSelectedProduct(null);
|
||||||
setQuery('');
|
setQuery('');
|
||||||
setQuantity(1);
|
|
||||||
setIsCarton(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const returnToLists = () => {
|
const returnToLists = () => {
|
||||||
navigate('/pick-lists');
|
navigate('/pick-lists');
|
||||||
};
|
};
|
||||||
|
|
||||||
const packagingLabel = isCarton
|
|
||||||
? selectedProduct?.bulk_name ?? 'Cartons'
|
|
||||||
: selectedProduct?.unit_type ?? 'Units';
|
|
||||||
const quantityHelperText = selectedProduct
|
|
||||||
? `Enter ${packagingLabel.toLowerCase()} to pick`
|
|
||||||
: 'Select a product to add it to the list';
|
|
||||||
const cartonCheckboxLabel = selectedProduct?.bulk_name
|
|
||||||
? `Carton (${selectedProduct.bulk_name})`
|
|
||||||
: 'Carton pick';
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container sx={{ py: 4 }}>
|
<Container sx={{ py: 4 }}>
|
||||||
<Stack spacing={2} mb={2}>
|
<Stack spacing={2} mb={2}>
|
||||||
@@ -195,22 +174,6 @@ export const ActivePickListScreen = () => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={1.5} alignItems="center">
|
|
||||||
<TextField
|
|
||||||
type="number"
|
|
||||||
label={`Quantity (${packagingLabel})`}
|
|
||||||
value={quantity}
|
|
||||||
onChange={(event) => setQuantity(Math.max(1, Number(event.target.value)))}
|
|
||||||
inputProps={{ min: 1 }}
|
|
||||||
helperText={quantityHelperText}
|
|
||||||
fullWidth
|
|
||||||
/>
|
|
||||||
<FormControlLabel
|
|
||||||
control={<Checkbox checked={isCarton} onChange={(event) => setIsCarton(event.target.checked)} />}
|
|
||||||
label={cartonCheckboxLabel}
|
|
||||||
disabled={!selectedProduct}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
<Typography variant="caption" color="text.secondary">
|
<Typography variant="caption" color="text.secondary">
|
||||||
Selecting a product immediately adds it to the pick list.
|
Selecting a product immediately adds it to the pick list.
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|||||||
Reference in New Issue
Block a user