"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useEffect, useState } from "react"; export type NavItem = { label: string; href: string }; const CUSTOMER_NAV: NavItem[] = [ { label: "Översikt", href: "/portal" }, { label: "Prenumerationer", href: "/portal/subscriptions" }, { label: "Filer", href: "/portal/files" }, { label: "Integrationer", href: "/portal/integrationer" }, { label: "Inställningar", href: "/portal/settings" }, ]; const ADMIN_NAV: NavItem[] = [ { label: "Översikt", href: "/admin" }, { label: "Källor", href: "/admin/sources" }, { label: "Jobb", href: "/admin/jobs" }, { label: "Kunder", href: "/admin/customers" }, ]; export function PortalShell({ variant, title, children, }: { variant: "customer" | "admin"; title: string; children: React.ReactNode; }) { const pathname = usePathname(); const nav = variant === "admin" ? ADMIN_NAV : CUSTOMER_NAV; const [email, setEmail] = useState(null); useEffect(() => { fetch("/api/auth/me") .then((r) => r.json()) .then((d) => setEmail(d?.user?.email ?? null)) .catch(() => {}); }, []); async function logout() { await fetch("/api/auth/logout", { method: "POST" }).catch(() => {}); setEmail(null); } return (
{/* top bar */}
0pt {variant === "admin" ? "admin" : "portal"}
{email ? ( <> {email} ) : ( Logga in )}
{/* sidebar */} {/* content */}

{title}

{children}
); } export function StatusPill({ status }: { status: string }) { const color = status === "delivered" || status === "accepted" ? "var(--prov-3)" : status === "in_production" || status === "review" ? "var(--accent-red)" : "var(--muted-foreground)"; return ( {status} ); }