Filter pick list product options by categories
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user