"use client"; /** * The admin's frame (§4, §10), as Cross Events' dashboard: a bar across the top (the pending change * count, Preview, who's signed in, Sign out), the sections down the side with icons in groups, and, * until the site is first published, the steps to get there above every page. */ import Link from "next/link"; import { usePathname } from "next/navigation"; import { useMemo, useState } from "react"; import { Eye, Globe, LogOut, Menu, X } from "lucide-react"; import { ROLE_NAMES } from "./api"; import { NAV_GROUPS } from "./nav"; import { SetupSteps } from "./SetupSteps"; import { cx, OverviewContext, useAdmin, type Overview } from "./ui"; const initials = (name: string) => name.split(/\s+/).filter(Boolean).slice(0, 2).map((p) => p[0]!.toUpperCase()).join("") || "?"; /** Pages that use the whole width: the editors with the preview beside them. */ const wide = (path: string) => path === "/admin/template" || /^\/admin\/pages\/[^/]+$/.test(path); function SideNav({ role, path, pending, onNavigate }: { role: string; path: string; pending: number; onNavigate?: () => void }) { const managers = ["owner", "admin"].includes(role); return ( ); } export function AdminShell({ user, children }: { user: { name: string; role: string }; children: React.ReactNode }) { const path = usePathname(); const [open, setOpen] = useState(false); const { data, reload } = useAdmin(`/overview?for=${encodeURIComponent(path)}`); const ctx = useMemo(() => ({ overview: data, refresh: reload }), [data, reload]); const pending = data?.pending ?? 0; return (
Skip to content
Website admin
{pending > 0 && {pending} {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 {initials(user.name)} {user.name}{ROLE_NAMES[user.role] ?? user.role}
{open && (
setOpen(false)} />
)}
{data && !data.lastPublished && } {children}
); }