Filter pick list product options by categories

This commit is contained in:
beatz174-bit
2025-11-23 16:17:14 +10:00
parent a1f80e2554
commit 62147659bb
2 changed files with 57 additions and 10 deletions
+15 -3
View File
@@ -98,18 +98,30 @@ export const ActivePickListScreen = () => {
);
}, [products]);
const categoryFilteredProducts = useMemo(() => {
if (!pickList?.categories?.length) return sortedProducts;
const allowedCategories = new Set(
pickList.categories.map((category) => category.trim().toLowerCase()),
);
return sortedProducts.filter((product) =>
allowedCategories.has(product.category.trim().toLowerCase()),
);
}, [pickList?.categories, sortedProducts]);
const hasCartonItems = useMemo(() => items.some((item) => item.is_carton), [items]);
const hasUnitItems = useMemo(() => items.some((item) => !item.is_carton), [items]);
const filteredProducts = useMemo(() => {
const normalizedQuery = query.trim().toLowerCase();
if (!normalizedQuery) return sortedProducts;
if (!normalizedQuery) return categoryFilteredProducts;
return sortedProducts.filter((product) => {
return categoryFilteredProducts.filter((product) => {
const searchableText = `${product.name} ${product.category} ${product.barcode ?? ''}`.toLowerCase();
return searchableText.includes(normalizedQuery);
});
}, [sortedProducts, query]);
}, [categoryFilteredProducts, query]);
useEffect(() => {
if (!selectedProduct) return;