From 3051e931ca134b9121ac557a373b3f76db4a6a00 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Thu, 9 Oct 2025 09:12:07 +0700 Subject: [PATCH] fix: enhance MainDrawer with typed MenuItem structure and submenu handling --- src/components/MainDrawer.tsx | 4 +++- src/config/constant.ts | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/MainDrawer.tsx b/src/components/MainDrawer.tsx index 6a5e6f38..f41316f4 100644 --- a/src/components/MainDrawer.tsx +++ b/src/components/MainDrawer.tsx @@ -189,6 +189,8 @@ const MainDrawer = ({ ); const traverseMenuTitle = (menu: typeof activeMenu) => { + if (!menu) return; + const hasSubmenu = menu?.submenu && menu?.submenu.length > 0; if (!title) { @@ -197,7 +199,7 @@ const MainDrawer = ({ title += ' - ' + menu?.title; } - if (!hasSubmenu) return; + if (!hasSubmenu || !menu.submenu) return; const activeSubmenu = menu.submenu.find((item) => isPathActive(pathname, item.link) diff --git a/src/config/constant.ts b/src/config/constant.ts index 1fbef81f..8a5ca62f 100644 --- a/src/config/constant.ts +++ b/src/config/constant.ts @@ -1,4 +1,13 @@ -export const MAIN_DRAWER_LINKS = [ +export type MenuItem = { + title: string; + link: string; + icon: string; + submenu?: MenuItem[]; +}; + +type MainDrawerLink = MenuItem; + +export const MAIN_DRAWER_LINKS: MainDrawerLink[] = [ { title: 'Dashboard', link: '/dashboard', @@ -119,4 +128,3 @@ export const PRODUCT_FLAG_OPTIONS = [ { label: 'VITAMIN', value: 'VITAMIN' }, { label: 'KIMIA', value: 'KIMIA' }, ]; -