The UI worked but read as an operator console: no public face, no way to describe or sell the thing, and no account surface beyond the node list. This adds the missing halves and reorganises what was already there around the incident, which is the unit of value the rest of the pipeline is built to produce. A shared design system replaces per-page styling: components/ui (Button, Card, Badge, EmptyState, Skeleton, PageHeader), a type scale and shadow set in the Tailwind config, and light-mode tokens in globals.css. The existing html:not(.dark) remap mechanism is extended rather than replaced -- a parallel theming system would have been two sources of truth for the same colours. Public marketing pages (/, /features, /pricing, /faq) load without a session. middleware.ts gained a PUBLIC_PATHS allowlist to permit that; it remains a UX redirect and is still NOT an authorisation boundary, which the comment there says explicitly. Real enforcement is unchanged and still lives server-side in c2-core's auth.py. Chrome switching is done by pathname in ChromeSwitcher instead of by route group, because a route group would have collided on / and forced most of app/ to move for no behavioural gain. Billing and API keys ship as typed stubs, not integrations. lib/billing.ts and lib/apiKeys.ts define the data model and the screens consume it, but every mutating call throws with a message naming the backend route that has to exist first, and the sample data is labelled as sample. Nothing here can charge anyone or mint a real credential -- picking a payment processor and holding its keys is a decision for a human, and a half-wired checkout is worse than an obviously absent one. The severity work from the c2-core change lands here too. severity is now a filter and sort dimension on the incident list rather than decoration, since a busy dispatch channel is only readable if you can collapse it to moderate and above. routine gets a muted treatment because it is the majority of traffic, legacy "unknown" still renders nothing, and TypeBadge handles the new "other" incident type. Severity rendering moved into lib/severity.tsx so the incident list, incident detail and call rows cannot drift apart. Deliberately not touched: calls, map, alerts, nodes, systems, tokens, trips and admin. They already share the palette and stay coherent, and rewriting them would have buried the parts that actually needed to change. No colour tokens were renamed, so nothing regressed there. Verified with tsc --noEmit (npm run typecheck), clean. No runtime verification was possible and none was done. No new environment variables.
189 lines
7.1 KiB
TypeScript
189 lines
7.1 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import Link from "next/link";
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
import { useUnconfiguredNodes } from "@/lib/useNodes";
|
|
import { useUnacknowledgedAlerts } from "@/lib/useAlerts";
|
|
import { useAuth } from "@/components/AuthProvider";
|
|
import { useTheme } from "@/components/ThemeProvider";
|
|
|
|
// Links visible to all authenticated roles (viewer+)
|
|
const viewerLinks = [
|
|
{ href: "/dashboard", label: "Dashboard" },
|
|
{ href: "/calls", label: "Calls" },
|
|
{ href: "/incidents", label: "Incidents" },
|
|
{ href: "/map", label: "Map" },
|
|
{ href: "/alerts", label: "Alerts" },
|
|
{ href: "/trips", label: "Trips" },
|
|
];
|
|
|
|
// Additional links for operators and admins
|
|
const operatorLinks = [
|
|
{ href: "/nodes", label: "Nodes" },
|
|
{ href: "/systems", label: "Systems" },
|
|
{ href: "/tokens", label: "Tokens" },
|
|
];
|
|
|
|
// Admin-only links
|
|
const adminLinks = [
|
|
{ href: "/admin", label: "Admin" },
|
|
{ href: "/settings", label: "Settings" },
|
|
];
|
|
|
|
function SunIcon() {
|
|
return (
|
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
<circle cx="12" cy="12" r="5"/>
|
|
<line x1="12" y1="1" x2="12" y2="3"/>
|
|
<line x1="12" y1="21" x2="12" y2="23"/>
|
|
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
|
|
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
|
|
<line x1="1" y1="12" x2="3" y2="12"/>
|
|
<line x1="21" y1="12" x2="23" y2="12"/>
|
|
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
|
|
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
|
|
</svg>
|
|
);
|
|
}
|
|
|
|
function MoonIcon() {
|
|
return (
|
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
|
|
</svg>
|
|
);
|
|
}
|
|
|
|
export function Nav() {
|
|
const { user, isAdmin, isOperator } = useAuth();
|
|
const pathname = usePathname();
|
|
const router = useRouter();
|
|
const { nodes: pending } = useUnconfiguredNodes();
|
|
const unackedAlerts = useUnacknowledgedAlerts();
|
|
const { theme, toggle } = useTheme();
|
|
const [mobileOpen, setMobileOpen] = useState(false);
|
|
|
|
if (!user) return null;
|
|
|
|
const allLinks = [
|
|
...viewerLinks,
|
|
...(isAdmin || isOperator ? operatorLinks : []),
|
|
...(isAdmin ? adminLinks : []),
|
|
];
|
|
|
|
function navLinkClass(href: string) {
|
|
return `text-sm font-mono transition-colors shrink-0 ${
|
|
pathname.startsWith(href) ? "text-white" : "text-gray-500 hover:text-gray-300"
|
|
}`;
|
|
}
|
|
|
|
return (
|
|
<nav className="sticky top-0 z-40 border-b border-gray-800 bg-gray-950/95 backdrop-blur">
|
|
{/* Main bar */}
|
|
<div className="px-4 md:px-6 py-3 flex items-center gap-4 md:gap-6">
|
|
<span className="font-mono font-bold text-white tracking-tight shrink-0">DRB</span>
|
|
|
|
{/* Desktop links */}
|
|
<div className="hidden md:flex items-center gap-6 overflow-x-auto">
|
|
{allLinks.map(({ href, label }) => (
|
|
<Link key={href} href={href} className={navLinkClass(href)}>
|
|
{label}
|
|
{label === "Nodes" && pending.length > 0 && (
|
|
<span className="ml-1.5 inline-flex items-center justify-center w-4 h-4 rounded-full bg-yellow-500 text-gray-950 text-xs font-bold">
|
|
{pending.length}
|
|
</span>
|
|
)}
|
|
{label === "Alerts" && unackedAlerts.length > 0 && (
|
|
<span className="ml-1.5 inline-flex items-center justify-center min-w-[1rem] h-4 rounded-full bg-red-600 text-white text-xs font-bold px-1">
|
|
{unackedAlerts.length}
|
|
</span>
|
|
)}
|
|
</Link>
|
|
))}
|
|
</div>
|
|
|
|
<div className="ml-auto flex items-center gap-3 shrink-0">
|
|
{/* Theme toggle */}
|
|
<button
|
|
onClick={toggle}
|
|
className="text-gray-500 hover:text-gray-300 transition-colors"
|
|
title={theme === "dark" ? "Switch to light mode" : "Switch to dark mode"}
|
|
>
|
|
{theme === "dark" ? <SunIcon /> : <MoonIcon />}
|
|
</button>
|
|
|
|
{/* Profile avatar (desktop) */}
|
|
<button
|
|
onClick={() => router.push("/profile")}
|
|
className={`hidden md:flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold transition-colors ${
|
|
pathname.startsWith("/profile")
|
|
? "bg-indigo-600 text-white"
|
|
: "bg-gray-800 text-gray-300 hover:bg-gray-700"
|
|
}`}
|
|
title="Profile"
|
|
>
|
|
{(user?.displayName || user?.email || "?")[0].toUpperCase()}
|
|
</button>
|
|
|
|
{/* Hamburger (mobile) */}
|
|
<button
|
|
onClick={() => setMobileOpen((v) => !v)}
|
|
className="md:hidden text-gray-400 hover:text-gray-200 transition-colors p-1"
|
|
aria-label="Toggle menu"
|
|
>
|
|
{mobileOpen ? (
|
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round">
|
|
<line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/>
|
|
</svg>
|
|
) : (
|
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round">
|
|
<line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="18" x2="21" y2="18"/>
|
|
</svg>
|
|
)}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Mobile drawer */}
|
|
{mobileOpen && (
|
|
<div className="md:hidden border-t border-gray-800 bg-gray-950 px-4 py-3 flex flex-col gap-1">
|
|
{allLinks.map(({ href, label }) => (
|
|
<Link
|
|
key={href}
|
|
href={href}
|
|
onClick={() => setMobileOpen(false)}
|
|
className={`py-2 text-sm font-mono transition-colors flex items-center gap-2 ${
|
|
pathname.startsWith(href) ? "text-white" : "text-gray-500"
|
|
}`}
|
|
>
|
|
{label}
|
|
{label === "Nodes" && pending.length > 0 && (
|
|
<span className="inline-flex items-center justify-center w-4 h-4 rounded-full bg-yellow-500 text-gray-950 text-xs font-bold">
|
|
{pending.length}
|
|
</span>
|
|
)}
|
|
{label === "Alerts" && unackedAlerts.length > 0 && (
|
|
<span className="inline-flex items-center justify-center min-w-[1rem] h-4 rounded-full bg-red-600 text-white text-xs font-bold px-1">
|
|
{unackedAlerts.length}
|
|
</span>
|
|
)}
|
|
</Link>
|
|
))}
|
|
<div className="border-t border-gray-800 pt-3 mt-1">
|
|
<Link
|
|
href="/profile"
|
|
onClick={() => setMobileOpen(false)}
|
|
className={`py-2 text-sm font-mono transition-colors flex items-center gap-2 ${
|
|
pathname.startsWith("/profile") ? "text-white" : "text-gray-500"
|
|
}`}
|
|
>
|
|
Profile
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</nav>
|
|
);
|
|
}
|