/* ═══════════════════════════════════════════════════════════════ 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/contact_types", label: "Contact types", blurb: "Roles an organization's contacts hold, eg. Minister. Contacts are added on the organization.", }, { 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/person_tag_types", label: "People tags", blurb: "Directories people can be tagged into, eg. Musicians. Who carries a tag is edited on the person.", }, { to: "/admin/tags", label: "Tags", blurb: "Descriptors for organizations and events, eg. Online, In-Person. Who carries a tag is edited on the record.", }, { to: "/admin/redirects", label: "Links/redirects", blurb: "Short /go/ links for the newsletter, with click counts, Plausible and UTM tracking.", }, { to: "/admin/blog_posts", label: "Blog posts", blurb: "Posts of our own, each at /blog/…, written here or imported from Word.", }, // A timeline entry can point at an event, an organization, an // award, a person or a team, so it's its own kind of record. { to: "/admin/timeline", label: "Timeline", blurb: "The History page's entries: milestones and the records they point at.", }, ], }; 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.", }, // The site's own pages, in the header's order: each is its // sections, built in the editor (sitePages.ts). { to: "/admin/retreats_page", label: "Retreats", blurb: "Its sections: the event carousels and grids, and anything else written for it.", }, { to: "/admin/community_page", label: "Community", blurb: "Its sections: the blog (and its pinned posts and feeds), groups map, regions and partners.", }, { to: "/admin/resources_page", label: "Resources", blurb: "Its sections and their content.", }, { to: "/admin/organization_page", label: "Organization", blurb: "Mission, vision and values, the leadership teams and volunteering, details and contact.", }, { to: "/admin/history_page", label: "History", blurb: "Its sections: the timeline (its entries are under Data), and anything else.", }, ], }; /* 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, featured cards and blocks of its own, ready to paste into Mailchimp or Gmail. Saved as drafts, and can become a blog post.", }, { 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"; }