shoc-frontend-new/src/config/menu.ts

90 lines
2.3 KiB
TypeScript

import type { LucideIcon } from "lucide-react";
import {
Building2,
ClipboardList,
DollarSign,
FileText,
LayoutDashboard,
MapPin,
Settings,
UserRound,
Wrench,
} from "lucide-react";
import { isAdminUser } from "@/lib/auth/user-utils";
export type NavItemDef = {
label: string;
icon: LucideIcon;
path: string;
badge?: number;
};
export type NavGroup = {
title: string;
items: NavItemDef[];
visible?: (userRoles: string | null | undefined) => boolean;
};
export const SIDEBAR_WIDTH = 244;
export const SIDEBAR_COLLAPSED_WIDTH = 76;
export const accountNavItem: NavItemDef = {
label: "My Account",
icon: Settings,
path: "/account",
};
export function getSidebarWidth(collapsed: boolean): number {
return collapsed ? SIDEBAR_COLLAPSED_WIDTH : SIDEBAR_WIDTH;
}
export const navGroups: NavGroup[] = [
{
title: "OPERATIONS",
items: [
{ label: "Work Orders", icon: ClipboardList, path: "/workorders" },
{ label: "Dashboard", icon: LayoutDashboard, path: "/" },
],
},
{
title: "DATA MANAGEMENT",
items: [
{ label: "Vendors", icon: Building2, path: "/vendors" },
{ label: "Sites", icon: MapPin, path: "/locations" },
{ label: "Services", icon: Wrench, path: "/services" },
{ label: "Completion Docs", icon: FileText, path: "/completion-docs" },
],
},
{
title: "TEAM",
visible: isAdminUser,
items: [{ label: "Team Members", icon: UserRound, path: "/employees" }],
},
{
title: "APPROVALS",
visible: isAdminUser,
items: [{ label: "Uplift Approvals", icon: DollarSign, path: "/uplifts" }],
},
];
export function getVisibleNavGroups(userRoles: string | null | undefined): NavGroup[] {
return navGroups.filter((group) => group.visible == null || group.visible(userRoles));
}
export function getVisibleBadge(badge?: number): number | undefined {
return badge != null && badge > 0 ? badge : undefined;
}
function collectNavPaths(): string[] {
return [...navGroups.flatMap((group) => group.items), accountNavItem].map((item) => item.path);
}
export function getActiveNavPath(pathname: string): string | undefined {
return collectNavPaths()
.filter((path) =>
path === "/" ? pathname === path : pathname === path || pathname.startsWith(`${path}/`),
)
.sort((firstPath, secondPath) => secondPath.length - firstPath.length)[0];
}