"use client"; import Link from "next/link"; import React, { useState } from "react"; import { Activity, Building2, DatabaseBackup, FileText, KeyRound, LayoutDashboard, Link2, Lock, LogIn, LogOut, Mail, Menu, ScrollText, ShieldCheck, Timer, User, Users, UserX, X, type LucideIcon, } from "lucide-react"; import { ChurchMark } from "@crosscode/ui"; import { useBranding } from "@/components/BrandingProvider"; /** Who's signed in, as the shell shows them (null: a public page such as the privacy notice). */ export type ShellUser = { name: string; email: string; role: "member" | "admin" }; type NavItem = { href: string; label: string; icon: LucideIcon }; export const ACCOUNT_NAV: NavItem[] = [ { href: "/account", label: "Overview", icon: LayoutDashboard }, { href: "/account/details", label: "Your details", icon: User }, { href: "/account/security", label: "Signing in", icon: ShieldCheck }, { href: "/account/privacy", label: "Privacy", icon: Lock }, { href: "/account/activity", label: "Activity", icon: Activity }, ]; export const ADMIN_NAV: NavItem[] = [ { href: "/admin", label: "People", icon: Users }, { href: "/admin/deletions", label: "Deletion requests", icon: UserX }, { href: "/admin/church", label: "Church profile", icon: Building2 }, { href: "/admin/linked", label: "Linked products", icon: Link2 }, { href: "/admin/signin", label: "Sign-in settings", icon: LogIn }, { href: "/admin/messages", label: "Email and WhatsApp", icon: Mail }, { href: "/admin/notice", label: "Privacy notice", icon: FileText }, { href: "/admin/backups", label: "Backups", icon: DatabaseBackup }, { href: "/admin/jobs", label: "Background jobs", icon: Timer }, { href: "/admin/licence", label: "Licence", icon: KeyRound }, { href: "/admin/audit", label: "Audit log", icon: ScrollText }, ]; /** Signs out of Accounts and every site of the church (RP-initiated logout), ending on /signed-out. */ export function signOutHref() { return `/api/oidc/session/end?client_id=accounts-self&post_logout_redirect_uri=${encodeURIComponent(`${window.location.origin}/signed-out`)}`; } const initials = (name: string) => name.split(/\s+/).filter(Boolean).slice(0, 2).map((p) => p[0]!.toUpperCase()).join("") || "?"; function Avatar({ name, small }: { name: string; small?: boolean }) { return {initials(name)}; } function RoleBadge({ role }: { role: ShellUser["role"] }) { return role === "admin" ? Accounts admin : Member; } function NavList({ title, items, active, onNavigate }: { title: string; items: NavItem[]; active: string; onNavigate?: () => void }) { return (

{title}

); } function SidebarContent({ me, active, onNavigate }: { me: ShellUser; active: string; onNavigate?: () => void }) { return ( <>
{me.name}
{me.role === "admin" && } ); } /** * The frame of the account and admin pages (1.3.0, as Cross Events' dashboard): the church's logo * and name across the top, a sidebar of sections, the page on a light grey, and a dark footer. * Without `me` (a public page) there's no sidebar. `active` is the current section's address. */ export function AppShell({ me, active = "", children }: { me: ShellUser | null; active?: string; children: React.ReactNode }) { const b = useBranding(); const [open, setOpen] = useState(false); const top = "text-sm border-b-2 pb-0.5 transition-colors"; const inAdmin = active.startsWith("/admin"); return (
Skip to content
{b.name} {me && ( <> )}
{me && open && (
setOpen(false)} /> { e.preventDefault(); window.location.assign(signOutHref()); }} className="mt-auto flex items-center gap-3 rounded-lg px-3 py-2 text-sm text-gray-600 hover:bg-gray-50"> Sign out
)}
{me && ( )}
{children}

© {new Date().getFullYear()} {b.name}. One church account for all its sites and apps.

Privacy notice {me && Your sign-ins}
); } /** A page's title and a line under it, at the top of the main column. */ export function PageTitle({ children, sub }: { children: React.ReactNode; sub?: React.ReactNode }) { return (

{children}

{sub &&

{sub}

}
); } /** While a page loads its data: the frame without a sidebar yet. */ export function ShellLoading() { return (

Loading…

); }