{{#if framework == "nextjs"}} "use client"; {{/if}} import { ChevronRight, Clapperboard, Heart, Image, LayoutDashboard, LifeBuoy, List, MoreVertical, Package, Shield, Tag, Users, } from "lucide-react"; {{#if framework == "nextjs"}} import Link from "next/link"; import { usePathname } from "next/navigation"; {{else}} import { Link, useLocation } from "react-router"; {{/if}} import { Tag, Users, Shield, LifeBuoy, List, Heart, Image, Clapperboard, } as const; export type IconMapKey = keyof typeof iconMap; export interface DashboardSidebarMenuItem { title: string; url: string; icon: IconMapKey; } export interface DashboardSidebarMenuGroup { label: string; items: DashboardSidebarMenuItem[]; } export interface DashboardSidebarProps { menu: DashboardSidebarMenuItem[] | DashboardSidebarMenuGroup[]; user: { id?: string; name?: string | null; email?: string | null; image?: string | null; role?: string; }; } export function DashboardSidebar({ menu = [], user }: DashboardSidebarProps) { {{#if framework == "nextjs"}} const pathname = usePathname(); {{else}} const { pathname } = useLocation(); {{/if}} const { toggleSidebar } = useSidebar(); const { mutate: logout, isPending } = useLogoutMutation(); const isActive = (url: string) => url === "/dashboard" || url === "/dashboard/admin" ? pathname === url : pathname.startsWith(url); const groupedMenu = ( menu.length > 0 && "items" in menu[0] ? (menu as DashboardSidebarMenuGroup[]) : [{ label: "Navigation", items: menu as DashboardSidebarMenuItem[] }] ).filter((group) => group.items.length > 0); return (
{{#if framework == "nextjs"}} StackKit {{else}} StackKit {{/if}}
{groupedMenu.map((group) => ( {group.label} {group.items.map((item) => { const Icon = iconMap[item.icon] ?? LayoutDashboard; const active = isActive(item.url); return ( {{#if framework == "nextjs"}} { if ( typeof window !== "undefined" && window.innerWidth < 768 ) { toggleSidebar(); } }} > {item.title} {{else}} { if ( typeof window !== "undefined" && window.innerWidth < 768 ) { toggleSidebar(); } }} > {item.title} {{/if}} ); })} ))} {user?.name?.toUpperCase().charAt(0) || "U"} {user?.name || "Admin"} {user?.email} Account {{#if framework == "nextjs"}} Profile {{else}} Profile {{/if}} logout()}> Log out
); } export default DashboardSidebar;