Accounts 1.8.0, Website 1.1.0: admins redesigned as Cross Events' dashboard and settings
- 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>
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* The live preview beside an editor: the page as it will look, with your saved drafts, on the right.
|
||||
* It folds away to a tab on the right edge (remembered in this browser), shows a desktop or a phone
|
||||
* width (the desktop scaled down to fit), and reloads where you were scrolled to each time
|
||||
* something is saved. On a small screen it's a button that opens it full screen.
|
||||
*
|
||||
* The frame's pages are the working copy because they're framed and you're signed in (site/load.ts).
|
||||
*/
|
||||
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||
import { Eye, ExternalLink, Monitor, PanelRightClose, PanelRightOpen, RotateCw, Smartphone, X } from "lucide-react";
|
||||
import { cx } from "./ui";
|
||||
|
||||
type Device = "desktop" | "phone";
|
||||
const WIDTH: Record<Device, number> = { desktop: 1280, phone: 390 };
|
||||
const OPEN_KEY = "ccw-admin-preview-open";
|
||||
const DEVICE_KEY = "ccw-admin-preview-device";
|
||||
|
||||
const read = (k: string) => { try { return window.localStorage.getItem(k); } catch { return null; } };
|
||||
const write = (k: string, v: string) => { try { window.localStorage.setItem(k, v); } catch { /* not kept */ } };
|
||||
|
||||
function Frame({ path, version, device }: { path: string; version: string; device: Device }) {
|
||||
const box = useRef<HTMLDivElement>(null);
|
||||
const frame = useRef<HTMLIFrameElement>(null);
|
||||
const scroll = useRef(0);
|
||||
const shown = useRef(version);
|
||||
const [size, setSize] = useState({ w: 0, h: 0 });
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const el = box.current;
|
||||
if (!el) return;
|
||||
const ro = new ResizeObserver(([e]) => setSize({ w: e!.contentRect.width, h: e!.contentRect.height }));
|
||||
ro.observe(el);
|
||||
return () => ro.disconnect();
|
||||
}, []);
|
||||
|
||||
// A save: reload the page in the frame (wherever it was clicked to), back at the same place.
|
||||
useEffect(() => {
|
||||
if (shown.current === version) return;
|
||||
shown.current = version;
|
||||
const w = frame.current?.contentWindow;
|
||||
if (!w) return;
|
||||
try {
|
||||
scroll.current = w.scrollY;
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
setLoading(true);
|
||||
w.location.reload();
|
||||
} catch {
|
||||
// Not the site's own page any more (a link out): leave it.
|
||||
}
|
||||
}, [version]);
|
||||
|
||||
const onLoad = useCallback(() => {
|
||||
setLoading(false);
|
||||
const w = frame.current?.contentWindow;
|
||||
if (w && scroll.current) {
|
||||
try { w.scrollTo(0, scroll.current); } catch { /* elsewhere */ }
|
||||
scroll.current = 0;
|
||||
}
|
||||
}, []);
|
||||
|
||||
// The page at its real width, scaled down to fit (a phone has a margin round it).
|
||||
const logical = WIDTH[device];
|
||||
const pad = device === "phone" ? 12 : 0;
|
||||
const scale = size.w ? Math.min(1, (size.w - pad * 2) / logical) : 1;
|
||||
return (
|
||||
<div ref={box} className="relative min-h-0 flex-1 overflow-hidden bg-gray-100">
|
||||
{size.w > 0 && (
|
||||
<iframe ref={frame} src={path} title="Live preview of this page" onLoad={onLoad}
|
||||
className={cx("absolute origin-top-left border-0 bg-white", device === "phone" && "rounded-2xl shadow-lg ring-1 ring-gray-300")}
|
||||
style={{ top: pad, left: (size.w - logical * scale) / 2, width: logical, height: (size.h - pad * 2) / scale, transform: `scale(${scale})` }} />
|
||||
)}
|
||||
{loading && <div className="pointer-events-none absolute right-3 top-3 rounded-full bg-white/90 px-2.5 py-1 text-xs text-gray-600 shadow" role="status">Loading…</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Toolbar({ path, device, setDevice, onReload, onClose, closeIcon }: { path: string; device: Device; setDevice: (d: Device) => void; onReload: () => void; onClose: () => void; closeIcon: "panel" | "x" }) {
|
||||
const btn = "rounded-md p-1.5 text-gray-500 hover:bg-gray-100 hover:text-gray-900";
|
||||
return (
|
||||
<div className="flex items-center gap-2 border-b border-gray-200 bg-white px-3 py-2">
|
||||
<Eye className="h-4 w-4 text-brand-text" aria-hidden />
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-sm font-semibold text-gray-900">Live preview</p>
|
||||
<p className="truncate text-xs text-gray-500">Updates each time you save · {path === "/" ? "Home page" : path}</p>
|
||||
</div>
|
||||
<div className="flex rounded-lg border border-gray-200 p-0.5" role="group" aria-label="Width">
|
||||
{(["desktop", "phone"] as const).map((d) => {
|
||||
const Icon = d === "desktop" ? Monitor : Smartphone;
|
||||
return (
|
||||
<button key={d} type="button" onClick={() => setDevice(d)} aria-pressed={device === d} aria-label={d === "desktop" ? "Computer width" : "Phone width"} title={d === "desktop" ? "Computer" : "Phone"}
|
||||
className={cx("rounded-md p-1", device === d ? "bg-brand/10 text-brand-text" : "text-gray-500 hover:text-gray-900")}><Icon className="h-4 w-4" aria-hidden /></button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<button type="button" onClick={onReload} className={btn} aria-label="Reload the preview" title="Reload"><RotateCw className="h-4 w-4" aria-hidden /></button>
|
||||
<a href={`/preview/start?to=${encodeURIComponent(path)}`} target="_blank" rel="noopener" className={btn} aria-label="Open the full preview in a new tab" title="Open the full preview"><ExternalLink className="h-4 w-4" aria-hidden /></a>
|
||||
<button type="button" onClick={onClose} className={btn} aria-label="Hide the preview" title="Hide the preview">
|
||||
{closeIcon === "panel" ? <PanelRightClose className="h-4 w-4" aria-hidden /> : <X className="h-4 w-4" aria-hidden />}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** An editor with the live preview of `path` beside it. `version` changes with each save (the saved data, say): the preview reloads. */
|
||||
export function WithPreview({ path, version, children }: { path: string; version: string; children: React.ReactNode }) {
|
||||
const [open, setOpenState] = useState(true);
|
||||
const [device, setDeviceState] = useState<Device>("desktop");
|
||||
const [sheet, setSheet] = useState(false);
|
||||
const [manual, setManual] = useState(0);
|
||||
useEffect(() => {
|
||||
// The browser remembers the last choice.
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
if (read(OPEN_KEY) === "0") setOpenState(false);
|
||||
if (read(DEVICE_KEY) === "phone") setDeviceState("phone");
|
||||
}, []);
|
||||
const setOpen = (v: boolean) => { setOpenState(v); write(OPEN_KEY, v ? "1" : "0"); };
|
||||
const setDevice = (d: Device) => { setDeviceState(d); write(DEVICE_KEY, d); };
|
||||
const v = `${version}·${manual}`;
|
||||
|
||||
return (
|
||||
<div className="lg:flex lg:items-start lg:gap-6">
|
||||
<div className="min-w-0 flex-1">{children}</div>
|
||||
|
||||
{/* Wide screens: beside the editor, or folded to a tab on the right edge. */}
|
||||
{open ? (
|
||||
<aside aria-label="Live preview" className="sticky top-[77px] hidden h-[calc(100vh-101px)] w-[45%] max-w-[52rem] shrink-0 flex-col overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm lg:flex">
|
||||
<Toolbar path={path} device={device} setDevice={setDevice} onReload={() => setManual((n) => n + 1)} onClose={() => setOpen(false)} closeIcon="panel" />
|
||||
<Frame path={path} version={v} device={device} />
|
||||
</aside>
|
||||
) : (
|
||||
<button type="button" onClick={() => setOpen(true)} aria-label="Show the live preview"
|
||||
className="fixed right-0 top-1/2 z-20 hidden -translate-y-1/2 items-center gap-2 rounded-l-xl border border-r-0 border-gray-200 bg-white px-2 py-4 text-sm font-semibold text-gray-700 shadow-lg hover:text-brand-text lg:flex [writing-mode:vertical-rl]">
|
||||
<PanelRightOpen className="h-4 w-4 rotate-90" aria-hidden /> Show preview
|
||||
</button>
|
||||
)}
|
||||
|
||||
{/* Small screens: a button that opens it full screen. */}
|
||||
<button type="button" onClick={() => setSheet(true)} className="fixed bottom-4 right-4 z-20 inline-flex items-center gap-2 rounded-full bg-brand px-4 py-3 text-sm font-semibold text-brand-on shadow-lg lg:hidden">
|
||||
<Eye className="h-4 w-4" aria-hidden /> Preview
|
||||
</button>
|
||||
{sheet && (
|
||||
<div className="fixed inset-0 z-50 flex flex-col bg-white lg:hidden" role="dialog" aria-modal="true" aria-label="Live preview">
|
||||
<Toolbar path={path} device={device} setDevice={setDevice} onReload={() => setManual((n) => n + 1)} onClose={() => setSheet(false)} closeIcon="x" />
|
||||
<Frame path={path} version={v} device={device} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* The steps to a first publish, across the top of every admin page until the site is live: each
|
||||
* step is a link, done ones are ticked, and "Next" goes to the first one still to do. It can be
|
||||
* folded to one line (remembered in this browser).
|
||||
*/
|
||||
import Link from "next/link";
|
||||
import { useEffect, useState } from "react";
|
||||
import { ArrowRight, Check, ChevronDown, ChevronUp, Rocket } from "lucide-react";
|
||||
import { cx, type Overview } from "./ui";
|
||||
|
||||
const KEY = "ccw-admin-steps-folded";
|
||||
|
||||
export function SetupSteps({ overview, path }: { overview: Overview; path: string }) {
|
||||
const [folded, setFolded] = useState(false);
|
||||
useEffect(() => {
|
||||
try {
|
||||
// Only the browser knows what was chosen last time.
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
setFolded(window.localStorage.getItem(KEY) === "1");
|
||||
} catch {
|
||||
// Storage blocked: the steps show unfolded.
|
||||
}
|
||||
}, []);
|
||||
const fold = (v: boolean) => {
|
||||
setFolded(v);
|
||||
try { window.localStorage.setItem(KEY, v ? "1" : "0"); } catch { /* not kept */ }
|
||||
};
|
||||
|
||||
const steps = overview.checklist;
|
||||
const done = steps.filter((s) => s.done).length;
|
||||
const next = steps.find((s) => !s.done) ?? null;
|
||||
const percent = steps.length ? Math.round((done / steps.length) * 100) : 0;
|
||||
|
||||
return (
|
||||
<section aria-label="Getting your site ready" className="mb-6 rounded-xl border border-brand/20 bg-white shadow-sm">
|
||||
<div className="flex flex-wrap items-center gap-x-4 gap-y-3 p-4">
|
||||
<span className="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-brand text-brand-on" aria-hidden><Rocket className="h-[18px] w-[18px]" /></span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<h2 className="text-sm font-semibold text-gray-900">Get your site ready to publish</h2>
|
||||
<div className="mt-1 flex items-center gap-2">
|
||||
<div className="h-1.5 w-32 overflow-hidden rounded-full bg-gray-200" role="progressbar" aria-valuenow={done} aria-valuemin={0} aria-valuemax={steps.length} aria-label="Steps done">
|
||||
<div className="h-full rounded-full bg-brand transition-all" style={{ width: `${percent}%` }} />
|
||||
</div>
|
||||
<span className="text-xs text-gray-500">{done} of {steps.length} done</span>
|
||||
</div>
|
||||
</div>
|
||||
{next?.href && (
|
||||
<Link href={next.href} className="order-last inline-flex w-full items-center justify-center gap-1.5 rounded-lg bg-brand px-3 py-2 text-sm font-semibold text-brand-on hover:bg-brand-dark sm:order-none sm:w-auto">
|
||||
<span className="hidden sm:inline">Next:</span> {next.label}<ArrowRight className="h-4 w-4" aria-hidden />
|
||||
</Link>
|
||||
)}
|
||||
<button type="button" onClick={() => fold(!folded)} aria-expanded={!folded} aria-label={folded ? "Show the steps" : "Hide the steps"} title={folded ? "Show the steps" : "Hide the steps"}
|
||||
className="rounded-lg p-2 text-gray-500 hover:bg-gray-100 hover:text-gray-800">
|
||||
{folded ? <ChevronDown className="h-4 w-4" aria-hidden /> : <ChevronUp className="h-4 w-4" aria-hidden />}
|
||||
</button>
|
||||
</div>
|
||||
{!folded && (
|
||||
<ol className="flex gap-2 overflow-x-auto border-t border-gray-100 px-4 py-3">
|
||||
{steps.map((s, i) => {
|
||||
const isNext = s === next;
|
||||
const here = !!s.href && (path === s.href || path.startsWith(`${s.href}/`));
|
||||
const body = (
|
||||
<>
|
||||
<span className={cx("flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-xs font-semibold",
|
||||
s.done ? "bg-green-600 text-white" : isNext ? "bg-brand text-brand-on ring-4 ring-brand/15" : "bg-gray-100 text-gray-500")} aria-hidden>
|
||||
{s.done ? <Check className="h-4 w-4" /> : i + 1}
|
||||
</span>
|
||||
<span className={cx("text-sm leading-tight", s.done ? "text-gray-500" : isNext ? "font-semibold text-gray-900" : "text-gray-700", here && "underline decoration-2 underline-offset-4")}>{s.label}</span>
|
||||
<span className="sr-only">{s.done ? "(done)" : isNext ? "(next)" : "(to do)"}</span>
|
||||
</>
|
||||
);
|
||||
return (
|
||||
<li key={s.key} className="flex min-w-[10rem] flex-1 items-center gap-2">
|
||||
{s.href ? (
|
||||
<Link href={s.href} aria-current={here ? "step" : undefined} className="flex flex-1 items-center gap-2 rounded-lg p-1.5 hover:bg-gray-50">{body}</Link>
|
||||
) : <span className="flex flex-1 items-center gap-2 p-1.5">{body}</span>}
|
||||
{i < steps.length - 1 && <span className={cx("hidden h-px w-6 shrink-0 lg:block", s.done ? "bg-green-600" : "bg-gray-200")} aria-hidden />}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ol>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -1,61 +1,117 @@
|
||||
"use client";
|
||||
|
||||
/** The admin's frame: navigation, the pending change count, Preview and Sign out (§4, §10). */
|
||||
/**
|
||||
* 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 { cx, useAdmin } from "./ui";
|
||||
import { NAV_GROUPS } from "./nav";
|
||||
import { SetupSteps } from "./SetupSteps";
|
||||
import { cx, OverviewContext, useAdmin, type Overview } from "./ui";
|
||||
|
||||
const NAV = [
|
||||
{ href: "/admin", label: "Dashboard" },
|
||||
{ href: "/admin/template", label: "Template and style" },
|
||||
{ href: "/admin/church", label: "Church details" },
|
||||
{ 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/settings", label: "Settings" },
|
||||
{ href: "/admin/people", label: "People", managers: true },
|
||||
{ href: "/admin/audit", label: "Audit log", managers: true },
|
||||
];
|
||||
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 { data } = useAdmin<{ pending: number }>(`/overview?for=${encodeURIComponent(path)}`);
|
||||
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 (
|
||||
<div className="min-h-screen bg-gray-50 font-sans text-gray-900">
|
||||
<header className="border-b border-gray-200 bg-white">
|
||||
<div className="mx-auto flex max-w-6xl flex-wrap items-center justify-between gap-3 px-4 py-3">
|
||||
<Link href="/admin" className="font-semibold">Website admin</Link>
|
||||
<div className="flex flex-wrap items-center gap-3 text-sm">
|
||||
{data && data.pending > 0 && <Link href="/admin/publish" className="rounded-full bg-amber-100 px-3 py-1 font-medium text-amber-900">{data.pending} {data.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="rounded-md border border-gray-300 px-3 py-1.5 font-semibold hover:bg-gray-50">Preview</a>
|
||||
<span className="text-gray-600">{user.name} · {ROLE_NAMES[user.role] ?? user.role}</span>
|
||||
<form method="post" action="/api/auth/signout"><button type="submit" className="text-gray-600 underline-offset-4 hover:underline">Sign out</button></form>
|
||||
<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>
|
||||
</header>
|
||||
<div className="mx-auto grid max-w-6xl gap-6 px-4 py-6 md:grid-cols-[13rem_1fr]">
|
||||
<nav aria-label="Admin">
|
||||
<ul className="flex gap-1 overflow-x-auto md:flex-col">
|
||||
{NAV.filter((n) => !("managers" in n) || ["owner", "admin"].includes(user.role)).map((n) => {
|
||||
const current = n.href === "/admin" ? path === "/admin" : path.startsWith(n.href);
|
||||
return (
|
||||
<li key={n.href}>
|
||||
<Link href={n.href} aria-current={current ? "page" : undefined}
|
||||
className={cx("block whitespace-nowrap rounded-md px-3 py-2 text-sm", current ? "bg-brand text-brand-on" : "text-gray-700 hover:bg-gray-100")}>{n.label}</Link>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</nav>
|
||||
<main>{children}</main>
|
||||
</div>
|
||||
</div>
|
||||
</OverviewContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/** The admin's sections, in groups (the sidebar) with a line each (the dashboard's tiles). */
|
||||
import {
|
||||
Building2, CalendarDays, FileText, HandHeart, Image as ImageIcon, LayoutDashboard, Link2, Mic, Palette, ScrollText,
|
||||
Send, Settings, UserCog, Users, type LucideIcon,
|
||||
} from "lucide-react";
|
||||
|
||||
export type NavItem = { href: string; label: string; description: string; icon: LucideIcon; managers?: boolean };
|
||||
|
||||
export const NAV_GROUPS: { title: string | null; items: NavItem[] }[] = [
|
||||
{ title: null, items: [{ href: "/admin", label: "Dashboard", description: "Where your site stands, and what to do next", icon: LayoutDashboard }] },
|
||||
{
|
||||
title: "Your site",
|
||||
items: [
|
||||
{ href: "/admin/template", label: "Template and style", description: "The look: template, home page layout, colours of sections", icon: Palette },
|
||||
{ href: "/admin/pages", label: "Pages", description: "Your home page, the fixed pages and your own", icon: FileText },
|
||||
{ href: "/admin/church", label: "Church details", description: "Name, logo, service times and address, for all your sites", icon: Building2 },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Content",
|
||||
items: [
|
||||
{ href: "/admin/ministries", label: "Ministries", description: "What happens in your church, each on the Ministries page", icon: HandHeart },
|
||||
{ href: "/admin/leaders", label: "Leadership", description: "Your pastors and team, with photos", icon: Users },
|
||||
{ href: "/admin/messages", label: "Messages", description: "Sermons, from YouTube or Spotify", icon: Mic },
|
||||
{ href: "/admin/events", label: "Events", description: "What's coming up, or your Cross Events calendar", icon: CalendarDays },
|
||||
{ href: "/admin/media", label: "Media library", description: "Your photos, what each shows, and storage", icon: ImageIcon },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Go live",
|
||||
items: [
|
||||
{ href: "/admin/publish", label: "Publish and history", description: "What's changed, publish it, share a preview, go back", icon: Send },
|
||||
{ href: "/admin/linked", label: "Linked products", description: "Cross Events and your church's other sites", icon: Link2 },
|
||||
{ href: "/admin/settings", label: "Settings", description: "Search engines, the menu order, the Coming soon line", icon: Settings },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Team",
|
||||
items: [
|
||||
{ href: "/admin/people", label: "People", description: "Who can edit the site, and what they can do", icon: UserCog, managers: true },
|
||||
{ href: "/admin/audit", label: "Audit log", description: "Who changed what, and when", icon: ScrollText, managers: true },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export const NAV: NavItem[] = NAV_GROUPS.flatMap((g) => g.items);
|
||||
|
||||
/** The section an address is in: the longest match, so /admin/pages/… is Pages. */
|
||||
export const sectionFor = (path: string): NavItem | undefined =>
|
||||
NAV.filter((n) => (n.href === "/admin" ? path === "/admin" : path === n.href || path.startsWith(`${n.href}/`))).sort((a, b) => b.href.length - a.href.length)[0];
|
||||
@@ -1,33 +1,105 @@
|
||||
"use client";
|
||||
|
||||
/** The admin's own building blocks: plain, calm, the church's colour for the main action. */
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
/** The admin's own building blocks: plain, calm, the church's colour for the main action (as Cross Events' dashboard). */
|
||||
import Link from "next/link";
|
||||
import { createContext, useCallback, useContext, useEffect, useState } from "react";
|
||||
import { ArrowRight, type LucideIcon } from "lucide-react";
|
||||
import { api, AdminError } from "./api";
|
||||
|
||||
export const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");
|
||||
|
||||
export function Title({ children, sub, actions }: { children: React.ReactNode; sub?: React.ReactNode; actions?: React.ReactNode }) {
|
||||
export function Title({ children, sub, actions, icon: Icon }: { children: React.ReactNode; sub?: React.ReactNode; actions?: React.ReactNode; icon?: LucideIcon }) {
|
||||
return (
|
||||
<div className="mb-6 flex flex-wrap items-end justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold text-gray-900">{children}</h1>
|
||||
{sub && <p className="mt-1 text-gray-600">{sub}</p>}
|
||||
<div className="flex min-w-0 items-start gap-3">
|
||||
{Icon && <span className="mt-0.5 hidden h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-brand/10 text-brand-text sm:flex" aria-hidden><Icon className="h-5 w-5" /></span>}
|
||||
<div className="min-w-0">
|
||||
<h1 className="text-2xl font-semibold text-gray-900">{children}</h1>
|
||||
{sub && <p className="mt-1 text-sm text-gray-600">{sub}</p>}
|
||||
</div>
|
||||
</div>
|
||||
{actions && <div className="flex flex-wrap gap-2">{actions}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function Panel({ children, className, title }: { children: React.ReactNode; className?: string; title?: string }) {
|
||||
/** A white card; with a title, an icon in a tile of the church's colour and a line under it. */
|
||||
export function Panel({ children, className, title, icon: Icon, sub, actions }: { children: React.ReactNode; className?: string; title?: string; icon?: LucideIcon; sub?: React.ReactNode; actions?: React.ReactNode }) {
|
||||
return (
|
||||
<section className={cx("rounded-lg border border-gray-200 bg-white p-5 shadow-sm", className)}>
|
||||
{title && <h2 className="mb-4 text-lg font-semibold text-gray-900">{title}</h2>}
|
||||
<section className={cx("rounded-xl border border-gray-200 bg-white p-5 shadow-sm", className)}>
|
||||
{title && (
|
||||
<div className="mb-4 flex flex-wrap items-start justify-between gap-3">
|
||||
<div className="flex min-w-0 items-start gap-3">
|
||||
{Icon && <span className="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-brand/10 text-brand-text" aria-hidden><Icon className="h-[18px] w-[18px]" /></span>}
|
||||
<div className="min-w-0">
|
||||
<h2 className="text-lg font-semibold text-gray-900">{title}</h2>
|
||||
{sub && <p className="mt-0.5 text-sm text-gray-500">{sub}</p>}
|
||||
</div>
|
||||
</div>
|
||||
{actions && <div className="flex flex-wrap gap-2">{actions}</div>}
|
||||
</div>
|
||||
)}
|
||||
{children}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
type BtnProps = React.ButtonHTMLAttributes<HTMLButtonElement> & { kind?: "primary" | "secondary" | "danger" | "link"; busy?: boolean };
|
||||
/** Icon tabs (as Cross Events' Site Settings): one part of a page at a time. */
|
||||
export function Tabs<T extends string>({ tabs, value, onChange, label }: { tabs: { id: T; label: string; icon: LucideIcon; badge?: React.ReactNode }[]; value: T; onChange: (id: T) => void; label: string }) {
|
||||
return (
|
||||
<div role="tablist" aria-label={label} className="mb-4 flex flex-wrap items-center gap-2">
|
||||
{tabs.map((t) => {
|
||||
const Icon = t.icon;
|
||||
const on = t.id === value;
|
||||
return (
|
||||
<button key={t.id} type="button" role="tab" aria-selected={on} onClick={() => onChange(t.id)}
|
||||
className={cx("inline-flex items-center gap-1.5 rounded-lg border px-3 py-1.5 text-sm font-medium transition-colors", on ? "border-brand bg-brand text-brand-on" : "border-gray-200 bg-white text-gray-700 hover:bg-gray-50")}>
|
||||
<Icon className="h-4 w-4" aria-hidden />
|
||||
{t.label}
|
||||
{t.badge}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const linkClass = "mt-3 inline-flex items-center gap-1 text-xs font-medium text-brand-text hover:underline";
|
||||
const TONES = { brand: "bg-brand/10 text-brand-text", amber: "bg-amber-50 text-amber-700", green: "bg-green-50 text-green-700", gray: "bg-gray-100 text-gray-600" };
|
||||
|
||||
/** A number on the dashboard: an icon tile, a label, the value, and where to go for more. */
|
||||
export function StatCard({ icon: Icon, label, value, detail, href, linkLabel, tone = "brand" }: { icon: LucideIcon; label: string; value: React.ReactNode; detail?: React.ReactNode; href?: string; linkLabel?: string; tone?: keyof typeof TONES }) {
|
||||
return (
|
||||
<div className="rounded-xl border border-gray-200 bg-white p-4 shadow-sm">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className={cx("flex h-10 w-10 shrink-0 items-center justify-center rounded-lg", TONES[tone])} aria-hidden><Icon className="h-5 w-5" /></span>
|
||||
<div className="min-w-0">
|
||||
<div className="text-xs leading-snug text-gray-500">{label}</div>
|
||||
<div className="truncate text-xl font-semibold text-gray-900">{value}</div>
|
||||
</div>
|
||||
</div>
|
||||
{detail && <div className="mt-2 text-xs text-gray-500">{detail}</div>}
|
||||
{href && (href.startsWith("/admin")
|
||||
? <Link href={href} className={linkClass}>{linkLabel ?? "Open"}<ArrowRight className="h-3 w-3" aria-hidden /></Link>
|
||||
: <a href={href} className={linkClass}>{linkLabel ?? "Open"}<ArrowRight className="h-3 w-3" aria-hidden /></a>)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** A quick-action tile: icon, title and a line about it; the whole tile is the link. */
|
||||
export function ActionTile({ icon: Icon, title, description, href }: { icon: LucideIcon; title: string; description: string; href: string }) {
|
||||
return (
|
||||
<Link href={href} className="flex items-start gap-3 rounded-xl border border-gray-200 bg-white p-4 shadow-sm transition hover:border-brand/40 hover:shadow">
|
||||
<span className="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-brand/10 text-brand-text" aria-hidden><Icon className="h-5 w-5" /></span>
|
||||
<span className="min-w-0">
|
||||
<span className="block text-sm font-semibold text-gray-900">{title}</span>
|
||||
<span className="mt-0.5 block text-xs text-gray-500">{description}</span>
|
||||
</span>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
type BtnProps = React.ButtonHTMLAttributes<HTMLButtonElement> & { kind?: "primary" | "secondary" | "danger" | "link" | "icon"; busy?: boolean };
|
||||
|
||||
export function Btn({ kind = "secondary", busy, className, children, disabled, ...rest }: BtnProps) {
|
||||
return (
|
||||
@@ -36,15 +108,17 @@ export function Btn({ kind = "secondary", busy, className, children, disabled, .
|
||||
{...rest}
|
||||
disabled={disabled || busy}
|
||||
className={cx(
|
||||
"inline-flex items-center justify-center gap-2 rounded-md px-4 py-2 text-sm font-semibold transition-colors disabled:cursor-not-allowed disabled:opacity-50",
|
||||
"inline-flex items-center justify-center gap-2 rounded-lg text-sm font-semibold transition-colors disabled:cursor-not-allowed disabled:opacity-50",
|
||||
kind !== "icon" && kind !== "link" && "px-4 py-2",
|
||||
kind === "primary" && "bg-brand text-brand-on hover:bg-brand-dark",
|
||||
kind === "secondary" && "border border-gray-300 bg-white text-gray-800 hover:bg-gray-50",
|
||||
kind === "danger" && "border border-red-300 bg-white text-red-700 hover:bg-red-50",
|
||||
kind === "link" && "px-0 py-0 text-brand-text underline-offset-4 hover:underline",
|
||||
kind === "icon" && "h-8 w-8 border border-gray-200 bg-white text-gray-600 hover:bg-gray-50 hover:text-gray-900",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{busy ? "Working…" : children}
|
||||
{busy && kind !== "icon" ? "Working…" : children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -60,11 +134,11 @@ export function Field({ label, hint, error, children }: { label: string; hint?:
|
||||
);
|
||||
}
|
||||
|
||||
export const inputClass = "w-full rounded-md border border-gray-300 px-3 py-2 text-sm text-gray-900 shadow-sm focus:border-brand focus:outline-none focus:ring-2 focus:ring-brand/30";
|
||||
export const inputClass = "w-full rounded-lg border border-gray-300 px-3 py-2 text-sm text-gray-900 shadow-sm focus:border-brand focus:outline-none focus:ring-2 focus:ring-brand/30";
|
||||
|
||||
export function Notice({ tone = "info", children }: { tone?: "info" | "error" | "success" | "warning"; children: React.ReactNode }) {
|
||||
const tones = { info: "border-blue-200 bg-blue-50 text-blue-900", error: "border-red-200 bg-red-50 text-red-900", success: "border-green-200 bg-green-50 text-green-900", warning: "border-amber-200 bg-amber-50 text-amber-900" };
|
||||
return <div role={tone === "error" ? "alert" : "status"} className={cx("rounded-md border px-4 py-3 text-sm", tones[tone])}>{children}</div>;
|
||||
return <div role={tone === "error" ? "alert" : "status"} className={cx("rounded-lg border px-4 py-3 text-sm", tones[tone])}>{children}</div>;
|
||||
}
|
||||
|
||||
/** Loads `path` from the admin API; `reload` fetches it again. */
|
||||
@@ -88,8 +162,18 @@ export function useAdmin<T>(path: string | null) {
|
||||
return { data, error, reload: load, setData };
|
||||
}
|
||||
|
||||
/** Runs an action, keeping its busy state, message and field errors. */
|
||||
/** The dashboard's numbers, shared by the frame (the change count, the setup steps) and the pages. */
|
||||
export type Overview = {
|
||||
pending: number;
|
||||
lastPublished: { number: number; at: string } | null;
|
||||
checklist: { key: string; label: string; done: boolean; href: string | null }[];
|
||||
};
|
||||
export const OverviewContext = createContext<{ overview: Overview | null; refresh: () => void }>({ overview: null, refresh: () => {} });
|
||||
export const useOverview = () => useContext(OverviewContext);
|
||||
|
||||
/** Runs an action, keeping its busy state, message and field errors. Afterwards the frame's change count and steps catch up. */
|
||||
export function useAction() {
|
||||
const { refresh } = useOverview();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [message, setMessage] = useState<{ tone: "error" | "success"; text: string } | null>(null);
|
||||
const [fields, setFields] = useState<Record<string, string>>({});
|
||||
@@ -107,8 +191,9 @@ export function useAction() {
|
||||
return null;
|
||||
} finally {
|
||||
setBusy(false);
|
||||
refresh();
|
||||
}
|
||||
}, []);
|
||||
}, [refresh]);
|
||||
return { busy, message, fields, run, setMessage };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user