From 318e9379c82a5ff5e163a0bde385557fa2d7761a Mon Sep 17 00:00:00 2001 From: Simon Axelsson Date: Wed, 24 Jun 2026 19:03:06 +0200 Subject: [PATCH] feat: catalog index page + wire nav to /katalog /kallor /portal + real order journey Configurator->POST /api/orders, deposit fetches order + PATCH in_production, header nav reaches the new pages (no orphans). New pages: katalog, katalog/[id], kallor, portal, shared states. tsc 0, build green (13 routes). Co-Authored-By: Claude Opus 4.8 --- app/bestall/forskott/page.tsx | 56 ++- app/bestall/page.tsx | 36 +- app/kallor/page.tsx | 309 +++++++++++++++++ app/katalog/[id]/page.tsx | 629 ++++++++++++++++++++++++++++++++++ app/katalog/page.tsx | 132 +++++++ app/portal/page.tsx | 259 ++++++++++++++ components/header.tsx | 6 +- components/states.tsx | 169 +++++++++ 8 files changed, 1582 insertions(+), 14 deletions(-) create mode 100644 app/kallor/page.tsx create mode 100644 app/katalog/[id]/page.tsx create mode 100644 app/katalog/page.tsx create mode 100644 app/portal/page.tsx create mode 100644 components/states.tsx diff --git a/app/bestall/forskott/page.tsx b/app/bestall/forskott/page.tsx index 01ac1a0..0c0bb54 100644 --- a/app/bestall/forskott/page.tsx +++ b/app/bestall/forskott/page.tsx @@ -1,6 +1,7 @@ "use client"; import Link from "next/link"; +import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { OrderStepper } from "@/components/order-stepper"; import { useReveal } from "@/hooks/use-reveal"; @@ -26,7 +27,10 @@ const TRUST = [ export default function DepositPage() { const [est, setEst] = useState(FALLBACK); const [recap, setRecap] = useState>({}); + const [orderId, setOrderId] = useState(null); + const [paying, setPaying] = useState(false); const reveal = useReveal(); + const router = useRouter(); useEffect(() => { try { @@ -42,8 +46,48 @@ export default function DepositPage() { }); } } catch {} + const oid = new URLSearchParams(window.location.search).get("order"); + if (oid) { + setOrderId(oid); + fetch(`/api/orders/${oid}`) + .then((r) => (r.ok ? r.json() : null)) + .then((o) => { + if (!o) return; + setEst((prev) => ({ + ...prev, + price: Math.round((o.total_ore ?? 0) / 100) || prev.price, + deposit: Math.round((o.deposit_ore ?? 0) / 100) || prev.deposit, + remainder: Math.round((o.balance_ore ?? 0) / 100) || prev.remainder, + })); + const c = o.config || {}; + setRecap({ + Marknader: (c.markets || []).join(" · "), + Typ: c.type, + Volym: new Intl.NumberFormat("sv-SE").format(c.volume || 0), + Frekvens: c.frequency, + }); + }) + .catch(() => {}); + } }, []); + async function pay() { + if (paying) return; + setPaying(true); + if (orderId) { + try { + await fetch(`/api/orders/${orderId}`, { + method: "PATCH", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ status: "in_production" }), + }); + } catch {} + router.push(`/order/${orderId}`); + return; + } + router.push("/order/SX-4471"); + } + return (
@@ -188,12 +232,14 @@ export default function DepositPage() {
- - Betala. Starta. → - + {paying ? "Startar…" : "Betala. Starta. →"} + void) => set(arr.includes(v) ? arr.filter((x) => x !== v) : [...arr, v]); @@ -307,12 +329,14 @@ export default function ConfiguratorPage() {
- - Betala förskott → - + {creating ? "Skapar…" : "Betala förskott →"} +

diff --git a/app/kallor/page.tsx b/app/kallor/page.tsx new file mode 100644 index 0000000..741aa85 --- /dev/null +++ b/app/kallor/page.tsx @@ -0,0 +1,309 @@ +"use client"; + +import { useEffect, useMemo, useState } from "react"; +import { Header } from "@/components/header"; +import { useReveal } from "@/hooks/use-reveal"; +import { CellProvenance, PROVENANCE_LEGEND } from "@/components/provenance-badge"; +import { LoadingSkeleton, EmptyState, ErrorState } from "@/components/states"; +import type { ProvLevel } from "@/lib/data"; + +// Shape of GET /api/sources (docs/04). Legal sourcing only — the transparency moat. +interface Source { + source_id: string; + name: string; + market: string; + access: string; // api | bulk | authorized_web | licensed + licence: string; + cadence: string; // daily | weekly | quarterly | ... + confidence: number; // 0..1 +} + +// Human, terse Swedish labels for the access ladder (CLAUDE.md §1 priority order). +const ACCESS_LABEL: Record = { + api: "Officiellt API", + bulk: "Bulk / öppen data", + authorized_web: "Auktoriserad webb", + licensed: "Licensierad partner", +}; + +// Confidence (0..1) → provenance level so each row carries an honest square. +function confidenceLevel(c: number): ProvLevel { + if (c >= 0.95) return 3; + if (c >= 0.9) return 2; + if (c > 0) return 1; + return 0; +} + +// Sortable columns mapped to the request: Källa · Marknad · Åtkomst · Licens · Färskhet · Konfidens. +type SortKey = "name" | "market" | "access" | "licence" | "cadence" | "confidence"; +const COLUMNS: { key: SortKey; label: string; mono?: boolean }[] = [ + { key: "name", label: "Källa" }, + { key: "market", label: "Marknad", mono: true }, + { key: "access", label: "Åtkomst", mono: true }, + { key: "licence", label: "Licens" }, + { key: "cadence", label: "Färskhet", mono: true }, + { key: "confidence", label: "Konfidens", mono: true }, +]; + +const ALL = "Alla"; + +export default function SourcesPage() { + const [sources, setSources] = useState(null); + const [status, setStatus] = useState<"loading" | "ready" | "error">("loading"); + const [reloadKey, setReloadKey] = useState(0); + + const [market, setMarket] = useState(ALL); + const [access, setAccess] = useState(ALL); + const [sort, setSort] = useState<{ key: SortKey; dir: 1 | -1 }>({ key: "confidence", dir: -1 }); + + const ref = useReveal(); + + useEffect(() => { + let cancelled = false; + setStatus("loading"); + fetch("/api/sources") + .then((r) => { + if (!r.ok) throw new Error(String(r.status)); + return r.json(); + }) + .then((data: Source[]) => { + if (cancelled) return; + setSources(Array.isArray(data) ? data : []); + setStatus("ready"); + }) + .catch(() => { + if (cancelled) return; + setSources(null); + setStatus("error"); + }); + return () => { + cancelled = true; + }; + }, [reloadKey]); + + const markets = useMemo(() => { + if (!sources) return [ALL]; + return [ALL, ...Array.from(new Set(sources.map((s) => s.market)))]; + }, [sources]); + + const accesses = useMemo(() => { + if (!sources) return [ALL]; + return [ALL, ...Array.from(new Set(sources.map((s) => s.access)))]; + }, [sources]); + + const rows = useMemo(() => { + if (!sources) return []; + const filtered = sources.filter( + (s) => (market === ALL || s.market === market) && (access === ALL || s.access === access), + ); + const { key, dir } = sort; + return [...filtered].sort((a, b) => { + const av = a[key]; + const bv = b[key]; + if (typeof av === "number" && typeof bv === "number") return (av - bv) * dir; + return String(av).localeCompare(String(bv), "sv") * dir; + }); + }, [sources, market, access, sort]); + + const setSortKey = (key: SortKey) => + setSort((p) => (p.key === key ? { key, dir: (p.dir * -1) as 1 | -1 } : { key, dir: key === "confidence" ? -1 : 1 })); + + const Pill = ({ + active, + onClick, + children, + }: { + active: boolean; + onClick: () => void; + children: React.ReactNode; + }) => ( + + ); + + return ( +

+
+ + {/* masthead — oversized faint numeral as graphic texture */} +
+ + 05 + +
+
+ +

Källkarta

+
+

+ Varje fält. +
+ Varje källa. +

+

+ Officiellt först. Sen öppen data. Sen licens. Aldrig gissat. +

+
+
+ +
+ {/* legend — the 4 provenance squares */} +
+ Härkomst + {PROVENANCE_LEGEND.map((l) => ( + + + {l.text} + + ))} +
+ + {/* filters — pills by Marknad / Åtkomst (Typ) */} + {status === "ready" && sources && sources.length > 0 ? ( +
+
+

Marknad

+
+ {markets.map((m) => ( + setMarket(m)}> + {m === ALL ? ALL : m === "global" ? "Global" : m} + + ))} +
+
+
+

Typ av åtkomst

+
+ {accesses.map((a) => ( + setAccess(a)}> + {a === ALL ? ALL : ACCESS_LABEL[a] ?? a} + + ))} +
+
+
+ ) : null} + + {/* states + table */} + {status === "loading" ? : null} + + {status === "error" ? ( + setReloadKey((k) => k + 1)} /> + ) : null} + + {status === "ready" && (!sources || sources.length === 0) ? ( + + ) : null} + + {status === "ready" && sources && sources.length > 0 && rows.length === 0 ? ( + + ) : null} + + {status === "ready" && rows.length > 0 ? ( +
+
+ + + + {COLUMNS.map((c) => { + const isSorted = sort.key === c.key; + return ( + + ); + })} + + + + {rows.map((s) => { + const level = confidenceLevel(s.confidence); + return ( + + + + + + + + + ); + })} + +
+ +
+ {s.name} + + {s.source_id} + + + {s.market === "global" ? "Global" : s.market} + + {ACCESS_LABEL[s.access] ?? s.access} + {s.licence} + {s.cadence} + + {Math.round(s.confidence * 100)}% + +
+
+
+

+ {rows.length} källor · varje fält bär sin härkomst +

+

+ Licensvillkor verifieras innan användning +

+
+
+ ) : null} +
+
+ ); +} diff --git a/app/katalog/[id]/page.tsx b/app/katalog/[id]/page.tsx new file mode 100644 index 0000000..683e2d8 --- /dev/null +++ b/app/katalog/[id]/page.tsx @@ -0,0 +1,629 @@ +"use client"; + +import Link from "next/link"; +import { useParams } from "next/navigation"; +import { useCallback, useEffect, useRef, useState } from "react"; +import { Header } from "@/components/header"; +import { DataArtifact } from "@/components/data-artifact"; +import { ProvenanceBadge, CellProvenance, PROVENANCE_LEGEND } from "@/components/provenance-badge"; +import { LoadingSkeleton, EmptyState, ErrorState } from "@/components/states"; +import { useReveal } from "@/hooks/use-reveal"; +import { FIELDS, SAMPLE_ROWS, MARKETS, formatSEK, type ProvLevel } from "@/lib/data"; + +// ───────────────────────────────────────────────────────────────────────────── +// Inline catalog. No detail API yet — keyed by slugified id with a safe fallback. +// Mirrors the slugs that the catalog cards (featured-products-section) imply. +// ───────────────────────────────────────────────────────────────────────────── + +interface Dataset { + id: string; + markets: string; + marketCodes: string[]; + title: string; + blurb: string; + count: string; + rows: number; + freshness: string; + level: ProvLevel; + source: string; + cat: string; + price: number; + artifact: "table" | "map" | "schema" | "chart"; +} + +const CATALOG: Dataset[] = [ + { + id: "nordisk-bolagsdata", + markets: "SE · NO · DK · FI", + marketCodes: ["SE", "NO", "DK", "FI"], + title: "Nordisk bolagsdata", + blurb: "Officiella register. Per fält.", + count: "4,9M poster", + rows: 4900000, + freshness: "daglig", + level: 3, + source: "GLEIF · Brreg", + cat: "Bolag", + price: 18400, + artifact: "table", + }, + { + id: "beslutsfattare-tech", + markets: "SE · NO · DK · FI", + marketCodes: ["SE", "NO", "DK", "FI"], + title: "Beslutsfattare i tech", + blurb: "Roll och väg. Källa per fält.", + count: "182k poster", + rows: 182000, + freshness: "veckovis", + level: 1, + source: "publik webb", + cat: "Beslutsfattare", + price: 9600, + artifact: "schema", + }, + { + id: "fordon-flotta", + markets: "SE", + marketCodes: ["SE"], + title: "Fordon & flotta", + blurb: "Tekniska data. VehIQ-synergin.", + count: "6,1M poster", + rows: 6100000, + freshness: "daglig", + level: 2, + source: "register", + cat: "Fordon", + price: 12200, + artifact: "map", + }, + { + id: "finansiella-serier", + markets: "SE · NO · DK · FI", + marketCodes: ["SE", "NO", "DK", "FI"], + title: "Finansiella serier", + blurb: "Omsättning, resultat, nyckeltal.", + count: "12 år", + rows: 240000, + freshness: "årlig", + level: 2, + source: "register", + cat: "Finansiellt", + price: 14800, + artifact: "chart", + }, +]; + +const TABS = ["Översikt", "Exempeldata", "Kvalitet", "Schema", "Täckning", "Pris"] as const; +type Tab = (typeof TABS)[number]; + +function findDataset(raw: string | undefined): Dataset | undefined { + if (!raw) return undefined; + const slug = decodeURIComponent(raw).toLowerCase(); + return CATALOG.find((d) => d.id === slug); +} + +export default function DatasetDetailPage() { + const { id } = useParams<{ id: string }>(); + const reveal = useReveal(); + + const [status, setStatus] = useState<"loading" | "ready" | "empty" | "error">("loading"); + const [dataset, setDataset] = useState(null); + const [tab, setTab] = useState("Översikt"); + const attempt = useRef(0); + + // Simulated detail fetch. Replace with GET /catalog/:id when the API lands. + const load = useCallback(() => { + setStatus("loading"); + attempt.current += 1; + const run = attempt.current; + const t = setTimeout(() => { + if (run !== attempt.current) return; + const hit = findDataset(id); + if (hit) { + setDataset(hit); + setStatus("ready"); + } else { + // Known id-space, no match → empty (not an error). + setDataset(null); + setStatus("empty"); + } + }, 540); + return () => clearTimeout(t); + }, [id]); + + useEffect(() => { + const cleanup = load(); + return cleanup; + }, [load]); + + return ( +
+
+ +
+ {status === "loading" ? ( +
+

+ Katalog — laddar +

+
+ +
+
+ ) : null} + + {status === "error" ? ( +
+ +
+ + ← Till katalogen + +
+
+ ) : null} + + {status === "empty" ? ( +
+ +
+ + ← Till katalogen + +
+
+ ) : null} + + {status === "ready" && dataset ? : null} +
+
+ ); +} + +// ───────────────────────────────────────────────────────────────────────────── + +function DatasetView({ + d, + tab, + setTab, +}: { + d: Dataset; + tab: Tab; + setTab: (t: Tab) => void; +}) { + const deposit = Math.round(d.price / 2); + const remainder = d.price - deposit; + + return ( + <> + {/* breadcrumb */} +
+ + Katalog + + / + {d.title} +
+ + {/* masthead — oversized faint numeral as texture */} +
+ + 02 + +

+ Katalog — {d.cat} +

+

+ {d.title}. +

+

{d.blurb}

+ +
+ + + {d.markets} + + · + {d.count} +
+
+ + {/* two columns — content + sticky order rail */} +
+
+ {/* tabs — shared baseline, single active marker */} + + +
+ {tab === "Översikt" ? : null} + {tab === "Exempeldata" ? : null} + {tab === "Kvalitet" ? : null} + {tab === "Schema" ? : null} + {tab === "Täckning" ? : null} + {tab === "Pris" ? : null} +
+
+ + {/* sticky right — order panel */} + +
+ + ); +} + +// ── Tab bodies ─────────────────────────────────────────────────────────────── + +function SectionHead({ num, kicker }: { num: string; kicker: string }) { + return ( +
+

{kicker}

+ + {num} + +
+ ); +} + +function OverviewTab({ d }: { d: Dataset }) { + const stats: [string, string][] = [ + [d.count, "omfattning"], + [`${d.marketCodes.length}`, "marknader"], + [d.freshness, "uppdatering"], + ]; + return ( +
+ +

+ Strukturerat per fält. Varje värde bär källa, färskhet och konfidens — så att du ser var det + kommer ifrån innan du litar på det. +

+ +
+ {stats.map(([n, l], i) => ( +
+

+ {n} +

+

{l}

+
+ ))} +
+ +
+ +
+
+ ); +} + +function SampleTab({ d }: { d: Dataset }) { + return ( +
+ +

+ Fem rader. Provenans per cell. +

+ + {/* primary view — generative table artifact */} +
+ +
+ + {/* concrete sample rows from lib/data */} +
+ + + + {["Org.nr", "Bolag", "Säte", "Anställda", "Oms (tkr)", "E-post"].map((h) => ( + + ))} + + + + {SAMPLE_ROWS.map((r) => ( + + + + + + + + + ))} + +
+ {h} +
+ {r.orgnr} + {r.bolag}{r.sate} + {new Intl.NumberFormat("sv-SE").format(r.anstallda)} + + {new Intl.NumberFormat("sv-SE").format(r.oms)} + + {r.epost ? ( + {r.epost} + ) : ( + ej tillgänglig + )} + +
+
+

+ Tom = licens krävs i marknaden. Inget gissat. Källa: {d.source}. +

+
+ ); +} + +function QualityTab({ d }: { d: Dataset }) { + const metrics: [string, number, ProvLevel][] = [ + ["Identifierad entitet", 99, 3], + ["LEI-länkad", 92, 3], + ["Dubbletter borttagna", 100, 3], + ["E-post verifierad (MX)", 71, 2], + ["Källor överens", 88, d.level], + ]; + return ( +
+ +

+ Mätt, inte påstått. Varje rad passerar expectations, dedup och en konfidenströskel innan den + levereras. +

+ +
+ {metrics.map(([label, pct, level]) => ( +
+ {label} +
+
= 3 ? "var(--prov-3)" : level >= 2 ? "var(--prov-2)" : "var(--prov-1)", + }} + /> +
+ {pct}% +
+ ))} +
+ + {/* provenance legend */} +
+

Härkomst

+
+ {PROVENANCE_LEGEND.map((p) => ( +
+ + {p.text} +
+ ))} +
+
+
+ ); +} + +function SchemaTab() { + return ( +
+ +

Fält, källa, vikt. Per fält.

+ +
+ +
+ +
+ {FIELDS.map((f, i) => ( +
+
+
+ + {String(i + 1).padStart(2, "0")} + + {f.name} + {f.locked ? ( + låst + ) : null} +
+

{f.sub}

+
+ +
+ ))} +
+
+ ); +} + +function CoverageTab({ d }: { d: Dataset }) { + const inSet = (code: string) => d.marketCodes.includes(code); + return ( +
+ +

+ Var datasetet lever idag. Markerade marknader ingår — resten är kommande. +

+ +
+ +
+ +
+ {MARKETS.slice(0, 12).map((m) => { + const included = inSet(m.code) && m.live; + return ( +
+
+

{m.code}

+ {included ? ( + + ) : null} +
+

+ {included ? `${m.coverage}%` : m.live ? "ej i set" : "kommande"} +

+
+ ); + })} +
+
+ ); +} + +function PriceTab({ price, deposit, remainder }: { price: number; deposit: number; remainder: number }) { + const lines: [string, string, boolean][] = [ + ["Listpris", formatSEK(price), false], + ["Förskott 50 % — startar produktion", formatSEK(deposit), true], + ["Vid godkänt — släpps ur escrow", formatSEK(remainder), false], + ]; + return ( +
+ +

+ Halva nu, halva vid godkänt. Resterande hålls i escrow tills du validerat resultatet. +

+ +
+ {lines.map(([label, val, hot]) => ( +
+ {label} + + {val} + +
+ ))} +
+ +
+ + Komponera & beställ + + → + + +
+
+ ); +} diff --git a/app/katalog/page.tsx b/app/katalog/page.tsx new file mode 100644 index 0000000..e198c15 --- /dev/null +++ b/app/katalog/page.tsx @@ -0,0 +1,132 @@ +"use client"; + +import Link from "next/link"; +import { useEffect, useMemo, useState } from "react"; +import { Header } from "@/components/header"; +import { useReveal } from "@/hooks/use-reveal"; +import { CellProvenance } from "@/components/provenance-badge"; +import { LoadingSkeleton, EmptyState, ErrorState } from "@/components/states"; +import { formatSEK, type ProvLevel } from "@/lib/data"; + +interface CatalogItem { + id: string; + title: string; + markets: string[]; + entity_type: string; + count: number; + updated: string; + price_ore: number; + confidence: number; +} + +const FILTERS: { key: string; label: string }[] = [ + { key: "all", label: "Alla" }, + { key: "company", label: "Bolag" }, + { key: "contact", label: "Beslutsfattare" }, + { key: "vehicle", label: "Fordon" }, + { key: "financials", label: "Finansiellt" }, +]; + +function level(c: number): ProvLevel { + if (c >= 0.9) return 3; + if (c >= 0.8) return 2; + if (c >= 0.5) return 1; + return 0; +} + +export default function CatalogPage() { + const ref = useReveal(); + const [items, setItems] = useState(null); + const [err, setErr] = useState(false); + const [filter, setFilter] = useState("all"); + const [q, setQ] = useState(""); + + function load() { + setErr(false); + setItems(null); + fetch("/api/catalog") + .then((r) => (r.ok ? r.json() : Promise.reject())) + .then(setItems) + .catch(() => setErr(true)); + } + useEffect(load, []); + + const shown = useMemo(() => { + if (!items) return []; + return items.filter( + (d) => + (filter === "all" || d.entity_type === filter) && + (q === "" || d.title.toLowerCase().includes(q.toLowerCase())), + ); + }, [items, filter, q]); + + return ( +
+
+
+
+ 02 +

02 — Katalog

+

Färdig data. Direkt.

+
+ +
+
+ {FILTERS.map((f) => ( + + ))} +
+ setQ(e.target.value)} + placeholder="Sök dataset…" + className="w-full max-w-xs border border-border bg-input px-3 py-2 font-mono text-xs outline-none focus:border-foreground sm:w-auto" + /> +
+ +
+ {err ? ( + + ) : items === null ? ( + + ) : shown.length === 0 ? ( + + ) : ( +
+ {shown.map((d, i) => ( +
+

{d.markets.join(" · ")}

+

{d.title}

+
+ {d.count > 0 ? new Intl.NumberFormat("sv-SE").format(d.count) + " poster" : "löpande"} + · + {d.updated} + +
+
+ {formatSEK(Math.round(d.price_ore / 100))} +
+ Visa → + Beställ +
+
+
+ ))} +
+ )} +
+
+
+ ); +} diff --git a/app/portal/page.tsx b/app/portal/page.tsx new file mode 100644 index 0000000..e75e1c8 --- /dev/null +++ b/app/portal/page.tsx @@ -0,0 +1,259 @@ +"use client"; + +import Link from "next/link"; +import { useCallback, useEffect, useState } from "react"; +import { Header } from "@/components/header"; +import { EmptyState, ErrorState, LoadingSkeleton } from "@/components/states"; +import { formatSEK } from "@/lib/data"; + +// Dashboard "Mina beställningar". Fetches GET /api/orders and renders the +// customer's order ledger. Money arrives in öre; status follows the canonical +// lifecycle (draft → … → in_production → review → accepted → delivered). + +interface OrderRow { + order_id: string; + flow: string; + status: string; + total_ore: number; + created_at: string; +} + +// Swedish labels for the canonical lifecycle states. +const STATUS_LABEL: Record = { + draft: "Utkast", + quoted: "Offererad", + deposit_pending: "Väntar förskott", + in_production: "I produktion", + review: "Granskas", + revision: "Revidering", + accepted: "Godkänd", + delivered: "Levererad", +}; + +const PRODUCTION_STATES = new Set(["in_production", "review", "revision"]); +const DELIVERED_STATES = new Set(["accepted", "delivered"]); + +function fmtDate(iso: string) { + if (!iso) return "—"; + const d = new Date(iso); + if (Number.isNaN(d.getTime())) return "—"; + return new Intl.DateTimeFormat("sv-SE", { year: "numeric", month: "2-digit", day: "2-digit" }).format(d); +} + +function shortId(id: string) { + // Org-friendly truncation for long UUIDs; leave short ids untouched. + return id.length > 12 ? `${id.slice(0, 8)}…` : id; +} + +export default function PortalPage() { + const [orders, setOrders] = useState(null); + const [error, setError] = useState(false); + + const load = useCallback(async () => { + setError(false); + setOrders(null); + try { + const res = await fetch("/api/orders", { cache: "no-store" }); + if (!res.ok) throw new Error(String(res.status)); + const data = (await res.json()) as OrderRow[]; + setOrders(Array.isArray(data) ? data : []); + } catch { + setError(true); + } + }, []); + + useEffect(() => { + void load(); + }, [load]); + + const total = orders?.length ?? 0; + const inProduction = orders?.filter((o) => PRODUCTION_STATES.has(o.status)).length ?? 0; + const delivered = orders?.filter((o) => DELIVERED_STATES.has(o.status)).length ?? 0; + + return ( +
+
+ +
+ {/* masthead — oversized numeral as graphic texture */} +
+ + 00 + +

+ Portal — Översikt +

+

+ Mina beställningar. +

+

+ Allt på ett ställe. +

+
+ + +
+
+ ); +} + +function Content({ + orders, + error, + total, + inProduction, + delivered, + onRetry, +}: { + orders: OrderRow[] | null; + error: boolean; + total: number; + inProduction: number; + delivered: number; + onRetry: () => void; +}) { + if (error) { + return ( +
+ +
+ ); + } + + if (orders === null) { + return ( +
+ +
+ ); + } + + if (orders.length === 0) { + return ( +
+ +
+ ); + } + + return ( + <> + {/* stats row — shared hairline baseline, no fills */} +
+ + + +
+ + {/* orders ledger */} +
+
+

+ Beställningar +

+ + {String(total).padStart(2, "0")} + +
+ + {/* desktop table */} +
+
+ ID + Flöde + Status + Summa + Datum +
+ {orders.map((o) => ( + + + {shortId(o.order_id)} + + {o.flow} + + + {STATUS_LABEL[o.status] ?? o.status} + + + {formatSEK(o.total_ore / 100)} + + + {fmtDate(o.created_at)} + + → + + + + ))} +
+ + {/* mobile stack */} +
+ {orders.map((o) => ( + +
+ {shortId(o.order_id)} + {formatSEK(o.total_ore / 100)} +
+ {o.flow} +
+ + + {STATUS_LABEL[o.status] ?? o.status} + + {fmtDate(o.created_at)} +
+ + ))} +
+
+ + ); +} + +function Stat({ label, value }: { label: string; value: string }) { + return ( +
+

{label}

+

+ {value} +

+
+ ); +} + +/** Square provenance-coloured state marker — no red here (reserved for the EmptyState CTA). */ +function StatusDot({ status }: { status: string }) { + const color = DELIVERED_STATES.has(status) + ? "var(--prov-3)" + : PRODUCTION_STATES.has(status) + ? "var(--prov-2)" + : "var(--muted-foreground)"; + return ( + + ); +} diff --git a/components/header.tsx b/components/header.tsx index 8d705e2..81a1304 100644 --- a/components/header.tsx +++ b/components/header.tsx @@ -4,9 +4,9 @@ import Link from "next/link"; import { useEffect, useState } from "react"; const NAV = [ - { label: "Katalog", href: "/#katalog" }, + { label: "Katalog", href: "/katalog" }, { label: "Så funkar det", href: "/#motorn" }, - { label: "Källor", href: "/#tackning" }, + { label: "Källor", href: "/kallor" }, { label: "Priser", href: "/#priser" }, ]; @@ -65,7 +65,7 @@ export function Header() {
Logga in diff --git a/components/states.tsx b/components/states.tsx new file mode 100644 index 0000000..e1355bc --- /dev/null +++ b/components/states.tsx @@ -0,0 +1,169 @@ +"use client"; + +import { DataArtifact } from "@/components/data-artifact"; + +/** + * Shared loading / empty / error states for the 0pt portal. + * Mono, square, radius 0. One red accent per screen, used at most once + * (the single EmptyState CTA). No fetching here — pure presentation. + * + * LoadingSkeleton: hairline rows with a slow left-to-right sweep (not pulsing + * blobs). EmptyState: centered, generous air, faint DataArtifact "grid" motif. + * ErrorState: terse interface voice + "Försök igen". + */ + +/** Hairline shimmer rows — a slow sweep travels left→right across each bar. */ +export function LoadingSkeleton({ rows = 5 }: { rows?: number }) { + return ( +
+
+ + laddar + + + · + +
+ {Array.from({ length: Math.max(1, rows) }).map((_, i) => ( +
+ + + +
+ ))} + Laddar innehåll + + +
+ ); +} + +/** Nothing here yet — centered, lots of air, faint grid motif, one red CTA max. */ +export function EmptyState({ + title, + line, + ctaHref, + ctaLabel, +}: { + title: string; + line: string; + ctaHref?: string; + ctaLabel?: string; +}) { + return ( +
+
+ +
+ +

+ tomt +

+

+ {title} +

+

+ {line} +

+ + {ctaHref && ctaLabel ? ( + + {ctaLabel} + → + + ) : null} +
+ ); +} + +/** Something broke — interface voice, single retry. */ +export function ErrorState({ + title = "Något gick fel", + onRetry, +}: { + title?: string; + onRetry?: () => void; +}) { + return ( +
+ + +

+ fel +

+

+ {title} +

+

+ Kunde inte hämta data. Ingen ändring sparad. +

+ + {onRetry ? ( + + ) : null} +
+ ); +}