"use client"; import { usePathname } from "next/navigation"; import Link from "next/link"; import { cn } from "@/lib/utils"; import { LayoutDashboard, FileText, Plus, CheckSquare, CreditCard, History, Receipt, Users, Ship, Building2, Briefcase, Store, Anchor, Package, Upload, MapPin, ShoppingCart, UserCircle, ShieldCheck, } from "lucide-react"; import type { Role } from "@prisma/client"; interface NavItem { href: string; label: string; icon: React.ElementType; roles?: Role[]; } const NAV_ITEMS: NavItem[] = [ { href: "/dashboard", label: "Dashboard", icon: LayoutDashboard }, { href: "/po/new", label: "New PO", icon: Plus, roles: ["TECHNICAL", "MANNING", "MANAGER", "SUPERUSER"] }, { href: "/my-orders", label: "Closed Purchase Orders", icon: FileText, roles: ["TECHNICAL", "MANNING", "MANAGER", "SUPERUSER"] }, { href: "/po/import", label: "Import PO", icon: Upload, roles: ["MANAGER", "SUPERUSER"] }, { href: "/approvals", label: "Approvals", icon: CheckSquare, roles: ["MANAGER", "SUPERUSER"] }, { href: "/payments", label: "Payments", icon: CreditCard, roles: ["ACCOUNTS"] }, { href: "/payments/history", label: "Payment History", icon: Receipt, roles: ["ACCOUNTS", "SUPERUSER"] }, { href: "/history", label: "History", icon: History, roles: ["MANAGER", "SUPERUSER", "AUDITOR", "ADMIN"] }, { href: "/profile", label: "My Profile", icon: UserCircle }, ]; const INVENTORY_ITEMS: NavItem[] = [ { href: "/inventory/items", label: "Items", icon: Package, roles: ["TECHNICAL", "MANNING", "SUPERUSER"] }, { href: "/inventory/vendors", label: "Vendors", icon: Store, roles: ["TECHNICAL", "MANNING", "SUPERUSER"] }, { href: "/inventory/cart", label: "Cart", icon: ShoppingCart, roles: ["TECHNICAL", "MANNING", "SUPERUSER", "MANAGER"] }, { href: "/admin/vendors", label: "Vendors", icon: Store, roles: ["MANAGER", "ACCOUNTS", "ADMIN"] }, { href: "/admin/products", label: "Items", icon: Package, roles: ["MANAGER", "ADMIN"] }, { href: "/admin/vessels", label: "Vessels", icon: Ship, roles: ["MANAGER", "ADMIN"] }, { href: "/admin/sites", label: "Sites", icon: MapPin, roles: ["MANAGER", "ADMIN"] }, ]; const ADMIN_ITEMS: NavItem[] = [ { href: "/admin/users", label: "Users", icon: Users }, { href: "/admin/superuser-requests", label: "SuperUser Requests", icon: ShieldCheck }, { href: "/admin/accounts", label: "Accounting Codes", icon: Building2 }, { href: "/admin/companies", label: "Companies", icon: Briefcase }, ]; export function Sidebar({ userRole }: { userRole: Role }) { const pathname = usePathname(); const isAdmin = userRole === "ADMIN"; const visible = NAV_ITEMS.filter( (item) => !item.roles || item.roles.includes(userRole) ); const visibleInventory = INVENTORY_ITEMS.filter( (item) => !item.roles || item.roles.includes(userRole) ); return ( ); } function NavLink({ item, pathname }: { item: NavItem; pathname: string }) { const isActive = pathname === item.href || pathname.startsWith(item.href + "/"); const Icon = item.icon; return ( {item.label} ); }