Events 3.3.0, Accounts 1.3.0, contracts 1.11.0: Accounts looks like Events, backups; sign-out and upload fixes
- Accounts: account and admin pages in Cross Events' layout (top bar, sidebar, a page per section, dark footer); quick links to the church's sites (GET /me/apps); nightly pg_dump backups with Admin -> Backups (run, keep, download, audited; heartbeat lastBackupAt); a fuller built-in privacy notice with headings and bullets; a fixed favicon. /backups/ ignored (anchored, so src/backups is kept). - Contracts 1.11.0: people.removeDemo (only @example.com, never an admin). - Events: uploads served from the folder they're saved in (a backend started outside backend/ answered 404 for a logo it had just saved); Branding checks the file loads before saving; logout waits for the sign-out call so Accounts signs out too; set-demo removes the last demo's people from Accounts. Tests: Accounts 62 + e2e 8, Events 782, contracts 225; npm run check passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@crosscode/accounts-frontend",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"private": true,
|
||||
"description": "Cross Code Accounts: the church's sign-in pages, the account page and admin",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import React, { useCallback, useState } from "react";
|
||||
import QRCode from "qrcode";
|
||||
import { Button, Card, Checkbox, Field, Heading, Notice, Shell } from "@crosscode/ui";
|
||||
import { Activity as ActivityIcon, ArrowUpRight, Calendar, CheckCircle2, Globe, Lock, Mail, ShieldAlert, ShieldCheck, Smartphone, User, type LucideIcon } from "lucide-react";
|
||||
import { Button, Checkbox, Field, Notice } from "@crosscode/ui";
|
||||
import { useBranding } from "@/components/BrandingProvider";
|
||||
import { AppShell, PageTitle, ShellLoading } from "@/components/AppShell";
|
||||
import { Card, Heading } from "@/components/Panel";
|
||||
import { call, selfSignIn } from "@/lib/api";
|
||||
import { useExternalEffect } from "@/lib/hooks";
|
||||
|
||||
@@ -23,37 +27,124 @@ const EVENT: Record<string, string> = {
|
||||
};
|
||||
const when = (iso: string | null) => (iso ? new Date(iso).toLocaleString("en-ZA", { day: "numeric", month: "short", year: "numeric", hour: "2-digit", minute: "2-digit" }) : "—");
|
||||
|
||||
/** The account page (docs/ACCOUNTS-1.0-PLAN.md §8): everything about one's own account. */
|
||||
export function Account() {
|
||||
export type AccountSection = "overview" | "details" | "security" | "privacy" | "activity";
|
||||
|
||||
const SECTIONS: Record<AccountSection, { path: string; title: string; sub: (church: string) => string }> = {
|
||||
overview: { path: "/account", title: "Your account", sub: (c) => `One account for all of ${c}'s sites and apps.` },
|
||||
details: { path: "/account/details", title: "Your details", sub: (c) => `Your name and contact details, shared with ${c}'s sites when you sign in.` },
|
||||
security: { path: "/account/security", title: "Signing in", sub: () => "Your password, two-step sign-in and recovery codes." },
|
||||
privacy: { path: "/account/privacy", title: "Privacy", sub: () => "Your news choices, a copy of your data, and deleting your account." },
|
||||
activity: { path: "/account/activity", title: "Activity", sub: () => "Recent sign-ins and changes to your account." },
|
||||
};
|
||||
|
||||
/**
|
||||
* The account page (docs/ACCOUNTS-1.0-PLAN.md §8): everything about one's own account. 1.3.0: in
|
||||
* sections down the side (as Cross Events' dashboard), with quick links to the church's sites.
|
||||
*/
|
||||
export function Account({ section = "overview" }: { section?: AccountSection }) {
|
||||
const branding = useBranding();
|
||||
const [me, setMe] = useState<Me | null>(null);
|
||||
const [msg, setMsg] = useState<{ tone: "success" | "error"; text: string } | null>(null);
|
||||
const s = SECTIONS[section] ?? SECTIONS.overview;
|
||||
|
||||
const load = useCallback(async () => {
|
||||
const r = await call<Me>("GET", "/me");
|
||||
if (r.status === 401) return window.location.assign(selfSignIn("/account"));
|
||||
if (r.status === 401) return window.location.assign(selfSignIn(s.path));
|
||||
if (r.ok) setMe(r.data);
|
||||
}, []);
|
||||
}, [s.path]);
|
||||
useExternalEffect(() => { void load(); }, [load]);
|
||||
|
||||
const done = (text: string) => { setMsg({ tone: "success", text }); void load(); };
|
||||
const fail = (text: string) => setMsg({ tone: "error", text });
|
||||
|
||||
if (!me) return <Shell branding={branding}><p className="text-gray-600">Loading…</p></Shell>;
|
||||
if (!me) return <ShellLoading />;
|
||||
|
||||
const signOut = <a href={`/api/oidc/session/end?client_id=accounts-self&post_logout_redirect_uri=${encodeURIComponent(`${window.location.origin}/signed-out`)}`} className="text-sm text-brand underline">Sign out</a>;
|
||||
const first = me.name.split(" ")[0] || me.name;
|
||||
return (
|
||||
<Shell branding={branding} wide aside={<div className="flex gap-4">{me.role === "admin" && <a href="/admin" className="text-sm text-brand underline">Admin</a>}{signOut}</div>}>
|
||||
<h1 className="mb-1 text-2xl font-semibold">Your account</h1>
|
||||
<p className="mb-6 text-sm text-gray-600">One account for all of {branding.name}'s sites and apps.</p>
|
||||
<AppShell me={me} active={s.path}>
|
||||
<PageTitle sub={s.sub(branding.name)}>{section === "overview" ? `Hi, ${first}` : s.title}</PageTitle>
|
||||
{msg && <Notice tone={msg.tone}>{msg.text}</Notice>}
|
||||
<div className="grid gap-6 md:grid-cols-2">
|
||||
<Profile me={me} onDone={done} onFail={fail} />
|
||||
<Security me={me} onDone={done} onFail={fail} />
|
||||
<Privacy me={me} onDone={done} onFail={fail} />
|
||||
<Activity onDone={done} />
|
||||
{section === "overview" && <Overview me={me} />}
|
||||
{section === "details" && <div className="max-w-2xl"><Profile me={me} onDone={done} onFail={fail} /></div>}
|
||||
{section === "security" && <div className="max-w-2xl"><Security me={me} onDone={done} onFail={fail} /></div>}
|
||||
{section === "privacy" && <div className="max-w-2xl"><Privacy me={me} onDone={done} onFail={fail} /></div>}
|
||||
{section === "activity" && <div className="max-w-2xl"><Activity onDone={done} /></div>}
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Overview: the church's sites, and how the account stands ────────────────
|
||||
|
||||
type App = { id: string; product: string; name: string; description: string | null; url: string };
|
||||
const APP_ICONS: Record<string, LucideIcon> = { events: Calendar, website: Globe, app: Smartphone };
|
||||
|
||||
function Overview({ me }: { me: Me }) {
|
||||
const branding = useBranding();
|
||||
const [apps, setApps] = useState<App[] | null>(null);
|
||||
useExternalEffect(() => {
|
||||
let alive = true;
|
||||
call<{ items: App[] }>("GET", "/me/apps").then((r) => { if (alive) setApps(r.ok ? r.data.items : []); });
|
||||
return () => { alive = false; };
|
||||
}, []);
|
||||
|
||||
const checks: { ok: boolean; label: string; detail: string; href: string; icon: LucideIcon }[] = [
|
||||
{ ok: !!me.twoFactor, label: me.twoFactor ? "Two-step sign-in is on" : "Two-step sign-in is off", detail: me.twoFactor ? `With ${METHOD[me.twoFactor]}${me.recoveryCodesLeft < 3 ? `, ${me.recoveryCodesLeft} recovery codes left` : ""}` : "Turn it on so a password alone can't open your account", href: "/account/security", icon: me.twoFactor ? ShieldCheck : ShieldAlert },
|
||||
{ ok: me.emailVerified, label: me.emailVerified ? "Email address confirmed" : "Email address not confirmed", detail: me.email, href: "/account/details", icon: Mail },
|
||||
{ ok: true, label: "Last sign-in", detail: when(me.lastSignInAt), href: "/account/activity", icon: ActivityIcon },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<section aria-labelledby="apps-title">
|
||||
<h2 id="apps-title" className="mb-3 text-sm font-semibold uppercase tracking-wide text-gray-500">Go to</h2>
|
||||
{apps === null && <p className="text-sm text-gray-500" role="status">Loading…</p>}
|
||||
{apps && !apps.length && (
|
||||
<Card><p className="text-sm text-gray-600">{branding.name}'s sites and apps will show here once they sign people in with this account.</p></Card>
|
||||
)}
|
||||
{apps && apps.length > 0 && (
|
||||
<div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-3">
|
||||
{apps.map((a) => {
|
||||
const Icon = APP_ICONS[a.product] ?? Globe;
|
||||
return (
|
||||
<a key={a.id} href={a.url} className="group flex items-center gap-4 rounded-xl border bg-white p-5 shadow-sm transition hover:border-brand/40 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand/50">
|
||||
<span className="flex h-12 w-12 shrink-0 items-center justify-center rounded-xl bg-brand text-white" aria-hidden><Icon className="h-6 w-6" /></span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block font-semibold text-gray-900">{a.name}</span>
|
||||
{a.description && <span className="block text-sm text-gray-500">{a.description}</span>}
|
||||
<span className="block truncate text-xs text-gray-400">{a.url.replace(/^https?:\/\//, "").replace(/\/.*$/, "")}</span>
|
||||
</span>
|
||||
<ArrowUpRight className="h-5 w-5 shrink-0 text-gray-300 transition group-hover:text-brand" aria-hidden />
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="status-title">
|
||||
<h2 id="status-title" className="mb-3 text-sm font-semibold uppercase tracking-wide text-gray-500">Your account</h2>
|
||||
<div className="grid gap-4 md:grid-cols-3">
|
||||
{checks.map((c) => {
|
||||
const Icon = c.icon;
|
||||
return (
|
||||
<a key={c.label} href={c.href} className="flex items-start gap-3 rounded-xl border bg-white p-4 shadow-sm hover:bg-gray-50">
|
||||
<span className={`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg ${c.ok ? "bg-brand/10 text-brand" : "bg-amber-50 text-amber-700"}`} aria-hidden><Icon className="h-4 w-4" /></span>
|
||||
<span className="min-w-0">
|
||||
<span className="block text-sm font-medium text-gray-900">{c.label}</span>
|
||||
<span className="block truncate text-xs text-gray-500">{c.detail}</span>
|
||||
</span>
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div className="flex flex-wrap gap-3 text-sm">
|
||||
<Link href="/account/details" className="inline-flex items-center gap-1.5 rounded-lg border bg-white px-3 py-2 text-gray-700 hover:bg-gray-50"><User className="h-4 w-4" aria-hidden /> Change your details</Link>
|
||||
<Link href="/account/privacy" className="inline-flex items-center gap-1.5 rounded-lg border bg-white px-3 py-2 text-gray-700 hover:bg-gray-50"><Lock className="h-4 w-4" aria-hidden /> Download your data</Link>
|
||||
{me.noticeVersionAccepted >= me.noticeVersion && <span className="inline-flex items-center gap-1.5 px-1 py-2 text-gray-500"><CheckCircle2 className="h-4 w-4 text-green-600" aria-hidden /> You've read the latest <a href="/privacy" className="text-brand underline">privacy notice</a></span>}
|
||||
</div>
|
||||
</Shell>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -64,7 +155,7 @@ function Profile({ me, onDone, onFail }: Props) {
|
||||
const [changingEmail, setChangingEmail] = useState(false);
|
||||
return (
|
||||
<Card>
|
||||
<Heading>Your details</Heading>
|
||||
<Heading icon={<User className="h-4 w-4" />} sub="Change them here and the church's sites get them too.">Your details</Heading>
|
||||
<form onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
const f = new FormData(e.currentTarget);
|
||||
@@ -111,7 +202,7 @@ function Security({ me, onDone, onFail }: Props) {
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<Heading>Signing in</Heading>
|
||||
<Heading icon={<ShieldCheck className="h-4 w-4" />}>Signing in</Heading>
|
||||
<p className="mb-3 text-sm text-gray-700">
|
||||
Two-step sign-in: {me.twoFactor ? <strong>on, with {METHOD[me.twoFactor]}</strong> : <strong>off</strong>}
|
||||
{me.twoFactor && <span className="text-gray-500"> · {me.recoveryCodesLeft} recovery codes left</span>}
|
||||
@@ -193,7 +284,7 @@ function Privacy({ me, onDone, onFail }: Props) {
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<Heading>Privacy</Heading>
|
||||
<Heading icon={<Lock className="h-4 w-4" />}>Privacy</Heading>
|
||||
<form onChange={async (e) => {
|
||||
const f = new FormData(e.currentTarget);
|
||||
const r = await call("PUT", "/me/news", { email: f.get("email") === "on", whatsapp: f.get("whatsapp") === "on" });
|
||||
@@ -249,7 +340,7 @@ function Activity({ onDone }: { onDone: (t: string) => void }) {
|
||||
}, []);
|
||||
return (
|
||||
<Card>
|
||||
<Heading sub="If you see something you don't recognise, change your password and sign out everywhere.">Recent activity</Heading>
|
||||
<Heading icon={<ActivityIcon className="h-4 w-4" />} sub="If you see something you don't recognise, change your password and sign out everywhere.">Recent activity</Heading>
|
||||
<ul className="mb-4 max-h-72 space-y-2 overflow-y-auto text-sm">
|
||||
{items.map((e, i) => (
|
||||
<li key={i} className="flex justify-between gap-3 border-b pb-2 last:border-0">
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { Account, type AccountSection } from "../Account";
|
||||
|
||||
const TITLES: Record<string, string> = { details: "Your details", security: "Signing in", privacy: "Privacy", activity: "Activity" };
|
||||
|
||||
export async function generateMetadata({ params }: { params: Promise<{ section: string }> }) {
|
||||
const { section } = await params;
|
||||
return { title: TITLES[section] ?? "Your account" };
|
||||
}
|
||||
|
||||
/** One section of the account page (1.3.0): /account/details, /security, /privacy, /activity. */
|
||||
export default async function AccountSectionPage({ params }: { params: Promise<{ section: string }> }) {
|
||||
const { section } = await params;
|
||||
if (!(section in TITLES)) notFound();
|
||||
return <Account section={section as AccountSection} />;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
import { Card, Heading, Notice, Shell } from "@crosscode/ui";
|
||||
import { useBranding } from "@/components/BrandingProvider";
|
||||
@@ -23,7 +24,7 @@ export function ConfirmEmail({ token }: { token: string }) {
|
||||
<Card>
|
||||
<Heading>Your email address</Heading>
|
||||
{state ? <Notice tone={state.ok ? "success" : "error"}>{state.text}</Notice> : <p className="text-gray-600">Confirming…</p>}
|
||||
<a href="/account" className="text-brand underline">Back to your account</a>
|
||||
<Link href="/account" className="text-brand underline">Back to your account</Link>
|
||||
</Card>
|
||||
</Shell>
|
||||
);
|
||||
|
||||
@@ -1,63 +1,70 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import React, { useCallback, useState } from "react";
|
||||
import { Button, Card, Checkbox, Field, Heading, Notice, Shell } from "@crosscode/ui";
|
||||
import { useBranding } from "@/components/BrandingProvider";
|
||||
import { DatabaseBackup, Download } from "lucide-react";
|
||||
import { Button, Checkbox, Field, Notice } from "@crosscode/ui";
|
||||
import { AppShell, PageTitle, ShellLoading, type ShellUser } from "@/components/AppShell";
|
||||
import { NoticeText } from "@/components/NoticeText";
|
||||
import { Card, Heading } from "@/components/Panel";
|
||||
import { call, selfSignIn } from "@/lib/api";
|
||||
import { useExternalEffect } from "@/lib/hooks";
|
||||
import { ADMIN_SECTIONS, type AdminSection } from "@/lib/sections";
|
||||
|
||||
const TABS = [
|
||||
["people", "People"], ["deletions", "Deletion requests"], ["church", "Church profile"], ["linked", "Linked products"],
|
||||
["signin", "Sign-in settings"], ["messages", "Email and WhatsApp"], ["notice", "Privacy notice"], ["licence", "Licence"], ["audit", "Audit log"],
|
||||
] as const;
|
||||
type Tab = (typeof TABS)[number][0];
|
||||
|
||||
const when = (iso: string | null | undefined) => (iso ? new Date(iso).toLocaleString("en-ZA", { day: "numeric", month: "short", year: "numeric", hour: "2-digit", minute: "2-digit" }) : "—");
|
||||
|
||||
type Flash = (tone: "success" | "error", text: string) => void;
|
||||
|
||||
/** Accounts' admin (docs/ACCOUNTS-1.0-PLAN.md §8). Admins only, signed in with their second step. */
|
||||
export function Admin() {
|
||||
const branding = useBranding();
|
||||
const [tab, setTab] = useState<Tab>("people");
|
||||
/**
|
||||
* Accounts' admin (docs/ACCOUNTS-1.0-PLAN.md §8). Admins only, signed in with their second step.
|
||||
* 1.3.0: one section per address, down the side (as Cross Events' settings), and Backups.
|
||||
*/
|
||||
export function Admin({ section = "people" }: { section?: AdminSection }) {
|
||||
const s = ADMIN_SECTIONS[section] ?? ADMIN_SECTIONS.people;
|
||||
const [me, setMe] = useState<ShellUser | null>(null);
|
||||
const [allowed, setAllowed] = useState<boolean | null>(null);
|
||||
const [msg, setMsg] = useState<{ tone: "success" | "error"; text: string } | null>(null);
|
||||
|
||||
useExternalEffect(() => {
|
||||
let alive = true;
|
||||
call("GET", "/admin/licence").then((r) => {
|
||||
Promise.all([call<ShellUser>("GET", "/me"), call("GET", "/admin/licence")]).then(([who, r]) => {
|
||||
if (!alive) return;
|
||||
if (r.status === 401) return window.location.assign(selfSignIn("/admin"));
|
||||
if (!r.ok && r.error.code === "MFA_REQUIRED") return window.location.assign(selfSignIn("/admin", "&acr=mfa"));
|
||||
if (who.status === 401 || r.status === 401) return window.location.assign(selfSignIn(s.path));
|
||||
if (!r.ok && r.error.code === "MFA_REQUIRED") return window.location.assign(selfSignIn(s.path, "&acr=mfa"));
|
||||
if (who.ok) setMe(who.data);
|
||||
setAllowed(r.ok);
|
||||
});
|
||||
return () => { alive = false; };
|
||||
}, []);
|
||||
}, [s.path]);
|
||||
|
||||
const flash: Flash = (tone, text) => setMsg({ tone, text });
|
||||
if (allowed === null) return <Shell branding={branding} wide><p className="text-gray-600">Loading…</p></Shell>;
|
||||
if (!allowed) return <Shell branding={branding}><Card><Notice tone="error">Only Accounts admins can open this page.</Notice><a href="/account" className="text-brand underline">Your account</a></Card></Shell>;
|
||||
if (allowed === null || !me) return <ShellLoading />;
|
||||
if (!allowed) {
|
||||
return (
|
||||
<AppShell me={me} active={s.path}>
|
||||
<div className="max-w-xl"><Card><Notice tone="error">Only Accounts admins can open this page.</Notice><Link href="/account" className="text-brand underline">Your account</Link></Card></div>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Shell branding={branding} wide aside={<a href="/account" className="text-sm text-brand underline">Your account</a>}>
|
||||
<h1 className="mb-4 text-2xl font-semibold">Accounts admin</h1>
|
||||
<nav className="mb-6 flex flex-wrap gap-2" aria-label="Admin sections">
|
||||
{TABS.map(([id, label]) => (
|
||||
<button key={id} type="button" onClick={() => { setTab(id); setMsg(null); }} aria-current={tab === id ? "page" : undefined}
|
||||
className={`rounded-full px-3 py-1.5 text-sm ${tab === id ? "bg-brand text-white" : "border bg-white text-gray-700"}`}>{label}</button>
|
||||
))}
|
||||
</nav>
|
||||
<AppShell me={me} active={s.path}>
|
||||
<PageTitle sub={s.sub}>{s.title}</PageTitle>
|
||||
{msg && <Notice tone={msg.tone}>{msg.text}</Notice>}
|
||||
{tab === "people" && <People flash={flash} />}
|
||||
{tab === "deletions" && <Deletions flash={flash} />}
|
||||
{tab === "church" && <Church flash={flash} />}
|
||||
{tab === "linked" && <Linked flash={flash} />}
|
||||
{tab === "signin" && <Settings flash={flash} keys={["signup_enabled", "two_factor_required_for_admins", "session_days"]} />}
|
||||
{tab === "messages" && <Settings flash={flash} keys={["smtp_host", "smtp_port", "smtp_user", "smtp_pass", "smtp_from", "smtp_secure", "wawp_access_token", "wawp_instance_id"]} />}
|
||||
{tab === "notice" && <NoticeTab flash={flash} />}
|
||||
{tab === "licence" && <Licence flash={flash} />}
|
||||
{tab === "audit" && <Audit />}
|
||||
</Shell>
|
||||
{section === "people" && <People flash={flash} />}
|
||||
<div className="max-w-3xl">
|
||||
{section === "deletions" && <Deletions flash={flash} />}
|
||||
{section === "church" && <Church flash={flash} />}
|
||||
{section === "linked" && <Linked flash={flash} />}
|
||||
{section === "signin" && <Settings flash={flash} keys={["signup_enabled", "two_factor_required_for_admins", "session_days"]} />}
|
||||
{section === "messages" && <Settings flash={flash} keys={["smtp_host", "smtp_port", "smtp_user", "smtp_pass", "smtp_from", "smtp_secure", "wawp_access_token", "wawp_instance_id"]} />}
|
||||
{section === "notice" && <NoticeTab flash={flash} />}
|
||||
{section === "backups" && <Backups flash={flash} />}
|
||||
{section === "licence" && <Licence flash={flash} />}
|
||||
{section === "audit" && <Audit />}
|
||||
</div>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -292,30 +299,48 @@ function Settings({ flash, keys }: { flash: Flash; keys: string[] }) {
|
||||
|
||||
// ─── Privacy notice, licence, audit ───────────────────────────────────────────
|
||||
|
||||
type NoticeVersion = { version: number; title: string; body: string };
|
||||
|
||||
function NoticeTab({ flash }: { flash: Flash }) {
|
||||
const [current, setCurrent] = useState<{ version: number; title: string; body: string } | null>(null);
|
||||
const [data, setData] = useState<{ current: NoticeVersion; builtIn: NoticeVersion | null } | null>(null);
|
||||
const [draft, setDraft] = useState<{ title: string; body: string } | null>(null);
|
||||
const load = useCallback(async () => {
|
||||
const r = await call<{ current: { version: number; title: string; body: string } }>("GET", "/admin/notices");
|
||||
if (r.ok) setCurrent(r.data.current);
|
||||
const r = await call<{ current: NoticeVersion; builtIn?: NoticeVersion }>("GET", "/admin/notices");
|
||||
if (r.ok) { setData({ current: r.data.current, builtIn: r.data.builtIn ?? null }); setDraft({ title: r.data.current.title, body: r.data.current.body }); }
|
||||
}, []);
|
||||
useExternalEffect(() => { void load(); }, [load]);
|
||||
if (!current) return <p className="text-gray-600">Loading…</p>;
|
||||
if (!data || !draft) return <p className="text-gray-600">Loading…</p>;
|
||||
const { current, builtIn } = data;
|
||||
const isBuiltIn = current.version === 1;
|
||||
return (
|
||||
<Card>
|
||||
<Heading sub={`Version ${current.version}. Publishing a new version asks everyone to read it the next time they sign in.`}>Privacy notice</Heading>
|
||||
<form onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
if (!window.confirm("Publish this as a new version? Everyone will be asked to read it when they next sign in.")) return;
|
||||
const f = new FormData(e.currentTarget);
|
||||
const r = await call("POST", "/admin/notices", { title: f.get("title"), body: f.get("body") });
|
||||
if (r.ok) { flash("success", "Published."); void load(); } else flash("error", r.error.message);
|
||||
}}>
|
||||
<Field label="Title" name="title" defaultValue={current.title} required />
|
||||
<label htmlFor="notice-body" className="mb-1 block text-sm font-medium">Text</label>
|
||||
<textarea id="notice-body" name="body" defaultValue={current.body} rows={14} className="mb-4 w-full rounded-lg border p-3 text-sm" required />
|
||||
<Button type="submit">Publish a new version</Button>
|
||||
</form>
|
||||
</Card>
|
||||
<div className="space-y-6">
|
||||
<Card>
|
||||
<Heading sub={`Version ${current.version}${isBuiltIn ? " (the built-in notice, filled in from the church profile)" : ""}. Publishing a new version asks everyone to read it the next time they sign in.`}>Edit and publish</Heading>
|
||||
{builtIn && !isBuiltIn && (
|
||||
<p className="mb-4 text-sm text-gray-600">
|
||||
The built-in notice was rewritten in Accounts 1.3.0 to say more fully what Accounts does.{" "}
|
||||
<Button type="button" variant="link" className="text-sm" onClick={() => setDraft({ title: builtIn.title, body: builtIn.body })}>Start from the built-in notice</Button>
|
||||
</p>
|
||||
)}
|
||||
<form onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
if (!window.confirm("Publish this as a new version? Everyone will be asked to read it when they next sign in.")) return;
|
||||
const r = await call("POST", "/admin/notices", draft);
|
||||
if (r.ok) { flash("success", "Published."); void load(); } else flash("error", r.error.message);
|
||||
}}>
|
||||
<Field label="Title" name="title" value={draft.title} onChange={(e) => setDraft({ ...draft, title: e.target.value })} required />
|
||||
<label htmlFor="notice-body" className="mb-1 block text-sm font-medium">Text</label>
|
||||
<textarea id="notice-body" name="body" value={draft.body} onChange={(e) => setDraft({ ...draft, body: e.target.value })} rows={18} className="mb-1 w-full rounded-lg border p-3 font-mono text-xs" required />
|
||||
<p className="mb-4 text-xs text-gray-500">A line starting with "## " is a heading, and one starting with "• " is a bullet.</p>
|
||||
<Button type="submit">Publish a new version</Button>
|
||||
</form>
|
||||
</Card>
|
||||
<Card>
|
||||
<Heading sub="As people will see it.">Preview</Heading>
|
||||
<h3 className="mb-3 text-base font-semibold text-gray-900">{draft.title}</h3>
|
||||
<div className="max-h-[32rem] overflow-y-auto rounded-lg border bg-gray-50 p-4"><NoticeText body={draft.body} compact /></div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -368,3 +393,73 @@ function Audit() {
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Backups (1.3.0) ─────────────────────────────────────────────────────────
|
||||
|
||||
type BackupList = { items: { filename: string; size: number; createdAt: string }[]; nightly: boolean; retain: number; lastError: string | null };
|
||||
|
||||
const size = (n: number) => (n < 1024 ? `${n} B` : n < 1024 * 1024 ? `${(n / 1024).toFixed(1)} KB` : `${(n / (1024 * 1024)).toFixed(1)} MB`);
|
||||
|
||||
function Backups({ flash }: { flash: Flash }) {
|
||||
const [data, setData] = useState<BackupList | null>(null);
|
||||
const [running, setRunning] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const load = useCallback(async () => {
|
||||
const r = await call<BackupList>("GET", "/admin/backups");
|
||||
if (r.ok) setData(r.data);
|
||||
}, []);
|
||||
useExternalEffect(() => { void load(); }, [load]);
|
||||
if (!data) return <p className="text-gray-600">Loading…</p>;
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Card>
|
||||
<Heading icon={<DatabaseBackup className="h-4 w-4" />} sub="Every night at 02:00, and before every update of Accounts. Kept on this server only, never sent anywhere.">Database backups</Heading>
|
||||
{data.lastError && <Notice tone="warning">The last backup didn't work: {data.lastError}</Notice>}
|
||||
<Button busy={running} onClick={async () => {
|
||||
setRunning(true);
|
||||
const r = await call<{ filename: string }>("POST", "/admin/backups/run");
|
||||
setRunning(false);
|
||||
if (r.ok) { flash("success", `Backup made: ${r.data.filename}`); } else flash("error", r.error.message);
|
||||
void load();
|
||||
}}>Back up now</Button>
|
||||
|
||||
<form className="mt-5 flex flex-wrap items-end gap-x-4 gap-y-2 border-t pt-4" onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
const f = new FormData(e.currentTarget);
|
||||
setSaving(true);
|
||||
const r = await call<{ deleted: number }>("PUT", "/admin/backups/settings", { retain: Number(f.get("retain")), nightly: f.get("nightly") === "on" });
|
||||
setSaving(false);
|
||||
if (r.ok) { flash("success", r.data.deleted ? `Saved. ${r.data.deleted} older backups were deleted.` : "Saved."); void load(); } else flash("error", r.error.message);
|
||||
}}>
|
||||
<div className="w-full"><Checkbox name="nightly" label="Back up every night" defaultChecked={data.nightly} hint="Backups before each update are made either way." /></div>
|
||||
<Field label="Keep the newest" name="retain" type="number" min={1} max={365} defaultValue={String(data.retain)} className="mb-0 w-32" />
|
||||
<span className="pb-3 text-sm text-gray-500">backups, and delete older ones</span>
|
||||
<Button type="submit" variant="secondary" busy={saving} className="mb-1 ml-auto">Save</Button>
|
||||
</form>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<Heading sub="A backup holds everyone's details: keep a downloaded copy somewhere safe, and delete it when you're done.">Backups on this server</Heading>
|
||||
<div className="overflow-x-auto rounded-lg border">
|
||||
<table className="min-w-full text-sm">
|
||||
<thead><tr className="border-b bg-gray-50 text-left text-gray-600"><th className="p-2.5 font-medium">Made</th><th className="p-2.5 font-medium">Size</th><th className="p-2.5 font-medium"><span className="sr-only">Download</span></th></tr></thead>
|
||||
<tbody>
|
||||
{data.items.map((b) => (
|
||||
<tr key={b.filename} className="border-t">
|
||||
<td className="p-2.5">{when(b.createdAt)}</td>
|
||||
<td className="p-2.5 text-gray-500">{size(b.size)}</td>
|
||||
<td className="p-2.5 text-right">
|
||||
<a href={`/api/v2/admin/backups/${encodeURIComponent(b.filename)}/download`} download className="inline-flex items-center gap-1.5 text-brand hover:underline">
|
||||
<Download className="h-3.5 w-3.5" aria-hidden /> Download
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{!data.items.length && <tr><td colSpan={3} className="p-3 text-gray-500">No backups yet.</td></tr>}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { ADMIN_SECTIONS, type AdminSection } from "@/lib/sections";
|
||||
import { Admin } from "../Admin";
|
||||
|
||||
export async function generateMetadata({ params }: { params: Promise<{ section: string }> }) {
|
||||
const { section } = await params;
|
||||
return { title: ADMIN_SECTIONS[section as AdminSection]?.title ?? "Admin" };
|
||||
}
|
||||
|
||||
/** One section of admin (1.3.0): /admin/deletions, /church, /linked, … (/admin itself is People). */
|
||||
export default async function AdminSectionPage({ params }: { params: Promise<{ section: string }> }) {
|
||||
const { section } = await params;
|
||||
if (section === "people" || !(section in ADMIN_SECTIONS)) notFound();
|
||||
return <Admin section={section as AdminSection} />;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
|
||||
<defs>
|
||||
<linearGradient id="bg" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0" stop-color="#2563eb"/>
|
||||
<stop offset="1" stop-color="#1e3a8a"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect width="64" height="64" rx="14" fill="url(#bg)"/>
|
||||
<path d="M32 9.5 51 17v13.6c0 12.2-8.1 20.6-19 24.4-10.9-3.8-19-12.2-19-24.4V17z" fill="#fff"/>
|
||||
<circle cx="32" cy="27" r="6.6" fill="#1e3a8a"/>
|
||||
<path d="M20.6 43.2c2.2-6.6 6.4-9.4 11.4-9.4s9.2 2.8 11.4 9.4c-3.1 3.4-7 5.9-11.4 7.4-4.4-1.5-8.3-4-11.4-7.4z" fill="#1e3a8a"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 594 B |
@@ -1,19 +1,29 @@
|
||||
import { Card, Heading, Shell } from "@crosscode/ui";
|
||||
import { loadBranding } from "@/lib/branding";
|
||||
import { FileText } from "lucide-react";
|
||||
import { AppShell } from "@/components/AppShell";
|
||||
import { NoticeText } from "@/components/NoticeText";
|
||||
import { Card } from "@/components/Panel";
|
||||
|
||||
export const metadata = { title: "Privacy notice" };
|
||||
|
||||
const api = (process.env.ACCOUNTS_API_URL || "http://127.0.0.1:5200").replace(/\/+$/, "");
|
||||
|
||||
/** The privacy notice for everyone, signed in or not (1.3.0: in the account pages' frame, with headings). */
|
||||
export default async function PrivacyPage() {
|
||||
const branding = await loadBranding();
|
||||
const n = await fetch(`${api}/api/v2/notice`, { cache: "no-store" }).then((r) => r.json()).catch(() => null) as { title: string; body: string } | null;
|
||||
const n = await fetch(`${api}/api/v2/notice`, { cache: "no-store" }).then((r) => r.json()).catch(() => null) as { title: string; body: string; version?: number } | null;
|
||||
return (
|
||||
<Shell branding={branding}>
|
||||
<Card>
|
||||
<Heading>{n?.title ?? "Privacy notice"}</Heading>
|
||||
<div className="whitespace-pre-line text-sm leading-6 text-gray-700">{n?.body ?? "The privacy notice couldn't be loaded. Please try again."}</div>
|
||||
</Card>
|
||||
</Shell>
|
||||
<AppShell me={null}>
|
||||
<div className="mx-auto max-w-3xl">
|
||||
<Card className="sm:p-8">
|
||||
<div className="mb-6 flex items-start gap-3 border-b pb-5">
|
||||
<span className="flex h-11 w-11 shrink-0 items-center justify-center rounded-xl bg-brand/10 text-brand" aria-hidden><FileText className="h-5 w-5" /></span>
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">{n?.title ?? "Privacy notice"}</h1>
|
||||
{n?.version && <p className="mt-1 text-sm text-gray-500">Version {n.version}</p>}
|
||||
</div>
|
||||
</div>
|
||||
{n ? <NoticeText body={n.body} /> : <p className="text-sm text-gray-700">The privacy notice couldn't be loaded. Please try again.</p>}
|
||||
</Card>
|
||||
</div>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import React, { useState } from "react";
|
||||
import { Button, Card, Field, Heading, Notice, Shell } from "@crosscode/ui";
|
||||
import { useBranding } from "@/components/BrandingProvider";
|
||||
@@ -26,7 +27,7 @@ export function Setup() {
|
||||
<Card>
|
||||
<Heading sub="Your church's sign-in for its website, app and Cross Events.">Set up Accounts</Heading>
|
||||
{!status ? <p className="text-gray-600">Loading…</p> : !status.needed ? (
|
||||
<Notice tone="info">Accounts is already set up. <a href="/account" className="underline">Sign in</a></Notice>
|
||||
<Notice tone="info">Accounts is already set up. <Link href="/account" className="underline">Sign in</Link></Notice>
|
||||
) : (
|
||||
<form onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -5,6 +5,7 @@ import React, { useState } from "react";
|
||||
import QRCode from "qrcode";
|
||||
import { Button, Card, Checkbox, Field, Heading, Notice, Shell } from "@crosscode/ui";
|
||||
import { useBranding } from "@/components/BrandingProvider";
|
||||
import { NoticeText } from "@/components/NoticeText";
|
||||
import { call, type ApiError } from "@/lib/api";
|
||||
import { useExternalEffect } from "@/lib/hooks";
|
||||
|
||||
@@ -260,7 +261,7 @@ function NoticeStep({ state, busy, err, onAccept }: { state: State; busy: boolea
|
||||
<>
|
||||
<Heading icon={<FileText className="h-5 w-5" />} sub={state.updated ? "Our privacy notice has changed. Please read it before you carry on." : "Please read our privacy notice before you carry on."}>{state.notice!.title}</Heading>
|
||||
{err}
|
||||
<div className="mb-4 max-h-80 overflow-y-auto whitespace-pre-line rounded-lg border bg-gray-50 p-4 text-sm text-gray-700">{state.notice!.body}</div>
|
||||
<div className="mb-4 max-h-80 overflow-y-auto rounded-lg border bg-gray-50 p-4"><NoticeText body={state.notice!.body} compact /></div>
|
||||
<Button type="button" busy={busy} className="w-full" onClick={onAccept}>I've read it</Button>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
"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, 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/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 <span className={`${small ? "h-8 w-8 text-xs" : "h-10 w-10 text-sm"} flex shrink-0 items-center justify-center rounded-full bg-brand/10 font-semibold text-brand-dark`} aria-hidden>{initials(name)}</span>;
|
||||
}
|
||||
|
||||
function RoleBadge({ role }: { role: ShellUser["role"] }) {
|
||||
return role === "admin"
|
||||
? <span className="inline-block rounded-full bg-brand/10 px-2 py-0.5 text-[11px] font-medium text-brand-dark">Accounts admin</span>
|
||||
: <span className="inline-block rounded-full bg-gray-100 px-2 py-0.5 text-[11px] font-medium text-gray-600">Member</span>;
|
||||
}
|
||||
|
||||
function NavList({ title, items, active, onNavigate }: { title: string; items: NavItem[]; active: string; onNavigate?: () => void }) {
|
||||
return (
|
||||
<div className="mb-6">
|
||||
<p className="mb-2 px-3 text-[11px] font-semibold uppercase tracking-wide text-gray-400">{title}</p>
|
||||
<nav className="space-y-1" aria-label={title}>
|
||||
{items.map((l) => {
|
||||
const Icon = l.icon;
|
||||
const on = active === l.href;
|
||||
return (
|
||||
<Link key={l.href} href={l.href} onClick={onNavigate} aria-current={on ? "page" : undefined}
|
||||
className={`flex items-center gap-3 rounded-lg px-3 py-2 text-sm transition-colors ${on ? "bg-brand/10 font-medium text-brand-dark" : "text-gray-600 hover:bg-gray-50"}`}>
|
||||
<Icon className="h-4 w-4 shrink-0" aria-hidden />
|
||||
{l.label}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarContent({ me, active, onNavigate }: { me: ShellUser; active: string; onNavigate?: () => void }) {
|
||||
return (
|
||||
<>
|
||||
<div className="mb-6 flex items-center gap-3 px-1">
|
||||
<Avatar name={me.name} />
|
||||
<div className="min-w-0">
|
||||
<div className="truncate text-sm font-semibold text-gray-900">{me.name}</div>
|
||||
<RoleBadge role={me.role} />
|
||||
</div>
|
||||
</div>
|
||||
<NavList title="Your account" items={ACCOUNT_NAV} active={active} onNavigate={onNavigate} />
|
||||
{me.role === "admin" && <NavList title="Admin" items={ADMIN_NAV} active={active} onNavigate={onNavigate} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (
|
||||
<div className="flex min-h-screen flex-col bg-gray-50">
|
||||
<a href="#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-40 bg-white shadow-md">
|
||||
<div className="mx-auto flex max-w-7xl items-center justify-between gap-3 px-4 py-3">
|
||||
<Link href={me ? "/account" : "/"} className="flex min-w-0 items-center gap-2">
|
||||
<ChurchMark branding={b} />
|
||||
<span className="truncate text-lg font-bold text-brand-dark sm:text-xl">{b.name}</span>
|
||||
</Link>
|
||||
{me && (
|
||||
<>
|
||||
<div className="hidden items-center gap-6 md:flex">
|
||||
<Link href="/account" className={`${top} ${!inAdmin ? "border-brand font-medium text-brand-dark" : "border-transparent text-gray-700 hover:text-brand"}`}>Your account</Link>
|
||||
{me.role === "admin" && <Link href="/admin" className={`${top} ${inAdmin ? "border-brand font-medium text-brand-dark" : "border-transparent text-gray-700 hover:text-brand"}`}>Admin</Link>}
|
||||
<a href="/signed-out" onClick={(e) => { e.preventDefault(); window.location.assign(signOutHref()); }} className={`${top} inline-flex items-center gap-1.5 border-transparent text-gray-700 hover:text-brand`}>
|
||||
<LogOut className="h-4 w-4" aria-hidden /> Sign out
|
||||
</a>
|
||||
</div>
|
||||
<button type="button" onClick={() => setOpen(true)} aria-label="Open the menu" aria-expanded={open} className="rounded-md p-2 hover:bg-gray-100 md:hidden">
|
||||
<Menu className="h-5 w-5" />
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{me && open && (
|
||||
<div className="fixed inset-0 z-50 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 flex w-72 max-w-[85vw] flex-col overflow-y-auto bg-white p-4 shadow-xl">
|
||||
<button type="button" onClick={() => setOpen(false)} aria-label="Close the menu" className="mb-2 self-end rounded-md p-2 hover:bg-gray-100"><X className="h-5 w-5" /></button>
|
||||
<SidebarContent me={me} active={active} onNavigate={() => setOpen(false)} />
|
||||
<a href="/signed-out" onClick={(e) => { 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">
|
||||
<LogOut className="h-4 w-4" aria-hidden /> Sign out
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mx-auto flex w-full max-w-7xl flex-1">
|
||||
{me && (
|
||||
<aside className="hidden w-64 shrink-0 border-r bg-white p-4 md:block">
|
||||
<div className="sticky top-20"><SidebarContent me={me} active={active} /></div>
|
||||
</aside>
|
||||
)}
|
||||
<main id="main" className="min-w-0 flex-1 p-4 sm:p-6">{children}</main>
|
||||
</div>
|
||||
|
||||
<footer className="bg-gray-900 py-6 text-center text-sm text-white">
|
||||
<p>© {new Date().getFullYear()} {b.name}. One church account for all its sites and apps.</p>
|
||||
<div className="mt-2 space-x-4">
|
||||
<a href="/privacy" className="text-gray-300 hover:underline">Privacy notice</a>
|
||||
{me && <Link href="/account/activity" className="text-gray-300 hover:underline">Your sign-ins</Link>}
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 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 (
|
||||
<div className="mb-6">
|
||||
<h1 className="text-2xl font-bold text-gray-900">{children}</h1>
|
||||
{sub && <p className="mt-1 text-sm text-gray-600">{sub}</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** While a page loads its data: the frame without a sidebar yet. */
|
||||
export function ShellLoading() {
|
||||
return (
|
||||
<AppShell me={null}>
|
||||
<p className="text-sm text-gray-500" role="status">Loading…</p>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import React from "react";
|
||||
|
||||
/**
|
||||
* A privacy notice's text (1.3.0): a line starting "## " is a heading, "• " (or "- ") a bullet,
|
||||
* anything else a paragraph. Notices published before 1.3.0 are plain paragraphs and look as before.
|
||||
*/
|
||||
export function NoticeText({ body, compact = false }: { body: string; compact?: boolean }) {
|
||||
const blocks: React.ReactNode[] = [];
|
||||
let bullets: string[] = [];
|
||||
const flush = () => {
|
||||
if (!bullets.length) return;
|
||||
blocks.push(<ul key={`u${blocks.length}`} className="mb-3 list-disc space-y-1 pl-5">{bullets.map((b, i) => <li key={i}>{b}</li>)}</ul>);
|
||||
bullets = [];
|
||||
};
|
||||
for (const raw of body.split(/\r?\n/)) {
|
||||
const line = raw.trim();
|
||||
if (/^[•-]\s+/.test(line)) { bullets.push(line.replace(/^[•-]\s+/, "")); continue; }
|
||||
flush();
|
||||
if (!line) continue;
|
||||
if (line.startsWith("## ")) blocks.push(<h2 key={`h${blocks.length}`} className={`${compact ? "mt-4 text-sm" : "mt-6 text-base"} mb-2 font-semibold text-gray-900 first:mt-0`}>{line.slice(3)}</h2>);
|
||||
else blocks.push(<p key={`p${blocks.length}`} className="mb-3">{line}</p>);
|
||||
}
|
||||
flush();
|
||||
return <div className={`${compact ? "text-sm" : "text-[15px]"} leading-relaxed text-gray-700`}>{blocks}</div>;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import React from "react";
|
||||
|
||||
/**
|
||||
* The account and admin pages' cards (1.3.0, as Cross Events' settings): a white panel with a
|
||||
* quiet border, and a header with an icon in a tile of the church's colour. Same names and props
|
||||
* as @crosscode/ui's Card and Heading, which the sign-in pages keep.
|
||||
*/
|
||||
export function Card({ children, className }: { children: React.ReactNode; className?: string }) {
|
||||
return <section className={`rounded-xl border bg-white p-5 shadow-sm ${className ?? ""}`}>{children}</section>;
|
||||
}
|
||||
|
||||
export function Heading({ children, sub, icon }: { children: React.ReactNode; sub?: React.ReactNode; icon?: React.ReactNode }) {
|
||||
return (
|
||||
<div className="mb-4 flex 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" aria-hidden>{icon}</span>}
|
||||
<div className="min-w-0">
|
||||
<h2 className="text-lg font-semibold text-gray-900">{children}</h2>
|
||||
{sub && <p className="mt-0.5 text-xs text-gray-500">{sub}</p>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/** The admin's sections (1.3.0): one address each, in the sidebar (components/AppShell.tsx). */
|
||||
export const ADMIN_SECTIONS = {
|
||||
people: { path: "/admin", title: "People", sub: "Everyone with a church account. Roles in each site (an Events supervisor, for example) are set in that site." },
|
||||
deletions: { path: "/admin/deletions", title: "Deletion requests", sub: "People who asked to delete their account." },
|
||||
church: { path: "/admin/church", title: "Church profile", sub: "The church's name, logo, colours and contact details, used by all its sites." },
|
||||
linked: { path: "/admin/linked", title: "Linked products", sub: "The church's sites and apps that sign people in here." },
|
||||
signin: { path: "/admin/signin", title: "Sign-in settings", sub: "Who may make an account, two-step sign-in for admins, and how long people stay signed in." },
|
||||
messages: { path: "/admin/messages", title: "Email and WhatsApp", sub: "How Accounts sends sign-in codes, password links and security notices." },
|
||||
notice: { path: "/admin/notice", title: "Privacy notice", sub: "What people read before they sign in for the first time, and after it changes." },
|
||||
backups: { path: "/admin/backups", title: "Backups", sub: "Copies of the Accounts database, kept on this server." },
|
||||
licence: { path: "/admin/licence", title: "Licence", sub: "Accounts' connection to Cross Code." },
|
||||
audit: { path: "/admin/audit", title: "Audit log", sub: "What admins and the church's sites changed here." },
|
||||
} as const;
|
||||
export type AdminSection = keyof typeof ADMIN_SECTIONS;
|
||||
@@ -29,5 +29,5 @@ export function proxy(request: NextRequest) {
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: [{ source: "/((?!api|_next/static|_next/image|favicon.ico).*)", missing: [{ type: "header", key: "next-router-prefetch" }] }],
|
||||
matcher: [{ source: "/((?!api|_next/static|_next/image|favicon.ico|icon.svg).*)", missing: [{ type: "header", key: "next-router-prefetch" }] }],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user