feat: admin Verktyg (live fordon + sanktioner lookup) + service-type pricing in configurator
/admin/verktyg uses live /api/vehicles (RDW) + /api/screen (OpenSanctions); added to admin nav. Configurator now has a Tjänst selector that applies each service's price multiplier (lib/services) to the live estimate + summary; service_type carried into the order so orders-store prices by service. tsc 0, build green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { PortalShell } from "@/components/portal-shell";
|
||||
|
||||
export default function ToolsPage() {
|
||||
return (
|
||||
<PortalShell variant="admin" title="Verktyg">
|
||||
<p className="font-mono text-[11px] uppercase tracking-[0.1em] text-muted-foreground">
|
||||
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 [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">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="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 ? "…" : "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 ?? "—"} · källa RDW</div>
|
||||
</div>
|
||||
) : <span className="text-muted-foreground">Ingen träff (ej tillgänglig).</span>}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function ScreenTool() {
|
||||
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">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="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 ? "…" : "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)" }}>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">Kräver verifierade OpenSanctions-villkor/nyckel för fullständiga träffar.</p>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user