|
|
|
@@ -2,6 +2,17 @@
|
|
|
|
|
|
|
|
|
|
import Link from 'next/link'
|
|
|
|
|
import { usePathname, useRouter } from 'next/navigation'
|
|
|
|
|
import {
|
|
|
|
|
AlignLeft,
|
|
|
|
|
CircleCheck,
|
|
|
|
|
ClipboardList,
|
|
|
|
|
LayoutDashboard,
|
|
|
|
|
LogOut,
|
|
|
|
|
Plus,
|
|
|
|
|
Settings,
|
|
|
|
|
User,
|
|
|
|
|
Users,
|
|
|
|
|
} from 'lucide-react'
|
|
|
|
|
import { NotificationBell } from '@/components/notifications/bell'
|
|
|
|
|
|
|
|
|
|
interface NavItem {
|
|
|
|
@@ -16,52 +27,15 @@ interface SidebarProps {
|
|
|
|
|
userEmail: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const IconGrid = () => (
|
|
|
|
|
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16M4 18h7" />
|
|
|
|
|
</svg>
|
|
|
|
|
)
|
|
|
|
|
const IconList = () => (
|
|
|
|
|
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" />
|
|
|
|
|
</svg>
|
|
|
|
|
)
|
|
|
|
|
const IconCheck = () => (
|
|
|
|
|
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
|
|
|
</svg>
|
|
|
|
|
)
|
|
|
|
|
const IconChart = () => (
|
|
|
|
|
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
|
|
|
|
|
</svg>
|
|
|
|
|
)
|
|
|
|
|
const IconSettings = () => (
|
|
|
|
|
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
|
|
|
|
|
</svg>
|
|
|
|
|
)
|
|
|
|
|
const IconUsers = () => (
|
|
|
|
|
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z" />
|
|
|
|
|
</svg>
|
|
|
|
|
)
|
|
|
|
|
const IconPlus = () => (
|
|
|
|
|
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4v16m8-8H4" />
|
|
|
|
|
</svg>
|
|
|
|
|
)
|
|
|
|
|
const IconLogout = () => (
|
|
|
|
|
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1" />
|
|
|
|
|
</svg>
|
|
|
|
|
)
|
|
|
|
|
const IconUser = () => (
|
|
|
|
|
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
|
|
|
|
|
</svg>
|
|
|
|
|
)
|
|
|
|
|
const IconGrid = () => <AlignLeft size={20} aria-hidden />
|
|
|
|
|
const IconList = () => <ClipboardList size={20} aria-hidden />
|
|
|
|
|
const IconCheck = () => <CircleCheck size={20} aria-hidden />
|
|
|
|
|
const IconChart = () => <LayoutDashboard size={20} aria-hidden />
|
|
|
|
|
const IconSettings = () => <Settings size={20} aria-hidden />
|
|
|
|
|
const IconUsers = () => <Users size={20} aria-hidden />
|
|
|
|
|
const IconPlus = () => <Plus size={20} aria-hidden />
|
|
|
|
|
const IconLogout = () => <LogOut size={16} aria-hidden />
|
|
|
|
|
const IconUser = () => <User size={16} aria-hidden />
|
|
|
|
|
|
|
|
|
|
const NAV_ITEMS: Record<string, NavItem[]> = {
|
|
|
|
|
reporter: [
|
|
|
|
@@ -94,6 +68,12 @@ const NAV_ITEMS: Record<string, NavItem[]> = {
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const EXACT_ROOTS = ['/reporter', '/supervisor', '/management', '/capa-owner', '/admin', '/report', '/account']
|
|
|
|
|
|
|
|
|
|
function isActivePath(href: string, pathname: string): boolean {
|
|
|
|
|
return EXACT_ROOTS.includes(href) ? pathname === href : pathname.startsWith(href)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initials(name: string): string {
|
|
|
|
|
return name
|
|
|
|
|
.split(' ')
|
|
|
|
@@ -107,23 +87,19 @@ function useNavItems(role: string): NavItem[] {
|
|
|
|
|
return NAV_ITEMS[role] ?? NAV_ITEMS.reporter
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function NavLink({ item, pathname }: { item: NavItem; pathname: string }) {
|
|
|
|
|
// Exact match for root-level single-page roles, prefix match otherwise
|
|
|
|
|
const exactRoots = ['/reporter', '/supervisor', '/management', '/capa-owner', '/admin', '/report', '/account']
|
|
|
|
|
const isActive = exactRoots.includes(item.href)
|
|
|
|
|
? pathname === item.href
|
|
|
|
|
: pathname.startsWith(item.href)
|
|
|
|
|
const LINK_BASE = 'flex items-center gap-3 px-3 py-2 text-sm border-l-2 transition-colors'
|
|
|
|
|
const LINK_ACTIVE = 'border-accent text-accent-700 font-extrabold bg-accent-100/50'
|
|
|
|
|
const LINK_IDLE = 'border-transparent text-ink/70 font-medium hover:bg-ink/7 hover:text-ink'
|
|
|
|
|
|
|
|
|
|
function NavLink({ item, pathname }: { item: NavItem; pathname: string }) {
|
|
|
|
|
const active = isActivePath(item.href, pathname)
|
|
|
|
|
return (
|
|
|
|
|
<Link
|
|
|
|
|
href={item.href}
|
|
|
|
|
className={`flex items-center gap-3 px-3 py-2 text-sm font-medium transition-colors ${
|
|
|
|
|
isActive
|
|
|
|
|
? 'bg-blue-50 text-blue-700'
|
|
|
|
|
: 'text-gray-600 hover:bg-gray-100 hover:text-gray-900'
|
|
|
|
|
}`}
|
|
|
|
|
aria-current={active ? 'page' : undefined}
|
|
|
|
|
className={`${LINK_BASE} ${active ? LINK_ACTIVE : LINK_IDLE}`}
|
|
|
|
|
>
|
|
|
|
|
<span className={isActive ? 'text-blue-600' : 'text-gray-400'}>{item.icon}</span>
|
|
|
|
|
<span className={active ? 'text-accent-700' : 'text-ink/50'}>{item.icon}</span>
|
|
|
|
|
{item.label}
|
|
|
|
|
</Link>
|
|
|
|
|
)
|
|
|
|
@@ -143,74 +119,67 @@ export function Sidebar({ role, userName, userEmail }: SidebarProps) {
|
|
|
|
|
|
|
|
|
|
const displayName = userName || userEmail || 'User'
|
|
|
|
|
const roleLabel = role.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase())
|
|
|
|
|
const accountActive = pathname === '/account'
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{/* Desktop sidebar */}
|
|
|
|
|
<aside className="hidden sm:flex fixed left-0 top-0 h-full w-60 bg-surface border-r border-divider flex-col z-40">
|
|
|
|
|
{/* Header */}
|
|
|
|
|
<div className="flex items-center justify-between px-4 py-4 border-b border-divider">
|
|
|
|
|
<span className="text-base font-bold text-gray-900 tracking-tight">IMS</span>
|
|
|
|
|
<aside className="hidden sm:flex fixed left-0 top-0 h-full w-60 bg-ground border-r-2 border-divider flex-col z-40">
|
|
|
|
|
<div className="flex items-center justify-between px-4 py-4 border-b-2 border-divider">
|
|
|
|
|
<span className="text-lg font-extrabold tracking-tight text-ink">IMS</span>
|
|
|
|
|
<NotificationBell />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Nav */}
|
|
|
|
|
<nav className="flex-1 overflow-y-auto px-3 py-3 space-y-1">
|
|
|
|
|
<nav className="flex-1 overflow-y-auto py-3">
|
|
|
|
|
{items.map(item => (
|
|
|
|
|
<NavLink key={item.href} item={item} pathname={pathname} />
|
|
|
|
|
))}
|
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
|
|
{/* User + logout */}
|
|
|
|
|
<div className="border-t border-divider px-3 py-3">
|
|
|
|
|
<div className="flex items-center gap-2 px-2 py-2 mb-1">
|
|
|
|
|
<div className="w-8 h-8 rounded-full bg-blue-600 flex items-center justify-center text-white text-xs font-bold flex-shrink-0">
|
|
|
|
|
<div className="border-t-2 border-divider py-3">
|
|
|
|
|
<div className="flex items-center gap-2 px-4 py-2 mb-1">
|
|
|
|
|
<div className="w-8 h-8 rounded-full bg-accent flex items-center justify-center text-ground text-xs font-extrabold flex-shrink-0">
|
|
|
|
|
{initials(displayName)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="min-w-0">
|
|
|
|
|
<p className="text-sm font-medium text-gray-900 truncate">{displayName}</p>
|
|
|
|
|
<p className="text-xs text-gray-500 truncate">{roleLabel}</p>
|
|
|
|
|
<p className="text-sm font-extrabold text-ink truncate">{displayName}</p>
|
|
|
|
|
<p className="text-xs text-ink/60 truncate">{roleLabel}</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<Link
|
|
|
|
|
href="/account"
|
|
|
|
|
className={`flex items-center gap-2 w-full px-3 py-2 text-sm transition-colors ${
|
|
|
|
|
pathname === '/account'
|
|
|
|
|
? 'bg-blue-50 text-blue-700'
|
|
|
|
|
: 'text-gray-600 hover:bg-gray-100 hover:text-gray-900'
|
|
|
|
|
}`}
|
|
|
|
|
aria-current={accountActive ? 'page' : undefined}
|
|
|
|
|
className={`${LINK_BASE} ${accountActive ? LINK_ACTIVE : LINK_IDLE}`}
|
|
|
|
|
>
|
|
|
|
|
<span className={pathname === '/account' ? 'text-blue-600' : 'text-gray-400'}>
|
|
|
|
|
<span className={accountActive ? 'text-accent-700' : 'text-ink/50'}>
|
|
|
|
|
<IconUser />
|
|
|
|
|
</span>
|
|
|
|
|
Account
|
|
|
|
|
</Link>
|
|
|
|
|
<button
|
|
|
|
|
onClick={logout}
|
|
|
|
|
className="flex items-center gap-2 w-full px-3 py-2 text-sm text-gray-600 hover:bg-gray-100 hover:text-gray-900 transition-colors"
|
|
|
|
|
className={`${LINK_BASE} ${LINK_IDLE} w-full text-left cursor-pointer`}
|
|
|
|
|
>
|
|
|
|
|
<IconLogout />
|
|
|
|
|
<span className="text-ink/50"><IconLogout /></span>
|
|
|
|
|
Logout
|
|
|
|
|
</button>
|
|
|
|
|
<div className="mt-3 pt-3 border-t border-divider px-2 text-center">
|
|
|
|
|
<p className="text-xs text-gray-400">v1.2.2</p>
|
|
|
|
|
<div className="mt-3 pt-3 border-t border-divider px-4">
|
|
|
|
|
<p className="text-xs text-ink/50">v1.2.2</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</aside>
|
|
|
|
|
|
|
|
|
|
{/* Mobile bottom tab bar */}
|
|
|
|
|
<nav className="sm:hidden fixed bottom-0 left-0 right-0 bg-surface border-t border-divider flex z-40 safe-area-pb">
|
|
|
|
|
<nav className="sm:hidden fixed bottom-0 left-0 right-0 bg-ground border-t-2 border-divider flex z-40 safe-area-pb">
|
|
|
|
|
{mobileItems.map(item => {
|
|
|
|
|
const exactRoots = ['/reporter', '/supervisor', '/management', '/capa-owner', '/admin', '/report', '/account']
|
|
|
|
|
const isActive = exactRoots.includes(item.href)
|
|
|
|
|
? pathname === item.href
|
|
|
|
|
: pathname.startsWith(item.href)
|
|
|
|
|
const active = isActivePath(item.href, pathname)
|
|
|
|
|
return (
|
|
|
|
|
<Link
|
|
|
|
|
key={item.href}
|
|
|
|
|
href={item.href}
|
|
|
|
|
className={`flex-1 flex flex-col items-center gap-1 py-2 text-[10px] font-medium transition-colors ${
|
|
|
|
|
isActive ? 'text-blue-600' : 'text-gray-400'
|
|
|
|
|
aria-current={active ? 'page' : undefined}
|
|
|
|
|
className={`flex-1 flex flex-col items-center gap-1 py-2 text-[10px] font-extrabold transition-colors ${
|
|
|
|
|
active ? 'text-accent-700' : 'text-ink/55'
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
{item.icon}
|
|
|
|
@@ -218,11 +187,10 @@ export function Sidebar({ role, userName, userEmail }: SidebarProps) {
|
|
|
|
|
</Link>
|
|
|
|
|
)
|
|
|
|
|
})}
|
|
|
|
|
{/* Mobile logout in "More" slot if room */}
|
|
|
|
|
{items.length <= 4 && (
|
|
|
|
|
<button
|
|
|
|
|
onClick={logout}
|
|
|
|
|
className="flex-1 flex flex-col items-center gap-1 py-2 text-[10px] font-medium text-gray-400"
|
|
|
|
|
className="flex-1 flex flex-col items-center gap-1 py-2 text-[10px] font-extrabold text-ink/55 cursor-pointer"
|
|
|
|
|
>
|
|
|
|
|
<IconLogout />
|
|
|
|
|
<span className="leading-none">Logout</span>
|
|
|
|
|