- Website: an icon sidebar in groups (Your site, Content, Go live, Team), a dashboard with cards and a tile per part of the admin, steps to the first publish across the top of every admin page, and a live preview beside the page editor and Template and style (computer or phone width, folds away, reloads on save). A framed request (Sec-Fetch-Dest: iframe) with an admin session reads the drafts, so no preview cookie is set. /preview/start takes ?to=. The page editor has Content and Page details tabs. - Accounts: /admin is an overview (cards, "Needs you", a tile per section); People moved to /admin/people; the sidebar shows the part you're in, grouped, with a count on Deletion requests; People redesigned, with a confirm before Deactivate; Email and WhatsApp split into two cards. - Both: darker grey labels for contrast; lucide-react in the Website. - e2e: the live preview shows drafts while the site stays live; axe on the page editor. - docs: VERSIONS, changelogs, WHATS-NEW. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
118 lines
7.4 KiB
TypeScript
118 lines
7.4 KiB
TypeScript
"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 (
|
|
<nav aria-label="Admin" className="space-y-5">
|
|
{NAV_GROUPS.map((g, gi) => {
|
|
const items = g.items.filter((n) => !n.managers || managers);
|
|
if (!items.length) return null;
|
|
return (
|
|
<div key={g.title ?? gi}>
|
|
{g.title && <p className="mb-1.5 px-3 text-[11px] font-semibold uppercase tracking-wide text-gray-500">{g.title}</p>}
|
|
<ul className="space-y-0.5">
|
|
{items.map((n) => {
|
|
const Icon = n.icon;
|
|
const current = n.href === "/admin" ? path === "/admin" : path === n.href || path.startsWith(`${n.href}/`);
|
|
return (
|
|
<li key={n.href}>
|
|
<Link href={n.href} onClick={onNavigate} aria-current={current ? "page" : undefined}
|
|
className={cx("flex items-center gap-3 rounded-lg px-3 py-2 text-sm transition-colors", current ? "bg-brand/10 font-medium text-brand-text" : "text-gray-600 hover:bg-gray-50 hover:text-gray-900")}>
|
|
<Icon className="h-4 w-4 shrink-0" aria-hidden />
|
|
<span className="flex-1">{n.label}</span>
|
|
{n.href === "/admin/publish" && pending > 0 && <span className="rounded-full bg-amber-100 px-1.5 text-xs font-semibold text-amber-900">{pending}<span className="sr-only"> not published</span></span>}
|
|
</Link>
|
|
</li>
|
|
);
|
|
})}
|
|
</ul>
|
|
</div>
|
|
);
|
|
})}
|
|
</nav>
|
|
);
|
|
}
|
|
|
|
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>(`/overview?for=${encodeURIComponent(path)}`);
|
|
const ctx = useMemo(() => ({ overview: data, refresh: reload }), [data, reload]);
|
|
const pending = data?.pending ?? 0;
|
|
|
|
return (
|
|
<OverviewContext.Provider value={ctx}>
|
|
<div className="min-h-screen bg-gray-50 font-sans text-gray-900">
|
|
<a href="#admin-main" className="sr-only focus:not-sr-only focus:absolute focus:left-4 focus:top-4 focus:z-50 focus:rounded focus:bg-white focus:px-3 focus:py-2">Skip to content</a>
|
|
<header className="sticky top-0 z-30 border-b border-gray-200 bg-white/95 backdrop-blur">
|
|
<div className="flex items-center justify-between gap-3 px-4 py-2.5">
|
|
<div className="flex min-w-0 items-center gap-2">
|
|
<button type="button" onClick={() => setOpen(true)} aria-label="Open the menu" aria-expanded={open} className="rounded-lg p-2 hover:bg-gray-100 md:hidden"><Menu className="h-5 w-5" /></button>
|
|
<Link href="/admin" className="flex min-w-0 items-center gap-2 font-semibold">
|
|
<span className="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-brand text-brand-on" aria-hidden><Globe className="h-4 w-4" /></span>
|
|
<span className="truncate">Website admin</span>
|
|
</Link>
|
|
</div>
|
|
<div className="flex items-center gap-2 text-sm sm:gap-3">
|
|
{pending > 0 && <Link href="/admin/publish" className="hidden rounded-full bg-amber-100 px-3 py-1 font-medium text-amber-900 hover:bg-amber-200 sm:inline-block">{pending} {pending === 1 ? "change" : "changes"} not published</Link>}
|
|
{/* 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 */}
|
|
<a href="/preview/start" className="inline-flex items-center gap-1.5 rounded-lg border border-gray-300 px-3 py-1.5 font-semibold hover:bg-gray-50"><Eye className="h-4 w-4" aria-hidden />Preview</a>
|
|
<span className="hidden items-center gap-2 lg:flex">
|
|
<span className="flex h-8 w-8 items-center justify-center rounded-full bg-brand/10 text-xs font-semibold text-brand-text" aria-hidden>{initials(user.name)}</span>
|
|
<span className="leading-tight"><span className="block font-medium">{user.name}</span><span className="block text-xs text-gray-500">{ROLE_NAMES[user.role] ?? user.role}</span></span>
|
|
</span>
|
|
<form method="post" action="/api/auth/signout">
|
|
<button type="submit" className="inline-flex items-center gap-1.5 rounded-lg px-2 py-1.5 text-gray-600 hover:bg-gray-100 hover:text-gray-900"><LogOut className="h-4 w-4" aria-hidden /><span className="hidden sm:inline">Sign out</span><span className="sr-only sm:hidden">Sign out</span></button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
{open && (
|
|
<div className="fixed inset-0 z-40 md:hidden" role="dialog" aria-modal="true" aria-label="Menu">
|
|
<button type="button" className="absolute inset-0 bg-black/30" aria-label="Close the menu" onClick={() => setOpen(false)} />
|
|
<div className="absolute inset-y-0 left-0 w-72 max-w-[85vw] overflow-y-auto bg-white p-4 shadow-xl">
|
|
<div className="mb-4 flex items-center justify-between">
|
|
<span className="text-sm"><span className="block font-semibold">{user.name}</span><span className="text-xs text-gray-500">{ROLE_NAMES[user.role] ?? user.role}</span></span>
|
|
<button type="button" onClick={() => setOpen(false)} aria-label="Close the menu" className="rounded-lg p-2 hover:bg-gray-100"><X className="h-5 w-5" /></button>
|
|
</div>
|
|
<SideNav role={user.role} path={path} pending={pending} onNavigate={() => setOpen(false)} />
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
<div className="flex">
|
|
<aside className="hidden w-60 shrink-0 border-r border-gray-200 bg-white md:block">
|
|
<div className="sticky top-[53px] max-h-[calc(100vh-53px)] overflow-y-auto p-4"><SideNav role={user.role} path={path} pending={pending} /></div>
|
|
</aside>
|
|
<main id="admin-main" className="min-w-0 flex-1 p-4 sm:p-6">
|
|
<div className={cx("mx-auto w-full", wide(path) ? "max-w-[100rem]" : "max-w-5xl")}>
|
|
{data && !data.lastPublished && <SetupSteps overview={data} path={path} />}
|
|
{children}
|
|
</div>
|
|
</main>
|
|
</div>
|
|
</div>
|
|
</OverviewContext.Provider>
|
|
);
|
|
}
|