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:
@@ -0,0 +1,85 @@
|
||||
import { useSessions, useStatus } from "../queries";
|
||||
import type { Session } from "../types";
|
||||
|
||||
const fmtKwh = (wh: number | null) => (wh == null ? "—" : (wh / 1000).toFixed(2));
|
||||
const fmtTime = (iso: string | null) =>
|
||||
iso ? new Date(iso).toLocaleString([], { dateStyle: "medium", timeStyle: "short" }) : "—";
|
||||
|
||||
function fmtDuration(a: string, b: string | null): string {
|
||||
if (!b) return "";
|
||||
const mins = Math.max(0, Math.round((new Date(b).getTime() - new Date(a).getTime()) / 60000));
|
||||
return mins >= 60 ? `${Math.floor(mins / 60)} h ${String(mins % 60).padStart(2, "0")} min` : `${mins} min`;
|
||||
}
|
||||
|
||||
function MethodChip({ method }: { method: string | null }) {
|
||||
if (method === "card") return <span className="chip chip--card">Card</span>;
|
||||
if (method === "app") return <span className="chip chip--app">In-app</span>;
|
||||
return <span className="chip">{method ?? "—"}</span>;
|
||||
}
|
||||
|
||||
function gunLabel(s: Session, chargers: Record<string, { label?: string; guns?: Record<string, string> }>) {
|
||||
const meta = chargers[s.cp];
|
||||
return meta?.guns?.[String(s.connector)] ?? `${s.cp} · gun ${s.connector}`;
|
||||
}
|
||||
|
||||
export default function History() {
|
||||
const { data: sessions, isLoading } = useSessions();
|
||||
const { data: status } = useStatus();
|
||||
|
||||
if (isLoading) return <p className="empty">Loading history…</p>;
|
||||
if (!sessions?.length)
|
||||
return (
|
||||
<p className="empty">
|
||||
No charging sessions yet. The first card tap or in-app start will appear here with who,
|
||||
when, how, and how many kWh.
|
||||
</p>
|
||||
);
|
||||
|
||||
const totalKwh = sessions.reduce((acc, s) => acc + (s.wh ?? 0), 0) / 1000;
|
||||
|
||||
return (
|
||||
<section className="panel">
|
||||
<header className="panel__head">
|
||||
<h2>Charging sessions</h2>
|
||||
<span className="panel__meta">
|
||||
{sessions.length} session{sessions.length === 1 ? "" : "s"} ·{" "}
|
||||
<strong className="mono">{totalKwh.toFixed(1)} kWh</strong> total
|
||||
</span>
|
||||
</header>
|
||||
<div className="table-wrap">
|
||||
<table className="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Who</th>
|
||||
<th>Via</th>
|
||||
<th>Gun</th>
|
||||
<th>Started</th>
|
||||
<th>Duration</th>
|
||||
<th className="num">kWh</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{sessions.map((s) => (
|
||||
<tr key={s.tx}>
|
||||
<td className="strong">{s.who || s.id_tag}</td>
|
||||
<td>
|
||||
<MethodChip method={s.method} />
|
||||
</td>
|
||||
<td>{gunLabel(s, status?.chargers ?? {})}</td>
|
||||
<td className="mono">{fmtTime(s.started)}</td>
|
||||
<td>
|
||||
{s.ended ? (
|
||||
fmtDuration(s.started, s.ended)
|
||||
) : (
|
||||
<span className="chip chip--live">charging</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="num mono strong">{fmtKwh(s.wh)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user