"use client"; /** The admin's frame: navigation, the pending change count, Preview and Sign out (§4, §10). */ import Link from "next/link"; import { usePathname } from "next/navigation"; import { ROLE_NAMES } from "./api"; import { cx, useAdmin } from "./ui"; const NAV = [ { href: "/admin", label: "Dashboard" }, { href: "/admin/template", label: "Template and style" }, { href: "/admin/pages", label: "Pages" }, { href: "/admin/ministries", label: "Ministries" }, { href: "/admin/leaders", label: "Leadership" }, { href: "/admin/messages", label: "Messages" }, { href: "/admin/events", label: "Events" }, { href: "/admin/linked", label: "Linked products" }, { href: "/admin/media", label: "Media library" }, { href: "/admin/publish", label: "Publish and history" }, { href: "/admin/people", label: "People", managers: true }, ]; export function AdminShell({ user, children }: { user: { name: string; role: string }; children: React.ReactNode }) { const path = usePathname(); const { data } = useAdmin<{ pending: number }>(`/overview?for=${encodeURIComponent(path)}`); return (
Website admin
{data && data.pending > 0 && {data.pending} {data.pending === 1 ? "change" : "changes"} not published} {/* eslint-disable-next-line @next/next/no-html-link-for-pages -- a route handler that sets the preview cookie: a full page load, not a client navigation */} Preview {user.name} · {ROLE_NAMES[user.role] ?? user.role}
{children}
); }