/* eslint-disable @typescript-eslint/prefer-find */ import ChevronDownIcon from '@heroicons/react/24/outline/ChevronDownIcon' import { useEffect, useState } from 'react' import { Link, useLocation } from 'react-router-dom' import type { Route } from './SideBar' function SidebarSubmenu({ submenu, name, icon, }: { path: string icon: React.JSX.Element name: string submenu?: Route[] }) { const location = useLocation() const [isExpanded, setIsExpanded] = useState(false) /** Open Submenu list if path found in routes, this is for directly loading submenu routes first time */ useEffect(() => { if ( submenu?.filter((m) => { return m.path === location.pathname })[0] ) setIsExpanded(true) // eslint-disable-next-line react-hooks/exhaustive-deps }, []) return (
{/** Route header */}
{ setIsExpanded(!isExpanded) }} > {icon} {name}
{/** Submenu list */}
) } export default SidebarSubmenu