masterplan-lock / check (pull_request) Successful in 4s
CI (SIAX Cloud) / security (push) Successful in 14s
CI (SIAX Cloud) / security (pull_request) Successful in 15s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 16s
CI (SIAX Cloud) / integration (pull_request) Successful in 26s
masterplan-lock / check (push) Successful in 35s
CI (SIAX Cloud) / quality (pull_request) Successful in 37s
Security Scan (SIAX Cloud) / security (push) Successful in 1m4s
CI (SIAX Cloud) / integration (push) Successful in 1m14s
CI (SIAX Cloud) / quality (push) Successful in 2m12s
298 lines
13 KiB
TypeScript
298 lines
13 KiB
TypeScript
"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>
|
|
);
|
|
}
|