Let a content request carry the record's details, and open its editor
The Request form asks each type for its main details (a chapter's city, meeting time, website and email; an event's dates, venue and registration link...), stored as one JSON column (migration 049). The server only checks the shape; the fields are src/data/requestTypes.ts. Forms → Content requests shows them, and for a new record opens the New editor filled in (URL ID from the name, links and a description paragraph added); for an update, picks the record (closest name first) and opens it with each requested value beside the current one to use or skip. Nothing is saved until Save. Also centres the image and file pickers, which Tailwind's reset had pinned to the top left. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7876e060e7
commit
4b249c9e52
10 changed files with 529 additions and 22 deletions
|
|
@ -6,6 +6,10 @@
|
|||
?type=chapter in the address picks one to start with, which is how
|
||||
the site's "Request" buttons open it.
|
||||
|
||||
Each type's details (its `fields` in requestTypes.ts: a chapter's
|
||||
city and meeting time, an event's dates) go as one JSON field; the
|
||||
admin opens the record's editor filled in from them.
|
||||
|
||||
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.
|
||||
|
|
@ -48,6 +52,8 @@ export default function RequestForm() {
|
|||
const [files, setFiles] = useState<File[]>([]);
|
||||
const [name, setName] = useState("");
|
||||
const [email, setEmail] = useState("");
|
||||
// By field key; kept when the type changes, since types share keys.
|
||||
const [details, setDetails] = useState<Record<string, string>>({});
|
||||
const [website, setWebsite] = useState(""); // honeypot
|
||||
|
||||
const [status, setStatus] = useState<"idle" | "sending" | "sent">("idle");
|
||||
|
|
@ -92,6 +98,15 @@ export default function RequestForm() {
|
|||
form.set("message", message.trim());
|
||||
form.set("name", name.trim());
|
||||
form.set("email", email.trim());
|
||||
// Only the chosen type's fields, and only filled ones.
|
||||
form.set(
|
||||
"details",
|
||||
JSON.stringify(
|
||||
Object.fromEntries(
|
||||
(type?.fields ?? []).map((f) => [f.key, (details[f.key] ?? "").trim()]).filter(([, value]) => value),
|
||||
),
|
||||
),
|
||||
);
|
||||
form.set("website", website);
|
||||
for (const file of files) form.append("files", file);
|
||||
|
||||
|
|
@ -111,6 +126,7 @@ export default function RequestForm() {
|
|||
|
||||
function reset() {
|
||||
setSubject("");
|
||||
setDetails({});
|
||||
setMessage("");
|
||||
setFiles([]);
|
||||
setStatus("idle");
|
||||
|
|
@ -204,6 +220,45 @@ export default function RequestForm() {
|
|||
<FieldError id="request-subject-error">{fieldErrors.subject}</FieldError>
|
||||
</div>
|
||||
|
||||
{type.fields.length > 0 && (
|
||||
<fieldset className="mt-8">
|
||||
<legend className="flex flex-wrap items-center text-base font-semibold text-body">
|
||||
Details
|
||||
<OptionalTag />
|
||||
</legend>
|
||||
<p className="mt-1 text-sm" style={{ color: MUTED }}>
|
||||
{action === "update"
|
||||
? "Only what should change; leave the rest blank."
|
||||
: "Whatever you know. Blanks are fine, and the rest can go in the message or a document."}
|
||||
</p>
|
||||
<div className="mt-4 grid gap-4 sm:grid-cols-2">
|
||||
{type.fields.map((f) => {
|
||||
const id = `request-detail-${f.key}`;
|
||||
const common = {
|
||||
id,
|
||||
value: details[f.key] ?? "",
|
||||
placeholder: f.placeholder,
|
||||
maxLength: 2000,
|
||||
className: fieldClass,
|
||||
};
|
||||
const set = (value: string) => setDetails((prev) => ({ ...prev, [f.key]: value }));
|
||||
return (
|
||||
<div key={f.key} className={f.input === "textarea" ? "sm:col-span-2" : ""}>
|
||||
<label htmlFor={id} className="block text-sm font-medium text-body">
|
||||
{f.label}
|
||||
</label>
|
||||
{f.input === "textarea" ? (
|
||||
<textarea {...common} rows={3} onChange={(e) => set(e.target.value)} className={`mt-2 resize-y ${fieldClass}`} />
|
||||
) : (
|
||||
<input {...common} type={f.input ?? "text"} onChange={(e) => set(e.target.value)} className={`mt-2 ${fieldClass}`} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</fieldset>
|
||||
)}
|
||||
|
||||
<div className="mt-8">
|
||||
<label htmlFor="request-message" className="text-base font-semibold text-body">
|
||||
{action === "update" ? "What should change?" : "Tell us about it"}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue