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:
parent
0e582c236b
commit
dc53af238f
31 changed files with 1318 additions and 113 deletions
|
|
@ -55,6 +55,7 @@ const Leadership = lazyPage(() => import("./pages/Leadership.tsx"))
|
|||
const Resources = lazyPage(() => import("./pages/Resources.tsx"))
|
||||
const History = lazyPage(() => import("./pages/History.tsx"))
|
||||
const Feedback = lazyPage(() => import("./pages/Feedback.tsx"))
|
||||
const Request = lazyPage(() => import("./pages/Request.tsx"))
|
||||
const Giving = lazyPage(() => import("./pages/Giving.tsx"))
|
||||
const QrCodes = lazyPage(() => import("./pages/QrCodes.tsx"))
|
||||
const Privacy = lazyPage(() => import("./pages/Privacy.tsx"))
|
||||
|
|
@ -104,6 +105,7 @@ export default function App() {
|
|||
<Route path="resources" element={<Resources />} />
|
||||
<Route path="history" element={<History />} />
|
||||
<Route path="feedback" element={<Feedback />} />
|
||||
<Route path="request" element={<Request />} />
|
||||
<Route path="qr" element={<QrCodes />} />
|
||||
<Route path="give" element={<Giving />} />
|
||||
<Route path="privacy" element={<Privacy />} />
|
||||
|
|
@ -129,6 +131,7 @@ export default function App() {
|
|||
</Route>
|
||||
<Route path="feedback" element={<AdminFeedback />} />
|
||||
<Route path="data-requests" element={<AdminFeedback kind="privacy" />} />
|
||||
<Route path="requests" element={<AdminFeedback kind="content" />} />
|
||||
<Route path="media" element={<AdminMedia />} />
|
||||
<Route element={<RequireRole role="admin" />}>
|
||||
<Route path="clips" element={<AdminClips />} />
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ type TouchLink = { label: string } & (
|
|||
|
||||
const Get_In_Touch: TouchLink[] = [
|
||||
{ label: "Feedback", to: "/feedback"},
|
||||
{ label: "Request", to: "/request" },
|
||||
{ label: "Contact Us", to: "/leadership#contact" },
|
||||
];
|
||||
|
||||
|
|
|
|||
18
src/components/RequestLink.tsx
Normal file
18
src/components/RequestLink.tsx
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { Link } from "react-router-dom";
|
||||
import { PaperPlaneTilt } from "@phosphor-icons/react";
|
||||
|
||||
import { requestLink } from "../data/requestTypes.ts";
|
||||
|
||||
/* A button to the Request form, opened on one kind of request
|
||||
(REQUEST_TYPES). Section manifests place it with `request`. */
|
||||
export default function RequestLink({ type, label, className = "" }: { type: string; label: string; className?: string }) {
|
||||
return (
|
||||
<Link
|
||||
to={requestLink(type)}
|
||||
className={`inline-flex items-center gap-2 rounded-full border border-brand/40 px-4 py-2 text-sm font-semibold text-link transition-colors hover:bg-tint print:hidden ${className}`}
|
||||
>
|
||||
<PaperPlaneTilt aria-hidden="true" weight="bold" className="h-4 w-4" />
|
||||
{label}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
37
src/data/requestTypes.ts
Normal file
37
src/data/requestTypes.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
REQUEST TYPES
|
||||
|
||||
What the Request form (/request) can ask for, and whether each can
|
||||
be new, an update, or both. The ids and actions must match
|
||||
CATEGORIES in server/src/routes/requests.js (and the CHECK in
|
||||
046_content_requests.sql); keep them in step.
|
||||
|
||||
A link can open the form on one: requestLink("chapter") is
|
||||
/request?type=chapter. People, teams and awards have no buttons on
|
||||
the site, but are here to pick.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
export type RequestAction = "new" | "update";
|
||||
|
||||
export const REQUEST_TYPES: {
|
||||
id: string;
|
||||
label: string;
|
||||
hint: string;
|
||||
actions: RequestAction[];
|
||||
// What the name field asks, for a new one and for an update.
|
||||
subject: string;
|
||||
}[] = [
|
||||
{ id: "blog", label: "Blog post", hint: "A story or article for the community blog", actions: ["new"], subject: "Its title" },
|
||||
{ id: "event", label: "Event", hint: "A retreat, gathering or calendar event", actions: ["new", "update"], subject: "The event's name" },
|
||||
{ id: "chapter", label: "Chapter", hint: "A local NGU chapter", actions: ["new", "update"], subject: "The chapter's name" },
|
||||
{ id: "region", label: "Region", hint: "Details for a Unity region", actions: ["update"], subject: "Which region" },
|
||||
{ id: "partner", label: "Partner", hint: "A partner organization", actions: ["new", "update"], subject: "The organization's name" },
|
||||
{ id: "team", label: "Team", hint: "A team or committee", actions: ["new", "update"], subject: "The team's name" },
|
||||
{ id: "award", label: "Award", hint: "An award and who received it", actions: ["new", "update"], subject: "The award's name" },
|
||||
{ id: "person", label: "Person", hint: "Someone's profile", actions: ["new", "update"], subject: "Their name" },
|
||||
];
|
||||
|
||||
export const requestLink = (type: string) => `/request?type=${type}`;
|
||||
|
||||
const BY_ID = new Map(REQUEST_TYPES.map((t) => [t.id, t.label]));
|
||||
export const requestTypeLabel = (id: string) => BY_ID.get(id) ?? id;
|
||||
|
|
@ -122,6 +122,16 @@ export const siteSettings = {
|
|||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
legend: "Notices",
|
||||
fields: [
|
||||
{
|
||||
path: "notify_emails",
|
||||
label: "Email new requests to",
|
||||
help: "Who gets an email for each new content request (the Request form) and data request (the Privacy page), separated by commas, eg. web@nextgenerationofunity.org, board@nextgenerationofunity.org. Needs Gmail set up on the server (docs/google-drive-and-mail.md). Default: none, check Forms instead.",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
children: [
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import { useState } from "react";
|
||||
|
||||
import RequestLink from "../components/RequestLink.tsx";
|
||||
|
||||
/* ═══════════════════════════════════════════════════════════════
|
||||
SECTION MANIFEST
|
||||
|
||||
|
|
@ -21,6 +23,10 @@ import { useState } from "react";
|
|||
default: "carousel",
|
||||
Toggle: EventCardsToggle,
|
||||
},
|
||||
request: { // optional button
|
||||
type: "chapter", // to the Request form
|
||||
label: "Add or update a chapter",
|
||||
},
|
||||
}
|
||||
|
||||
Sections fetch their own data. The page never does, which is why
|
||||
|
|
@ -50,20 +56,25 @@ export function useSectionManifest(manifest) {
|
|||
const setView = (id, value) => setViews(prev => ({ ...prev, [id]: value }));
|
||||
|
||||
return manifest.map(entry => {
|
||||
const { Component, props, views: spec, ...heading } = entry;
|
||||
const { Component, props, views: spec, request, ...heading } = entry;
|
||||
const view = views[entry.id];
|
||||
const Toggle = spec?.Toggle;
|
||||
|
||||
return {
|
||||
...heading,
|
||||
|
||||
actions: Toggle ? (
|
||||
<Toggle
|
||||
view={view}
|
||||
setView={value => setView(entry.id, value)}
|
||||
accent={entry.accent}
|
||||
options={spec.options}
|
||||
/>
|
||||
actions: Toggle || request ? (
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
{request && <RequestLink type={request.type} label={request.label} />}
|
||||
{Toggle && (
|
||||
<Toggle
|
||||
view={view}
|
||||
setView={value => setView(entry.id, value)}
|
||||
accent={entry.accent}
|
||||
options={spec.options}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
) : undefined,
|
||||
|
||||
content: (
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import siteConfiguration from '../../site.json'
|
|||
|
||||
type PageText = { title: string; description: string }
|
||||
|
||||
type SiteText = { title?: string; pages?: Record<string, PageText>; privacyEmail?: string }
|
||||
type SiteText = { title?: string; pages?: Record<string, PageText>; privacyEmail?: string; requestFiles?: boolean }
|
||||
|
||||
/* What the server wrote into the page, if it did. */
|
||||
const fromServer: SiteText =
|
||||
|
|
@ -38,6 +38,11 @@ export const SITE_ORIGIN: string = siteConfiguration.url
|
|||
* settings, else site.json). Blank: the Privacy page's form only. */
|
||||
export const PRIVACY_EMAIL: string = fromServer.privacyEmail ?? siteConfiguration.privacyEmail
|
||||
|
||||
/** Whether the Request form takes files (Google Drive is set up on
|
||||
* the server). Unknown (the Vite dev server) offers them, and the
|
||||
* server says so if it can't. */
|
||||
export const REQUEST_FILES: boolean = fromServer.requestFiles ?? true
|
||||
|
||||
/** A site path as a full URL on the live site. */
|
||||
export const siteUrl = (path: string): string => new URL(path, SITE_ORIGIN).href
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import { accentText, BRAND } from "../lib/color.ts"
|
|||
import PostContents from "../components/PostContents.tsx"
|
||||
import { headingAnchors } from "../lib/contents.ts"
|
||||
import QrCode from "../components/QrCode.tsx"
|
||||
import RequestLink from "../components/RequestLink.tsx"
|
||||
import { siteUrl } from "../lib/site.ts"
|
||||
import { FilePdf } from "@phosphor-icons/react"
|
||||
|
||||
|
|
@ -148,6 +149,11 @@ export default function BlogPost() {
|
|||
|
||||
<ContentBlocks blocks={post.blocks} accent={BRAND} />
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3 border-t border-brand/15 pt-6 text-sm text-muted print:hidden">
|
||||
Have a story to share?
|
||||
<RequestLink type="blog" label="Write for the blog" />
|
||||
</div>
|
||||
|
||||
{/* Only on paper (Download PDF): where the post lives online,
|
||||
as a link and as a code to scan. */}
|
||||
<footer className="hidden break-inside-avoid items-center gap-6 border-t border-brand/20 pt-6 print:flex">
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ const SECTIONS = [
|
|||
accent: BRAND,
|
||||
background: "var(--color-tint)",
|
||||
Component: OrgListMap,
|
||||
request: { type: "chapter", label: "Add or update a chapter" },
|
||||
views: { options: ["map", "grid"], default: "map", Toggle: OrgMapToggle },
|
||||
},
|
||||
{
|
||||
|
|
@ -44,6 +45,7 @@ const SECTIONS = [
|
|||
accent: "#4a6b72",
|
||||
background: "var(--color-surface)",
|
||||
Component: OrgListVertical,
|
||||
request: { type: "region", label: "Update a region" },
|
||||
props: {
|
||||
kind: "region",
|
||||
pageLabel: "Region page",
|
||||
|
|
@ -62,6 +64,7 @@ const SECTIONS = [
|
|||
accent: ACCENTS.mint,
|
||||
background: "var(--color-tint)",
|
||||
Component: OrgListCards,
|
||||
request: { type: "partner", label: "Add or update a partner" },
|
||||
props: {
|
||||
kind: "partner",
|
||||
pageLabel: "Partner page",
|
||||
|
|
@ -81,6 +84,7 @@ export default function CommunityPage() {
|
|||
accent: BRAND,
|
||||
background: "var(--color-surface)",
|
||||
Component: CommunityBlog,
|
||||
request: { type: "blog", label: "Write for the blog" },
|
||||
},
|
||||
...SECTIONS,
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ const PAGE = sitePage("/privacy");
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
Privacy policy, cookie notice included.
|
||||
|
||||
What it says must stay true of the code: what the feedback form
|
||||
stores (routes/feedback.js), what the browser keeps (Banner,
|
||||
What it says must stay true of the code: what the feedback and
|
||||
request forms store (routes/feedback.js, routes/requests.js), what the browser keeps (Banner,
|
||||
PrivacyNotice, the theme toggle), which embeds wait for a click
|
||||
(VideoPlayer, HeroStage, ScheduleBlock), and that nothing about
|
||||
a minor is shown. Change the date when the wording changes.
|
||||
|
|
@ -24,7 +24,7 @@ const PAGE = sitePage("/privacy");
|
|||
'privacy', in Admin → Forms → Data requests.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
const LAST_UPDATED = "September 28, 2026";
|
||||
const LAST_UPDATED = "September 29, 2026";
|
||||
|
||||
const link = "underline underline-offset-2 text-link";
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ const PARTS: LegalPart[] = [
|
|||
<strong>Feedback and requests you send.</strong> Your message, the page it's about, and, if you
|
||||
give them, your name and email. With it we keep your browser's description (its user agent) and
|
||||
a scrambled form of your IP address that can't be turned back into the address; we use it only to
|
||||
spot abuse.
|
||||
spot abuse. Files you attach to a <Link to="/request" className={link}>request</Link> are kept with it.
|
||||
</>,
|
||||
<>
|
||||
<strong>People on the site.</strong> Leaders, speakers and volunteers can appear with a name,
|
||||
|
|
@ -119,9 +119,13 @@ const PARTS: LegalPart[] = [
|
|||
<>
|
||||
<strong>Staff sign-in</strong> can use a Google account on our own domain.
|
||||
</>,
|
||||
<>
|
||||
<strong>Files attached to requests</strong> are stored in our Google Workspace (Google Drive), and
|
||||
our staff may be told of a new request by email through it.
|
||||
</>,
|
||||
],
|
||||
after: [
|
||||
"This site runs on a server we rent and manage ourselves; your information is stored there, not with an outside website service.",
|
||||
"This site runs on a server we rent and manage ourselves; your information is stored there, not with an outside website service, apart from request files as above.",
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
|||
33
src/pages/Request.tsx
Normal file
33
src/pages/Request.tsx
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import PageShell from "../components/PageShell.tsx";
|
||||
import { sitePage } from "../lib/site.ts";
|
||||
import RequestForm from "./sections/RequestForm.tsx";
|
||||
import { BRAND } from "../lib/color.ts";
|
||||
|
||||
/* Title and intro: site.json, which also gives the search metadata. */
|
||||
const PAGE = sitePage("/request");
|
||||
|
||||
/* ═══════════════════════════════════════════════════════════════
|
||||
Request page: ask for something to be added to the site or
|
||||
changed on it. The form (sections/RequestForm) reads ?type= to
|
||||
start on one kind of request; requestLink() makes those links.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
const SECTIONS = [
|
||||
{
|
||||
id: "request",
|
||||
title: "Send a request",
|
||||
blurb:
|
||||
"Tell us what you'd like on the site, or what should change. Attach a Word document with the details and we'll take it from there.",
|
||||
accent: BRAND,
|
||||
background: "var(--color-tint)",
|
||||
content: (
|
||||
<div className="mx-auto max-w-3xl px-6">
|
||||
<RequestForm />
|
||||
</div>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
export default function Request() {
|
||||
return <PageShell title={PAGE.title} intro={PAGE.description} sections={SECTIONS} />;
|
||||
}
|
||||
|
|
@ -52,6 +52,7 @@ const SECTIONS = [
|
|||
Component: EventListCards,
|
||||
props: { scope: "national", ...RETREATS },
|
||||
views: { ...CARD_VIEWS, default: "carousel" },
|
||||
request: { type: "event", label: "Add or update an event" },
|
||||
},
|
||||
{
|
||||
id: "regional",
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -118,6 +118,11 @@ export const FORMS_NAV = {
|
|||
label: "Website feedback",
|
||||
blurb: "The triage queue for the feedback form.",
|
||||
},
|
||||
{
|
||||
to: "/admin/requests",
|
||||
label: "Content requests",
|
||||
blurb: "Requests for blog posts, events, and new or updated organizations, teams, awards and people, with their files.",
|
||||
},
|
||||
{
|
||||
to: "/admin/data-requests",
|
||||
label: "Data requests",
|
||||
|
|
|
|||
|
|
@ -34,16 +34,16 @@ const WHOLE_PAGE = "";
|
|||
|
||||
/* ── Shared field chrome ─────────────────────────────────────── */
|
||||
|
||||
const fieldClass =
|
||||
export const fieldClass =
|
||||
"w-full rounded-xl border border-muted/50 bg-surface px-4 py-3 text-body " +
|
||||
"placeholder:text-muted outline-none transition-colors " +
|
||||
"focus:border-brand focus:ring-2 focus:ring-brand/25";
|
||||
|
||||
const errorFieldClass = "border-danger focus:border-danger focus:ring-danger/20";
|
||||
export const errorFieldClass = "border-danger focus:border-danger focus:ring-danger/20";
|
||||
|
||||
const selectClass = `${fieldClass} appearance-none pr-10`;
|
||||
|
||||
function OptionalTag() {
|
||||
export function OptionalTag() {
|
||||
return (
|
||||
<span className="ml-2 rounded-full bg-tint px-2 py-0.5 text-xs font-medium text-link">
|
||||
Optional
|
||||
|
|
@ -51,7 +51,7 @@ function OptionalTag() {
|
|||
);
|
||||
}
|
||||
|
||||
function FieldError({ id, children }) {
|
||||
export function FieldError({ id, children }) {
|
||||
if (!children) return null;
|
||||
return (
|
||||
<p id={id} className="mt-2 text-sm text-danger">
|
||||
|
|
@ -82,26 +82,38 @@ function Select({ id, label, value, onChange, children }) {
|
|||
);
|
||||
}
|
||||
|
||||
/* ── Type picker ─────────────────────────────────────────────── */
|
||||
/* ── Type picker: a tile per option (the Request form's too) ─── */
|
||||
|
||||
function TypePicker({ value, onChange }) {
|
||||
export function TilePicker({
|
||||
legend,
|
||||
blurb,
|
||||
name,
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
legend: string;
|
||||
blurb: string;
|
||||
name: string;
|
||||
options: { id: string; label: string; hint: string }[];
|
||||
value: string | null;
|
||||
onChange: (id: string) => void;
|
||||
}) {
|
||||
return (
|
||||
<fieldset>
|
||||
<legend className="text-base font-semibold text-body">
|
||||
What kind of feedback is this?
|
||||
</legend>
|
||||
<legend className="text-base font-semibold text-body">{legend}</legend>
|
||||
<p className="mt-1 text-sm" style={{ color: MUTED }}>
|
||||
Pick the closest fit. It helps us route it to the right person.
|
||||
{blurb}
|
||||
</p>
|
||||
|
||||
<div className="mt-4 grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{FEEDBACK_TYPES.map((type) => {
|
||||
{options.map((type) => {
|
||||
const selected = value === type.id;
|
||||
return (
|
||||
<label key={type.id} className="cursor-pointer">
|
||||
<input
|
||||
type="radio"
|
||||
name="feedbackType"
|
||||
name={name}
|
||||
value={type.id}
|
||||
checked={selected}
|
||||
onChange={() => onChange(type.id)}
|
||||
|
|
@ -317,7 +329,14 @@ export default function FeedbackForm({ fixedType }: { fixedType?: string } = {})
|
|||
>
|
||||
{!fixedType && (
|
||||
<>
|
||||
<TypePicker value={type} onChange={setType} />
|
||||
<TilePicker
|
||||
legend="What kind of feedback is this?"
|
||||
blurb="Pick the closest fit. It helps us route it to the right person."
|
||||
name="feedbackType"
|
||||
options={FEEDBACK_TYPES}
|
||||
value={type}
|
||||
onChange={setType}
|
||||
/>
|
||||
|
||||
<div className="mt-10">
|
||||
<LocationPicker
|
||||
|
|
|
|||
336
src/pages/sections/RequestForm.tsx
Normal file
336
src/pages/sections/RequestForm.tsx
Normal file
|
|
@ -0,0 +1,336 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
REQUEST FORM
|
||||
|
||||
Posts to /api/requests (server/src/routes/requests.js), as a form
|
||||
so files can go with it. What can be asked for is REQUEST_TYPES;
|
||||
?type=chapter in the address picks one to start with, which is how
|
||||
the site's "Request" buttons open it.
|
||||
|
||||
Files go to Google Drive on the server; when Drive isn't set up
|
||||
(REQUEST_FILES) the file field isn't shown. The limits here match
|
||||
the server's, so nobody waits on an upload that will be refused.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useState } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
|
||||
import { ApiError, upload } from "../../lib/api.ts";
|
||||
import { accentText, BRAND } from "../../lib/color.ts";
|
||||
import { REQUEST_FILES } from "../../lib/site.ts";
|
||||
import { REQUEST_TYPES, type RequestAction } from "../../data/requestTypes.ts";
|
||||
import { FieldError, OptionalTag, TilePicker, errorFieldClass, fieldClass } from "./FeedbackForm.tsx";
|
||||
|
||||
const MUTED = "var(--color-muted)";
|
||||
const MAX_CHARS = 5000;
|
||||
const MIN_MESSAGE = 10; // matches the server
|
||||
const MAX_FILES = 3;
|
||||
const MAX_FILE_MB = 10;
|
||||
const ACCEPT = ".docx,.pdf,.jpg,.jpeg,.png";
|
||||
|
||||
const ACTION_LABEL: Record<RequestAction, string> = {
|
||||
new: "Something new",
|
||||
update: "An update to what's there",
|
||||
};
|
||||
|
||||
const PLACEHOLDER: Record<string, string> = {
|
||||
blog: "A few lines about the post: what it's about, and anything we should know. Attach the post as a Word document.",
|
||||
event: "When and where, who it's for, how to register, and who to contact.",
|
||||
};
|
||||
|
||||
export default function RequestForm() {
|
||||
const [params] = useSearchParams();
|
||||
const start = REQUEST_TYPES.find((t) => t.id === params.get("type")) ?? null;
|
||||
|
||||
const [category, setCategory] = useState<string | null>(start?.id ?? null);
|
||||
const [action, setAction] = useState<RequestAction | null>(start?.actions.length === 1 ? start.actions[0] : null);
|
||||
const [subject, setSubject] = useState("");
|
||||
const [message, setMessage] = useState("");
|
||||
const [files, setFiles] = useState<File[]>([]);
|
||||
const [name, setName] = useState("");
|
||||
const [email, setEmail] = useState("");
|
||||
const [website, setWebsite] = useState(""); // honeypot
|
||||
|
||||
const [status, setStatus] = useState<"idle" | "sending" | "sent">("idle");
|
||||
const [formError, setFormError] = useState<string | null>(null);
|
||||
const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({});
|
||||
|
||||
const type = REQUEST_TYPES.find((t) => t.id === category);
|
||||
const sending = status === "sending";
|
||||
|
||||
const fileError =
|
||||
files.length > MAX_FILES
|
||||
? `${MAX_FILES} files at most.`
|
||||
: files.find((f) => f.size > MAX_FILE_MB * 1024 * 1024)
|
||||
? `Files can be ${MAX_FILE_MB} MB each at most.`
|
||||
: null;
|
||||
const ready =
|
||||
Boolean(type && action) &&
|
||||
subject.trim() !== "" &&
|
||||
message.trim().length >= MIN_MESSAGE &&
|
||||
email.trim() !== "" &&
|
||||
!fileError;
|
||||
|
||||
function pick(id: string) {
|
||||
const next = REQUEST_TYPES.find((t) => t.id === id);
|
||||
setCategory(id);
|
||||
// One choice picks itself; otherwise keep what was chosen if it still applies.
|
||||
setAction((prev) => (next?.actions.length === 1 ? next.actions[0] : prev && next?.actions.includes(prev) ? prev : null));
|
||||
}
|
||||
|
||||
async function handleSubmit(event) {
|
||||
event.preventDefault();
|
||||
if (!ready || sending || !category || !action) return;
|
||||
|
||||
setStatus("sending");
|
||||
setFormError(null);
|
||||
setFieldErrors({});
|
||||
|
||||
const form = new FormData();
|
||||
form.set("category", category);
|
||||
form.set("action", action);
|
||||
form.set("subject", subject.trim());
|
||||
form.set("message", message.trim());
|
||||
form.set("name", name.trim());
|
||||
form.set("email", email.trim());
|
||||
form.set("website", website);
|
||||
for (const file of files) form.append("files", file);
|
||||
|
||||
try {
|
||||
await upload("/requests", form);
|
||||
setStatus("sent");
|
||||
} catch (error) {
|
||||
setStatus("idle");
|
||||
if (error instanceof ApiError) {
|
||||
setFieldErrors(error.fields ?? {});
|
||||
setFormError(error.fields ? "Have another look at the highlighted fields." : error.message);
|
||||
} else {
|
||||
setFormError("Couldn't reach the server. Try again in a moment.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function reset() {
|
||||
setSubject("");
|
||||
setMessage("");
|
||||
setFiles([]);
|
||||
setStatus("idle");
|
||||
setFormError(null);
|
||||
setFieldErrors({});
|
||||
}
|
||||
|
||||
if (status === "sent") {
|
||||
return (
|
||||
<div aria-live="polite" className="rounded-2xl border border-brand/20 bg-surface p-8 sm:p-10">
|
||||
<h3 className="text-2xl font-bold" style={{ color: accentText(BRAND) }}>
|
||||
Thanks, we've got it
|
||||
</h3>
|
||||
<p className="mt-3 max-w-prose" style={{ color: MUTED }}>
|
||||
We'll look it over and follow up at {email}, usually within a week.
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={reset}
|
||||
className="mt-6 rounded-full border border-brand px-5 py-2.5 font-semibold text-link transition-colors hover:bg-tint focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand/40"
|
||||
>
|
||||
Send another request
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} noValidate className="rounded-2xl border border-brand/20 bg-surface p-6 sm:p-8">
|
||||
<TilePicker
|
||||
legend="What is this about?"
|
||||
blurb="Pick the closest fit."
|
||||
name="category"
|
||||
options={REQUEST_TYPES}
|
||||
value={category}
|
||||
onChange={pick}
|
||||
/>
|
||||
<FieldError id="request-category-error">{fieldErrors.category}</FieldError>
|
||||
|
||||
{type && type.actions.length > 1 && (
|
||||
<fieldset className="mt-8">
|
||||
<legend className="text-base font-semibold text-body">New, or an update?</legend>
|
||||
<div className="mt-3 flex flex-wrap gap-3">
|
||||
{type.actions.map((a) => (
|
||||
<label key={a} className="cursor-pointer">
|
||||
<input
|
||||
type="radio"
|
||||
name="action"
|
||||
value={a}
|
||||
checked={action === a}
|
||||
onChange={() => setAction(a)}
|
||||
className="peer sr-only"
|
||||
/>
|
||||
<span
|
||||
className={
|
||||
"inline-block rounded-full border px-5 py-2 text-sm font-semibold transition-colors " +
|
||||
"peer-focus-visible:ring-2 peer-focus-visible:ring-brand/40 " +
|
||||
(action === a ? "border-brand bg-tint text-link" : "border-muted/30 text-body hover:border-brand/50")
|
||||
}
|
||||
>
|
||||
{ACTION_LABEL[a]}
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
<FieldError id="request-action-error">{fieldErrors.action}</FieldError>
|
||||
</fieldset>
|
||||
)}
|
||||
{type?.id === "region" && (
|
||||
<p className="mt-4 text-sm" style={{ color: MUTED }}>
|
||||
Regions are set by Unity, so this is for updating one that's on the site.
|
||||
</p>
|
||||
)}
|
||||
|
||||
{type && (
|
||||
<>
|
||||
<div className="mt-8">
|
||||
<label htmlFor="request-subject" className="text-base font-semibold text-body">
|
||||
{action === "update" && type.actions.length > 1 ? `Which ${type.label.toLowerCase()}?` : type.subject}
|
||||
</label>
|
||||
<input
|
||||
id="request-subject"
|
||||
type="text"
|
||||
maxLength={200}
|
||||
value={subject}
|
||||
onChange={(e) => setSubject(e.target.value)}
|
||||
aria-invalid={Boolean(fieldErrors.subject)}
|
||||
aria-describedby={fieldErrors.subject ? "request-subject-error" : undefined}
|
||||
className={`mt-3 ${fieldClass} ${fieldErrors.subject ? errorFieldClass : ""}`}
|
||||
/>
|
||||
<FieldError id="request-subject-error">{fieldErrors.subject}</FieldError>
|
||||
</div>
|
||||
|
||||
<div className="mt-8">
|
||||
<label htmlFor="request-message" className="text-base font-semibold text-body">
|
||||
{action === "update" ? "What should change?" : "Tell us about it"}
|
||||
</label>
|
||||
<textarea
|
||||
id="request-message"
|
||||
rows={7}
|
||||
maxLength={MAX_CHARS}
|
||||
value={message}
|
||||
onChange={(e) => setMessage(e.target.value)}
|
||||
placeholder={
|
||||
action === "update"
|
||||
? "What's there now, and what it should say instead."
|
||||
: (PLACEHOLDER[type.id] ?? "Everything we'd need to add it: a description, links, and who to contact.")
|
||||
}
|
||||
aria-invalid={Boolean(fieldErrors.message)}
|
||||
aria-describedby={fieldErrors.message ? "request-message-error" : undefined}
|
||||
className={`mt-3 resize-y ${fieldClass} ${fieldErrors.message ? errorFieldClass : ""}`}
|
||||
/>
|
||||
<div className="mt-2 flex items-start justify-between gap-4">
|
||||
<FieldError id="request-message-error">{fieldErrors.message}</FieldError>
|
||||
<span className="ml-auto shrink-0 text-xs tabular-nums" style={{ color: MUTED }}>
|
||||
{message.length} / {MAX_CHARS}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{REQUEST_FILES && (
|
||||
<div className="mt-8">
|
||||
<div className="flex flex-wrap items-center">
|
||||
<label htmlFor="request-files" className="text-base font-semibold text-body">
|
||||
Files
|
||||
</label>
|
||||
<OptionalTag />
|
||||
</div>
|
||||
<p className="mt-1 max-w-prose text-sm" style={{ color: MUTED }}>
|
||||
A Word document (.docx) with the details or the post itself, photos (JPEG or PNG) or a PDF. Up to{" "}
|
||||
{MAX_FILES}, {MAX_FILE_MB} MB each.
|
||||
</p>
|
||||
<input
|
||||
id="request-files"
|
||||
type="file"
|
||||
multiple
|
||||
accept={ACCEPT}
|
||||
onChange={(e) => setFiles(Array.from(e.target.files ?? []))}
|
||||
aria-invalid={Boolean(fileError || fieldErrors.files)}
|
||||
aria-describedby={fileError || fieldErrors.files ? "request-files-error" : undefined}
|
||||
className="mt-3 block w-full text-sm text-body file:mr-4 file:rounded-full file:border-0 file:bg-tint file:px-4 file:py-2 file:font-semibold file:text-link hover:file:bg-tint-soft"
|
||||
/>
|
||||
<FieldError id="request-files-error">{fileError ?? fieldErrors.files}</FieldError>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
<div className="mt-8 rounded-xl border border-dashed border-muted/30 bg-tint/60 p-5 sm:p-6">
|
||||
<h3 className="text-base font-semibold text-body">How we reach you</h3>
|
||||
<p className="mt-1 max-w-prose text-sm" style={{ color: MUTED }}>
|
||||
We use these only to follow up on this request, and we won't add you to any list.
|
||||
</p>
|
||||
<div className="mt-5 grid gap-4 sm:grid-cols-2">
|
||||
<div>
|
||||
<label htmlFor="request-name" className="block text-sm font-medium text-body">
|
||||
Name <span className="font-normal text-muted">(optional)</span>
|
||||
</label>
|
||||
<input
|
||||
id="request-name"
|
||||
type="text"
|
||||
autoComplete="name"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
className={`mt-2 ${fieldClass}`}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="request-email" className="block text-sm font-medium text-body">
|
||||
Email <span className="font-normal text-muted">(required)</span>
|
||||
</label>
|
||||
<input
|
||||
id="request-email"
|
||||
type="email"
|
||||
autoComplete="email"
|
||||
required
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
aria-invalid={Boolean(fieldErrors.email)}
|
||||
aria-describedby={fieldErrors.email ? "request-email-error" : undefined}
|
||||
className={`mt-2 ${fieldClass} ${fieldErrors.email ? errorFieldClass : ""}`}
|
||||
/>
|
||||
<FieldError id="request-email-error">{fieldErrors.email}</FieldError>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Honeypot, as on the feedback form. */}
|
||||
<div aria-hidden="true" className="absolute -left-[9999px] h-0 w-0 overflow-hidden">
|
||||
<label htmlFor="request-website">Website</label>
|
||||
<input
|
||||
id="request-website"
|
||||
type="text"
|
||||
tabIndex={-1}
|
||||
autoComplete="off"
|
||||
value={website}
|
||||
onChange={(e) => setWebsite(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{formError && (
|
||||
<p role="alert" className="mt-8 rounded-xl border border-danger/30 bg-danger-tint px-4 py-3 text-sm text-danger">
|
||||
{formError}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="mt-6 flex flex-wrap items-center gap-4">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={!ready || sending}
|
||||
className="rounded-full bg-action px-7 py-3 font-semibold text-white transition-colors hover:bg-action-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand/40 disabled:cursor-not-allowed disabled:bg-muted/25 disabled:text-white/80"
|
||||
>
|
||||
{sending ? (files.length ? "Uploading…" : "Sending…") : "Send request"}
|
||||
</button>
|
||||
{!ready && !sending && (
|
||||
<p className="text-sm" style={{ color: MUTED }}>
|
||||
Choose what it's about, give it a name, write at least a sentence and give an email address to send.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
|
@ -9,17 +9,21 @@
|
|||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import EventCalendar from '../EventCalendar.tsx'
|
||||
import RequestLink from '../../../components/RequestLink.tsx'
|
||||
|
||||
type CalendarBandProps = { id: string; title: string; blurb?: string | null }
|
||||
|
||||
export default function CalendarBand({ id, title, blurb }: CalendarBandProps) {
|
||||
return (
|
||||
<section id={id} className="py-24" style={{ background: 'var(--color-tint-soft)' }}>
|
||||
<div className="mx-auto mb-10 max-w-6xl px-6">
|
||||
<h2 className="font-display text-4xl font-extrabold text-ink md:text-5xl">
|
||||
{title}
|
||||
</h2>
|
||||
{blurb && <p className="mt-3 max-w-xl text-lg text-muted">{blurb}</p>}
|
||||
<div className="mx-auto mb-10 flex max-w-6xl flex-wrap items-end justify-between gap-4 px-6">
|
||||
<div>
|
||||
<h2 className="font-display text-4xl font-extrabold text-ink md:text-5xl">
|
||||
{title}
|
||||
</h2>
|
||||
{blurb && <p className="mt-3 max-w-xl text-lg text-muted">{blurb}</p>}
|
||||
</div>
|
||||
<RequestLink type="event" label="Add or update an event" />
|
||||
</div>
|
||||
|
||||
<EventCalendar />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue