"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" }; export 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 }, ]; /** 1.8.0: the admin's sections in groups, as Cross Events' settings, with the overview first. */ export const ADMIN_GROUPS: { title: string | null; items: NavItem[] }[] = [ { title: null, items: [{ href: "/admin", label: "Overview", icon: LayoutDashboard }] }, { title: "People", items: [{ href: "/admin/people", label: "People", icon: Users }, { href: "/admin/deletions", label: "Deletion requests", icon: UserX }] }, { title: "Church", items: [{ href: "/admin/church", label: "Church profile", icon: Building2 }, { href: "/admin/linked", label: "Linked products", icon: Link2 }] }, { title: "Signing in", items: [{ 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 }], }, { title: "System", items: [{ 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 }], }, ]; export const ADMIN_NAV: NavItem[] = ADMIN_GROUPS.flatMap((g) => g.items); /** 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; } /** Counts beside a section (deletion requests waiting, say), by its address. */ export type Badges = Record; function NavLinks({ items, active, badges, onNavigate }: { items: NavItem[]; active: string; badges?: Badges; onNavigate?: () => void }) { return ( ); } function AccountNav({ active, onNavigate }: { active: string; onNavigate?: () => void }) { return (

Your account

); } function AdminNav({ active, badges, onNavigate }: { active: string; badges?: Badges; onNavigate?: () => void }) { return ( ); } /** * The sidebar: who's signed in, then the sections of the part you're in (1.8.0: your account or * admin, not both at once; the bar across the top switches). In the phone menu, both. */ function SidebarContent({ me, active, badges, both, onNavigate }: { me: ShellUser; active: string; badges?: Badges; both?: boolean; onNavigate?: () => void }) { const inAdmin = me.role === "admin" && active.startsWith("/admin"); return ( <>
{me.name}
{(both || !inAdmin) && } {me.role === "admin" && (both || inAdmin) && } {!both && me.role === "admin" && ( {inAdmin ? : } {inAdmin ? "Go to your account" : "Go to 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 = "", badges, children }: { me: ShellUser | null; active?: string; badges?: Badges; 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; with the section's icon. */ export function PageTitle({ children, sub, icon: Icon }: { children: React.ReactNode; sub?: React.ReactNode; icon?: LucideIcon }) { return (
{Icon && }

{children}

{sub &&

{sub}

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

Loading…

); }