Files
0pt/app/admin/verktyg/page.tsx
T
adminandClaude Opus 4.8 60455ab61a feat(i18n): finish English-base conversion (admin/* + portal settings/integrations + configurator + portal + beskriv)
Second hardened fan-out converted the 7 untouched admin/portal files; hand-finished the configurator (8 block labels + full summary column), portal dashboard, and describe-intake. English renders by default; SV toggle flips the whole app. A few tuple-array data labels intentionally left SV (no-reshape safety) + lib/data label i18n remain as follow-up. build green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-25 02:48:52 +02:00

96 lines
5.2 KiB
TypeScript

"use client";
import { useState } from "react";
import { PortalShell } from "@/components/portal-shell";
import { useT } from "@/components/locale-provider";
export default function ToolsPage() {
const t = useT();
return (
<PortalShell variant="admin" title={t({ en: "Tools", sv: "Verktyg" })}>
<p className="font-mono text-[11px] uppercase tracking-[0.1em] text-muted-foreground">
{t({ en: "Quick lookups against legal sources. Provenance on every hit.", sv: "Snabboppslag mot lagliga källor. Härkomst på varje träff." })}
</p>
<div className="mt-8 grid grid-cols-1 gap-6 lg:grid-cols-2">
<VehicleTool />
<ScreenTool />
</div>
</PortalShell>
);
}
function VehicleTool() {
const t = useT();
const [plate, setPlate] = useState("");
const [res, setRes] = useState<Record<string, unknown> | null>(null);
const [busy, setBusy] = useState(false);
async function lookup() {
if (!plate.trim()) return;
setBusy(true); setRes(null);
try { setRes(await (await fetch(`/api/vehicles?plate=${encodeURIComponent(plate)}`)).json()); } catch { setRes({ error: true }); }
setBusy(false);
}
const v = (res?.vehicle ?? null) as { make?: string; model?: string; year?: string; reg_plate?: string } | null;
return (
<section className="border border-border p-6">
<div className="flex items-center justify-between border-b border-border pb-3">
<h2 className="font-mono text-[11px] uppercase tracking-[0.12em] text-muted-foreground">{t({ en: "Vehicle — RDW (NL)", sv: "Fordon — RDW (NL)" })}</h2>
<span className="inline-block h-2 w-2" style={{ backgroundColor: "var(--prov-3)" }} />
</div>
<div className="mt-4 flex gap-2">
<input value={plate} onChange={(e) => setPlate(e.target.value)} placeholder={t({ en: "Registration no. (NL)", sv: "Registreringsnr (NL)" })} className="flex-1 border border-border bg-input px-3 py-2 font-mono text-xs uppercase outline-none focus:border-foreground" />
<button onClick={lookup} disabled={busy} className="bg-foreground px-4 py-2 font-mono text-[11px] uppercase tracking-[0.1em] text-background transition-colors hover:bg-[var(--accent-red)] disabled:opacity-50">{busy ? "…" : t({ en: "Look up", sv: "Slå upp" })}</button>
</div>
<div className="mt-4 min-h-[60px] font-mono text-xs">
{res === null ? <span className="text-muted-foreground">—</span>
: v ? (
<div className="space-y-1">
<div>{v.make} {v.model}</div>
<div className="text-muted-foreground">{v.reg_plate} · {v.year ?? "—"} · {t({ en: "source RDW", sv: "källa RDW" })}</div>
</div>
) : <span className="text-muted-foreground">{t({ en: "No match (not available).", sv: "Ingen träff (ej tillgänglig)." })}</span>}
</div>
</section>
);
}
function ScreenTool() {
const t = useT();
const [q, setQ] = useState("");
const [matches, setMatches] = useState<{ name: string; score: number; schema: string }[] | null>(null);
const [busy, setBusy] = useState(false);
async function screen() {
if (!q.trim()) return;
setBusy(true); setMatches(null);
try { const d = await (await fetch(`/api/screen?q=${encodeURIComponent(q)}`)).json(); setMatches(d.matches ?? []); } catch { setMatches([]); }
setBusy(false);
}
return (
<section className="border border-border p-6">
<div className="flex items-center justify-between border-b border-border pb-3">
<h2 className="font-mono text-[11px] uppercase tracking-[0.12em] text-muted-foreground">{t({ en: "Sanctions / PEP — OpenSanctions", sv: "Sanktioner / PEP — OpenSanctions" })}</h2>
<span className="inline-block h-2 w-2" style={{ backgroundColor: "var(--prov-2)" }} />
</div>
<div className="mt-4 flex gap-2">
<input value={q} onChange={(e) => setQ(e.target.value)} placeholder={t({ en: "Name or company", sv: "Namn eller bolag" })} className="flex-1 border border-border bg-input px-3 py-2 font-mono text-xs outline-none focus:border-foreground" />
<button onClick={screen} disabled={busy} className="bg-foreground px-4 py-2 font-mono text-[11px] uppercase tracking-[0.1em] text-background transition-colors hover:bg-[var(--accent-red)] disabled:opacity-50">{busy ? "…" : t({ en: "Screen", sv: "Skärma" })}</button>
</div>
<div className="mt-4 min-h-[60px] font-mono text-xs">
{matches === null ? <span className="text-muted-foreground">—</span>
: matches.length === 0 ? <span style={{ color: "var(--prov-3)" }}>{t({ en: "No matches.", sv: "Inga träffar." })}</span>
: (
<ul className="space-y-1">
{matches.map((m, i) => (
<li key={i} className="flex justify-between gap-3">
<span>{m.name}</span>
<span className="text-muted-foreground">{m.schema}{m.score ? ` · ${Math.round(m.score * 100)}%` : ""}</span>
</li>
))}
</ul>
)}
<p className="mt-3 text-[10.5px] text-muted-foreground/70">{t({ en: "Requires verified OpenSanctions terms/key for full matches.", sv: "Kräver verifierade OpenSanctions-villkor/nyckel för fullständiga träffar." })}</p>
</div>
</section>
);
}