Converts every last bare-Swedish const array across landing sections
(STATS, TILES, CHAIN, PIPELINE, MODELS, DATASETS, PRINCIPLES, COLUMNS)
and shared components (data-artifact, provenance-badge) to {en,sv} Loc
objects consumed via useT(). Verified by per-file verify agent: 10/10
clean, zero remaining bare-Swedish display text. tsc 0 + build green.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
375 lines
16 KiB
TypeScript
375 lines
16 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import { useT } from "@/components/locale-provider";
|
|
import { PortalShell, StatusPill } from "@/components/portal-shell";
|
|
import { LoadingSkeleton, ErrorState } from "@/components/states";
|
|
|
|
/**
|
|
* Integrationer & åtkomst (kundvy).
|
|
*
|
|
* API-nycklar — maskerad platshållarnyckel, "Generera" inaktiv tills inloggad.
|
|
* Databas-åtkomst — kunden skapar en read-only, tidsbegränsad roll och POSTar
|
|
* conn-string + scope + utgångsdatum till /api/connections/db-grant.
|
|
* Endpointen är env-gardad: 501 → lugn vägledning, aldrig fel-toast.
|
|
* Leverans — FiveCRM / Webhook / Google Sheets, presentationella toggles.
|
|
*
|
|
* GDPR: vi ber aldrig om admin. Åtkomst dras av kunden, är tidsbegränsad och
|
|
* raderas efter jobbet. Inga råa creds lagras i klartext.
|
|
*/
|
|
|
|
const SCOPES: { id: string; label: { en: string; sv: string } }[] = [
|
|
{ id: "read_only", label: { en: "Read only", sv: "Endast läsning" } },
|
|
{ id: "selected_table", label: { en: "Selected table", sv: "Utvald tabell" } },
|
|
{ id: "selected_view", label: { en: "Selected view", sv: "Vald vy" } },
|
|
];
|
|
|
|
const SECTION =
|
|
"border border-border bg-background";
|
|
const SECTION_HEAD =
|
|
"flex items-center justify-between border-b border-border px-5 py-3";
|
|
const LABEL =
|
|
"font-mono text-[10px] uppercase tracking-[0.18em] text-muted-foreground";
|
|
const INPUT =
|
|
"w-full border border-border bg-background px-3 py-2.5 font-mono text-[13px] text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background";
|
|
|
|
export default function IntegrationerPage() {
|
|
const t = useT();
|
|
return (
|
|
<PortalShell variant="customer" title={t({ en: "Integrations & access", sv: "Integrationer & åtkomst" })}>
|
|
<div className="flex flex-col gap-10">
|
|
<ApiKeys />
|
|
<DbAccess />
|
|
<Delivery />
|
|
</div>
|
|
</PortalShell>
|
|
);
|
|
}
|
|
|
|
/* ── API-nycklar ─────────────────────────────────────────────────────────── */
|
|
|
|
function ApiKeys() {
|
|
const t = useT();
|
|
const [email, setEmail] = useState<string | null>(null);
|
|
const [state, setState] = useState<"loading" | "ready" | "error">("loading");
|
|
|
|
function load() {
|
|
setState("loading");
|
|
fetch("/api/auth/me")
|
|
.then((r) => r.json())
|
|
.then((d) => {
|
|
setEmail(d?.user?.email ?? null);
|
|
setState("ready");
|
|
})
|
|
.catch(() => setState("error"));
|
|
}
|
|
useEffect(load, []);
|
|
|
|
const loggedIn = !!email;
|
|
|
|
return (
|
|
<section className={SECTION}>
|
|
<div className={SECTION_HEAD}>
|
|
<span className={LABEL}>{t({ en: "API keys", sv: "API-nycklar" })}</span>
|
|
<span className={LABEL}>{t({ en: "1 key", sv: "1 nyckel" })}</span>
|
|
</div>
|
|
|
|
{state === "loading" ? (
|
|
<div className="p-5">
|
|
<LoadingSkeleton rows={2} />
|
|
</div>
|
|
) : state === "error" ? (
|
|
<ErrorState title={t({ en: "Could not read account", sv: "Kunde inte läsa konto" })} onRetry={load} />
|
|
) : (
|
|
<div className="flex flex-col gap-5 p-5">
|
|
<div className="flex flex-col gap-2 border border-border px-4 py-3.5 sm:flex-row sm:items-center sm:justify-between">
|
|
<div className="flex flex-col gap-1">
|
|
<span className="font-mono text-[13px] tracking-tight text-foreground">
|
|
opt_live_••••••••••••••••••••3f2a
|
|
</span>
|
|
<span className="font-mono text-[10px] uppercase tracking-[0.14em] text-muted-foreground">
|
|
{t({ en: "masked · shown on generation", sv: "maskerad · visas vid generering" })}
|
|
</span>
|
|
</div>
|
|
<StatusPill status={loggedIn ? "in_production" : "vilande"} />
|
|
</div>
|
|
|
|
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
|
<p className="max-w-sm text-pretty text-[13px] leading-relaxed text-muted-foreground">
|
|
{t({
|
|
en: "The key authorizes read access to your job. Rotate it anytime; the full key is shown once.",
|
|
sv: "Nyckeln auktoriserar läsning mot ditt jobb. Roteras när som helst, full nyckel visas en gång.",
|
|
})}
|
|
</p>
|
|
<button
|
|
type="button"
|
|
disabled={!loggedIn}
|
|
className="shrink-0 border border-foreground bg-foreground px-5 py-2.5 font-mono text-[11px] uppercase tracking-[0.12em] text-background transition-colors duration-200 hover:bg-[var(--accent-red)] hover:border-[var(--accent-red)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:border-border disabled:bg-secondary disabled:text-muted-foreground disabled:hover:bg-secondary"
|
|
>
|
|
{t({ en: "Generate", sv: "Generera" })}
|
|
</button>
|
|
</div>
|
|
|
|
{!loggedIn ? (
|
|
<p className="border-l-2 border-border pl-3 font-mono text-[11px] leading-relaxed text-muted-foreground">
|
|
{t({
|
|
en: "Sign in to generate. The key is bound to your account.",
|
|
sv: "Logga in för att generera. Nyckeln binds till ditt konto.",
|
|
})}
|
|
</p>
|
|
) : null}
|
|
</div>
|
|
)}
|
|
</section>
|
|
);
|
|
}
|
|
|
|
/* ── Databas-åtkomst ─────────────────────────────────────────────────────── */
|
|
|
|
function DbAccess() {
|
|
const t = useT();
|
|
const [conn, setConn] = useState("");
|
|
const [scope, setScope] = useState(SCOPES[0].id);
|
|
const [expires, setExpires] = useState("");
|
|
const [submitting, setSubmitting] = useState(false);
|
|
const [guidance, setGuidance] = useState<string | null>(null);
|
|
const [error, setError] = useState(false);
|
|
|
|
async function submit(e: React.FormEvent) {
|
|
e.preventDefault();
|
|
setSubmitting(true);
|
|
setError(false);
|
|
setGuidance(null);
|
|
try {
|
|
const res = await fetch("/api/connections/db-grant", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ conn, scope, expires }),
|
|
});
|
|
if (res.status === 501) {
|
|
const d = await res.json().catch(() => null);
|
|
setGuidance(
|
|
d?.message ??
|
|
t({
|
|
en: "Secure storage activates on deployment. Your details were not forwarded and never stored.",
|
|
sv: "Säker lagring aktiveras vid driftsättning. Din uppgift skickades inte vidare och sparades aldrig.",
|
|
}),
|
|
);
|
|
} else if (res.ok) {
|
|
setGuidance(
|
|
t({
|
|
en: "Access registered. We revoke it when the job ends.",
|
|
sv: "Åtkomst registrerad. Vi drar den vid jobbets slut.",
|
|
}),
|
|
);
|
|
} else {
|
|
setError(true);
|
|
}
|
|
} catch {
|
|
setError(true);
|
|
} finally {
|
|
setSubmitting(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<section className={SECTION}>
|
|
<div className={SECTION_HEAD}>
|
|
<span className={LABEL}>{t({ en: "Database access", sv: "Databas-åtkomst" })}</span>
|
|
<span className="inline-flex items-center gap-1.5 font-mono text-[10px] uppercase tracking-[0.14em] text-muted-foreground">
|
|
<span
|
|
className="inline-block h-2 w-2"
|
|
style={{ backgroundColor: "var(--prov-3)" }}
|
|
/>
|
|
read-only
|
|
</span>
|
|
</div>
|
|
|
|
<div className="grid gap-0 md:grid-cols-[1.4fr_1fr]">
|
|
<form onSubmit={submit} className="flex flex-col gap-5 p-5">
|
|
<label className="flex flex-col gap-2">
|
|
<span className={LABEL}>{t({ en: "Connection string", sv: "Connection-sträng" })}</span>
|
|
<input
|
|
value={conn}
|
|
onChange={(e) => setConn(e.target.value)}
|
|
required
|
|
placeholder="postgres://readonly:•••@host:5432/db"
|
|
className={INPUT}
|
|
/>
|
|
</label>
|
|
|
|
<div className="grid gap-5 sm:grid-cols-2">
|
|
<label className="flex flex-col gap-2">
|
|
<span className={LABEL}>{t({ en: "Scope", sv: "Scope" })}</span>
|
|
<select
|
|
value={scope}
|
|
onChange={(e) => setScope(e.target.value)}
|
|
className={INPUT}
|
|
>
|
|
{SCOPES.map((s) => (
|
|
<option key={s.id} value={s.id}>
|
|
{t(s.label)}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
|
|
<label className="flex flex-col gap-2">
|
|
<span className={LABEL}>{t({ en: "Expiry date", sv: "Utgångsdatum" })}</span>
|
|
<input
|
|
type="date"
|
|
value={expires}
|
|
onChange={(e) => setExpires(e.target.value)}
|
|
required
|
|
className={INPUT}
|
|
/>
|
|
</label>
|
|
</div>
|
|
|
|
<div className="flex items-center justify-between gap-4">
|
|
<span className="font-mono text-[10px] uppercase tracking-[0.14em] text-muted-foreground">
|
|
{t({ en: "pulled by you · never admin", sv: "pull av dig · aldrig admin" })}
|
|
</span>
|
|
<button
|
|
type="submit"
|
|
disabled={submitting}
|
|
className="shrink-0 border border-foreground bg-foreground px-5 py-2.5 font-mono text-[11px] uppercase tracking-[0.12em] text-background transition-colors duration-200 hover:bg-[var(--accent-red)] hover:border-[var(--accent-red)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-60"
|
|
>
|
|
{submitting ? t({ en: "Sending…", sv: "Skickar…" }) : t({ en: "Grant access", sv: "Ge åtkomst" })}
|
|
</button>
|
|
</div>
|
|
|
|
{guidance ? (
|
|
<p
|
|
role="status"
|
|
className="border-l-2 pl-3 text-pretty text-[13px] leading-relaxed text-muted-foreground"
|
|
style={{ borderColor: "var(--prov-2)" }}
|
|
>
|
|
{guidance}
|
|
</p>
|
|
) : null}
|
|
|
|
{error ? (
|
|
<p
|
|
role="alert"
|
|
className="border-l-2 pl-3 text-pretty text-[13px] leading-relaxed text-muted-foreground"
|
|
style={{ borderColor: "var(--accent-red)" }}
|
|
>
|
|
{t({
|
|
en: "Could not reach the service. No details saved.",
|
|
sv: "Kunde inte nå tjänsten. Ingen uppgift sparad.",
|
|
})}
|
|
</p>
|
|
) : null}
|
|
</form>
|
|
|
|
<aside className="flex flex-col gap-4 border-t border-border p-5 md:border-l md:border-t-0">
|
|
<span className={LABEL}>{t({ en: "How it works", sv: "Så fungerar det" })}</span>
|
|
<ul className="flex flex-col gap-3 text-[13px] leading-relaxed text-muted-foreground">
|
|
{[
|
|
{ h: { en: "Read-only", sv: "Read-only" }, b: { en: "Read rights only. No writes.", sv: "Endast läsrättigheter. Inga skrivningar." } },
|
|
{ h: { en: "Time-boxed", sv: "Tidsbegränsad" }, b: { en: "The role expires on your chosen date.", sv: "Rollen löper ut på ditt valda datum." } },
|
|
{ h: { en: "Deleted afterwards", sv: "Raderad efteråt" }, b: { en: "Access is revoked when the job ends.", sv: "Åtkomsten dras vid jobbets slut." } },
|
|
].map((row) => (
|
|
<li key={row.h.en} className="flex gap-3">
|
|
<span
|
|
className="mt-1.5 inline-block h-2 w-2 shrink-0"
|
|
style={{ backgroundColor: "var(--prov-3)" }}
|
|
/>
|
|
<span>
|
|
<span className="font-medium text-foreground">{t(row.h)}.</span> {t(row.b)}
|
|
</span>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
<p className="mt-1 text-pretty text-[12px] leading-relaxed text-muted-foreground">
|
|
{t({
|
|
en: "You create the role in your database. We never store raw creds in plaintext.",
|
|
sv: "Du skapar rollen i din databas. Vi lagrar aldrig råa creds i klartext.",
|
|
})}
|
|
</p>
|
|
</aside>
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
/* ── Leverans ────────────────────────────────────────────────────────────── */
|
|
|
|
const CHANNELS: { id: string; name: string; sub: { en: string; sv: string }; on: boolean }[] = [
|
|
{ id: "fivecrm", name: "FiveCRM", sub: { en: "push of enriched records", sv: "push av berikade poster" }, on: true },
|
|
{ id: "webhook", name: "Webhook", sub: { en: "HTTPS POST per batch", sv: "HTTPS POST per batch" }, on: false },
|
|
{ id: "sheets", name: "Google Sheets", sub: { en: "mirror to spreadsheet", sv: "spegla till kalkylark" }, on: false },
|
|
];
|
|
|
|
function Delivery() {
|
|
const t = useT();
|
|
const [on, setOn] = useState<Record<string, boolean>>(
|
|
Object.fromEntries(CHANNELS.map((c) => [c.id, c.on])),
|
|
);
|
|
|
|
return (
|
|
<section className={SECTION}>
|
|
<div className={SECTION_HEAD}>
|
|
<span className={LABEL}>{t({ en: "Delivery", sv: "Leverans" })}</span>
|
|
<span className={LABEL}>{t({ en: "destinations", sv: "destinationer" })}</span>
|
|
</div>
|
|
|
|
<div className="flex flex-col">
|
|
{CHANNELS.map((c) => {
|
|
const active = on[c.id];
|
|
return (
|
|
<div
|
|
key={c.id}
|
|
className="flex items-center justify-between gap-4 border-b border-border px-5 py-4 last:border-b-0"
|
|
>
|
|
<div className="flex items-center gap-3">
|
|
<span
|
|
className="inline-block h-2.5 w-2.5 shrink-0"
|
|
style={{
|
|
backgroundColor: active
|
|
? "var(--prov-3)"
|
|
: "var(--muted-foreground)",
|
|
}}
|
|
/>
|
|
<div className="flex flex-col">
|
|
<span className="text-[14px] tracking-tight text-foreground">
|
|
{c.name}
|
|
</span>
|
|
<span className="font-mono text-[10px] uppercase tracking-[0.14em] text-muted-foreground">
|
|
{t(c.sub)}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<button
|
|
type="button"
|
|
role="switch"
|
|
aria-checked={active}
|
|
aria-label={c.name}
|
|
onClick={() => setOn((p) => ({ ...p, [c.id]: !p[c.id] }))}
|
|
className="relative inline-flex h-6 w-11 shrink-0 items-center border border-border bg-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
|
style={active ? { backgroundColor: "var(--foreground)" } : undefined}
|
|
>
|
|
<span
|
|
className="inline-block h-4 w-4 transition-transform"
|
|
style={{
|
|
backgroundColor: active
|
|
? "var(--background)"
|
|
: "var(--muted-foreground)",
|
|
transform: active ? "translateX(22px)" : "translateX(3px)",
|
|
}}
|
|
/>
|
|
</button>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
|
|
<p className="border-t border-border px-5 py-3 font-mono text-[10px] uppercase tracking-[0.14em] text-muted-foreground">
|
|
{t({ en: "connected at delivery", sv: "kopplas vid leverans" })}
|
|
</p>
|
|
</section>
|
|
);
|
|
}
|