fix(recovery): restore source removed by production documentation merge
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Header } from "@/components/header";
|
||||
import { OrderStepper } from "@/components/order-stepper";
|
||||
import { SERVICES, DESTINATIONS_CRM, serviceById } from "@/lib/services";
|
||||
import { createOrder } from "@/lib/order-client";
|
||||
import { useT } from "@/components/locale-provider";
|
||||
|
||||
export default function DescribePage() {
|
||||
const t = useT();
|
||||
const PLACEHOLDER = t({
|
||||
en: "E.g. \"Consolidate our admin data and push every Swedish customer with revenue and decision-makers to HubSpot\" or \"Scrape every Norwegian construction company with email\".",
|
||||
sv: "T.ex. \"Konsolidera vår admindata och pusha alla svenska kunder med omsättning och beslutsfattare till HubSpot\" eller \"Skrapa alla norska bolag inom bygg med e-post\".",
|
||||
});
|
||||
const router = useRouter();
|
||||
const [service, setService] = useState("data");
|
||||
const [text, setText] = useState("");
|
||||
const [destination, setDestination] = useState<string>("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [rationale, setRationale] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
const s = new URLSearchParams(window.location.search).get("service");
|
||||
if (s && serviceById(s)) setService(s);
|
||||
}, []);
|
||||
|
||||
const svc = serviceById(service);
|
||||
const showDest = service === "consolidation" || service === "enrichment" || service === "icp";
|
||||
|
||||
async function submit() {
|
||||
if (busy || !text.trim()) return;
|
||||
setBusy(true);
|
||||
setRationale("");
|
||||
let config: Record<string, unknown> = { service_type: service, description: text, destination: destination || null };
|
||||
try {
|
||||
const ai = await fetch("/api/ai/parse", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ text: `${svc?.name ?? ""}. ${text}` }) });
|
||||
if (ai.ok) {
|
||||
const d = await ai.json();
|
||||
config = { ...d.config, service_type: service, description: text, destination: destination || d.config?.destination || null };
|
||||
setRationale(d.rationale ?? "");
|
||||
}
|
||||
} catch {}
|
||||
const flow = svc?.flow === "subscription" ? "subscription" : "custom";
|
||||
const id = await createOrder(flow, config);
|
||||
if (id) { router.push(`/bestall/forskott?order=${encodeURIComponent(id)}`); return; }
|
||||
setBusy(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<main id="main-content" className="min-h-screen bg-background text-foreground">
|
||||
<Header />
|
||||
<OrderStepper active={1} />
|
||||
<div className="mx-auto max-w-[60rem] px-6 py-16">
|
||||
<p className="font-mono text-[11px] uppercase tracking-[0.16em] text-muted-foreground">{t({ en: "Tailored — Describe", sv: "Skräddarsytt — Beskriv" })}</p>
|
||||
<h1 className="mt-4 max-w-[16ch] text-5xl font-medium leading-[0.95] tracking-[-0.035em] md:text-7xl">{t({ en: "Describe your need.", sv: "Beskriv behovet." })}</h1>
|
||||
<p className="mt-5 max-w-[48ch] font-mono text-[12px] uppercase tracking-[0.06em] text-muted-foreground">
|
||||
{t({ en: "Say it in plain words. We interpret, price, and scope it — you approve.", sv: "Säg det på svenska. Vi tolkar, prissätter, scopar — du godkänner." })}
|
||||
</p>
|
||||
|
||||
<div className="mt-10">
|
||||
<p className="font-mono text-[11px] uppercase tracking-[0.12em] text-muted-foreground">{t({ en: "Service", sv: "Tjänst" })}</p>
|
||||
<div className="mt-3 flex flex-wrap gap-2">
|
||||
{SERVICES.map((s) => (
|
||||
<button
|
||||
key={s.id}
|
||||
onClick={() => setService(s.id)}
|
||||
aria-pressed={service === s.id}
|
||||
className="border px-3 py-2 font-mono text-[11px] uppercase tracking-[0.08em] transition-colors"
|
||||
style={{
|
||||
borderColor: service === s.id ? "var(--foreground)" : "var(--border)",
|
||||
backgroundColor: service === s.id ? "var(--foreground)" : "transparent",
|
||||
color: service === s.id ? "var(--background)" : "var(--foreground)",
|
||||
}}
|
||||
>
|
||||
{t(s.name)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{svc ? <p className="mt-3 text-sm text-muted-foreground">{t(svc.covers)} <span className="text-muted-foreground">→ {t(svc.deliverable)}</span></p> : null}
|
||||
</div>
|
||||
|
||||
<div className="mt-8">
|
||||
<p className="font-mono text-[11px] uppercase tracking-[0.12em] text-muted-foreground">{t({ en: "Your need", sv: "Ditt behov" })}</p>
|
||||
<textarea
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
placeholder={PLACEHOLDER}
|
||||
aria-label={t({ en: "Describe your data need", sv: "Beskriv ditt databehov" })}
|
||||
rows={5}
|
||||
className="mt-3 w-full resize-none border border-border bg-input px-4 py-3 text-sm outline-none focus:border-foreground"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{showDest ? (
|
||||
<div className="mt-6">
|
||||
<p className="font-mono text-[11px] uppercase tracking-[0.12em] text-muted-foreground">{t({ en: "Deliver to (CRM/ERP)", sv: "Leverera till (CRM/ERP)" })}</p>
|
||||
<div className="mt-3 flex flex-wrap gap-2">
|
||||
{DESTINATIONS_CRM.map((d) => (
|
||||
<button
|
||||
key={d}
|
||||
onClick={() => setDestination(destination === d ? "" : d)}
|
||||
aria-pressed={destination === d}
|
||||
className="border px-3 py-2 font-mono text-[11px] uppercase tracking-[0.08em] transition-colors"
|
||||
style={{
|
||||
borderColor: destination === d ? "var(--accent-red)" : "var(--border)",
|
||||
backgroundColor: destination === d ? "rgba(228,0,20,0.06)" : "transparent",
|
||||
}}
|
||||
>
|
||||
{d}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{rationale ? <p className="mt-6 font-mono text-[11px] text-muted-foreground">{rationale}</p> : null}
|
||||
|
||||
<div className="mt-10 flex flex-wrap items-center gap-4">
|
||||
<button
|
||||
onClick={submit}
|
||||
disabled={busy || !text.trim()}
|
||||
className="bg-foreground px-6 py-3.5 font-mono text-[12px] uppercase tracking-[0.1em] text-background transition-colors hover:bg-[var(--accent-red)] disabled:opacity-50"
|
||||
>
|
||||
{busy ? t({ en: "Interpreting…", sv: "Tolkar…" }) : t({ en: "Get estimate →", sv: "Få estimat →" })}
|
||||
</button>
|
||||
<Link href="/bestall" className="font-mono text-[11px] uppercase tracking-[0.08em] text-muted-foreground underline-offset-4 hover:text-foreground hover:underline">
|
||||
{t({ en: "Or build it in detail", sv: "Eller bygg detaljerat" })}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useEffect, useState } from "react";
|
||||
import { OrderStepper } from "@/components/order-stepper";
|
||||
import { useT } from "@/components/locale-provider";
|
||||
import { useReveal } from "@/hooks/use-reveal";
|
||||
import {
|
||||
formatSEK, computeEstimate, entityLabel, FREQUENCY_LABEL,
|
||||
type Estimate, type EntityType, type Frequency,
|
||||
} from "@/lib/data";
|
||||
|
||||
const FALLBACK: Estimate = computeEstimate({
|
||||
markets: ["SE", "NO", "DK", "FI"],
|
||||
type: "Bolag",
|
||||
fieldIds: ["lei", "financials", "contact"],
|
||||
enrichmentIds: ["nace"],
|
||||
volume: 5000,
|
||||
frequency: "Engångs",
|
||||
confidence: 92,
|
||||
});
|
||||
|
||||
const TRUST: { title: { en: string; sv: string }; body: { en: string; sv: string } }[] = [
|
||||
{
|
||||
title: { en: "Provenance per field", sv: "Härkomst per fält" },
|
||||
body: { en: "Source, freshness, confidence.", sv: "Källa, färskhet, konfidens." },
|
||||
},
|
||||
{
|
||||
title: { en: "GDPR-native", sv: "GDPR-native" },
|
||||
body: { en: "DPA and lawful basis per field.", sv: "DPA och laglig grund per fält." },
|
||||
},
|
||||
{
|
||||
title: { en: "You push your data", sv: "Du pushar din data" },
|
||||
body: {
|
||||
en: "Read-only role. Time-boxed. Deleted afterwards.",
|
||||
sv: "Read-only roll. Tidsbegränsad. Raderad efteråt.",
|
||||
},
|
||||
},
|
||||
{
|
||||
title: { en: "Audit log", sv: "Revisionslogg" },
|
||||
body: { en: "What. When. Why.", sv: "Vad. När. Varför." },
|
||||
},
|
||||
];
|
||||
|
||||
const RECAP_LABELS: Record<string, { en: string; sv: string }> = {
|
||||
markets: { en: "Markets", sv: "Marknader" },
|
||||
type: { en: "Type", sv: "Typ" },
|
||||
volume: { en: "Volume", sv: "Volym" },
|
||||
frequency: { en: "Frequency", sv: "Frekvens" },
|
||||
};
|
||||
|
||||
export default function DepositPage() {
|
||||
const t = useT();
|
||||
const [est, setEst] = useState<Estimate>(FALLBACK);
|
||||
const [recap, setRecap] = useState<{ markets: string; type: EntityType; volume: string; frequency: Frequency }>({
|
||||
markets: "SE · NO · DK · FI", type: "Bolag", volume: "5 000", frequency: "Engångs",
|
||||
});
|
||||
const [orderId, setOrderId] = useState<string | null>(null);
|
||||
const [paying, setPaying] = useState(false);
|
||||
const [paymentError, setPaymentError] = useState(false);
|
||||
const reveal = useReveal<HTMLDivElement>();
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
const raw = sessionStorage.getItem("0pt-order");
|
||||
if (raw) {
|
||||
const o = JSON.parse(raw);
|
||||
if (o.est) setEst(o.est);
|
||||
setRecap({
|
||||
markets: (o.markets || []).join(" · "),
|
||||
type: (o.type as EntityType) || "Bolag",
|
||||
volume: new Intl.NumberFormat("sv-SE").format(o.volume || 0),
|
||||
frequency: (o.frequency as Frequency) || "Engångs",
|
||||
});
|
||||
}
|
||||
} 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({
|
||||
markets: (c.markets || []).join(" · "),
|
||||
type: (c.type as EntityType) || "Bolag",
|
||||
volume: new Intl.NumberFormat("sv-SE").format(c.volume || 0),
|
||||
frequency: (c.frequency as Frequency) || "Engångs",
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
}, []);
|
||||
|
||||
async function pay() {
|
||||
if (paying) return;
|
||||
setPaying(true);
|
||||
setPaymentError(false);
|
||||
if (orderId) {
|
||||
try {
|
||||
const r = await fetch(`/api/payments/${orderId}/deposit`, { method: "POST" });
|
||||
if (r.ok) {
|
||||
const body = await r.json() as { url?: string };
|
||||
if (body.url) { window.location.href = body.url; return; }
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
// No Checkout URL means no payment. Keep the draft and let the customer
|
||||
// retry; never simulate a successful payment or redirect to a demo order.
|
||||
setPaymentError(true);
|
||||
setPaying(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<main id="main-content" className="min-h-screen bg-background text-foreground">
|
||||
<OrderStepper active={2} />
|
||||
|
||||
<div ref={reveal} className="mx-auto max-w-[80rem] px-6 py-16 md:py-24">
|
||||
{/* header */}
|
||||
<div className="reveal flex items-start justify-between gap-6 border-b border-border pb-8">
|
||||
<div>
|
||||
<p className="font-mono text-[11px] uppercase tracking-[0.16em] text-muted-foreground">
|
||||
{t({ en: "Step 2 — Deposit", sv: "Steg 2 — Förskott" })}
|
||||
</p>
|
||||
<h1 className="mt-4 text-5xl font-medium leading-[0.95] tracking-[-0.03em] md:text-7xl">
|
||||
{t({ en: "Half now.", sv: "Halva nu." })}
|
||||
<br />
|
||||
{t({ en: "Half in escrow.", sv: "Halva i depå." })}
|
||||
</h1>
|
||||
</div>
|
||||
<span
|
||||
aria-hidden
|
||||
className="select-none font-mono text-7xl font-medium leading-none tracking-[-0.04em] text-border md:text-8xl"
|
||||
>
|
||||
02
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="mt-16 grid grid-cols-1 gap-px bg-border lg:grid-cols-[1fr_360px]">
|
||||
<div className="flex flex-col gap-px bg-border">
|
||||
{/* split */}
|
||||
<section className="reveal bg-background">
|
||||
<div className="flex items-center justify-between border-b border-border px-1 pb-3">
|
||||
<p className="font-mono text-[11px] uppercase tracking-[0.14em] text-muted-foreground">
|
||||
{t({ en: "Payment structure", sv: "Betalningsupplägg" })}
|
||||
</p>
|
||||
<p className="font-mono text-[11px] uppercase tracking-[0.14em] text-muted-foreground">
|
||||
50 / 50
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2">
|
||||
<div
|
||||
className="group relative border-b border-border p-8 transition-opacity sm:border-b-0 sm:border-r"
|
||||
style={{ backgroundColor: "rgba(228,0,20,0.05)" }}
|
||||
>
|
||||
<p
|
||||
className="font-mono text-[10.5px] uppercase tracking-[0.12em]"
|
||||
style={{ color: "var(--accent-red)" }}
|
||||
>
|
||||
{t({ en: "Now", sv: "Nu" })}
|
||||
</p>
|
||||
<p
|
||||
className="mt-4 text-5xl font-medium tabular-nums tracking-[-0.02em]"
|
||||
style={{ color: "var(--accent-red)" }}
|
||||
>
|
||||
{formatSEK(est.deposit)}
|
||||
</p>
|
||||
<p className="mt-3 font-mono text-[11px] text-muted-foreground">
|
||||
{t({ en: "Starts the job. Today.", sv: "Startar jobbet. Idag." })}
|
||||
</p>
|
||||
</div>
|
||||
<div className="group relative p-8 transition-opacity">
|
||||
<p className="font-mono text-[10.5px] uppercase tracking-[0.12em] text-muted-foreground">
|
||||
{t({ en: "On approval", sv: "Vid godkänt" })}
|
||||
</p>
|
||||
<p className="mt-4 text-5xl font-medium tabular-nums tracking-[-0.02em]">
|
||||
{formatSEK(est.remainder)}
|
||||
</p>
|
||||
<p className="mt-3 font-mono text-[11px] text-muted-foreground">
|
||||
{t({ en: "Released from escrow.", sv: "Frigörs ur depå." })}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p className="border-t border-border px-1 pt-3 text-sm text-muted-foreground">
|
||||
{t({ en: "The other half isn't touched until you click Approve.", sv: "Andra halvan rörs först när du tryckt Godkänn." })}
|
||||
</p>
|
||||
</section>
|
||||
|
||||
{/* trust */}
|
||||
<section className="reveal delay-1 bg-background">
|
||||
<p className="border-b border-border px-1 pb-3 font-mono text-[11px] uppercase tracking-[0.14em] text-muted-foreground">
|
||||
{t({ en: "Data & access", sv: "Data & åtkomst" })}
|
||||
</p>
|
||||
<dl>
|
||||
{TRUST.map((item, i) => (
|
||||
<div
|
||||
key={item.title.en}
|
||||
className="group flex items-baseline gap-4 border-b border-border py-4 transition-colors last:border-b-0"
|
||||
>
|
||||
<span
|
||||
aria-hidden
|
||||
className="w-6 shrink-0 font-mono text-[11px] tabular-nums text-muted-foreground"
|
||||
>
|
||||
{String(i + 1).padStart(2, "0")}
|
||||
</span>
|
||||
<dt className="w-44 shrink-0 text-sm font-medium tracking-[-0.01em]">{t(item.title)}</dt>
|
||||
<dd className="text-sm text-muted-foreground">{t(item.body)}</dd>
|
||||
<span
|
||||
aria-hidden
|
||||
className="ml-auto h-2 w-2 shrink-0 self-center"
|
||||
style={{ backgroundColor: "var(--prov-3)" }}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
{/* summary */}
|
||||
<aside className="bg-background lg:sticky lg:top-6 lg:self-start">
|
||||
<div className="reveal reveal-right border border-border">
|
||||
<p className="border-b border-border px-4 py-3 font-mono text-[11px] uppercase tracking-[0.14em] text-muted-foreground">
|
||||
{t({ en: "Your order", sv: "Din beställning" })}
|
||||
</p>
|
||||
<dl className="divide-y divide-border">
|
||||
<div className="flex items-center justify-between px-4 py-3">
|
||||
<dt className="font-mono text-[10.5px] uppercase tracking-[0.1em] text-muted-foreground">{t(RECAP_LABELS.markets)}</dt>
|
||||
<dd className="max-w-[60%] truncate text-right font-mono text-xs tracking-[-0.01em]">{recap.markets || "—"}</dd>
|
||||
</div>
|
||||
<div className="flex items-center justify-between px-4 py-3">
|
||||
<dt className="font-mono text-[10.5px] uppercase tracking-[0.1em] text-muted-foreground">{t(RECAP_LABELS.type)}</dt>
|
||||
<dd className="max-w-[60%] truncate text-right font-mono text-xs tracking-[-0.01em]">{t(entityLabel(recap.type))}</dd>
|
||||
</div>
|
||||
<div className="flex items-center justify-between px-4 py-3">
|
||||
<dt className="font-mono text-[10.5px] uppercase tracking-[0.1em] text-muted-foreground">{t(RECAP_LABELS.volume)}</dt>
|
||||
<dd className="max-w-[60%] truncate text-right font-mono text-xs tracking-[-0.01em]">{recap.volume || "—"}</dd>
|
||||
</div>
|
||||
<div className="flex items-center justify-between px-4 py-3">
|
||||
<dt className="font-mono text-[10.5px] uppercase tracking-[0.1em] text-muted-foreground">{t(RECAP_LABELS.frequency)}</dt>
|
||||
<dd className="max-w-[60%] truncate text-right font-mono text-xs tracking-[-0.01em]">{t(FREQUENCY_LABEL[recap.frequency] ?? { en: recap.frequency, sv: recap.frequency })}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
<div className="border-t border-border p-4">
|
||||
<div className="flex items-baseline justify-between">
|
||||
<p
|
||||
className="font-mono text-[10.5px] uppercase tracking-[0.12em]"
|
||||
style={{ color: "var(--accent-red)" }}
|
||||
>
|
||||
{t({ en: "To pay now", sv: "Att betala nu" })}
|
||||
</p>
|
||||
<p className="font-mono text-[10.5px] uppercase tracking-[0.1em] text-muted-foreground">
|
||||
{t({ en: "excl. VAT · Stripe", sv: "exkl. moms · Stripe" })}
|
||||
</p>
|
||||
</div>
|
||||
<p className="mt-2 font-mono text-3xl font-medium tabular-nums tracking-[-0.02em]">
|
||||
{formatSEK(est.deposit)}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="border-t border-border p-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={pay}
|
||||
disabled={paying}
|
||||
className="block w-full bg-foreground py-4 text-center font-mono text-[12px] uppercase tracking-[0.12em] text-background transition-colors hover:bg-[var(--accent-red)] disabled:opacity-50"
|
||||
>
|
||||
{paying ? t({ en: "Starting…", sv: "Startar…" }) : t({ en: "Pay. Start. →", sv: "Betala. Starta. →" })}
|
||||
</button>
|
||||
{paymentError && (
|
||||
<p role="alert" className="mt-3 text-sm text-[var(--accent-red)]">
|
||||
{t({ en: "Payment could not be started. Your order is still a draft; please try again.", sv: "Betalningen kunde inte startas. Din order är fortfarande ett utkast; försök igen." })}
|
||||
</p>
|
||||
)}
|
||||
<Link
|
||||
href="/bestall"
|
||||
className="mt-4 block text-center font-mono text-[11px] uppercase tracking-[0.1em] text-muted-foreground underline-offset-4 transition-colors hover:text-foreground hover:underline"
|
||||
>
|
||||
{t({ en: "← Back", sv: "← Tillbaka" })}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,376 @@
|
||||
"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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user