"use client"; import React, { useCallback, useEffect, useState } from "react"; import { apiFetch } from "@/lib/api"; import { errorMessage } from "@/lib/utils"; const fmt = (d: string | null) => (d ? new Date(d).toLocaleString(undefined, { day: "numeric", month: "short", year: "numeric", hour: "2-digit", minute: "2-digit" }) : "—"); const selectCls = "border rounded-lg px-3 py-2 text-sm bg-white"; function Pager({ page, total, pageSize, onPage }: { page: number; total: number; pageSize: number; onPage: (p: number) => void }) { const pages = Math.max(1, Math.ceil(total / pageSize)); if (pages <= 1) return

{total} record{total === 1 ? "" : "s"}

; return (
Page {page} of {pages} · {total} records
); } // ─── Consent log ────────────────────────────────────────────────────────────── type ConsentType = "news" | "notice" | "parental"; type NewsRow = { id: string; at: string; name: string | null; email: string | null; channel: string; granted: boolean; source: string; ip: string | null }; type NoticeRow = { id: string; at: string; name: string | null; email: string | null; version: number; source: string; ip: string | null }; type ParentalRow = { id: string; at: string | null; child: string; event: string; status: string; signedName: string | null; parentName: string | null; textVersion: number; photoConsent: boolean | null; ip: string | null; medicalDeleted: boolean }; type LogResponse = { rows: T[]; total: number; pageSize: number }; const SOURCE: Record = { signup: "Sign-up", activation: "Account activation", privacy_centre: "Privacy page", prompt: "Asked after login", unsubscribe_link: "Unsubscribe link", whatsapp_stop: "Replied STOP", existing_account: "Existing account (1.38.0)", admin: "Administrator", }; /** Admin → Privacy → Consent log: proof of who agreed to what, when and how. */ export function ConsentLogPanel({ token }: { token: string }) { const [type, setType] = useState("news"); const [q, setQ] = useState(""); const [query, setQuery] = useState(""); const [page, setPage] = useState(1); const [data, setData] = useState | null>(null); const [error, setError] = useState(null); const load = useCallback(async () => { setData(null); try { setData(await apiFetch(`/api/privacy/consent-log?type=${type}&page=${page}${query ? `&q=${encodeURIComponent(query)}` : ""}`, { authToken: token })); setError(null); } catch (e) { setError(errorMessage(e) || "Could not load the consent log."); } }, [token, type, page, query]); useEffect(() => { load(); }, [load]); return (

Who agreed to what, when and how. Entries are never changed or removed (after an account is deleted they stay, without the IP address).

{ e.preventDefault(); setPage(1); setQuery(q.trim()); }} className="flex flex-wrap gap-2"> setQ(e.target.value)} placeholder="Name or email" aria-label="Search" />
{error &&

{error}

} {!data ?

Loading…

: data.rows.length === 0 ?

Nothing recorded yet.

: (
{type === "news" && ( <> {(data.rows as NewsRow[]).map(r => ( ))} )} {type === "notice" && ( <> {(data.rows as NoticeRow[]).map(r => ( ))} )} {type === "parental" && ( <> {(data.rows as ParentalRow[]).map(r => ( ))} )}
WhenPersonChannelChoiceHow
{fmt(r.at)} {r.name || No account}
{r.email}
{r.channel === "whatsapp" ? "WhatsApp" : "Email"} {r.granted ? Opted in : Opted out} {SOURCE[r.source] || r.source}{r.ip ?
{r.ip}
: null}
WhenPersonVersionHow
{fmt(r.at)} {r.name}
{r.email}
{r.version === 0 ? "Built-in" : r.version} {SOURCE[r.source] || r.source}{r.ip ?
{r.ip}
: null}
WhenChild · eventAnswerSigned byWording
{fmt(r.at)} {r.child}
{r.event}
{r.status === "given" ? Given : Declined}{r.photoConsent != null &&
Photos: {r.photoConsent ? "yes" : "no"}
}
{r.signedName || "—"}{r.ip ?
{r.ip}
: null}
v{r.textVersion}{r.medicalDeleted &&
medical details deleted
}
)} {data && }
); } // ─── Access log ─────────────────────────────────────────────────────────────── type AccessRow = { id: string; at: string; actor: string; actorRole: string; action: string; what: string; records: number | null; ip: string | null; sensitive: boolean }; type AccessResponse = LogResponse & { actions: Record; actors: { id: string; name: string }[] }; /** Admin → Privacy → Access log: who took personal information out of the system in bulk. */ export function AccessLogPanel({ token }: { token: string }) { const [action, setAction] = useState(""); const [actorId, setActorId] = useState(""); const [sensitiveOnly, setSensitiveOnly] = useState(false); const [page, setPage] = useState(1); const [data, setData] = useState(null); const [error, setError] = useState(null); const load = useCallback(async () => { try { const params = new URLSearchParams({ page: String(page) }); if (action) params.set("action", action); if (actorId) params.set("actorId", actorId); if (sensitiveOnly) params.set("sensitive", "true"); setData(await apiFetch(`/api/privacy/access-log?${params}`, { authToken: token })); setError(null); } catch (e) { setError(errorMessage(e) || "Could not load the access log."); } }, [token, action, actorId, sensitiveOnly, page]); useEffect(() => { load(); }, [load]); return (

Every time someone downloads, emails or opens personal information in bulk — reports, attendance registers, certificates, group lists, form answers, the consent and medical lists, backups — and every time an admin views the site as someone else.

{error &&

{error}

} {!data ?

Loading…

: data.rows.length === 0 ?

Nothing recorded yet.

: (
{data.rows.map(r => ( ))}
WhenWhoWhatRecords
{fmt(r.at)} {r.actor}
{r.actorRole}{r.ip ? ` · ${r.ip}` : ""}
{data.actions[r.action] || r.action} {r.sensitive && children/medical}
{r.what}
{r.records ?? "—"}
)} {data && }
); }