|
|
@@ -11,7 +11,7 @@ import {
|
|
11
|
11
|
CardMedia,
|
|
12
|
12
|
} from "@mui/material";
|
|
13
|
13
|
import { useSelector } from "react-redux";
|
|
14
|
|
-import { getMenuCollectionTitlesByProductType } from "../../config/menuCollections";
|
|
|
14
|
+import { isProductInVisibleMenu } from "../../config/menuCollections";
|
|
15
|
15
|
|
|
16
|
16
|
function doesSubstringExistInArray(array, substring) {
|
|
17
|
17
|
|
|
|
@@ -23,23 +23,6 @@ function doesSubstringExistInArray(array, substring) {
|
|
23
|
23
|
return array.some(element => element.toLowerCase().includes(lowerCaseSubstring));
|
|
24
|
24
|
}
|
|
25
|
25
|
|
|
26
|
|
-// Define allowed search collections for each product type
|
|
27
|
|
-const allowedSearchCollectionsByProductType = getMenuCollectionTitlesByProductType();
|
|
28
|
|
-
|
|
29
|
|
-const normalizeTitle = (value = "") => value.trim().toUpperCase();
|
|
30
|
|
-
|
|
31
|
|
-const isProductAllowedInSearch = (product) => {
|
|
32
|
|
- const allowedCollections = allowedSearchCollectionsByProductType[product?.productType];
|
|
33
|
|
-
|
|
34
|
|
- if (!allowedCollections) return false;
|
|
35
|
|
-
|
|
36
|
|
- const allowedCollectionSet = new Set(allowedCollections.map(normalizeTitle));
|
|
37
|
|
-
|
|
38
|
|
- return product?.collections?.some((collection) =>
|
|
39
|
|
- allowedCollectionSet.has(normalizeTitle(collection?.title || ""))
|
|
40
|
|
- );
|
|
41
|
|
-}
|
|
42
|
|
-
|
|
43
|
26
|
const SearchProduct = ({ onClose }) => {
|
|
44
|
27
|
const products = useSelector((state) => state.products.products.data);
|
|
45
|
28
|
const [searchedProducts, setSearchedProducts] = useState([]);
|
|
|
@@ -49,8 +32,8 @@ const SearchProduct = ({ onClose }) => {
|
|
49
|
32
|
|
|
50
|
33
|
if(searchQuery?.length < 2) return
|
|
51
|
34
|
|
|
52
|
|
- // let filteredProducts = products.filter((product) => {
|
|
53
|
|
- let filteredProducts = products.filter(isProductAllowedInSearch).filter((product) => {
|
|
|
35
|
+ // let filteredProducts = products.filter(isProductAllowedInSearch).filter((product) => {
|
|
|
36
|
+ let filteredProducts = products.filter((product) => isProductInVisibleMenu(product, products)).filter((product) => {
|
|
54
|
37
|
|
|
55
|
38
|
let title = product?.title?.toLowerCase();
|
|
56
|
39
|
let search = searchQuery.toLowerCase();
|