|
|
@@ -29,7 +29,11 @@ import { Scrollbar, A11y, Navigation } from 'swiper/modules';
|
|
29
|
29
|
|
|
30
|
30
|
import ChevronLeftIcon from '@mui/icons-material/ChevronLeft';
|
|
31
|
31
|
import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight';
|
|
32
|
|
-import { NAV_MENU_STRUCTURE as SHARED_NAV_MENU_STRUCTURE } from "../../config/menuCollections";
|
|
|
32
|
+import {
|
|
|
33
|
+ NAV_MENU_STRUCTURE as SHARED_NAV_MENU_STRUCTURE,
|
|
|
34
|
+ buildNavMenuFromProducts,
|
|
|
35
|
+ normalizeTitle,
|
|
|
36
|
+} from "../../config/menuCollections";
|
|
33
|
37
|
|
|
34
|
38
|
function calculateTotalQuantity(cartItems) {
|
|
35
|
39
|
return cartItems.reduce((total, item) => total + item.quantity, 0);
|
|
|
@@ -84,8 +88,6 @@ const COLLECTION_PRIORITY_BY_TYPE = {
|
|
84
|
88
|
],
|
|
85
|
89
|
};
|
|
86
|
90
|
|
|
87
|
|
-const normalizeTitle = (value = "") => value.trim().toUpperCase();
|
|
88
|
|
-
|
|
89
|
91
|
const getProductTypeMenuLabel = (productType = "") => {
|
|
90
|
92
|
return normalizeTitle(productType) === "BEAUTY" ? "Essentials" : productType;
|
|
91
|
93
|
};
|
|
|
@@ -192,6 +194,9 @@ const Navbar = () => {
|
|
192
|
194
|
const [activeMenu, setActiveMenu] = useState(null);
|
|
193
|
195
|
const [activeGroup, setActiveGroup] = useState(null);
|
|
194
|
196
|
const [dropdownTopOffset, setDropdownTopOffset] = useState(52);
|
|
|
197
|
+ const dynamicNavMenu = products?.length > 0
|
|
|
198
|
+ ? buildNavMenuFromProducts(products)
|
|
|
199
|
+ : NAV_MENU_STRUCTURE;
|
|
195
|
200
|
|
|
196
|
201
|
const [displayCollection, setDisplayCollection] = useState({
|
|
197
|
202
|
productType: null,
|
|
|
@@ -394,15 +399,19 @@ const Navbar = () => {
|
|
394
|
399
|
|
|
395
|
400
|
const findCollectionForMenuItem = (productType, item) => {
|
|
396
|
401
|
const targetTitles = (item?.titles || []).map(normalizeTitle);
|
|
|
402
|
+ const targetHandles = (item?.handles || []).map(normalizeTitle);
|
|
397
|
403
|
|
|
398
|
404
|
return products
|
|
399
|
405
|
.filter((product) => product.productType === productType)
|
|
400
|
406
|
.flatMap((product) => product.collections || [])
|
|
401
|
|
- .find((collection) => targetTitles.includes(normalizeTitle(collection?.title || "")));
|
|
|
407
|
+ .find((collection) =>
|
|
|
408
|
+ targetTitles.includes(normalizeTitle(collection?.title || "")) ||
|
|
|
409
|
+ targetHandles.includes(normalizeTitle(collection?.handle || ""))
|
|
|
410
|
+ );
|
|
402
|
411
|
}
|
|
403
|
412
|
|
|
404
|
413
|
const getMenuCollectionTitles = (productType) => {
|
|
405
|
|
- const menu = NAV_MENU_STRUCTURE.find((menuItem) => menuItem.productType === productType);
|
|
|
414
|
+ const menu = dynamicNavMenu.find((menuItem) => menuItem.productType === productType);
|
|
406
|
415
|
|
|
407
|
416
|
if (!menu) return [];
|
|
408
|
417
|
|
|
|
@@ -545,7 +554,8 @@ const Navbar = () => {
|
|
545
|
554
|
}}
|
|
546
|
555
|
>
|
|
547
|
556
|
|
|
548
|
|
- {NAV_MENU_STRUCTURE.map((menu) => (
|
|
|
557
|
+ {/* Navigation Menu Items */}
|
|
|
558
|
+ {dynamicNavMenu.map((menu) => (
|
|
549
|
559
|
<Box
|
|
550
|
560
|
key={menu.label}
|
|
551
|
561
|
ref={(node) => {
|
|
|
@@ -984,7 +994,7 @@ const Navbar = () => {
|
|
984
|
994
|
</AppBar>
|
|
985
|
995
|
{showSearch && <SearchProduct onClose={() => { setShowSearch(false) }} />}
|
|
986
|
996
|
|
|
987
|
|
- <MobileNav open={openSideMenu} menu={NAV_MENU_STRUCTURE} products={products} infomenu={navItemCompanyInfo} onClose={() => { setOpenSideMenu(false) }} />
|
|
|
997
|
+ <MobileNav open={openSideMenu} menu={dynamicNavMenu} products={products} infomenu={navItemCompanyInfo} onClose={() => { setOpenSideMenu(false) }} />
|
|
988
|
998
|
<SideCart open={openSideCart} onClose={() => { setOpenSideCart(false) }} />
|
|
989
|
999
|
|
|
990
|
1000
|
</>
|