Separate data requests from website feedback in the admin
Forms now has two queues, Website feedback and Data requests, each its own card on the admin home and a tab on the page, with what's new in each. The API takes ?kind=feedback|privacy and counts per queue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7c1723b0ad
commit
99d83eb090
5 changed files with 69 additions and 12 deletions
|
|
@ -23,6 +23,8 @@ const NOTE_LIMIT = 2000;
|
||||||
|
|
||||||
/* ── GET /api/admin/feedback ─────────────────────────────────────
|
/* ── GET /api/admin/feedback ─────────────────────────────────────
|
||||||
?status=new one of STATUSES, or omitted for all
|
?status=new one of STATUSES, or omitted for all
|
||||||
|
?kind=feedback website feedback (every type but 'privacy')
|
||||||
|
?kind=privacy data requests from the Privacy page
|
||||||
?type=broken feedback_type
|
?type=broken feedback_type
|
||||||
?q=retreat substring of the message
|
?q=retreat substring of the message
|
||||||
?before=41 cursor: rows with a lower id than this
|
?before=41 cursor: rows with a lower id than this
|
||||||
|
|
@ -31,11 +33,17 @@ const NOTE_LIMIT = 2000;
|
||||||
|
|
||||||
admin.get("/feedback", (c) => {
|
admin.get("/feedback", (c) => {
|
||||||
const db = c.get("db");
|
const db = c.get("db");
|
||||||
const { status, type, q, before, limit } = c.req.query();
|
const { status, type, kind, q, before, limit } = c.req.query();
|
||||||
|
|
||||||
const where = [];
|
const where = [];
|
||||||
const params = [];
|
const params = [];
|
||||||
|
|
||||||
|
// Data requests and website feedback share the table but are two
|
||||||
|
// queues in the admin (Forms → Website feedback, Data requests).
|
||||||
|
const kindWhere =
|
||||||
|
kind === "privacy" ? "feedback_type = 'privacy'" : kind === "feedback" ? "feedback_type <> 'privacy'" : null;
|
||||||
|
if (kindWhere) where.push(kindWhere);
|
||||||
|
|
||||||
if (STATUSES.includes(status)) {
|
if (STATUSES.includes(status)) {
|
||||||
where.push("status = ?");
|
where.push("status = ?");
|
||||||
params.push(status);
|
params.push(status);
|
||||||
|
|
@ -69,19 +77,27 @@ admin.get("/feedback", (c) => {
|
||||||
const hasMore = rows.length > take;
|
const hasMore = rows.length > take;
|
||||||
const page = hasMore ? rows.slice(0, take) : rows;
|
const page = hasMore ? rows.slice(0, take) : rows;
|
||||||
|
|
||||||
// Counts are unfiltered on purpose: the tabs should show what's
|
// Status counts cover this queue (kind) but ignore the other
|
||||||
// waiting overall, not what's left after the current filter.
|
// filters: the tabs show what's waiting, not what's left after a
|
||||||
|
// search. newByKind is what's new in each queue, for the queue tabs.
|
||||||
const counts = Object.fromEntries(STATUSES.map((s) => [s, 0]));
|
const counts = Object.fromEntries(STATUSES.map((s) => [s, 0]));
|
||||||
for (const row of db
|
for (const row of db
|
||||||
.prepare("SELECT status, COUNT(*) AS n FROM feedback GROUP BY status")
|
.prepare(`SELECT status, COUNT(*) AS n FROM feedback ${kindWhere ? `WHERE ${kindWhere}` : ""} GROUP BY status`)
|
||||||
.all()) {
|
.all()) {
|
||||||
counts[row.status] = row.n;
|
counts[row.status] = row.n;
|
||||||
}
|
}
|
||||||
|
const newByKind = db
|
||||||
|
.prepare(
|
||||||
|
`SELECT SUM(feedback_type <> 'privacy') AS feedback, SUM(feedback_type = 'privacy') AS privacy
|
||||||
|
FROM feedback WHERE status = 'new'`,
|
||||||
|
)
|
||||||
|
.get();
|
||||||
|
|
||||||
return c.json(
|
return c.json(
|
||||||
{
|
{
|
||||||
feedback: page,
|
feedback: page,
|
||||||
counts,
|
counts,
|
||||||
|
newByKind: { feedback: newByKind?.feedback ?? 0, privacy: newByKind?.privacy ?? 0 },
|
||||||
nextCursor: hasMore ? page[page.length - 1].id : null,
|
nextCursor: hasMore ? page[page.length - 1].id : null,
|
||||||
},
|
},
|
||||||
200,
|
200,
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,7 @@ export default function App() {
|
||||||
<Route path="panel" element={<AdminPanel />} />
|
<Route path="panel" element={<AdminPanel />} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="feedback" element={<AdminFeedback />} />
|
<Route path="feedback" element={<AdminFeedback />} />
|
||||||
|
<Route path="data-requests" element={<AdminFeedback kind="privacy" />} />
|
||||||
<Route path="media" element={<AdminMedia />} />
|
<Route path="media" element={<AdminMedia />} />
|
||||||
<Route element={<RequireRole role="admin" />}>
|
<Route element={<RequireRole role="admin" />}>
|
||||||
<Route path="clips" element={<AdminClips />} />
|
<Route path="clips" element={<AdminClips />} />
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ const PAGE = sitePage("/privacy");
|
||||||
|
|
||||||
The contact address is Panel → Site settings → Privacy contact
|
The contact address is Panel → Site settings → Privacy contact
|
||||||
email. Requests from the form below are feedback rows of type
|
email. Requests from the form below are feedback rows of type
|
||||||
'privacy', in Admin → Feedback.
|
'privacy', in Admin → Forms → Data requests.
|
||||||
═══════════════════════════════════════════════════════════════ */
|
═══════════════════════════════════════════════════════════════ */
|
||||||
|
|
||||||
const LAST_UPDATED = "September 28, 2026";
|
const LAST_UPDATED = "September 28, 2026";
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
═══════════════════════════════════════════════════════════════ */
|
═══════════════════════════════════════════════════════════════ */
|
||||||
|
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
import { del, get, patch, ApiError } from "../../lib/api.ts";
|
import { del, get, patch, ApiError } from "../../lib/api.ts";
|
||||||
import { isUnauthorized, useAuth } from "../../lib/auth.tsx";
|
import { isUnauthorized, useAuth } from "../../lib/auth.tsx";
|
||||||
|
|
@ -225,9 +225,25 @@ function FeedbackCard({ row, onChange, onRemove, canWrite, canRemove }) {
|
||||||
|
|
||||||
/* ── The page ────────────────────────────────────────────────── */
|
/* ── The page ────────────────────────────────────────────────── */
|
||||||
|
|
||||||
export default function AdminFeedback() {
|
/* The two queues this page shows: the website feedback form, and
|
||||||
|
data requests from the Privacy page. Same table, same triage. */
|
||||||
|
const QUEUES = {
|
||||||
|
feedback: {
|
||||||
|
to: "/admin/feedback",
|
||||||
|
title: "Website feedback",
|
||||||
|
blurb: "Everything submitted through the site's feedback form.",
|
||||||
|
},
|
||||||
|
privacy: {
|
||||||
|
to: "/admin/data-requests",
|
||||||
|
title: "Data requests",
|
||||||
|
blurb: "Requests to see, correct or delete someone's information, from the Privacy page. Each has an email to answer.",
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export default function AdminFeedback({ kind = "feedback" }: { kind?: keyof typeof QUEUES }) {
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const queue = QUEUES[kind];
|
||||||
|
|
||||||
const [status, setStatus] = useState("new");
|
const [status, setStatus] = useState("new");
|
||||||
const [query, setQuery] = useState("");
|
const [query, setQuery] = useState("");
|
||||||
|
|
@ -235,6 +251,7 @@ export default function AdminFeedback() {
|
||||||
|
|
||||||
const [rows, setRows] = useState<any[]>([]);
|
const [rows, setRows] = useState<any[]>([]);
|
||||||
const [counts, setCounts] = useState<any>({});
|
const [counts, setCounts] = useState<any>({});
|
||||||
|
const [newByKind, setNewByKind] = useState<any>({});
|
||||||
const [cursor, setCursor] = useState<any>(null);
|
const [cursor, setCursor] = useState<any>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<any>(null);
|
const [error, setError] = useState<any>(null);
|
||||||
|
|
@ -249,6 +266,7 @@ export default function AdminFeedback() {
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
params.set("kind", kind);
|
||||||
if (status !== "all") params.set("status", status);
|
if (status !== "all") params.set("status", status);
|
||||||
if (search) params.set("q", search);
|
if (search) params.set("q", search);
|
||||||
if (before) params.set("before", String(before));
|
if (before) params.set("before", String(before));
|
||||||
|
|
@ -257,6 +275,7 @@ export default function AdminFeedback() {
|
||||||
const data = await get(`/admin/feedback?${params}`, { ttl: 0 });
|
const data = await get(`/admin/feedback?${params}`, { ttl: 0 });
|
||||||
setRows((prev) => (before ? [...prev, ...data.feedback] : data.feedback));
|
setRows((prev) => (before ? [...prev, ...data.feedback] : data.feedback));
|
||||||
setCounts(data.counts);
|
setCounts(data.counts);
|
||||||
|
setNewByKind(data.newByKind ?? {});
|
||||||
setCursor(data.nextCursor);
|
setCursor(data.nextCursor);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (isUnauthorized(err)) {
|
if (isUnauthorized(err)) {
|
||||||
|
|
@ -271,7 +290,7 @@ export default function AdminFeedback() {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[status, search, navigate],
|
[kind, status, search, navigate],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -306,11 +325,27 @@ export default function AdminFeedback() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-3xl font-bold text-link">Feedback</h1>
|
{/* The two queues, each with what's new in it. */}
|
||||||
|
<nav aria-label="Forms" className="mb-6 flex gap-1 border-b border-brand/15">
|
||||||
|
{Object.entries(QUEUES).map(([id, q]) => (
|
||||||
|
<Link
|
||||||
|
key={id}
|
||||||
|
to={q.to}
|
||||||
|
aria-current={id === kind ? "page" : undefined}
|
||||||
|
className={
|
||||||
|
"-mb-px border-b-2 px-4 py-2 text-sm font-semibold transition-colors " +
|
||||||
|
(id === kind ? "border-link text-link" : "border-transparent text-muted hover:text-link")
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{q.title}
|
||||||
|
{newByKind[id] ? ` (${newByKind[id]} new)` : ""}
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<h1 className="text-3xl font-bold text-link">{queue.title}</h1>
|
||||||
<p className="mt-2 text-sm text-muted">
|
<p className="mt-2 text-sm text-muted">
|
||||||
{canWrite
|
{canWrite ? queue.blurb : "Read-only: your account can't change statuses or notes."}
|
||||||
? "Everything submitted through the site form."
|
|
||||||
: "Read-only: your account can't change statuses or notes."}
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{/* Filters */}
|
{/* Filters */}
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,11 @@ export const FORMS_NAV = {
|
||||||
label: "Website feedback",
|
label: "Website feedback",
|
||||||
blurb: "The triage queue for the feedback form.",
|
blurb: "The triage queue for the feedback form.",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
to: "/admin/data-requests",
|
||||||
|
label: "Data requests",
|
||||||
|
blurb: "Requests to see, correct or delete someone's information, from the Privacy page.",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue