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
|
|
@ -9,29 +9,230 @@
|
|||
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.
|
||||
|
||||
`fields` are the details the form asks for on top of the name and
|
||||
message, stored together as JSON on the request (feedback.details,
|
||||
049). Only here: the server keeps whatever keys come, so adding a
|
||||
field is a change to this file alone. Each field's `to` says where
|
||||
it goes when Forms → Content requests opens the record's editor
|
||||
from the request (EntityEdit's fromRequest):
|
||||
|
||||
{ path } a field in the editor, eg. "locality"
|
||||
{ link, label } a row in the record's links
|
||||
{ block: "card" } a paragraph of the record's description
|
||||
(none) shown in the admin only, eg. a region's
|
||||
name, which the admin picks by hand
|
||||
|
||||
`entity` is the admin record it becomes, `preset` the values a new
|
||||
one starts with (a chapter is an organization of kind chapter), and
|
||||
`heading` the editor field the request's name fills.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
export type RequestAction = "new" | "update";
|
||||
|
||||
export const REQUEST_TYPES: {
|
||||
export type RequestField = {
|
||||
key: string;
|
||||
label: string;
|
||||
input?: "text" | "date" | "url" | "email" | "textarea";
|
||||
placeholder?: string;
|
||||
to?: { path: string } | { link: "website" | "email" | "action"; label: string } | { block: "card" };
|
||||
};
|
||||
|
||||
export type RequestType = {
|
||||
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" },
|
||||
entity: string;
|
||||
heading: string;
|
||||
preset?: Record<string, string>;
|
||||
fields: RequestField[];
|
||||
};
|
||||
|
||||
const CITY: RequestField = { key: "city", label: "City", to: { path: "locality" } };
|
||||
const STATE: RequestField = { key: "state", label: "State or province", placeholder: "eg. MO", to: { path: "state_code" } };
|
||||
const COUNTRY: RequestField = { key: "country", label: "Country", placeholder: "eg. US", to: { path: "country" } };
|
||||
const WEBSITE: RequestField = { key: "website", label: "Website", input: "url", placeholder: "https://", to: { link: "website", label: "Website" } };
|
||||
const EMAIL: RequestField = { key: "email", label: "Contact email", input: "email", to: { link: "email", label: "Email" } };
|
||||
const DESCRIPTION: RequestField = { key: "description", label: "Short description", input: "textarea", to: { block: "card" } };
|
||||
|
||||
export const REQUEST_TYPES: RequestType[] = [
|
||||
{
|
||||
id: "blog",
|
||||
label: "Blog post",
|
||||
hint: "A story or article for the community blog",
|
||||
actions: ["new"],
|
||||
subject: "Its title",
|
||||
entity: "blog_posts",
|
||||
heading: "title",
|
||||
fields: [
|
||||
{ key: "author", label: "Author's name, as it should appear", to: { path: "guest_author" } },
|
||||
{ key: "excerpt", label: "A line or two for the post's card", input: "textarea", to: { path: "excerpt" } },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "event",
|
||||
label: "Event",
|
||||
hint: "A retreat, gathering or calendar event",
|
||||
actions: ["new", "update"],
|
||||
subject: "The event's name",
|
||||
entity: "events",
|
||||
heading: "title",
|
||||
fields: [
|
||||
{ key: "starts_on", label: "Starts", input: "date", to: { path: "starts_on" } },
|
||||
{ key: "ends_on", label: "Ends", input: "date", to: { path: "ends_on" } },
|
||||
{ key: "venue", label: "Venue", placeholder: "eg. Unity Village", to: { path: "venue" } },
|
||||
CITY,
|
||||
STATE,
|
||||
{ key: "register", label: "Registration link", input: "url", placeholder: "https://", to: { link: "action", label: "Register" } },
|
||||
DESCRIPTION,
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "chapter",
|
||||
label: "Chapter",
|
||||
hint: "A local NGU chapter",
|
||||
actions: ["new", "update"],
|
||||
subject: "The chapter's name",
|
||||
entity: "organizations",
|
||||
heading: "name",
|
||||
preset: { kind: "chapter" },
|
||||
fields: [
|
||||
{ key: "region", label: "Region it's in", placeholder: "eg. Great Lakes" },
|
||||
CITY,
|
||||
STATE,
|
||||
COUNTRY,
|
||||
{ key: "meets", label: "When it meets", placeholder: "eg. 2nd Sundays, 6:00pm", to: { path: "chapter.meets" } },
|
||||
WEBSITE,
|
||||
EMAIL,
|
||||
DESCRIPTION,
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "region",
|
||||
label: "Region",
|
||||
hint: "Details for a Unity region",
|
||||
actions: ["update"],
|
||||
subject: "Which region",
|
||||
entity: "organizations",
|
||||
heading: "name",
|
||||
preset: { kind: "region" },
|
||||
fields: [WEBSITE, EMAIL, DESCRIPTION],
|
||||
},
|
||||
{
|
||||
id: "partner",
|
||||
label: "Partner",
|
||||
hint: "A partner organization",
|
||||
actions: ["new", "update"],
|
||||
subject: "The organization's name",
|
||||
entity: "organizations",
|
||||
heading: "name",
|
||||
preset: { kind: "partner" },
|
||||
fields: [CITY, STATE, COUNTRY, WEBSITE, EMAIL, DESCRIPTION],
|
||||
},
|
||||
{
|
||||
id: "team",
|
||||
label: "Team",
|
||||
hint: "A team or committee",
|
||||
actions: ["new", "update"],
|
||||
subject: "The team's name",
|
||||
entity: "teams",
|
||||
heading: "name",
|
||||
fields: [
|
||||
{ key: "organization", label: "Which organization it belongs to", placeholder: "eg. NGU national" },
|
||||
{ key: "tagline", label: "What it does, in a line", to: { path: "tagline" } },
|
||||
EMAIL,
|
||||
DESCRIPTION,
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "award",
|
||||
label: "Award",
|
||||
hint: "An award and who received it",
|
||||
actions: ["new", "update"],
|
||||
subject: "The award's name",
|
||||
entity: "awards",
|
||||
heading: "name",
|
||||
fields: [
|
||||
{ key: "organization", label: "Who gives it", placeholder: "eg. NGU national" },
|
||||
{ key: "description", label: "What it's for", input: "textarea", to: { path: "description" } },
|
||||
{ key: "recipients", label: "Who received it, and when", input: "textarea" },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "person",
|
||||
label: "Person",
|
||||
hint: "Someone's profile",
|
||||
actions: ["new", "update"],
|
||||
subject: "Their name",
|
||||
entity: "people",
|
||||
heading: "display_name",
|
||||
fields: [
|
||||
{ key: "pronouns", label: "Pronouns", placeholder: "eg. she/her", to: { path: "pronouns" } },
|
||||
{ key: "tagline", label: "Role or title", to: { path: "tagline" } },
|
||||
CITY,
|
||||
STATE,
|
||||
{ key: "email", label: "Public email", input: "email", to: { path: "public_email" } },
|
||||
WEBSITE,
|
||||
{ key: "bio", label: "Short bio", input: "textarea", to: { path: "bio" } },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
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;
|
||||
const BY_ID = new Map(REQUEST_TYPES.map((t) => [t.id, t]));
|
||||
export const requestType = (id: string) => BY_ID.get(id);
|
||||
export const requestTypeLabel = (id: string) => BY_ID.get(id)?.label ?? id;
|
||||
|
||||
/* ── Into the admin editor ─────────────────────────────────────── */
|
||||
|
||||
/* What EntityEdit applies from a request (location.state.fromRequest):
|
||||
`set` fields by path, `add` child rows (links, a description
|
||||
paragraph). A new record gets all of it; an existing one lists each
|
||||
beside its current value to use or skip. */
|
||||
export type FromRequest = {
|
||||
request: number;
|
||||
set: { path: string; label: string; value: string }[];
|
||||
add: { child: string; label: string; row: Record<string, unknown> }[];
|
||||
};
|
||||
|
||||
export function fromRequest(
|
||||
row: { id: number; category: string; request_action: string; subject?: string | null; details?: Record<string, string> | null },
|
||||
): FromRequest | null {
|
||||
const type = requestType(row.category);
|
||||
if (!type) return null;
|
||||
const details = row.details ?? {};
|
||||
const set: FromRequest["set"] = [];
|
||||
const add: FromRequest["add"] = [];
|
||||
if (row.request_action === "new") {
|
||||
for (const [path, value] of Object.entries(type.preset ?? {})) set.push({ path, label: path, value });
|
||||
if (row.subject) set.push({ path: type.heading, label: "Name", value: row.subject });
|
||||
}
|
||||
for (const field of type.fields) {
|
||||
const value = details[field.key]?.trim();
|
||||
if (!value || !field.to) continue;
|
||||
if ("path" in field.to) set.push({ path: field.to.path, label: field.label, value });
|
||||
else if ("link" in field.to) {
|
||||
add.push({
|
||||
child: "links",
|
||||
label: `${field.label}: ${value}`,
|
||||
row: {
|
||||
kind: field.to.link,
|
||||
label: field.to.label,
|
||||
url: field.to.link === "email" && !value.startsWith("mailto:") ? `mailto:${value}` : value,
|
||||
is_primary: 0,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
add.push({
|
||||
child: "content_blocks",
|
||||
label: `${field.label} (a paragraph)`,
|
||||
row: { slot: field.to.block, type: "paragraph", text: value, items: [] },
|
||||
});
|
||||
}
|
||||
}
|
||||
return { request: row.id, set, add };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue