- aria-label + aria-value* attrs on confidence range slider (screen readers) - aria-label on volume number input - aria-pressed on service/destination selector buttons in beskriv flow - aria-label on describe textarea Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
137 lines
6.7 KiB
TypeScript
137 lines
6.7 KiB
TypeScript
"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/60">→ {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>
|
|
);
|
|
}
|