RouteReveal layout component applies in-view on every route change. useReveal hook falls back to immediate rAF when element is already visible. bestall/page.tsx: added missing useReveal ref. katalog/[id]/page.tsx: DatasetView uses useReveal directly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
377 lines
17 KiB
TypeScript
377 lines
17 KiB
TypeScript
"use client";
|
||
|
||
import { useRouter } from "next/navigation";
|
||
import { useMemo, useState, useEffect } from "react";
|
||
import { toast } from "sonner";
|
||
import { OrderStepper } from "@/components/order-stepper";
|
||
import { ProvenanceBadge } from "@/components/provenance-badge";
|
||
import { useT } from "@/components/locale-provider";
|
||
import { useReveal } from "@/hooks/use-reveal";
|
||
import { createOrder } from "@/lib/order-client";
|
||
import { SERVICES, serviceById } from "@/lib/services";
|
||
import {
|
||
MARKETS,
|
||
ENTITY_TYPES,
|
||
FIELDS,
|
||
ENRICHMENTS,
|
||
FREQUENCIES,
|
||
DELIVERY_FORMATS,
|
||
FREQUENCY_LABEL,
|
||
FORMAT_LABEL,
|
||
entityLabel,
|
||
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 t = useT();
|
||
const revealRef = useReveal<HTMLDivElement>();
|
||
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 [service, setService] = useState("data");
|
||
|
||
const est = useMemo(
|
||
() => computeEstimate({ markets, type, fieldIds, enrichmentIds, volume, frequency, confidence, serviceMult: serviceById(service)?.mult ?? 1 }),
|
||
[markets, type, fieldIds, enrichmentIds, volume, frequency, confidence, service],
|
||
);
|
||
|
||
// 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 router = useRouter();
|
||
const [creating, setCreating] = useState(false);
|
||
async function submit() {
|
||
if (creating) return;
|
||
setCreating(true);
|
||
const config = { markets, type, fieldIds, enrichmentIds, volume, frequency, confidence, formats, service_type: service };
|
||
const id = await createOrder(frequency === "Engångs" ? "custom" : "subscription", config);
|
||
if (id) {
|
||
toast.success(t({ en: "Order created. Proceeding to deposit.", sv: "Order skapad. Fortsätter till förskott." }));
|
||
router.push(`/bestall/forskott?order=${encodeURIComponent(id)}`);
|
||
} else {
|
||
toast.error(t({ en: "Could not create order. Please try again.", sv: "Kunde inte skapa order. Försök igen." }));
|
||
setCreating(false);
|
||
}
|
||
}
|
||
|
||
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}
|
||
aria-pressed={active}
|
||
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 = ({ index, label, children }: { index: string; label: string; children: React.ReactNode }) => (
|
||
<div className="group border border-border transition-colors hover:border-foreground">
|
||
<div className="flex items-center gap-3 border-b border-border px-4 py-2.5">
|
||
<span className="font-mono text-[11px] tabular-nums text-muted-foreground transition-colors group-hover:text-foreground">
|
||
{index}
|
||
</span>
|
||
<span className="h-3 w-px bg-border" />
|
||
<span className="font-mono text-[11px] uppercase tracking-[0.12em] text-foreground">{label}</span>
|
||
</div>
|
||
<div className="p-4">{children}</div>
|
||
</div>
|
||
);
|
||
|
||
return (
|
||
<main id="main-content" className="min-h-screen bg-background text-foreground">
|
||
<OrderStepper active={1} />
|
||
|
||
<div ref={revealRef} className="mx-auto max-w-[80rem] px-6 py-16">
|
||
{/* Editorial masthead — oversized index as graphic texture */}
|
||
<div className="reveal relative border-b border-border pb-10">
|
||
<span
|
||
aria-hidden
|
||
className="pointer-events-none absolute -top-6 right-0 select-none font-mono text-[7rem] leading-none tracking-[-0.04em] text-muted-foreground/10 md:text-[10rem]"
|
||
>
|
||
01
|
||
</span>
|
||
<p className="font-mono text-[11px] uppercase tracking-[0.18em] text-muted-foreground">
|
||
{t({ en: "Step 01 / Configure", sv: "Steg 01 / Konfigurera" })}
|
||
</p>
|
||
<h1 className="mt-4 max-w-[14ch] text-5xl font-medium leading-[0.95] tracking-[-0.035em] md:text-7xl">
|
||
{t({ en: "Build the job.", sv: "Bygg jobbet." })}
|
||
</h1>
|
||
<p className="mt-5 max-w-[34ch] font-mono text-[12px] uppercase tracking-[0.06em] text-muted-foreground">
|
||
{t({ en: "Seven choices. One price. Nothing guessed.", sv: "Sju val. Ett pris. Inget gissat." })}
|
||
</p>
|
||
</div>
|
||
|
||
<div className="mt-12 grid grid-cols-1 gap-6 lg:grid-cols-[1fr_360px]">
|
||
{/* LEFT — builder */}
|
||
<div className="reveal-left flex flex-col gap-4">
|
||
<Block index="00" label={t({ en: "Service", sv: "Tjänst" })}>
|
||
<div className="flex flex-wrap gap-2">
|
||
{SERVICES.map((s) => (
|
||
<Chip key={s.id} active={service === s.id} onClick={() => setService(s.id)}>
|
||
{t(s.name)}
|
||
</Chip>
|
||
))}
|
||
</div>
|
||
{serviceById(service) ? (
|
||
<p className="mt-3 text-xs text-muted-foreground">{t(serviceById(service)!.covers)}</p>
|
||
) : null}
|
||
</Block>
|
||
|
||
<Block index="01" label={t({ en: "Markets", sv: "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">
|
||
{t({ en: "Nordics live. The rest is coming.", sv: "Norden live. Övriga kommer." })}
|
||
</p>
|
||
</Block>
|
||
|
||
<Block index="02" label={t({ en: "Record type", sv: "Typ av poster" })}>
|
||
<div className="flex gap-2">
|
||
{ENTITY_TYPES.map((e) => (
|
||
<Chip key={e.id} active={type === e.id} onClick={() => setType(e.id)}>
|
||
{t(e.label)}
|
||
</Chip>
|
||
))}
|
||
</div>
|
||
</Block>
|
||
|
||
<Block index="03" label={t({ en: "Fields to include", sv: "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">{t(f.name)}</span>
|
||
<span className="ml-2 text-xs text-muted-foreground">{t(f.sub)}</span>
|
||
{f.locked ? (
|
||
<span className="ml-2 font-mono text-[10px] uppercase text-muted-foreground">{t({ en: "locked", sv: "låst" })}</span>
|
||
) : null}
|
||
</span>
|
||
<ProvenanceBadge level={f.level as ProvLevel} source={t(f.source)} freshness={t(f.freshness)} />
|
||
</label>
|
||
);
|
||
})}
|
||
</div>
|
||
</Block>
|
||
|
||
<Block index="04" label={t({ en: "Enrichment & matching", sv: "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)}
|
||
>
|
||
{t(e.label)}
|
||
</Chip>
|
||
))}
|
||
</div>
|
||
</Block>
|
||
|
||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||
<Block index="05" label={t({ en: "Volume", sv: "Volym" })}>
|
||
<input
|
||
type="number"
|
||
min={100}
|
||
step={100}
|
||
value={volume}
|
||
onChange={(e) => setVolume(Math.max(100, Number(e.target.value) || 0))}
|
||
aria-label={t({ en: "Volume (records)", sv: "Volym (poster)" })}
|
||
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)}>
|
||
{t(FREQUENCY_LABEL[fr])}
|
||
</Chip>
|
||
))}
|
||
</div>
|
||
</Block>
|
||
|
||
<Block index="06" label={t({ en: "Confidence target", sv: "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))}
|
||
aria-label={t({ en: "Confidence target (%)", sv: "Konfidensmål (%)" })}
|
||
aria-valuemin={80}
|
||
aria-valuemax={99}
|
||
aria-valuenow={confidence}
|
||
aria-valuetext={`${confidence}%`}
|
||
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 index="07" label={t({ en: "Delivery format", sv: "Leveransformat" })}>
|
||
<div className="flex flex-wrap gap-2">
|
||
{DELIVERY_FORMATS.map((f) => (
|
||
<Chip key={f} active={formats.includes(f)} onClick={() => toggle(formats, f, setFormats)}>
|
||
{t(FORMAT_LABEL[f] ?? { en: f, sv: f })}
|
||
</Chip>
|
||
))}
|
||
</div>
|
||
</Block>
|
||
</div>
|
||
|
||
{/* RIGHT — sticky summary */}
|
||
<aside className="reveal-right lg:sticky lg:top-6 lg:self-start">
|
||
<div className="border border-border">
|
||
<div className="flex items-center gap-3 border-b border-border px-4 py-2.5">
|
||
<span className="font-mono text-[11px] tabular-nums text-muted-foreground">∑</span>
|
||
<span className="h-3 w-px bg-border" />
|
||
<span className="font-mono text-[11px] uppercase tracking-[0.12em] text-foreground">Order</span>
|
||
</div>
|
||
<dl className="divide-y divide-border">
|
||
{[
|
||
[t({ en: "Service", sv: "Tjänst" }), serviceById(service) ? t(serviceById(service)!.name) : service],
|
||
[t({ en: "Markets", sv: "Marknader" }), markets.join(" · ") || "—"],
|
||
[t({ en: "Type", sv: "Typ" }), t(entityLabel(type))],
|
||
[t({ en: "Fields", sv: "Fält" }), String(FIELDS.filter((f) => f.locked || fieldIds.includes(f.id)).length)],
|
||
[t({ en: "Enrichment", sv: "Berikning" }), String(enrichmentIds.length)],
|
||
[t({ en: "Volume", sv: "Volym" }), new Intl.NumberFormat("sv-SE").format(volume)],
|
||
[t({ en: "Frequency", sv: "Frekvens" }), t(FREQUENCY_LABEL[frequency])],
|
||
[t({ en: "Delivery", sv: "Leverans" }), `≈ ${est.timelineDays} ${t({ en: "days", sv: "dgr" })}`],
|
||
[t({ en: "Confidence", sv: "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 — oversized numeral */}
|
||
<div className="border-t border-border p-4">
|
||
<p className="font-mono text-[10.5px] uppercase tracking-[0.08em] text-muted-foreground">
|
||
{t({ en: "Fee", sv: "Arvode" })}{est.recurring ? t({ en: " /mo", sv: " /mån" }) : ""}
|
||
</p>
|
||
<p className="mt-1 text-[40px] font-medium leading-none tracking-[-0.03em] tabular-nums">
|
||
{formatSEK(est.price)}
|
||
</p>
|
||
</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)" }}>
|
||
{t({ en: "Deposit · 50%", sv: "Förskott · 50 %" })}
|
||
</p>
|
||
<p className="mt-1 font-mono text-2xl font-medium tabular-nums">{formatSEK(est.deposit)}</p>
|
||
<p className="mt-2 text-xs text-muted-foreground">
|
||
{t({ en: "The rest in escrow. Released on approved delivery.", sv: "Resten i depå. Frigörs vid godkänd leverans." })}
|
||
</p>
|
||
</div>
|
||
|
||
<div className="p-4 pt-0">
|
||
<button
|
||
type="button"
|
||
onClick={submit}
|
||
disabled={creating}
|
||
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)] disabled:opacity-50"
|
||
>
|
||
{creating ? t({ en: "Creating…", sv: "Skapar…" }) : t({ en: "Pay deposit →", sv: "Betala förskott →" })}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<p className="mt-3 text-center font-mono text-[10px] uppercase tracking-[0.08em] text-muted-foreground">
|
||
{t({ en: "Source per field · GDPR-native · nothing guessed", sv: "Källa per fält · GDPR-native · inget gissat" })}
|
||
</p>
|
||
</aside>
|
||
</div>
|
||
</div>
|
||
</main>
|
||
);
|
||
}
|