From 2456d64a685804574228474c9bd3f5ec39d596e8 Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Wed, 1 Oct 2025 13:44:26 +0700 Subject: [PATCH] feat(FE-40): create MainDrawer component --- src/components/MainDrawer.tsx | 205 ++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 src/components/MainDrawer.tsx diff --git a/src/components/MainDrawer.tsx b/src/components/MainDrawer.tsx new file mode 100644 index 00000000..ad9a7a9c --- /dev/null +++ b/src/components/MainDrawer.tsx @@ -0,0 +1,205 @@ +'use client'; + +import { useState } from 'react'; +import { usePathname } from 'next/navigation'; + +import Image from 'next/image'; +import { Icon } from '@iconify/react'; +import Drawer from '@/components/Drawer'; +import Menu from '@/components/menu/Menu'; +import MenuItem from '@/components/menu/MenuItem'; +import Navbar from '@/components/Navbar'; +import Collapse from '@/components/Collapse'; + +import { useUiStore } from '@/stores/ui/ui.store'; +import { MAIN_DRAWER_LINKS } from '@/config/constant'; +import { cn } from '@/lib/helper'; + +type CollapseMenuProps = { + title: string; + link: string; + icon: string; + submenu?: CollapseMenuProps[]; + depth?: number; +}; + +const isPathActive = (pathname: string, link?: string) => { + if (!link) return false; + + const splittedPathname = pathname.split('/'); + const splittedLink = link.split('/'); + + return splittedPathname.every((pathnameChunk, idx) => { + return pathnameChunk === splittedLink[idx]; + }); +}; + +const isCollapseActive = (pathname: string, link?: string) => { + if (!link) return false; + + return pathname === link || pathname.startsWith(link); +}; + +const CollapseMenu = ({ + title, + link, + icon, + submenu, + depth = 0, +}: CollapseMenuProps) => { + const pathname = usePathname(); + const [open, setOpen] = useState(isCollapseActive(pathname, link)); + + const menuCollapseTitle = ( +
+
+ + {title} +
+ + +
+ ); + + const paddingLeftDepth = `pl-${4 * (depth + 1)}`; + + return ( + + + {submenu?.map((item, idx) => { + const hasSubmenu = item.submenu && item.submenu.length > 0; + + if (!hasSubmenu) { + return ( + + ); + } + + return ( + + ); + })} + + + ); +}; + +const MainDrawerMenu = () => { + const pathname = usePathname(); + + return ( + + {MAIN_DRAWER_LINKS.map((item, idx) => { + const hasSubmenu = item.submenu && item.submenu.length > 0; + + if (!hasSubmenu) { + return ( + + ); + } + + return ( + + ); + })} + + ); +}; + +const MainDrawerContent = () => { + return ( +
+
+ MBU Logo + +

LTI ERP

+
+ + +
+ ); +}; +const MainDrawer = ({ + children, +}: Readonly<{ + children: React.ReactNode; +}>) => { + const { mainDrawerOpen, setMainDrawerOpen } = useUiStore(); + const pathname = usePathname(); + + const pageTitle = MAIN_DRAWER_LINKS.find((item) => + pathname.startsWith(item.link) + )?.title; + + const toggleSidebar = () => { + setMainDrawerOpen(!mainDrawerOpen); + }; + + return ( + } + > +
+ + + {children} +
+
+ ); +}; + +export default MainDrawer;