Files
charging_station/frontend/src/components/Layout.tsx
T
julian 069d544bb5 feat: private session history, own-permissions view, plug-gated start button
- non-admins now see ONLY their own sessions in /api/sessions (own app
  starts + own linked cards); gun scopes grant control, not visibility;
  admins see everything
- Account page shows the logged-in user's permissions in plain words
  (Administrator badge, or the guns/relays they control), built solely
  from data already visible to them
- Start button arms only when the gun reports Preparing (cable in the
  car); idle unplugged gun shows an explanatory hint instead
- keep owner's app rename to 'Art IoT'
- smoke test: 59 checks (gun-scoped user sees no foreign sessions)
2026-07-12 09:04:06 +02:00

89 lines
2.6 KiB
TypeScript

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">Art IoT</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">
<NavLink to="/account" className="topbar__who" title="Account settings">
{me?.name}
</NavLink>
<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>
);
}