NGU-Web/src/pages/admin/adminNav.ts
Zaldimmar 2a926971f7 A newsletter builder (Tools → Newsletter)
Tick upcoming events, published blog posts and the front page's
featured cards, write a title and intro, and copy an email-ready
newsletter (table layout, inline styles, the palette in hex, a
plain-text copy alongside) into Mailchimp, Gmail or Church Center,
or download it. Picked posts are read from their public pages, so
only live posts make it in; links and images point at the live
site. Nothing is sent or stored. The builder is src/lib/newsletter.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 22:38:04 -05:00

214 lines
7.2 KiB
TypeScript

/* ═══════════════════════════════════════════════════════════════
ADMIN NAVIGATION: src/pages/admin/adminNav.ts
One list, read by two things: the header (a menu per group, its
items on hover or focus, and the open group's items in the strip
below) and the admin home page (a block of cards per group).
Adding an entity stays one entry here plus a descriptor; there's
no second list to keep in step.
Five groups, each a menu in the header and a block on the home
page:
Data the records: events, organizations, teams, awards, people
Pages what edits a page rather than a record type: the front
page, the history timeline, the blog and its Community
section
Forms what the public site has sent us
Tools pages that make something: the media library, QR codes
Panel accounts and the server (superadmins only)
Clicking a group's name opens its first item. That's also the
touch path, where hover doesn't exist: the strip under the header
lists the rest of the open group.
`blurb` is only read by the home cards. The header ignores it.
`superOnly` hides an entry from anyone below superadmin. It
hides, nothing more: the route still has to be guarded and the
API still has to say no. Treating a filtered menu as access
control is how you end up with a URL that works.
Three areas, three titles. The area is derived from the path
rather than declared per route, so a page added under
/admin/panel/… inherits the right title without registering
anything.
═══════════════════════════════════════════════════════════════ */
import { atLeast, isSuper } from "../../lib/roles.ts";
export const ADMIN_HOME = "/admin/home";
export const ADMIN_PANEL = "/admin/panel";
export const AREA_TITLES = {
home: "NGU Admin Home",
cms: "NGU Admin CMS",
panel: "NGU Admin Panel",
};
export const DATA_NAV = {
label: "Data",
blurb: "The records the site is built from.",
children: [
{
to: "/admin/events",
label: "Events",
blurb: "Retreats, conferences and gatherings, with their sections and rosters.",
},
{
to: "/admin/organizations",
label: "Organizations",
blurb: "The national organization, regions, groups and partners.",
},
{
to: "/admin/teams",
label: "Teams",
blurb: "Boards, committees and leadership teams within an organization.",
},
{
to: "/admin/awards",
label: "Awards",
blurb: "Awards an organization gives. Who received one is edited on the person.",
},
{
to: "/admin/people",
label: "People",
blurb: "Bios, contact details, affiliations and awards received.",
},
{
to: "/admin/blog_posts",
label: "Blog posts",
blurb: "Posts of our own, each at /blog/…, written here or imported from Word.",
},
],
};
export const PAGES_NAV = {
label: "Pages",
blurb: "What a page shows and in what order.",
children: [
// One record, not a list: the item opens it directly.
{
to: "/admin/front_page",
label: "Front page",
blurb: "The hero, its photos or livestream, and which bands the home page draws.",
},
// A timeline entry can point at an event, an organization, an
// award, a person or a team, so it isn't filed under any of them.
{
to: "/admin/timeline",
label: "Timeline",
blurb: "What the history page shows, and the order it shows it in.",
},
{
to: "/admin/community_page",
label: "Community blog section",
blurb: "The Community page's blog: headings, pinned posts and feeds.",
},
],
};
/* Submissions coming in rather than content going out. */
export const FORMS_NAV = {
label: "Forms",
blurb: "Whatever the public site has sent us.",
children: [
{
to: "/admin/feedback",
label: "Website feedback",
blurb: "The triage queue for the feedback form.",
},
{
to: "/admin/requests",
label: "Content requests",
blurb: "Requests for blog posts, events, and new or updated organizations, teams, awards and people, with their files.",
},
{
to: "/admin/data-requests",
label: "Data requests",
blurb: "Requests to see, correct or delete someone's information, from the Privacy page.",
},
],
};
/* Pages that make something rather than edit a record. The QR page
lives on the public site, so opening it leaves the admin. */
export const TOOLS_NAV = {
label: "Tools",
blurb: "Handy pages for making things.",
children: [
{
to: "/admin/media",
label: "Media",
blurb: "Uploaded images: logos, photos and backgrounds, ready to reuse.",
},
{
to: "/admin/clips",
label: "Video clips",
blurb: "Cut clips from our YouTube and Facebook videos: trimmed, reshaped for Reels, or audio only.",
minRole: "admin",
},
{
to: "/admin/newsletter",
label: "Newsletter",
blurb: "An email newsletter from upcoming events, blog posts and featured cards, ready to paste into Mailchimp or Gmail.",
},
{
to: "/qr",
label: "QR code generator",
blurb: "Codes for flyers, slides and signs: any page or link, in your choice of colors.",
},
],
};
/* Accounts, server state and what the site says about itself: the
superadmin's area, its own area rather than a group of CMS pages. */
export const SITE_SETTINGS = "/admin/site_settings";
export const PANEL_NAV = {
label: "Panel",
blurb: "Only superadmins see this.",
separated: true,
superOnly: true,
children: [
{
to: ADMIN_PANEL,
label: "Accounts and server",
blurb: "Accounts, sessions and the state of the server.",
},
{
to: SITE_SETTINGS,
label: "Site settings",
blurb: "The site's name, description, preview image, icons, page titles and search indexing.",
},
],
};
export const NAV: any[] = [DATA_NAV, PAGES_NAV, FORMS_NAV, TOOLS_NAV, PANEL_NAV];
/* A group's items this user may see: one with `minRole` is left out
below that rank (Video clips is admin and up). */
export function visibleItems(items, user) {
return (items ?? []).filter((item) => !item.minRole || atLeast(user, item.minRole));
}
/* What this user may see. Call it with the user from useAuth. */
export function navFor(user) {
return NAV.filter((item) => !item.superOnly || isSuper(user)).map((item) =>
item.children ? { ...item, children: visibleItems(item.children, user) } : item,
);
}
/* An item owns its own page and everything below it, so editing
/admin/teams/ngu-board keeps Teams lit. */
export const matches = (pathname, to) =>
Boolean(to) && (pathname === to || pathname.startsWith(`${to}/`));
/* Where a group's name goes: its own page, else its first item. */
export const target = (item) => item.to ?? item.children?.[0]?.to;
export function areaFor(pathname) {
if (matches(pathname, ADMIN_HOME)) return "home";
if (matches(pathname, ADMIN_PANEL) || matches(pathname, SITE_SETTINGS)) return "panel";
return "cms";
}