import { Activity, LayoutDashboard, ListChecks, PackageSearch } from "lucide-react"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { NavLink, Outlet, useNavigate } from "react-router-dom"; import { useAdminAuth } from "../features/admin/AdminAuthContext"; import "./AdminLayout.scss"; /** * One entry in the admin sidebar's nav. `key` maps to `admin.nav.` in * the locale file — adding a section is one array entry plus one locale key. * Paths are absolute under `/admin` (the admin route group lives inside * `apps/web`'s `App.tsx`, mounted at `/admin`). */ const NAV_ITEMS = [ { to: "/admin", key: "dashboard", Icon: LayoutDashboard, end: true }, { to: "/admin/monitoring", key: "monitoring", Icon: Activity, end: false }, { to: "/admin/corrections", key: "corrections", Icon: ListChecks, end: false }, { to: "/admin/catalogue", key: "catalog", Icon: PackageSearch, end: false }, ] as const; /** * Shell for every authenticated admin page: a fixed sidebar (brand, section * nav, the signed-in admin's name + logout) plus a main area rendering the * matched child route via ``. Mounted once as the parent of the * whole `RequireAdmin`-guarded route group (see `App.tsx`), so `admin` is * guaranteed non-null here. */ export function AdminLayout() { const { t } = useTranslation(); const { admin, logout } = useAdminAuth(); const navigate = useNavigate(); const [isLoggingOut, setIsLoggingOut] = useState(false); async function handleLogout() { setIsLoggingOut(true); try { await logout(); void navigate("/admin/login"); } catch { // Even if the network call failed, the local session state was // cleared optimistically enough for the guard to bounce to /login; // nothing useful to show the operator here. void navigate("/admin/login"); } } return (
); }