feat: React control panel; pending-card review workflow; auth-method audit

Frontend rewrite (frontend/, replacing backend/static/):
- Vite + TypeScript + React 19, React Router 7, zustand, TanStack Query 5
- dev: vite proxy /api -> :9000; prod: npm run build -> dist/, served by
  the backend with SPA fallback
- pages: Control (gun bays w/ scope+readiness-gated start/stop, relays),
  History (who/via/gun/when/duration/kWh audit), Cards (pending review,
  enrolled, rejected), Users (permission checkbox matrix)
- self-contained: fonts bundled, no CDN; light/dark; reduced-motion safe

Backend:
- learn mode removed: unknown cards are always refused and queued in
  pending_cards; admin approves (name + owner + gun restrictions in one
  step) or rejects (denied_cards, silent, un-rejectable); pending count
  rides /api/status as the notification signal
- sessions record the auth method (card tap vs in-app button) for audit
- GET /api/permissions: grantable-permission catalog driving the UI matrix
- SPA static serving with path-traversal guard; 503 hint when not built

Smoke test: 54 checks incl. approve/reject round-trips over a fake charge
point and method audit assertions.
This commit is contained in:
2026-07-11 20:52:20 +02:00
parent 56c9020d9f
commit 75869364b0
41 changed files with 4057 additions and 610 deletions
+34
View File
@@ -0,0 +1,34 @@
/** The signature element: a physical indicator lamp, like the ones on the
* charger cabinet itself. Tone encodes state everywhere in the app. */
export type LampTone = "off" | "green" | "amber" | "red" | "pulse";
const TONE_CLASS: Record<LampTone, string> = {
off: "lamp",
green: "lamp lamp--green",
amber: "lamp lamp--amber",
red: "lamp lamp--red",
pulse: "lamp lamp--green lamp--pulse",
};
export function Lamp({ tone, title }: { tone: LampTone; title?: string }) {
return <span className={TONE_CLASS[tone]} title={title} aria-hidden />;
}
export function statusTone(ocppStatus: string, charging: boolean): LampTone {
if (charging) return "pulse";
switch (ocppStatus) {
case "Charging":
return "pulse";
case "Preparing":
case "Finishing":
case "Reserved":
return "amber";
case "Available":
return "green";
case "Faulted":
case "Unavailable":
return "red";
default:
return "off";
}
}
+86
View File
@@ -0,0 +1,86 @@
import { NavLink, Outlet } from "react-router-dom";
import { api, isAdmin } from "../api";
import { useApp } from "../store";
import { useStatus } from "../queries";
const NAV = [
{ to: "/", label: "Control", exact: true },
{ to: "/history", label: "History" },
];
const ADMIN_NAV = [
{ to: "/cards", label: "Cards" },
{ to: "/users", label: "Users" },
];
export default function Layout() {
const { me, setMe, toasts } = useApp();
const { data: status } = useStatus();
const admin = me ? isAdmin(me.scopes) : false;
const pending = status?.pending_cards ?? 0;
async function logout() {
await api.post("/logout").catch(() => undefined);
setMe(null);
}
return (
<div className="shell">
<header className="topbar">
<div className="brand">
<svg viewBox="0 0 100 100" className="brand__mark" aria-hidden>
<path d="M55 12 L28 56 L46 56 L41 88 L72 42 L52 42 Z" />
</svg>
<div>
<span className="brand__name">Charge Control</span>
<span className="brand__sub">private CSMS</span>
</div>
</div>
<nav className="nav" aria-label="Main">
{NAV.map((n) => (
<NavLink key={n.to} to={n.to} end={n.exact} className="nav__link">
{n.label}
</NavLink>
))}
{admin &&
ADMIN_NAV.map((n) => (
<NavLink key={n.to} to={n.to} className="nav__link">
{n.label}
{n.to === "/cards" && pending > 0 && (
<span className="badge" title={`${pending} card(s) awaiting review`}>
{pending}
</span>
)}
</NavLink>
))}
</nav>
<div className="topbar__user">
<span className="topbar__who">{me?.name}</span>
<button className="btn btn--ghost btn--sm" onClick={logout}>
Log out
</button>
</div>
</header>
{admin && pending > 0 && (
<NavLink to="/cards" className="alert">
<span className="lamp lamp--amber" />
{pending === 1 ? "An unknown card was presented" : `${pending} unknown cards were presented`}
&nbsp;— review and approve or reject.
</NavLink>
)}
<main className="content">
<Outlet />
</main>
<div className="toasts" role="status">
{toasts.map((t) => (
<div key={t.id} className={`toast toast--${t.tone}`}>
{t.text}
</div>
))}
</div>
</div>
);
}