Files
0pt/app/bestall/page.tsx
T
adminandClaude Opus 4.8 24035dec8b 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]>
2026-06-24 17:28:24 +02:00

309 lines
12 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import Link from "next/link";
import { useMemo, useState, useEffect } from "react";
import { OrderStepper } from "@/components/order-stepper";
import { ProvenanceBadge } from "@/components/provenance-badge";
import {
MARKETS,
ENTITY_TYPES,
FIELDS,
ENRICHMENTS,
FREQUENCIES,
DELIVERY_FORMATS,
computeEstimate,
formatSEK,
type EntityType,
type Frequency,
type ProvLevel,
} from "@/lib/data";
function confidenceColor(v: number) {
if (v >= 92) return "var(--prov-3)";
if (v >= 87) return "var(--prov-2)";
return "var(--prov-1)";
}
export default function ConfiguratorPage() {
const [markets, setMarkets] = useState<string[]>(["SE", "NO", "DK", "FI"]);
const [type, setType] = useState<EntityType>("Bolag");
const [fieldIds, setFieldIds] = useState<string[]>(["lei", "financials", "contact"]);
const [enrichmentIds, setEnrichmentIds] = useState<string[]>(["nace"]);
const [volume, setVolume] = useState(5000);
const [frequency, setFrequency] = useState<Frequency>("Engångs");
const [confidence, setConfidence] = useState(92);
const [formats, setFormats] = useState<string[]>(["CSV", "Tabellvy (NocoDB)"]);
const est = useMemo(
() => computeEstimate({ markets, type, fieldIds, enrichmentIds, volume, frequency, confidence }),
[markets, type, fieldIds, enrichmentIds, volume, frequency, confidence],
);
// Persist so the deposit screen shows the same numbers.
useEffect(() => {
try {
sessionStorage.setItem(
"0pt-order",
JSON.stringify({ markets, type, fieldIds, enrichmentIds, volume, frequency, confidence, formats, est }),
);
} catch {}
}, [markets, type, fieldIds, enrichmentIds, volume, frequency, confidence, formats, est]);
const toggle = (arr: string[], v: string, set: (x: string[]) => void) =>
set(arr.includes(v) ? arr.filter((x) => x !== v) : [...arr, v]);
const Chip = ({
active,
disabled,
onClick,
children,
}: {
active?: boolean;
disabled?: boolean;
onClick?: () => void;
children: React.ReactNode;
}) => (
<button
type="button"
disabled={disabled}
onClick={onClick}
className="border px-3 py-2 font-mono text-[11px] uppercase tracking-[0.08em] transition-colors disabled:cursor-not-allowed disabled:opacity-35"
style={{
borderColor: active ? "var(--foreground)" : "var(--border)",
backgroundColor: active ? "var(--foreground)" : "transparent",
color: active ? "var(--background)" : "var(--foreground)",
}}
>
{children}
</button>
);
const Block = ({ label, children }: { label: string; children: React.ReactNode }) => (
<div className="border border-border">
<div className="border-b border-border px-4 py-2 font-mono text-[11px] uppercase tracking-[0.12em] text-muted-foreground">
{label}
</div>
<div className="p-4">{children}</div>
</div>
);
return (
<main className="min-h-screen bg-background text-foreground">
<OrderStepper active={1} />
<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 1 — Konfigurera
</p>
<h1 className="mt-3 text-4xl font-medium tracking-[-0.025em] md:text-5xl">
Sätt ihop ditt datajobb.
</h1>
<div className="mt-8 grid grid-cols-1 gap-6 lg:grid-cols-[1fr_360px]">
{/* LEFT — builder */}
<div className="flex flex-col gap-4">
<Block label="Marknader">
<div className="flex flex-wrap gap-2">
{MARKETS.map((m) => (
<Chip
key={m.code}
active={markets.includes(m.code)}
disabled={!m.live}
onClick={() => toggle(markets, m.code, setMarkets)}
>
{m.code}
{!m.live ? " ·" : ""}
</Chip>
))}
</div>
<p className="mt-3 font-mono text-[10.5px] uppercase tracking-[0.08em] text-muted-foreground">
Nordiska marknader är live. Övriga markeras "kommande".
</p>
</Block>
<Block label="Typ av poster">
<div className="flex gap-2">
{ENTITY_TYPES.map((e) => (
<Chip key={e.id} active={type === e.id} onClick={() => setType(e.id)}>
{e.id}
</Chip>
))}
</div>
</Block>
<Block label="Fält att inkludera">
<div className="flex flex-col">
{FIELDS.map((f, i) => {
const on = f.locked || fieldIds.includes(f.id);
return (
<label
key={f.id}
className="flex items-center gap-3 border-border py-3 [&:not(:last-child)]:border-b"
style={{ cursor: f.locked ? "default" : "pointer" }}
>
<span
className="flex h-4 w-4 shrink-0 items-center justify-center border"
style={{
borderColor: on ? "var(--foreground)" : "var(--border)",
backgroundColor: on ? "var(--foreground)" : "transparent",
color: "var(--background)",
}}
>
{on ? "✓" : ""}
</span>
<input
type="checkbox"
className="sr-only"
checked={on}
disabled={f.locked}
onChange={() => toggle(fieldIds, f.id, setFieldIds)}
/>
<span className="flex-1">
<span className="text-sm">{f.name}</span>
<span className="ml-2 text-xs text-muted-foreground">{f.sub}</span>
{f.locked ? (
<span className="ml-2 font-mono text-[10px] uppercase text-muted-foreground">låst</span>
) : null}
</span>
<ProvenanceBadge level={f.level as ProvLevel} source={f.source} freshness={f.freshness} />
</label>
);
})}
</div>
</Block>
<Block label="Berikning & matchning">
<div className="flex flex-wrap gap-2">
{ENRICHMENTS.map((e) => (
<Chip
key={e.id}
active={enrichmentIds.includes(e.id)}
onClick={() => toggle(enrichmentIds, e.id, setEnrichmentIds)}
>
{e.label}
</Chip>
))}
</div>
</Block>
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
<Block label="Volym (antal poster)">
<input
type="number"
min={100}
step={100}
value={volume}
onChange={(e) => setVolume(Math.max(100, Number(e.target.value) || 0))}
className="w-full border border-border bg-input px-3 py-2 font-mono text-sm outline-none focus:border-foreground"
/>
<div className="mt-3 flex gap-2">
{FREQUENCIES.map((fr) => (
<Chip key={fr} active={frequency === fr} onClick={() => setFrequency(fr)}>
{fr}
</Chip>
))}
</div>
</Block>
<Block label="Konfidensmål">
<div className="flex items-baseline justify-between">
<span className="font-mono text-2xl" style={{ color: confidenceColor(confidence) }}>
{confidence}%
</span>
<span className="font-mono text-[10.5px] uppercase tracking-[0.08em] text-muted-foreground">
80 – 99
</span>
</div>
<input
type="range"
min={80}
max={99}
value={confidence}
onChange={(e) => setConfidence(Number(e.target.value))}
className="mt-3 w-full"
style={{ accentColor: confidenceColor(confidence) }}
/>
<div className="mt-2 h-1.5 w-full bg-secondary">
<div
className="h-full transition-all"
style={{ width: `${((confidence - 80) / 19) * 100}%`, backgroundColor: confidenceColor(confidence) }}
/>
</div>
</Block>
</div>
<Block label="Leveransformat">
<div className="flex flex-wrap gap-2">
{DELIVERY_FORMATS.map((f) => (
<Chip key={f} active={formats.includes(f)} onClick={() => toggle(formats, f, setFormats)}>
{f}
</Chip>
))}
</div>
</Block>
</div>
{/* RIGHT — sticky summary */}
<aside className="lg:sticky lg:top-6 lg:self-start">
<div className="border border-border">
<div className="border-b border-border px-4 py-2 font-mono text-[11px] uppercase tracking-[0.12em] text-muted-foreground">
Sammanfattning
</div>
<dl className="divide-y divide-border">
{[
["Marknader", markets.join(" · ") || "—"],
["Typ", type],
["Fält", String(FIELDS.filter((f) => f.locked || fieldIds.includes(f.id)).length)],
["Berikning", String(enrichmentIds.length)],
["Volym", new Intl.NumberFormat("sv-SE").format(volume)],
["Frekvens", frequency],
["Leveranstid", `≈ ${est.timelineDays} dgr`],
["Est. konfidens", `${est.estConfidence}%`],
].map(([k, v]) => (
<div key={k} className="flex items-center justify-between px-4 py-2.5">
<dt className="font-mono text-[10.5px] uppercase tracking-[0.08em] text-muted-foreground">{k}</dt>
<dd className="max-w-[60%] truncate text-right font-mono text-xs">{v}</dd>
</div>
))}
</dl>
{/* price */}
<div className="border-t border-border p-4">
<div className="flex items-baseline justify-between">
<span className="font-mono text-[10.5px] uppercase tracking-[0.08em] text-muted-foreground">
Totalt arvode{est.recurring ? " /mån" : ""}
</span>
<span className="text-[34px] font-medium tracking-[-0.02em]">{formatSEK(est.price)}</span>
</div>
</div>
{/* deposit — the only red on this screen */}
<div className="m-4 mt-0 border p-4" style={{ borderColor: "var(--accent-red)" }}>
<p className="font-mono text-[10.5px] uppercase tracking-[0.1em]" style={{ color: "var(--accent-red)" }}>
Förskott 50 % för att starta
</p>
<p className="mt-1 font-mono text-2xl font-medium">{formatSEK(est.deposit)}</p>
<p className="mt-1 text-xs text-muted-foreground">
Resterande {formatSEK(est.remainder)} hålls i depå och frigörs vid godkänd leverans.
</p>
</div>
<div className="p-4 pt-0">
<Link
href="/bestall/forskott"
className="block w-full bg-foreground py-3.5 text-center font-mono text-[12px] uppercase tracking-[0.1em] text-background transition-colors hover:bg-[var(--accent-red)]"
>
Gå till förskott →
</Link>
</div>
</div>
<p className="mt-3 text-center font-mono text-[10px] uppercase tracking-[0.08em] text-muted-foreground">
Härkomst per fält · GDPR-native · ingen uppgift gissad
</p>
</aside>
</div>
</div>
</main>
);
}