Build 0pt ordering flow: configurator, deposit/escrow, production tracker, validation

Customer order lifecycle on the mono design system: red + provenance tokens, useReveal hook, lib/data pricing model, ProvenanceBadge/CellProvenance, OrderStepper, and 4 routes with live pricing, 50/50 escrow, simulated production, 4-view validation. tsc clean; next build green (5 routes).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
2026-06-24 17:28:24 +02:00
co-authored by Claude Opus 4.8
parent 5e53a6d71c
commit 24035dec8b
12 changed files with 1253 additions and 0 deletions
+200
View File
@@ -0,0 +1,200 @@
"use client";
import Link from "next/link";
import { useParams } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import { OrderStepper } from "@/components/order-stepper";
const STAGES = [
{ key: "source", title: "Källracing", meta: "GLEIF · Brreg · CVR · PRH" },
{ key: "extract", title: "Extraktion & OCR", meta: "register-API · dokument" },
{ key: "structure", title: "Strukturering & matchning", meta: "NER · entity resolution · LEI-länk" },
{ key: "enrich", title: "Berikning & fusion", meta: "multi-source agreement" },
{ key: "quality", title: "Kvalitetskontroll", meta: "expectations · dedup · tröskel" },
];
const MARKET_KEYS = [
{ code: "SE", speed: 1.0 },
{ code: "NO", speed: 0.85 },
{ code: "DK", speed: 0.7 },
{ code: "FI", speed: 0.5 },
];
function prefersReduced() {
return typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}
export default function ProductionPage() {
const { id } = useParams<{ id: string }>();
const [running, setRunning] = useState(false);
const [done, setDone] = useState(false);
const [progress, setProgress] = useState<number[]>([0, 0, 0, 0, 0]);
const [markets, setMarkets] = useState<number[]>([0, 0, 0, 0]);
const [conf, setConf] = useState(0);
const [feed, setFeed] = useState<{ t: string; msg: string; kind: "ok" | "run" }[]>([]);
const timer = useRef<ReturnType<typeof setInterval> | null>(null);
const tick = useRef(0);
const finish = () => {
setProgress([100, 100, 100, 100, 100]);
setMarkets([100, 100, 100, 100]);
setConf(94);
setDone(true);
setRunning(false);
setFeed((f) => [{ t: stamp(), msg: "Leverans klar · konfidens 94 % · 4 980 poster", kind: "ok" }, ...f]);
};
const stamp = () => {
const s = 10 + Math.floor(tick.current / 2);
return `00:${String(s).padStart(2, "0")}`;
};
const start = () => {
if (running || done) return;
if (prefersReduced()) {
finish();
return;
}
setRunning(true);
setFeed([{ t: "00:00", msg: `Order ${id} startad · depå mottagen`, kind: "run" }]);
timer.current = setInterval(() => {
tick.current += 1;
setProgress((prev) => {
const next = [...prev];
const i = next.findIndex((p) => p < 100);
if (i === -1) return prev;
next[i] = Math.min(100, next[i] + 8 + Math.random() * 10);
if (next[i] >= 100 && i < STAGES.length) {
setFeed((f) => [{ t: stamp(), msg: `${STAGES[i].title} klar`, kind: "ok" }, ...f].slice(0, 12));
}
return next;
});
setMarkets((prev) => prev.map((m, idx) => Math.min(100, m + (6 + Math.random() * 6) * MARKET_KEYS[idx].speed)));
setConf((c) => Math.min(94, c + 2.5 + Math.random() * 2));
}, 320);
};
useEffect(() => {
if (progress.every((p) => p >= 100) && running) finish();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [progress, running]);
useEffect(() => () => { if (timer.current) clearInterval(timer.current); }, []);
const overall = Math.round(progress.reduce((a, b) => a + b, 0) / STAGES.length);
return (
<main className="min-h-screen bg-background text-foreground">
<OrderStepper active={3} />
<div className="mx-auto max-w-[80rem] px-6 py-10">
<p className="font-mono text-[11px] uppercase tracking-[0.14em] text-muted-foreground">Steg 3 — Produktion</p>
<h1 className="mt-3 text-4xl font-medium tracking-[-0.025em] md:text-5xl">Följ jobbet — i realtid.</h1>
{/* control row */}
<div className="mt-6 flex flex-wrap items-center gap-3">
<button
type="button"
onClick={start}
disabled={running || done}
className="bg-foreground px-5 py-3 font-mono text-[12px] uppercase tracking-[0.1em] text-background transition-colors hover:bg-[var(--accent-red)] disabled:opacity-40"
>
{done ? "✓ Klart" : running ? "Kör…" : "▸ Starta simulering"}
</button>
<span className="border border-border px-3 py-2 font-mono text-[11px] uppercase tracking-[0.08em] text-muted-foreground">
Order {id} · {done ? "klar" : running ? `${overall}%` : "väntar"}
</span>
<span className="border border-border px-3 py-2 font-mono text-[11px] uppercase tracking-[0.08em] text-muted-foreground">
ETA ≈ 4 dgr (simulerad)
</span>
</div>
<div className="mt-8 grid grid-cols-1 gap-6 lg:grid-cols-[1fr_320px]">
{/* stages */}
<div className="flex flex-col gap-3">
{STAGES.map((s, i) => {
const p = Math.round(progress[i]);
const isDone = p >= 100;
const isRun = !isDone && (i === 0 || progress[i - 1] >= 100) && running;
const color = isDone ? "var(--prov-3)" : isRun ? "var(--accent-red)" : "var(--border)";
return (
<div key={s.key} className="border p-4" style={{ borderColor: color }}>
<div className="flex items-center justify-between">
<span className="text-sm font-medium">{s.title}</span>
<span className="font-mono text-xs text-muted-foreground">{p}%</span>
</div>
<div className="mt-2 h-1.5 w-full bg-secondary">
<div className="h-full transition-all" style={{ width: `${p}%`, backgroundColor: isDone ? "var(--prov-3)" : "var(--foreground)" }} />
</div>
<p className="mt-2 font-mono text-[10.5px] uppercase tracking-[0.06em] text-muted-foreground">{s.meta}</p>
</div>
);
})}
</div>
{/* right column */}
<div className="flex flex-col gap-4">
<div className="border border-border p-5 text-center">
<ConfidenceRing value={conf} />
<p className="mt-2 font-mono text-[10.5px] uppercase tracking-[0.1em] text-muted-foreground">Levererbart</p>
</div>
<div className="border border-border p-4">
<p className="font-mono text-[10.5px] uppercase tracking-[0.1em] text-muted-foreground">Per marknad</p>
<div className="mt-3 flex flex-col gap-2">
{MARKET_KEYS.map((m, i) => (
<div key={m.code} className="flex items-center gap-2">
<span className="w-7 font-mono text-xs">{m.code}</span>
<div className="h-1.5 flex-1 bg-secondary">
<div className="h-full bg-foreground transition-all" style={{ width: `${Math.round(markets[i])}%` }} />
</div>
<span className="w-9 text-right font-mono text-[10.5px] text-muted-foreground">{Math.round(markets[i])}%</span>
</div>
))}
</div>
</div>
<div className="border border-border p-4">
<p className="font-mono text-[10.5px] uppercase tracking-[0.1em] text-muted-foreground">Aktivitet</p>
<div className="mt-3 flex flex-col gap-1.5 font-mono text-[11px]">
{feed.length === 0 ? <span className="text-muted-foreground">— väntar på start —</span> : null}
{feed.map((f, i) => (
<div key={i} className="flex gap-2">
<span className="text-muted-foreground">{f.t}</span>
<span style={{ color: f.kind === "ok" ? "var(--prov-3)" : "var(--accent-red)" }}>{f.msg}</span>
</div>
))}
</div>
</div>
</div>
</div>
{done ? (
<div className="mt-8">
<Link
href={`/order/${id}/validera`}
className="inline-block bg-foreground px-6 py-3.5 font-mono text-[12px] uppercase tracking-[0.1em] text-background transition-colors hover:bg-[var(--accent-red)]"
>
Granska & validera resultatet →
</Link>
</div>
) : null}
</div>
</main>
);
}
function ConfidenceRing({ value }: { value: number }) {
const r = 52;
const c = 2 * Math.PI * r;
const off = c - (value / 100) * c;
return (
<svg viewBox="0 0 130 130" className="mx-auto h-36 w-36">
<circle cx="65" cy="65" r={r} fill="none" stroke="var(--secondary)" strokeWidth="8" />
<circle
cx="65" cy="65" r={r} fill="none" stroke="var(--prov-3)" strokeWidth="8"
strokeDasharray={c} strokeDashoffset={off} strokeLinecap="butt"
transform="rotate(-90 65 65)" style={{ transition: "stroke-dashoffset .3s" }}
/>
<text x="65" y="72" textAnchor="middle" className="fill-foreground font-mono" style={{ fontSize: 24 }}>
{Math.round(value)}%
</text>
</svg>
);
}
+226
View File
@@ -0,0 +1,226 @@
"use client";
import { useParams } from "next/navigation";
import { useState } from "react";
import { OrderStepper } from "@/components/order-stepper";
import { CellProvenance, ProvenanceBadge, PROVENANCE_LEGEND } from "@/components/provenance-badge";
import { MARKETS, SAMPLE_ROWS, formatSEK } from "@/lib/data";
const TABS = ["Tabell", "Täckning", "Schema & arkitektur", "Kvalitetsrapport"] as const;
type Tab = (typeof TABS)[number];
const DESTINATIONS = ["CSV", "Tabellvy (NocoDB)", "Parquet", "JSON", "Dashboard (Metabase)", "API", "Webhook", "FiveCRM", "Google Sheets"];
const DIMENSIONS: [string, number, boolean][] = [
["Komplett", 97, false], ["Färskhet", 93, false], ["Korroborering", 88, true], ["Unikhet", 99, false], ["Giltighet", 96, false],
];
const CHECKS = [
"Org.nr mot register-checksumma", "LEI mot GLEIF", "E-post MX-verifierad",
"Dubbletter sammanslagna", "20 poster under tröskel utelämnade", "Sanktions/PEP-skärm utan träff",
];
const ENTITIES = [
{ name: "dim_company", key: true, cols: ["company_id PK", "org_nr", "lei FK", "name"] },
{ name: "fact_financials", key: false, cols: ["company_id FK", "year", "revenue", "result"] },
{ name: "dim_contact", key: false, cols: ["contact_id PK", "company_id FK", "email"] },
{ name: "dim_ubo", key: false, cols: ["ubo_id PK", "company_id FK", "share_pct"] },
{ name: "bridge_provenance", key: true, cols: ["field_id PK", "source_id FK", "confidence", "fetched_at"] },
{ name: "dim_source", key: false, cols: ["source_id PK", "name", "license", "freshness"] },
];
export default function ValidationPage() {
const { id } = useParams<{ id: string }>();
const [tab, setTab] = useState<Tab>("Tabell");
const [dests, setDests] = useState<string[]>(["CSV", "Tabellvy (NocoDB)"]);
const [approved, setApproved] = useState(false);
const toggleDest = (d: string) => setDests((p) => (p.includes(d) ? p.filter((x) => x !== d) : [...p, d]));
return (
<main className="min-h-screen bg-background text-foreground">
<OrderStepper active={4} />
<div className="mx-auto max-w-[80rem] px-6 py-10">
<p className="font-mono text-[11px] uppercase tracking-[0.14em] text-muted-foreground">Steg 4 — Validera & leverera</p>
<h1 className="mt-3 text-4xl font-medium tracking-[-0.025em] md:text-5xl">Granska allt. Godkänn fritt.</h1>
{/* tabs */}
<div className="mt-8 flex flex-wrap gap-0 border-b border-border">
{TABS.map((t) => (
<button
key={t}
onClick={() => setTab(t)}
className="px-4 py-3 font-mono text-[11px] uppercase tracking-[0.1em] transition-colors"
style={{
color: tab === t ? "var(--foreground)" : "var(--muted-foreground)",
borderBottom: tab === t ? "2px solid var(--accent-red)" : "2px solid transparent",
}}
>
{t}
</button>
))}
</div>
<div className="mt-6">
{tab === "Tabell" ? (
<div>
<div className="mb-4 flex flex-wrap gap-2">
{PROVENANCE_LEGEND.map((l) => (
<ProvenanceBadge key={l.level} level={l.level} source={l.text} />
))}
</div>
<div className="overflow-x-auto border border-border">
<table className="w-full border-collapse text-sm">
<thead>
<tr className="border-b border-border bg-secondary">
{["Org.nr", "Bolag", "Säte", "SNI", "Anställda", "Oms. (tkr)", "E-post", "LEI"].map((h) => (
<th key={h} className="px-3 py-2 text-left font-mono text-[10.5px] uppercase tracking-[0.08em] text-muted-foreground">{h}</th>
))}
</tr>
</thead>
<tbody>
{SAMPLE_ROWS.map((r) => (
<tr key={r.orgnr} className="border-b border-border last:border-b-0 hover:bg-secondary/50">
<td className="px-3 py-2 font-mono text-xs">{r.orgnr}<CellProvenance level={3} /></td>
<td className="px-3 py-2">{r.bolag}<CellProvenance level={3} /></td>
<td className="px-3 py-2">{r.sate}<CellProvenance level={3} /></td>
<td className="px-3 py-2 font-mono text-xs">{r.sni}<CellProvenance level={2} /></td>
<td className="px-3 py-2 font-mono text-xs">{new Intl.NumberFormat("sv-SE").format(r.anstallda)}<CellProvenance level={2} /></td>
<td className="px-3 py-2 font-mono text-xs">{new Intl.NumberFormat("sv-SE").format(r.oms)}<CellProvenance level={2} /></td>
<td className="px-3 py-2 text-xs">
{r.epost ? (<>{r.epost}<CellProvenance level={r.epostLevel} /></>) : (<span className="text-muted-foreground">— licens (FI)<CellProvenance level={0} /></span>)}
</td>
<td className="px-3 py-2 font-mono text-xs">{r.lei}<CellProvenance level={3} /></td>
</tr>
))}
</tbody>
</table>
</div>
</div>
) : null}
{tab === "Täckning" ? (
<div>
<div className="grid grid-cols-[repeat(auto-fill,minmax(96px,1fr))] gap-px bg-border">
{MARKETS.filter((m) => m.live).map((m) => (
<div key={m.code} className="bg-background p-3">
<p className="font-mono text-sm font-semibold">{m.code}</p>
<p className="font-mono text-[10.5px] text-muted-foreground">{m.coverage}%</p>
<div className="mt-2 h-1 w-full bg-secondary">
<div className="h-full" style={{ width: `${m.coverage}%`, backgroundColor: m.coverage >= 95 ? "var(--prov-3)" : "var(--prov-2)" }} />
</div>
</div>
))}
</div>
<div className="mt-4 grid grid-cols-1 gap-px bg-border sm:grid-cols-3">
{[["4 980", "poster levererade"], ["20", "utelämnade — ej gissade"], ["3,2", "källor per bekräftat fält"]].map(([n, l]) => (
<div key={l} className="bg-background p-5">
<p className="text-3xl font-medium">{n}</p>
<p className="mt-1 font-mono text-[10.5px] uppercase tracking-[0.08em] text-muted-foreground">{l}</p>
</div>
))}
</div>
</div>
) : null}
{tab === "Schema & arkitektur" ? (
<div className="border border-border p-6" style={{ backgroundImage: "radial-gradient(var(--border) 1px, transparent 1px)", backgroundSize: "16px 16px" }}>
<div className="grid grid-cols-2 gap-4 md:grid-cols-3">
{ENTITIES.map((e) => (
<div key={e.name} className="bg-background" style={{ border: e.key ? "1px solid var(--accent-red)" : "1px solid var(--border)" }}>
<div className="border-b border-border px-3 py-2 font-mono text-[11px]">{e.name}</div>
<ul className="px-3 py-2 font-mono text-[10.5px] text-muted-foreground">
{e.cols.map((c) => (<li key={c}>{c}</li>))}
</ul>
</div>
))}
</div>
<p className="mt-4 font-mono text-[10.5px] uppercase tracking-[0.06em] text-muted-foreground">
→ varje fält länkar till bridge_provenance · ingen uppgift utan spårbar källa
</p>
</div>
) : null}
{tab === "Kvalitetsrapport" ? (
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
<div className="border border-border p-5">
<p className="font-mono text-[10.5px] uppercase tracking-[0.1em] text-muted-foreground">Per dimension</p>
<div className="mt-4 flex flex-col gap-3">
{DIMENSIONS.map(([name, v, amber]) => (
<div key={name}>
<div className="flex justify-between font-mono text-xs"><span>{name}</span><span className="text-muted-foreground">{v}%</span></div>
<div className="mt-1 h-1.5 w-full bg-secondary">
<div className="h-full" style={{ width: `${v}%`, backgroundColor: amber ? "var(--prov-2)" : "var(--prov-3)" }} />
</div>
</div>
))}
</div>
</div>
<div className="border border-border p-5">
<p className="font-mono text-[10.5px] uppercase tracking-[0.1em] text-muted-foreground">Kontroller som passerade</p>
<ul className="mt-4 flex flex-col gap-2 text-sm">
{CHECKS.map((c) => (
<li key={c} className="flex items-start gap-2">
<span style={{ color: "var(--prov-3)" }}>✓</span>
<span>{c}</span>
</li>
))}
</ul>
</div>
</div>
) : null}
</div>
{/* destinations */}
<div className="mt-8">
<p className="font-mono text-[10.5px] uppercase tracking-[0.1em] text-muted-foreground">Leverera till</p>
<div className="mt-3 flex flex-wrap gap-2">
{DESTINATIONS.map((d) => {
const on = dests.includes(d);
return (
<button
key={d}
onClick={() => toggleDest(d)}
className="border px-3 py-2 font-mono text-[11px] uppercase tracking-[0.08em] transition-colors"
style={{
borderColor: on ? "var(--accent-red)" : "var(--border)",
backgroundColor: on ? "rgba(228,0,20,0.06)" : "transparent",
color: "var(--foreground)",
}}
>
{d}
</button>
);
})}
</div>
</div>
{/* action bar */}
<div className="mt-8 border border-border p-5">
{approved ? (
<div className="border p-4" style={{ borderColor: "var(--prov-3)" }}>
<p className="font-mono text-sm" style={{ color: "var(--prov-3)" }}>
✓ Leverans godkänd. Slutbetalning frigjord. Export upplåst.
</p>
<p className="mt-1 text-xs text-muted-foreground">Order {id} · levererad till {dests.join(" · ") || "—"}.</p>
</div>
) : (
<div className="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
<p className="max-w-xl text-sm text-muted-foreground">
Godkänn leveransen — frigör resterande belopp ur depån och lås upp full export. Inte nöjd? Begär revidering utan kostnad.
</p>
<div className="flex gap-3">
<button className="border border-foreground px-5 py-3 font-mono text-[12px] uppercase tracking-[0.1em] transition-colors hover:bg-foreground hover:text-background">
Begär revidering
</button>
<button
onClick={() => setApproved(true)}
className="bg-foreground px-5 py-3 font-mono text-[12px] uppercase tracking-[0.1em] text-background transition-colors hover:bg-[var(--accent-red)]"
>
Godkänn & frigör 50 %
</button>
</div>
</div>
)}
</div>
</div>
</main>
);
}