Bump version to 2.0.0 (breaking: reporter, supervisor and capa_owner merged into ssa, routes moved under /ssa). Add 2.0.0 release notes to docs/CHANGELOG.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
136 lines
5.2 KiB
TypeScript
136 lines
5.2 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useRef } from 'react'
|
|
import Link from 'next/link'
|
|
import { usePathname, useRouter } from 'next/navigation'
|
|
import { LogOut, Search, ShieldCheck, User } from 'lucide-react'
|
|
import { NotificationBell } from '@/components/notifications/bell'
|
|
import { Avatar } from '@/components/ui/avatar'
|
|
import { cx } from '@/components/ui/cx'
|
|
import { MobileShell } from './mobile-shell'
|
|
import { isActivePath, navItemsFor, searchHrefFor } from './nav-items'
|
|
|
|
const ITEM = 'flex items-center gap-2.5 h-8 px-2.5 rounded-md text-[13px] w-full text-left'
|
|
const ITEM_ACTIVE = 'bg-surface text-ink font-semibold shadow-chip'
|
|
const ITEM_IDLE = 'text-ink-3 hover:bg-rule-2'
|
|
|
|
export function AppShell({
|
|
role,
|
|
userName,
|
|
children,
|
|
}: {
|
|
role: string
|
|
userName: string
|
|
children: React.ReactNode
|
|
}) {
|
|
const pathname = usePathname()
|
|
const router = useRouter()
|
|
const items = navItemsFor(role)
|
|
const searchHref = searchHrefFor(role)
|
|
const searchRef = useRef<HTMLInputElement>(null)
|
|
const displayName = userName || 'User'
|
|
const roleLabel = role.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase())
|
|
|
|
useEffect(() => {
|
|
const onKey = (e: KeyboardEvent) => {
|
|
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') {
|
|
e.preventDefault()
|
|
searchRef.current?.focus()
|
|
}
|
|
}
|
|
document.addEventListener('keydown', onKey)
|
|
return () => document.removeEventListener('keydown', onKey)
|
|
}, [])
|
|
|
|
const logout = async () => {
|
|
await fetch('/api/auth/logout', { method: 'POST' })
|
|
router.push('/login')
|
|
router.refresh()
|
|
}
|
|
|
|
const accountActive = pathname === '/account'
|
|
|
|
return (
|
|
<div className="min-h-screen bg-ground">
|
|
<header className="hidden md:flex fixed top-0 left-0 right-0 z-40 h-14 items-center justify-between gap-4 pl-5 pr-4 bg-topbar">
|
|
<div className="flex items-center gap-2.5 w-56">
|
|
<span className="inline-grid place-items-center w-7 h-7 rounded-md bg-accent text-white">
|
|
<ShieldCheck size={16} strokeWidth={2} aria-hidden />
|
|
</span>
|
|
<span className="text-[15px] font-[650] text-white tracking-tight">IMS</span>
|
|
<span className="text-[13px] text-neutral-400">Setia HSE</span>
|
|
</div>
|
|
|
|
{searchHref ? (
|
|
<form action={searchHref} method="get" className="flex-1 max-w-[520px]">
|
|
<label className="flex items-center gap-2 h-[34px] px-2.5 rounded-[10px] bg-ink-2 shadow-[inset_0_0_0_1px_var(--color-ink-3)] text-neutral-400 text-[13px]">
|
|
<Search size={16} strokeWidth={2} aria-hidden />
|
|
<input
|
|
ref={searchRef}
|
|
name="q"
|
|
type="search"
|
|
placeholder="Search incidents"
|
|
aria-label="Search incidents"
|
|
className="flex-1 bg-transparent text-white placeholder:text-neutral-400 outline-none"
|
|
/>
|
|
<kbd className="font-mono text-[11px] text-neutral-400">⌘K</kbd>
|
|
</label>
|
|
</form>
|
|
) : (
|
|
<div className="flex-1" />
|
|
)}
|
|
|
|
<div className="flex items-center gap-2 w-56 justify-end">
|
|
<NotificationBell />
|
|
<div className="flex items-center gap-2 py-1 pl-1 pr-2.5 rounded-md bg-ink-2">
|
|
<Avatar name={displayName} />
|
|
<span className="text-[13px] text-rule-2 max-w-32 truncate">{displayName}</span>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<aside className="hidden md:flex fixed top-14 left-0 bottom-0 z-30 w-60 flex-col gap-0.5 p-3 bg-rule border-r border-rule-2">
|
|
{items.map(item => {
|
|
const active = isActivePath(item.href, pathname)
|
|
const Icon = item.icon
|
|
return (
|
|
<Link
|
|
key={item.href}
|
|
href={item.href}
|
|
aria-current={active ? 'page' : undefined}
|
|
className={cx(ITEM, active ? ITEM_ACTIVE : ITEM_IDLE)}
|
|
>
|
|
<Icon size={16} strokeWidth={2} className={active ? 'text-accent' : 'text-ink-3'} aria-hidden />
|
|
<span className="flex-1">{item.label}</span>
|
|
</Link>
|
|
)
|
|
})}
|
|
<div className="flex-1" />
|
|
<div className="flex flex-col gap-0.5 pt-2.5 border-t border-rule-2">
|
|
<div className="px-2.5 pb-1">
|
|
<p className="text-[13px] font-semibold truncate">{displayName}</p>
|
|
<p className="text-xs text-muted truncate">{roleLabel}</p>
|
|
</div>
|
|
<Link
|
|
href="/account"
|
|
aria-current={accountActive ? 'page' : undefined}
|
|
className={cx(ITEM, accountActive ? ITEM_ACTIVE : ITEM_IDLE)}
|
|
>
|
|
<User size={16} strokeWidth={2} className={accountActive ? 'text-accent' : 'text-ink-3'} aria-hidden />
|
|
Account
|
|
</Link>
|
|
<button type="button" onClick={logout} className={cx(ITEM, ITEM_IDLE, 'cursor-pointer')}>
|
|
<LogOut size={16} strokeWidth={2} className="text-ink-3" aria-hidden />
|
|
Log out
|
|
</button>
|
|
<p className="px-2.5 pt-2 text-xs text-faint">v2.0.0</p>
|
|
</div>
|
|
</aside>
|
|
|
|
<main className="md:pl-60 md:pt-14 pb-16 md:pb-0">{children}</main>
|
|
|
|
<MobileShell items={items} pathname={pathname} onLogout={logout} />
|
|
</div>
|
|
)
|
|
}
|