60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import {
|
|
AlignLeft,
|
|
CircleCheck,
|
|
ClipboardList,
|
|
LayoutDashboard,
|
|
Plus,
|
|
Settings,
|
|
Users,
|
|
type LucideIcon,
|
|
} from 'lucide-react'
|
|
|
|
export interface NavItem {
|
|
label: string
|
|
href: string
|
|
icon: LucideIcon
|
|
}
|
|
|
|
const NAV_ITEMS: Record<string, NavItem[]> = {
|
|
reporter: [
|
|
{ label: 'My Reports', href: '/reporter', icon: ClipboardList },
|
|
{ label: 'New Incident', href: '/report', icon: Plus },
|
|
],
|
|
supervisor: [
|
|
{ label: 'Overview', href: '/supervisor', icon: AlignLeft },
|
|
{ label: 'Incidents', href: '/supervisor/incidents', icon: ClipboardList },
|
|
],
|
|
hse: [
|
|
{ label: 'Dashboard', href: '/hse/dashboard', icon: LayoutDashboard },
|
|
{ label: 'Incidents', href: '/hse/incidents', icon: ClipboardList },
|
|
{ label: 'CAPA', href: '/hse/capa', icon: CircleCheck },
|
|
{ label: 'Settings', href: '/hse/settings', icon: Settings },
|
|
],
|
|
management: [{ label: 'Dashboard', href: '/management', icon: LayoutDashboard }],
|
|
capa_owner: [{ label: 'My CAPAs', href: '/capa-owner', icon: CircleCheck }],
|
|
admin: [
|
|
{ label: 'Admin', href: '/admin', icon: Users },
|
|
{ label: 'Dashboard', href: '/hse/dashboard', icon: LayoutDashboard },
|
|
{ label: 'Incidents', href: '/hse/incidents', icon: ClipboardList },
|
|
{ label: 'CAPA', href: '/hse/capa', icon: CircleCheck },
|
|
{ label: 'Management', href: '/management', icon: AlignLeft },
|
|
{ label: 'Settings', href: '/hse/settings', icon: Settings },
|
|
],
|
|
}
|
|
|
|
const EXACT_ROOTS = ['/reporter', '/supervisor', '/management', '/capa-owner', '/admin', '/report', '/account']
|
|
|
|
export function navItemsFor(role: string): NavItem[] {
|
|
return NAV_ITEMS[role] ?? NAV_ITEMS.reporter
|
|
}
|
|
|
|
export function isActivePath(href: string, pathname: string): boolean {
|
|
return EXACT_ROOTS.includes(href) ? pathname === href : pathname.startsWith(href)
|
|
}
|
|
|
|
export function searchHrefFor(role: string): string | null {
|
|
if (role === 'hse' || role === 'admin') return '/hse/incidents'
|
|
if (role === 'supervisor') return '/supervisor/incidents'
|
|
return null
|
|
}
|