feat(portal+admin): shared shell, customer portal (dashboard nav, subscriptions, settings) + admin portal (order queue w/ status actions, source registry) + admin/subscriptions APIs
PortalShell (sidebar + session bar via /api/auth/me + logout). Customer: /portal nav, /portal/subscriptions (create feed), /portal/settings (dev-login + DPA). Admin: /admin (metrics + order queue with inline status advance), /admin/sources. APIs: /api/admin/metrics, /api/subscriptions. tsc 0, build green. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { PortalShell, StatusPill } from "@/components/portal-shell";
|
||||
import { LoadingSkeleton, EmptyState, ErrorState } from "@/components/states";
|
||||
|
||||
interface Sub {
|
||||
sub_id: string;
|
||||
order_id: string;
|
||||
cadence: string;
|
||||
status: string;
|
||||
webhook_url: string | null;
|
||||
}
|
||||
|
||||
export default function SubscriptionsPage() {
|
||||
const [subs, setSubs] = useState<Sub[] | null>(null);
|
||||
const [error, setError] = useState(false);
|
||||
const [orderId, setOrderId] = useState("");
|
||||
const [cadence, setCadence] = useState("weekly");
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setError(false);
|
||||
try { setSubs(await (await fetch("/api/subscriptions", { cache: "no-store" })).json()); }
|
||||
catch { setError(true); }
|
||||
}, []);
|
||||
useEffect(() => { void load(); }, [load]);
|
||||
|
||||
async function create() {
|
||||
if (!orderId || busy) return;
|
||||
setBusy(true);
|
||||
await fetch("/api/subscriptions", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ order_id: orderId, cadence }) }).catch(() => {});
|
||||
setOrderId("");
|
||||
setBusy(false);
|
||||
void load();
|
||||
}
|
||||
|
||||
return (
|
||||
<PortalShell variant="customer" title="Prenumerationer & flöden">
|
||||
<div className="border border-border p-5">
|
||||
<p className="font-mono text-[11px] uppercase tracking-[0.12em] text-muted-foreground">Gör om en order till ett flöde</p>
|
||||
<div className="mt-4 flex flex-wrap items-end gap-3">
|
||||
<input value={orderId} onChange={(e) => setOrderId(e.target.value)} placeholder="order_id" className="border border-border bg-input px-3 py-2 font-mono text-xs outline-none focus:border-foreground" />
|
||||
<select value={cadence} onChange={(e) => setCadence(e.target.value)} className="border border-border bg-input px-3 py-2 font-mono text-xs outline-none focus:border-foreground">
|
||||
<option value="weekly">Veckovis</option>
|
||||
<option value="daily">Dagligt</option>
|
||||
</select>
|
||||
<button onClick={create} disabled={busy || !orderId} className="bg-foreground px-5 py-2 font-mono text-[11px] uppercase tracking-[0.1em] text-background transition-colors hover:bg-[var(--accent-red)] disabled:opacity-50">
|
||||
{busy ? "Skapar…" : "Skapa flöde"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-8">
|
||||
{error ? <ErrorState onRetry={load} /> : !subs ? <LoadingSkeleton rows={4} /> : subs.length === 0 ? (
|
||||
<EmptyState title="Inga flöden än." line="Gör om en order till ett återkommande flöde." />
|
||||
) : (
|
||||
<div className="border border-border">
|
||||
<div className="grid grid-cols-[1.6fr_1fr_1fr_1fr] border-b border-border bg-secondary/50 px-4 py-2.5 font-mono text-[10px] uppercase tracking-[0.1em] text-muted-foreground">
|
||||
<span>Order</span><span>Kadens</span><span>Status</span><span>Webhook</span>
|
||||
</div>
|
||||
{subs.map((s) => (
|
||||
<div key={s.sub_id} className="grid grid-cols-[1.6fr_1fr_1fr_1fr] items-center border-b border-border px-4 py-3 text-sm last:border-b-0">
|
||||
<span className="font-mono text-[12px] tabular-nums">{s.order_id.slice(0, 8)}…</span>
|
||||
<span className="font-mono text-xs">{s.cadence}</span>
|
||||
<StatusPill status={s.status} />
|
||||
<span className="truncate font-mono text-[11px] text-muted-foreground">{s.webhook_url ?? "—"}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</PortalShell>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user