diff --git a/apps/accounts/backend/src/public/routes.ts b/apps/accounts/backend/src/public/routes.ts index 870f3f4..04a5b7b 100644 --- a/apps/accounts/backend/src/public/routes.ts +++ b/apps/accounts/backend/src/public/routes.ts @@ -9,6 +9,7 @@ import { handle, limit } from '../http.js'; import { branding, church } from '../church/profile.js'; import { acceptConnect, acceptDisconnect, LinkError } from '../links/connect.js'; import { setupNeeded } from '../setup/routes.js'; +import { currentNotice } from '../privacy/notice.js'; const strip = (p: string) => p.replace(/^\/api/, ''); @@ -24,6 +25,12 @@ export function publicRouter(ctx: Ctx) { r.get('/v2/branding', handle(async () => ({ ...(await branding(ctx)), setupNeeded: await setupNeeded(ctx) }))); + // The privacy notice, for the sign-up page's link (public). + r.get('/v2/notice', handle(async () => { + const n = await currentNotice(ctx); + return { version: n.version, title: n.title, body: n.body, publishedAt: n.publishedAt }; + })); + r.get(strip(CHURCH_PATHS.profile), limit(600), handle(async (_req, res) => { res.set('Cache-Control', 'public, max-age=60'); return church(ctx); diff --git a/apps/accounts/frontend/.gitignore b/apps/accounts/frontend/.gitignore new file mode 100644 index 0000000..a20cfa5 --- /dev/null +++ b/apps/accounts/frontend/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +.next/ +next-env.d.ts +.env* diff --git a/apps/accounts/frontend/eslint.config.mjs b/apps/accounts/frontend/eslint.config.mjs new file mode 100644 index 0000000..b371683 --- /dev/null +++ b/apps/accounts/frontend/eslint.config.mjs @@ -0,0 +1,17 @@ +import { defineConfig, globalIgnores } from "eslint/config"; +import nextVitals from "eslint-config-next/core-web-vitals"; +import nextTs from "eslint-config-next/typescript"; + +// Next.js 16's own flat configs, as Cross Events. Run with `npm run lint`. +export default defineConfig([ + ...nextVitals, + ...nextTs, + { + rules: { + "react-hooks/exhaustive-deps": ["warn", { additionalHooks: "^useExternalEffect$" }], + // Logos and QR codes are small and come from the church's own settings. + "@next/next/no-img-element": "off", + }, + }, + globalIgnores([".next/**", "out/**", "next-env.d.ts"]), +]); diff --git a/apps/accounts/frontend/next.config.ts b/apps/accounts/frontend/next.config.ts new file mode 100644 index 0000000..34ec21f --- /dev/null +++ b/apps/accounts/frontend/next.config.ts @@ -0,0 +1,25 @@ +import type { NextConfig } from "next"; + +// Everything under /api is the backend (docs/ACCOUNTS-1.0-PLAN.md §1). On a server nginx sends it +// there; in development (and when Next is reached directly) this rewrite does. +const api = (process.env.ACCOUNTS_API_URL || "http://127.0.0.1:5200").replace(/\/+$/, ""); + +const nextConfig: NextConfig = { + poweredByHeader: false, + transpilePackages: ["@crosscode/ui"], + async rewrites() { + return [{ source: "/api/:path*", destination: `${api}/api/:path*` }]; + }, + async headers() { + return [{ + source: "/:path*", + headers: [ + { key: "X-Robots-Tag", value: "noindex, nofollow" }, + { key: "Referrer-Policy", value: "same-origin" }, + { key: "X-Content-Type-Options", value: "nosniff" }, + ], + }]; + }, +}; + +export default nextConfig; diff --git a/apps/accounts/frontend/postcss.config.js b/apps/accounts/frontend/postcss.config.js new file mode 100644 index 0000000..cce4985 --- /dev/null +++ b/apps/accounts/frontend/postcss.config.js @@ -0,0 +1 @@ +module.exports = { plugins: { tailwindcss: {}, autoprefixer: {} } }; diff --git a/apps/accounts/frontend/src/app/account/Account.tsx b/apps/accounts/frontend/src/app/account/Account.tsx new file mode 100644 index 0000000..8cc7733 --- /dev/null +++ b/apps/accounts/frontend/src/app/account/Account.tsx @@ -0,0 +1,269 @@ +"use client"; + +import React, { useCallback, useState } from "react"; +import QRCode from "qrcode"; +import { Button, Card, Checkbox, Field, Heading, Notice, Shell } from "@crosscode/ui"; +import { useBranding } from "@/components/BrandingProvider"; +import { call, selfSignIn } from "@/lib/api"; +import { useExternalEffect } from "@/lib/hooks"; + +type Me = { + id: string; name: string; email: string; emailVerified: boolean; phone: string | null; role: "member" | "admin"; + twoFactor: "totp" | "email" | "whatsapp" | null; recoveryCodesLeft: number; news: { email: boolean; whatsapp: boolean }; + noticeVersionAccepted: number; noticeVersion: number; lastSignInAt: string | null; +}; +type SignIn = { type: string; at: string; ip: string | null; device: string | null; site: string | null }; +type Export = { id: string; status: string; createdAt: string; readyAt: string | null; expiresAt: string }; + +const METHOD = { totp: "an authenticator app", email: "a code by email", whatsapp: "a code on WhatsApp" } as const; +const EVENT: Record = { + sign_in: "Signed in", sign_in_failed: "Wrong password", locked: "Locked after too many tries", password_reset: "Password reset", password_changed: "Password changed", + two_factor_on: "Two-step sign-in turned on", two_factor_off: "Two-step sign-in turned off", recovery_code_used: "Recovery code used", recovery_codes_replaced: "New recovery codes", + signed_out_everywhere: "Signed out everywhere", email_changed: "Email address changed", account_created: "Account created", +}; +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() { + const branding = useBranding(); + const [me, setMe] = useState(null); + const [msg, setMsg] = useState<{ tone: "success" | "error"; text: string } | null>(null); + + const load = useCallback(async () => { + const r = await call("GET", "/me"); + if (r.status === 401) return window.location.assign(selfSignIn("/account")); + if (r.ok) setMe(r.data); + }, []); + 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

Loading…

; + + const signOut = Sign out; + return ( + {me.role === "admin" && Admin}{signOut}}> +

Your account

+

One account for all of {branding.name}'s sites and apps.

+ {msg && {msg.text}} +
+ + + + +
+
+ ); +} + +type Props = { me: Me; onDone: (t: string) => void; onFail: (t: string) => void }; + +function Profile({ me, onDone, onFail }: Props) { + const [busy, setBusy] = useState(false); + const [changingEmail, setChangingEmail] = useState(false); + return ( + + Your details +
{ + e.preventDefault(); + const f = new FormData(e.currentTarget); + setBusy(true); + const r = await call("PUT", "/me", { name: f.get("name"), phone: f.get("phone") || null }); + setBusy(false); + if (r.ok) onDone("Your details are saved, and the church's sites have them too."); + else onFail(r.error.message); + }}> + + + + +
+

Email address: {me.email}

+ {!changingEmail ? ( + + ) : ( +
{ + e.preventDefault(); + const f = new FormData(e.currentTarget); + const r = await call("POST", "/me/email", { email: f.get("email"), password: f.get("password") }); + if (r.ok) { setChangingEmail(false); onDone("Check your new email address for a link to confirm it. Until then you sign in with the old one."); } else onFail(r.error.message); + }}> + + + + + )} +
+
+ ); +} + +function Security({ me, onDone, onFail }: Props) { + const [setup, setSetup] = useState<{ method: string; secret?: string; otpauthUrl?: string; sentTo?: string; qr?: string } | null>(null); + const [codes, setCodes] = useState(null); + + const start = async (method: string) => { + const r = await call<{ method: string; secret?: string; otpauthUrl?: string; sentTo?: string }>("POST", "/me/two-factor/setup", { method }); + if (!r.ok) return onFail(r.error.message); + setSetup({ ...r.data, qr: r.data.otpauthUrl ? await QRCode.toDataURL(r.data.otpauthUrl, { margin: 1, width: 200 }) : undefined }); + }; + + return ( + + Signing in +

+ Two-step sign-in: {me.twoFactor ? on, with {METHOD[me.twoFactor]} : off} + {me.twoFactor && · {me.recoveryCodesLeft} recovery codes left} +

+ {codes && ( + + Save these recovery codes somewhere safe. Each works once; they won't be shown again. +
{codes.join("\n")}
+
+ )} + {setup ? ( +
{ + e.preventDefault(); + const r = await call<{ recoveryCodes: string[] }>("POST", "/me/two-factor/confirm", { method: setup.method, code: new FormData(e.currentTarget).get("code") }); + if (!r.ok) return onFail(r.error.message); + setSetup(null); + setCodes(r.data.recoveryCodes); + onDone("Two-step sign-in is on."); + }}> + {setup.qr && QR code for your authenticator app} + {setup.secret &&

Key: {setup.secret}

} + {setup.sentTo &&

We sent a code to {setup.sentTo}.

} + +
+ + ) : ( +
+ + +
+ )} + {me.twoFactor && !setup && ( + { + const r = await call<{ recoveryCodes: string[] }>("POST", "/me/recovery-codes", { password }); + if (r.ok) { setCodes(r.data.recoveryCodes); onDone("New recovery codes made; the old ones no longer work."); } else onFail(r.error.message); + }} /> + )} + {me.twoFactor && !setup && me.role !== "admin" && ( + { + const r = await call("POST", "/me/two-factor/off", { password }); + if (r.ok) onDone("Two-step sign-in is off."); else onFail(r.error.message); + }} /> + )} +
+
{ + e.preventDefault(); + const f = new FormData(e.currentTarget); + const r = await call("POST", "/me/password", { current: f.get("current"), password: f.get("password") }); + if (r.ok) { e.currentTarget.reset(); onDone("Your password is changed."); } else onFail(r.error.message); + }}> + + + + +
+
+ ); +} + +function PasswordAction({ label, button, danger, onSubmit }: { label: string; button: string; danger?: boolean; onSubmit: (password: string) => void }) { + const [open, setOpen] = useState(false); + if (!open) return

; + return ( +
{ e.preventDefault(); onSubmit(String(new FormData(e.currentTarget).get("password"))); setOpen(false); }}> + +
+ + ); +} + +function Privacy({ me, onDone, onFail }: Props) { + const [exports, setExports] = useState([]); + const [confirmDelete, setConfirmDelete] = useState(false); + const loadExports = useCallback(async () => { + const r = await call<{ items: Export[] }>("GET", "/me/exports"); + if (r.ok) setExports(r.data.items); + }, []); + useExternalEffect(() => { void loadExports(); }, [loadExports]); + + return ( + + Privacy +
{ + const f = new FormData(e.currentTarget); + const r = await call("PUT", "/me/news", { email: f.get("email") === "on", whatsapp: f.get("whatsapp") === "on" }); + if (r.ok) onDone("Your news choices are saved."); else onFail(r.error.message); + }}> + + + +

Read the privacy notice

+ +
+

Download my data

+

Everything the church's sites hold about you, in one file. It takes a few minutes; we'll email you when it's ready.

+ {exports.map((x) => ( +

+ {when(x.createdAt)}: {x.status === "ready" ? Download : x.status === "collecting" ? "being put together…" : "expired"} +

+ ))} + +
+ +
+

Delete my account

+ {!confirmDelete ? ( + + ) : ( +
{ + e.preventDefault(); + const r = await call("POST", "/me/delete", { password: new FormData(e.currentTarget).get("password") }); + // A full page load: the signed-out page has nothing of this session left. + // eslint-disable-next-line @next/next/no-location-assign-relative-destination + if (r.ok) window.location.assign("/signed-out"); else onFail(r.error.message); + }}> + You'll be signed out of all the church's sites straight away. An admin then confirms the deletion, and each site removes what it holds about you (a site may wait until an event you're booked for is over). + +
+ + )} +
+
+ ); +} + +function Activity({ onDone }: { onDone: (t: string) => void }) { + const [items, setItems] = useState([]); + useExternalEffect(() => { + let alive = true; + call<{ items: SignIn[] }>("GET", "/me/sign-ins").then((r) => { if (alive && r.ok) setItems(r.data.items); }); + return () => { alive = false; }; + }, []); + return ( + + Recent activity +
    + {items.map((e, i) => ( +
  • + {EVENT[e.type] ?? e.type}{e.site ? · {e.site.replace(/^https?:\/\//, "")} : null} + {when(e.at)} +
  • + ))} + {!items.length &&
  • Nothing yet.
  • } +
+ +
+ ); +} diff --git a/apps/accounts/frontend/src/app/account/confirm-email/ConfirmEmail.tsx b/apps/accounts/frontend/src/app/account/confirm-email/ConfirmEmail.tsx new file mode 100644 index 0000000..9789885 --- /dev/null +++ b/apps/accounts/frontend/src/app/account/confirm-email/ConfirmEmail.tsx @@ -0,0 +1,30 @@ +"use client"; + +import { useState } from "react"; +import { Card, Heading, Notice, Shell } from "@crosscode/ui"; +import { useBranding } from "@/components/BrandingProvider"; +import { call, selfSignIn } from "@/lib/api"; +import { useExternalEffect } from "@/lib/hooks"; + +export function ConfirmEmail({ token }: { token: string }) { + const branding = useBranding(); + const [state, setState] = useState<{ ok: boolean; text: string } | null>(null); + useExternalEffect(() => { + let alive = true; + call("POST", "/me/email/confirm", { token }).then((r) => { + if (!alive) return; + if (r.status === 401) return window.location.assign(selfSignIn(`/account/confirm-email?token=${encodeURIComponent(token)}`)); + setState(r.ok ? { ok: true, text: "Your new email address is confirmed. Sign in with it from now on." } : { ok: false, text: r.error.message }); + }); + return () => { alive = false; }; + }, [token]); + return ( + + + Your email address + {state ? {state.text} :

Confirming…

} + Back to your account +
+
+ ); +} diff --git a/apps/accounts/frontend/src/app/account/confirm-email/page.tsx b/apps/accounts/frontend/src/app/account/confirm-email/page.tsx new file mode 100644 index 0000000..3cd2207 --- /dev/null +++ b/apps/accounts/frontend/src/app/account/confirm-email/page.tsx @@ -0,0 +1,8 @@ +import { ConfirmEmail } from "./ConfirmEmail"; + +export const metadata = { title: "Confirm your email address" }; + +export default async function Page({ searchParams }: { searchParams: Promise<{ token?: string }> }) { + const { token } = await searchParams; + return ; +} diff --git a/apps/accounts/frontend/src/app/account/page.tsx b/apps/accounts/frontend/src/app/account/page.tsx new file mode 100644 index 0000000..686be13 --- /dev/null +++ b/apps/accounts/frontend/src/app/account/page.tsx @@ -0,0 +1,7 @@ +import { Account } from "./Account"; + +export const metadata = { title: "Your account" }; + +export default function AccountPage() { + return ; +} diff --git a/apps/accounts/frontend/src/app/admin/Admin.tsx b/apps/accounts/frontend/src/app/admin/Admin.tsx new file mode 100644 index 0000000..c0067c3 --- /dev/null +++ b/apps/accounts/frontend/src/app/admin/Admin.tsx @@ -0,0 +1,369 @@ +"use client"; + +import React, { useCallback, useState } from "react"; +import { Button, Card, Checkbox, Field, Heading, Notice, Shell } from "@crosscode/ui"; +import { useBranding } from "@/components/BrandingProvider"; +import { call, selfSignIn } from "@/lib/api"; +import { useExternalEffect } from "@/lib/hooks"; + +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("people"); + const [allowed, setAllowed] = useState(null); + const [msg, setMsg] = useState<{ tone: "success" | "error"; text: string } | null>(null); + + useExternalEffect(() => { + let alive = true; + call("GET", "/admin/licence").then((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")); + setAllowed(r.ok); + }); + return () => { alive = false; }; + }, []); + + const flash: Flash = (tone, text) => setMsg({ tone, text }); + if (allowed === null) return

Loading…

; + if (!allowed) return Only Accounts admins can open this page.Your account; + + return ( + Your account}> +

Accounts admin

+ + {msg && {msg.text}} + {tab === "people" && } + {tab === "deletions" && } + {tab === "church" && } + {tab === "linked" && } + {tab === "signin" && } + {tab === "messages" && } + {tab === "notice" && } + {tab === "licence" && } + {tab === "audit" && } +
+ ); +} + +// ─── People ────────────────────────────────────────────────────────────────── + +type Person = { id: string; name: string; email: string; role: string; status: string; twoFactor: string | null; lastSignInAt: string | null }; +type PersonDetail = Person & { phone: string | null; emailVerified: boolean; recoveryCodesLeft: number; createdAt: string; lockedUntil: string | null; signIns: { type: string; at: string; ip: string | null }[] }; + +function People({ flash }: { flash: Flash }) { + const [q, setQ] = useState(""); + const [list, setList] = useState<{ items: Person[]; total: number } | null>(null); + const [open, setOpen] = useState(null); + const search = useCallback(async (query: string) => { + const r = await call<{ items: Person[]; total: number }>("GET", `/admin/people?q=${encodeURIComponent(query)}`); + if (r.ok) setList(r.data); + }, []); + useExternalEffect(() => { void search(""); }, [search]); + const show = async (id: string) => { + const r = await call("GET", `/admin/people/${id}`); + if (r.ok) setOpen(r.data); + }; + const act = async (path: string, body: unknown, ok: string) => { + const r = await call(path.endsWith("/role") || path.endsWith("/status") ? "PUT" : "POST", path, body); + if (r.ok) { flash("success", ok); if (open) void show(open.id); void search(q); } else flash("error", r.error.message); + }; + + return ( +
+ +
{ e.preventDefault(); void search(q); }} className="mb-4 flex gap-2"> + setQ(e.target.value)} placeholder="Name or email" className="flex-1 rounded-lg border px-3 py-2" /> + +
+

{list?.total ?? 0} people

+
    + {list?.items.map((p) => ( +
  • + +
  • + ))} +
+
+ {open && ( + + {open.name} +
+
Phone
{open.phone ?? "—"}
+
Email confirmed
{open.emailVerified ? "yes" : "no"}
+
Two-step sign-in
{open.twoFactor ?? "off"}{open.twoFactor ? ` (${open.recoveryCodesLeft} codes left)` : ""}
+
Account since
{when(open.createdAt)}
+
Locked until
{when(open.lockedUntil)}
+
+
+ {open.twoFactor && } + {open.lockedUntil && } + + +
+

Roles in each product (an Events supervisor, for example) are set in that product, not here.

+

Recent sign-ins

+
    {open.signIns.map((s, i) =>
  • {s.type} · {when(s.at)} {s.ip && · {s.ip}}
  • )}
+
+ )} +
+ ); +} + +// ─── Deletions ─────────────────────────────────────────────────────────────── + +type Deletion = { id: string; status: string; requestedAt: string; products: Record; person: { name: string; email: string } }; + +function Deletions({ flash }: { flash: Flash }) { + const [items, setItems] = useState([]); + const load = useCallback(async () => { + const r = await call<{ items: Deletion[] }>("GET", "/admin/deletions"); + if (r.ok) setItems(r.data.items); + }, []); + useExternalEffect(() => { void load(); }, [load]); + return ( + + Deletion requests + {!items.length &&

None waiting.

} +
    + {items.map((d) => ( +
  • +

    {d.person.name} {d.person.email} · asked {when(d.requestedAt)}

    + {d.status === "waiting_approval" ? ( +
    + + +
    + ) : ( +
      + {Object.entries(d.products).map(([id, s]) =>
    • {s.product ?? id}: {s.status === "deferred" ? `waiting — ${s.reason} (asking again ${when(s.retryAfter)})` : s.status}
    • )} +
    + )} +
  • + ))} +
+
+ ); +} + +// ─── Church profile ────────────────────────────────────────────────────────── + +type ChurchData = { name: string; shortName: string | null; branding: { logoUrl: string | null; colours: { primary: string; accent: string | null } }; contact: { email: string | null; phone: string | null; whatsapp: string | null } }; + +function Church({ flash }: { flash: Flash }) { + const [c, setC] = useState(null); + const [fields, setFields] = useState>({}); + useExternalEffect(() => { + let alive = true; + call("GET", "/admin/church").then((r) => { if (alive && r.ok) setC(r.data); }); + return () => { alive = false; }; + }, []); + if (!c) return

Loading…

; + const nul = (v: FormDataEntryValue | null) => (v ? String(v) : null); + return ( + + Church profile +
{ + e.preventDefault(); + const f = new FormData(e.currentTarget); + const r = await call("PUT", "/admin/church", { + name: f.get("name"), shortName: nul(f.get("shortName")), + branding: { ...c.branding, logoUrl: nul(f.get("logoUrl")), colours: { primary: f.get("primary"), accent: nul(f.get("accent")) } }, + contact: { ...c.contact, email: nul(f.get("email")), phone: nul(f.get("phone")), whatsapp: nul(f.get("whatsapp")) }, + }); + if (r.ok) { setC(r.data); setFields({}); flash("success", "Saved. The church's products are told about the change."); } else { setFields(r.error.fields ?? {}); flash("error", r.error.message); } + }}> + + + +
+ + +
+ + + + + +
+ ); +} + +// ─── Linked products ───────────────────────────────────────────────────────── + +type LinkedItem = { installId: string; product: string; name: string; url: string; listed: boolean; connectedAt: string | null; signsInHere: boolean }; + +function Linked({ flash }: { flash: Flash }) { + const [data, setData] = useState<{ hubConnected: boolean; items: LinkedItem[] } | null>(null); + const load = useCallback(async () => { + const r = await call<{ hubConnected: boolean; items: LinkedItem[] }>("GET", "/admin/linked-products"); + if (r.ok) setData(r.data); + }, []); + useExternalEffect(() => { void load(); }, [load]); + if (!data) return

Loading…

; + return ( + + Linked products + {!data.hubConnected && Accounts isn't connected to the Hub yet (Licence).} + {!data.items.length &&

The church has no other Cross Code products yet.

} +
    + {data.items.map((l) => ( +
  • + {l.name} {l.url.replace(/^https?:\/\//, "")}
    + {l.signsInHere ? `Connected ${when(l.connectedAt)}` : "Not connected"}{!l.listed && " · no longer listed by the Hub"}
    + {l.signsInHere + ? + : } +
  • + ))} +
+
+ ); +} + +// ─── Settings ──────────────────────────────────────────────────────────────── + +const SETTING_LABELS: Record = { + signup_enabled: ["Members can create their own account", "bool"], + two_factor_required_for_admins: ["Admins must use two-step sign-in", "bool"], + session_days: ['Days "Keep me signed in" lasts', "number"], + smtp_host: ["SMTP server", "text"], smtp_port: ["SMTP port", "number"], smtp_user: ["SMTP user name", "text"], smtp_pass: ["SMTP password", "secret"], + smtp_from: ["Send from (email address)", "text"], smtp_secure: ["Use TLS from the start (port 465)", "bool"], + wawp_access_token: ["WAWP access token", "secret"], wawp_instance_id: ["WAWP instance id", "text"], +}; + +function Settings({ flash, keys }: { flash: Flash; keys: string[] }) { + const [values, setValues] = useState | null>(null); + useExternalEffect(() => { + let alive = true; + call>("GET", "/admin/settings").then((r) => { if (alive && r.ok) setValues(r.data); }); + return () => { alive = false; }; + }, []); + if (!values) return

Loading…

; + const defaults: Record = { signup_enabled: true, two_factor_required_for_admins: true }; + return ( + +
{ + e.preventDefault(); + const f = new FormData(e.currentTarget); + const body: Record = {}; + for (const k of keys) { + const kind = SETTING_LABELS[k]![1]; + if (kind === "bool") body[k] = f.get(k) === "on" ? "true" : "false"; + else body[k] = String(f.get(k) ?? ""); + } + const r = await call("PUT", "/admin/settings", body); + if (r.ok) flash("success", "Saved."); else flash("error", r.error.message); + }}> + {keys.map((k) => { + const [label, kind] = SETTING_LABELS[k]!; + const v = values[k]; + if (kind === "bool") return ; + if (kind === "secret") return ; + return ; + })} +
+ + {keys.includes("smtp_host") && } +
+ +
+ ); +} + +// ─── Privacy notice, licence, audit ─────────────────────────────────────────── + +function NoticeTab({ flash }: { flash: Flash }) { + const [current, setCurrent] = useState<{ version: number; 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); + }, []); + useExternalEffect(() => { void load(); }, [load]); + if (!current) return

Loading…

; + return ( + + Privacy notice +
{ + 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); + }}> + + +