Add a Request form, with files in Google Drive and email notices

One form at /request for blog posts, events, and new or updated
chapters, regions (updates only), partners, teams, awards and people.
?type= opens it on one; buttons on the Community sections, blog posts,
Retreats and the front page calendar do. Files (.docx, PDF, JPEG, PNG)
go to a Google Drive folder through a service account.

Requests are feedback rows of type 'content' (migration 046), in a
third Forms queue: files download from Drive, a .docx can become a
draft blog post, and deleting a request deletes its files. New content
and data requests email the addresses in Site settings through Gmail.

Setup: docs/google-drive-and-mail.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-29 15:54:00 -05:00
parent 0e582c236b
commit dc53af238f
31 changed files with 1318 additions and 113 deletions

View file

@ -20,10 +20,11 @@
import { useCallback, useEffect, useState } from "react";
import { Link, useNavigate } from "react-router-dom";
import { del, get, patch, ApiError } from "../../lib/api.ts";
import { del, get, patch, post, ApiError } from "../../lib/api.ts";
import { isUnauthorized, useAuth } from "../../lib/auth.tsx";
import { canWrite as roleCanWrite, canDelete } from "../../lib/roles.ts";
import { feedbackTypeLabel } from "../../data/feedbackTypes.ts";
import { requestTypeLabel } from "../../data/requestTypes.ts";
const STATUSES = ["new", "read", "actioned", "archived", "spam"];
@ -46,6 +47,63 @@ function formatDate(value) {
});
}
const sizeOf = (bytes) => (bytes < 1024 * 1024 ? `${Math.ceil(bytes / 1024)} KB` : `${(bytes / 1024 / 1024).toFixed(1)} MB`);
/* A content request's files: each downloads from Drive through the
server, and a Word document can become a draft blog post
(the same import as Blog posts → Import from Word). */
function RequestFiles({ row, canWrite }) {
const navigate = useNavigate();
const [busy, setBusy] = useState<number | null>(null);
const [error, setError] = useState<string | null>(null);
async function makePost(file) {
setBusy(file.id);
setError(null);
try {
const result = await post(`/admin/feedback/${row.id}/files/${file.id}/blog-post`, {});
navigate(`/admin/blog_posts/${result.id}`, { state: { imported: result.summary } });
} catch (err) {
setError(err instanceof ApiError ? err.message : "Couldn't reach the server.");
setBusy(null);
}
}
return (
<div className="mt-4">
<ul className="space-y-2">
{row.files.map((file) => (
<li key={file.id} className="flex flex-wrap items-center gap-x-3 gap-y-1 text-sm">
<a
href={`/api/admin/feedback/${row.id}/files/${file.id}`}
download={file.name}
className="font-medium text-link underline underline-offset-2"
>
{file.name}
</a>
<span className="text-xs text-muted">{sizeOf(file.size)}</span>
{canWrite && /\.docx$/i.test(file.name) && (
<button
type="button"
disabled={busy !== null}
onClick={() => makePost(file)}
className="rounded-full border border-link px-3 py-0.5 text-xs font-semibold text-link transition-colors hover:bg-tint disabled:opacity-60"
>
{busy === file.id ? "Making the post…" : "Make a blog post from it"}
</button>
)}
</li>
))}
</ul>
{error && (
<p role="alert" className="mt-2 text-sm text-danger">
{error}
</p>
)}
</div>
);
}
function locationOf(row) {
if (!row.page_path) return "Not page-specific";
return row.section_id ? `${row.page_path} #${row.section_id}` : row.page_path;
@ -93,7 +151,9 @@ function FeedbackCard({ row, onChange, onRemove, canWrite, canRemove }) {
<article className="rounded-2xl border border-brand/20 bg-surface p-5">
<div className="flex flex-wrap items-center gap-x-4 gap-y-2 text-sm">
<span className="font-semibold text-body">
{feedbackTypeLabel(row.feedback_type)}
{row.feedback_type === "content"
? `${row.request_action === "update" ? "Update" : "New"} ${requestTypeLabel(row.category).toLowerCase()}`
: feedbackTypeLabel(row.feedback_type)}
</span>
<span
className={`rounded-full px-2.5 py-0.5 text-xs font-medium ${
@ -102,13 +162,15 @@ function FeedbackCard({ row, onChange, onRemove, canWrite, canRemove }) {
>
{row.status}
</span>
<span className="text-muted">{locationOf(row)}</span>
{row.feedback_type !== "content" && <span className="text-muted">{locationOf(row)}</span>}
<span className="ml-auto text-xs text-muted">
#{row.id} · {formatDate(row.created_at)}
</span>
</div>
<p className="mt-4 whitespace-pre-wrap text-body">{row.message}</p>
{row.subject && <h2 className="mt-4 text-lg font-semibold text-body">{row.subject}</h2>}
<p className={`${row.subject ? "mt-2" : "mt-4"} whitespace-pre-wrap text-body`}>{row.message}</p>
{row.files?.length > 0 && <RequestFiles row={row} canWrite={canWrite} />}
<p className="mt-4 text-sm text-muted">
{row.name || row.email ? (
@ -117,7 +179,7 @@ function FeedbackCard({ row, onChange, onRemove, canWrite, canRemove }) {
{row.name && row.email && " · "}
{row.email && (
<a
href={`mailto:${row.email}?subject=Your%20NGU%20site%20feedback`}
href={`mailto:${row.email}?subject=${encodeURIComponent(row.subject ? `Your request: ${row.subject}` : "Your NGU site feedback")}`}
className="text-link underline underline-offset-2"
>
{row.email}
@ -225,14 +287,20 @@ function FeedbackCard({ row, onChange, onRemove, canWrite, canRemove }) {
/* ── The page ────────────────────────────────────────────────── */
/* The two queues this page shows: the website feedback form, and
data requests from the Privacy page. Same table, same triage. */
/* The queues this page shows: the website feedback form, content
requests from /request, 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.",
},
content: {
to: "/admin/requests",
title: "Content requests",
blurb: "Requests from the site's Request form: blog posts, events, and new or updated organizations, teams, awards and people. Files open from Google Drive.",
},
privacy: {
to: "/admin/data-requests",
title: "Data requests",