'use client'; import { useCallback } from 'react'; import { usePathname } from 'next/navigation'; import Image from 'next/image'; import { Icon } from '@iconify/react'; import Drawer from '@/components/Drawer'; import Navbar from '@/components/Navbar'; import Button from '@/components/Button'; import SidebarMenu from '@/components/molecules/SidebarMenu'; import PermissionNotFound from '@/components/helper/PermissionNotFound'; import { useUiStore } from '@/stores/ui/ui.store'; import { MAIN_DRAWER_LINKS } from '@/config/constant'; import { isPathActive } from '@/lib/helper'; import { ROUTE_PERMISSIONS } from '@/config/route-permission'; import { useAuth } from '@/services/hooks/useAuth'; const MainDrawerContent = () => { const pathname = usePathname(); const { setMainDrawerOpen } = useUiStore(); const closeMainDrawerHandler = () => { setMainDrawerOpen(false); }; return (
MBU Logo

LTI ERP

); }; const MainDrawer = ({ children, }: Readonly<{ children: React.ReactNode; }>) => { const { mainDrawerOpen, setMainDrawerOpen } = useUiStore(); const pathname = usePathname(); const { permissionCheck } = useAuth(); const isPermitted = ROUTE_PERMISSIONS[pathname]?.some((permission) => permissionCheck(permission) ); const getPageTitle = useCallback(() => { let title = ''; const activeMenu = MAIN_DRAWER_LINKS.find((item) => isPathActive(pathname, item.link) ); const traverseMenuTitle = (menu: typeof activeMenu) => { if (!menu) return; const hasSubmenu = menu?.submenu && menu?.submenu.length > 0; if (!title) { title += menu?.text; } else { title += ' - ' + menu?.text; } if (!hasSubmenu || !menu.submenu) return; const activeSubmenu = menu.submenu?.find((item) => isPathActive(pathname, item.link) ); traverseMenuTitle(activeSubmenu); }; traverseMenuTitle(activeMenu); return title; }, [pathname]); const pageTitle = getPageTitle(); const toggleSidebar = () => { setMainDrawerOpen(!mainDrawerOpen); }; if (!isPermitted) { return ; } return ( } >
{children}
); }; export default MainDrawer;