Fix barcode lookup initialization and unit test script
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"test": "vitest",
|
"test": "vitest",
|
||||||
|
"test:unit": "vitest run",
|
||||||
"test:coverage": "vitest run --coverage",
|
"test:coverage": "vitest run --coverage",
|
||||||
"test:e2e": "playwright test",
|
"test:e2e": "playwright test",
|
||||||
"coverage:unit": "npm run test:coverage",
|
"coverage:unit": "npm run test:coverage",
|
||||||
|
|||||||
@@ -59,32 +59,6 @@ export const AddProductDialog = ({
|
|||||||
setScannerOpen(false);
|
setScannerOpen(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (open) {
|
|
||||||
if (categoryOptions.length > 0 && !categoryOptions.includes(category)) {
|
|
||||||
setCategory(categoryOptions[0]);
|
|
||||||
}
|
|
||||||
if (initialBarcode) {
|
|
||||||
setBarcode(initialBarcode);
|
|
||||||
void lookupBarcode(initialBarcode);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
resetForm();
|
|
||||||
}
|
|
||||||
}, [category, categoryOptions, initialBarcode, lookupBarcode, open, resetForm]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!open || !barcode) return;
|
|
||||||
void lookupBarcode(barcode);
|
|
||||||
}, [barcode, lookupBarcode, open]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!barcode) {
|
|
||||||
setLookupStatus('idle');
|
|
||||||
}
|
|
||||||
setBarcodeError('');
|
|
||||||
}, [barcode]);
|
|
||||||
|
|
||||||
const categoryMap = useMemo(() => new Map(categoryOptions.map((c) => [c, c])), [categoryOptions]);
|
const categoryMap = useMemo(() => new Map(categoryOptions.map((c) => [c, c])), [categoryOptions]);
|
||||||
|
|
||||||
const findBarcodeConflict = useCallback(
|
const findBarcodeConflict = useCallback(
|
||||||
@@ -198,6 +172,32 @@ export const AddProductDialog = ({
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
if (categoryOptions.length > 0 && !categoryOptions.includes(category)) {
|
||||||
|
setCategory(categoryOptions[0]);
|
||||||
|
}
|
||||||
|
if (initialBarcode) {
|
||||||
|
setBarcode(initialBarcode);
|
||||||
|
void lookupBarcode(initialBarcode);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
resetForm();
|
||||||
|
}
|
||||||
|
}, [category, categoryOptions, initialBarcode, lookupBarcode, open, resetForm]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open || !barcode) return;
|
||||||
|
void lookupBarcode(barcode);
|
||||||
|
}, [barcode, lookupBarcode, open]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!barcode) {
|
||||||
|
setLookupStatus('idle');
|
||||||
|
}
|
||||||
|
setBarcodeError('');
|
||||||
|
}, [barcode]);
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
setNameError('');
|
setNameError('');
|
||||||
setBarcodeError('');
|
setBarcodeError('');
|
||||||
|
|||||||
Reference in New Issue
Block a user