Archived
The built-in notice now covers volunteer rosters, event series, season passes, webhooks, how people agree to it, and the provider-notices storage item. Sites with their own published version see what changed in the editor (sections marked, use new text per section or all, add missing sections, "Done - hide this"). Account activation asks for agreement to the terms and notice; anyone who never accepted is asked once after login. The cookie button shows above any cookie section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
192 lines
12 KiB
TypeScript
192 lines
12 KiB
TypeScript
"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 <p className="text-xs text-gray-500">{total} record{total === 1 ? "" : "s"}</p>;
|
|
return (
|
|
<div className="flex items-center gap-2 text-sm">
|
|
<button onClick={() => onPage(page - 1)} disabled={page <= 1} className="px-2 py-1 rounded border bg-white disabled:opacity-40">Previous</button>
|
|
<span className="text-gray-600">Page {page} of {pages} · {total} records</span>
|
|
<button onClick={() => onPage(page + 1)} disabled={page >= pages} className="px-2 py-1 rounded border bg-white disabled:opacity-40">Next</button>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// ─── 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<T> = { rows: T[]; total: number; pageSize: number };
|
|
|
|
const SOURCE: Record<string, string> = {
|
|
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<ConsentType>("news");
|
|
const [q, setQ] = useState("");
|
|
const [query, setQuery] = useState("");
|
|
const [page, setPage] = useState(1);
|
|
const [data, setData] = useState<LogResponse<NewsRow | NoticeRow | ParentalRow> | null>(null);
|
|
const [error, setError] = useState<string | null>(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 (
|
|
<div className="space-y-3">
|
|
<p className="text-sm text-gray-600">Who agreed to what, when and how. Entries are never changed or removed (after an account is deleted they stay, without the IP address).</p>
|
|
<form onSubmit={e => { e.preventDefault(); setPage(1); setQuery(q.trim()); }} className="flex flex-wrap gap-2">
|
|
<select className={selectCls} value={type} onChange={e => { setType(e.target.value as ConsentType); setPage(1); }} aria-label="Kind of consent">
|
|
<option value="news">News & announcements opt-in</option>
|
|
<option value="notice">Privacy notice accepted</option>
|
|
<option value="parental">Parental consent</option>
|
|
</select>
|
|
<input className="border rounded-lg px-3 py-2 text-sm flex-1 min-w-[12rem]" value={q} onChange={e => setQ(e.target.value)} placeholder="Name or email" aria-label="Search" />
|
|
<button className="px-3 py-2 rounded-lg bg-brand-600 text-white text-sm">Search</button>
|
|
</form>
|
|
{error && <p className="text-sm text-red-700">{error}</p>}
|
|
{!data ? <p className="text-sm text-gray-400">Loading…</p> : data.rows.length === 0 ? <p className="text-sm text-gray-500">Nothing recorded yet.</p> : (
|
|
<div className="overflow-x-auto border rounded-xl bg-white">
|
|
<table className="w-full text-sm">
|
|
{type === "news" && (
|
|
<>
|
|
<thead className="bg-gray-50 text-left text-xs text-gray-500"><tr><th className="p-2">When</th><th className="p-2">Person</th><th className="p-2">Channel</th><th className="p-2">Choice</th><th className="p-2">How</th></tr></thead>
|
|
<tbody>{(data.rows as NewsRow[]).map(r => (
|
|
<tr key={r.id} className="border-t">
|
|
<td className="p-2 whitespace-nowrap">{fmt(r.at)}</td>
|
|
<td className="p-2">{r.name || <span className="text-gray-400">No account</span>}<div className="text-xs text-gray-500 break-all">{r.email}</div></td>
|
|
<td className="p-2">{r.channel === "whatsapp" ? "WhatsApp" : "Email"}</td>
|
|
<td className="p-2">{r.granted ? <span className="text-green-700">Opted in</span> : <span className="text-gray-700">Opted out</span>}</td>
|
|
<td className="p-2 text-gray-600">{SOURCE[r.source] || r.source}{r.ip ? <div className="text-xs text-gray-400">{r.ip}</div> : null}</td>
|
|
</tr>
|
|
))}</tbody>
|
|
</>
|
|
)}
|
|
{type === "notice" && (
|
|
<>
|
|
<thead className="bg-gray-50 text-left text-xs text-gray-500"><tr><th className="p-2">When</th><th className="p-2">Person</th><th className="p-2">Version</th><th className="p-2">How</th></tr></thead>
|
|
<tbody>{(data.rows as NoticeRow[]).map(r => (
|
|
<tr key={r.id} className="border-t">
|
|
<td className="p-2 whitespace-nowrap">{fmt(r.at)}</td>
|
|
<td className="p-2">{r.name}<div className="text-xs text-gray-500 break-all">{r.email}</div></td>
|
|
<td className="p-2">{r.version === 0 ? "Built-in" : r.version}</td>
|
|
<td className="p-2 text-gray-600">{SOURCE[r.source] || r.source}{r.ip ? <div className="text-xs text-gray-400">{r.ip}</div> : null}</td>
|
|
</tr>
|
|
))}</tbody>
|
|
</>
|
|
)}
|
|
{type === "parental" && (
|
|
<>
|
|
<thead className="bg-gray-50 text-left text-xs text-gray-500"><tr><th className="p-2">When</th><th className="p-2">Child · event</th><th className="p-2">Answer</th><th className="p-2">Signed by</th><th className="p-2">Wording</th></tr></thead>
|
|
<tbody>{(data.rows as ParentalRow[]).map(r => (
|
|
<tr key={r.id} className="border-t">
|
|
<td className="p-2 whitespace-nowrap">{fmt(r.at)}</td>
|
|
<td className="p-2">{r.child}<div className="text-xs text-gray-500">{r.event}</div></td>
|
|
<td className="p-2">{r.status === "given" ? <span className="text-green-700">Given</span> : <span className="text-red-700">Declined</span>}{r.photoConsent != null && <div className="text-xs text-gray-500">Photos: {r.photoConsent ? "yes" : "no"}</div>}</td>
|
|
<td className="p-2">{r.signedName || "—"}{r.ip ? <div className="text-xs text-gray-400">{r.ip}</div> : null}</td>
|
|
<td className="p-2 text-gray-600">v{r.textVersion}{r.medicalDeleted && <div className="text-xs text-gray-400">medical details deleted</div>}</td>
|
|
</tr>
|
|
))}</tbody>
|
|
</>
|
|
)}
|
|
</table>
|
|
</div>
|
|
)}
|
|
{data && <Pager page={page} total={data.total} pageSize={data.pageSize} onPage={setPage} />}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// ─── 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<AccessRow> & { actions: Record<string, string>; 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<AccessResponse | null>(null);
|
|
const [error, setError] = useState<string | null>(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<AccessResponse>(`/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 (
|
|
<div className="space-y-3">
|
|
<p className="text-sm text-gray-600">
|
|
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.
|
|
</p>
|
|
<div className="flex flex-wrap gap-2">
|
|
<select className={selectCls} value={action} onChange={e => { setAction(e.target.value); setPage(1); }} aria-label="What">
|
|
<option value="">Everything</option>
|
|
{Object.entries(data?.actions || {}).map(([k, label]) => <option key={k} value={k}>{label}</option>)}
|
|
</select>
|
|
<select className={selectCls} value={actorId} onChange={e => { setActorId(e.target.value); setPage(1); }} aria-label="Who">
|
|
<option value="">Everyone</option>
|
|
{(data?.actors || []).map(a => <option key={a.id} value={a.id}>{a.name}</option>)}
|
|
</select>
|
|
<label className="flex items-center gap-2 text-sm text-gray-700">
|
|
<input type="checkbox" className="h-4 w-4 accent-brand-600" checked={sensitiveOnly} onChange={e => { setSensitiveOnly(e.target.checked); setPage(1); }} />
|
|
Children's or medical information only
|
|
</label>
|
|
</div>
|
|
{error && <p className="text-sm text-red-700">{error}</p>}
|
|
{!data ? <p className="text-sm text-gray-400">Loading…</p> : data.rows.length === 0 ? <p className="text-sm text-gray-500">Nothing recorded yet.</p> : (
|
|
<div className="overflow-x-auto border rounded-xl bg-white">
|
|
<table className="w-full text-sm">
|
|
<thead className="bg-gray-50 text-left text-xs text-gray-500"><tr><th className="p-2">When</th><th className="p-2">Who</th><th className="p-2">What</th><th className="p-2 text-right">Records</th></tr></thead>
|
|
<tbody>{data.rows.map(r => (
|
|
<tr key={r.id} className="border-t align-top">
|
|
<td className="p-2 whitespace-nowrap">{fmt(r.at)}</td>
|
|
<td className="p-2">{r.actor}<div className="text-xs text-gray-500">{r.actorRole}{r.ip ? ` · ${r.ip}` : ""}</div></td>
|
|
<td className="p-2">
|
|
{data.actions[r.action] || r.action}
|
|
{r.sensitive && <span className="ml-2 text-[11px] px-1.5 py-0.5 rounded bg-rose-50 text-rose-700" title="Children's or special personal information">children/medical</span>}
|
|
<div className="text-xs text-gray-500">{r.what}</div>
|
|
</td>
|
|
<td className="p-2 text-right">{r.records ?? "—"}</td>
|
|
</tr>
|
|
))}</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
{data && <Pager page={page} total={data.total} pageSize={data.pageSize} onPage={setPage} />}
|
|
</div>
|
|
);
|
|
}
|