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
|
|
@ -273,7 +273,7 @@ The numbers band's "Number Source" dropdown works the same way:
|
||||||
| History page decade headers | `src/data/historyDecades.ts` | Title, tagline and blurb per decade. |
|
| History page decade headers | `src/data/historyDecades.ts` | Title, tagline and blurb per decade. |
|
||||||
| Chapter map tiles and area names | `src/data/mapGrid.ts` | `AREAS` (tile positions) and `AREA_NAMES`. Which region paints which tile is in the database (Admin → Data → Organizations → a region → Map areas). |
|
| Chapter map tiles and area names | `src/data/mapGrid.ts` | `AREAS` (tile positions) and `AREA_NAMES`. Which region paints which tile is in the database (Admin → Data → Organizations → a region → Map areas). |
|
||||||
| Feedback form types | `src/data/feedbackTypes.ts` **and** `TYPES` in `server/src/routes/feedback.js` | Keep the ids identical in both; the server stores unknown ids as `general`. Labels and hints are client-only. `DATA_REQUEST` ('privacy') isn't a tile: the Privacy page's form sends it, and the server requires an email for it. |
|
| Feedback form types | `src/data/feedbackTypes.ts` **and** `TYPES` in `server/src/routes/feedback.js` | Keep the ids identical in both; the server stores unknown ids as `general`. Labels and hints are client-only. `DATA_REQUEST` ('privacy') isn't a tile: the Privacy page's form sends it, and the server requires an email for it. |
|
||||||
| Request form types (what `/request` can ask for) | `src/data/requestTypes.ts` **and** `CATEGORIES` in `server/src/routes/requests.js` **and** the CHECK on `feedback.category` (`046_content_requests.sql`) | Ids and allowed actions (new, update) identical in all three; a new id needs a migration. Labels, hints and the name field's question are client-only. A button to the form opened on one type: `request: { type, label }` on a section manifest entry, or `<RequestLink>` (`src/components/RequestLink.tsx`). |
|
| Request form types (what `/request` can ask for) | `src/data/requestTypes.ts` **and** `CATEGORIES` in `server/src/routes/requests.js` **and** the CHECK on `feedback.category` (`046_content_requests.sql`) | Ids and allowed actions (new, update) identical in all three; a new id needs a migration. Labels, hints, the name field's question and each type's `fields` (the details it asks for, and where each lands in the admin editor: a field path, a link row or a description paragraph) are client-only: the server stores whatever detail keys come as JSON (`feedback.details`, 049), so adding a field needs no migration. A button to the form opened on one type: `request: { type, label }` on a section manifest entry, or `<RequestLink>` (`src/components/RequestLink.tsx`). |
|
||||||
| The site's colours, light and dark | the database over `src/index.css` | Admin → Panel → Site settings → Colours (superadmins): pick a colour, set its light and/or dark value; saving refuses anything that makes text hard to read. The defaults are `THEME_DEFAULTS` in `server/src/themeDefaults.js` (the admin and the contrast check read it) and the same values as CSS in `src/index.css`; the build stops if the two differ. The admin's labels for them are `THEME_LABELS` in `src/lib/adminSchema/siteSettings.ts`. Change a token's value in both modes and every use follows. Use the token utilities (`text-muted`, `bg-surface`, `border-brand/20`) or `var(--color-…)`, not hex. A colour that arrives as data (a page accent, an event's or region's colour) goes through `src/lib/color.ts`: `withAlpha` for tints, `accentText` for text in it, `readableOn` for text on it. |
|
| The site's colours, light and dark | the database over `src/index.css` | Admin → Panel → Site settings → Colours (superadmins): pick a colour, set its light and/or dark value; saving refuses anything that makes text hard to read. The defaults are `THEME_DEFAULTS` in `server/src/themeDefaults.js` (the admin and the contrast check read it) and the same values as CSS in `src/index.css`; the build stops if the two differ. The admin's labels for them are `THEME_LABELS` in `src/lib/adminSchema/siteSettings.ts`. Change a token's value in both modes and every use follows. Use the token utilities (`text-muted`, `bg-surface`, `border-brand/20`) or `var(--color-…)`, not hex. A colour that arrives as data (a page accent, an event's or region's colour) goes through `src/lib/color.ts`: `withAlpha` for tints, `accentText` for text in it, `readableOn` for text on it. |
|
||||||
| The icons a Front page "Find your way in" path can pick | `src/data/pathIcons.ts` (keys and labels) **and** `ICONS` in `src/pages/sections/home/Pathfinder.tsx` (the Phosphor icon for each key) | Add a line to both. A path saved with an emoji from before the list shows it as it is. |
|
| The icons a Front page "Find your way in" path can pick | `src/data/pathIcons.ts` (keys and labels) **and** `ICONS` in `src/pages/sections/home/Pathfinder.tsx` (the Phosphor icon for each key) | Add a line to both. A path saved with an emoji from before the list shows it as it is. |
|
||||||
| A page section's accent colour | `BRAND` and `ACCENTS` in `src/lib/color.ts` | Pages pick from these (`accent: ACCENTS.green`); add a colour there, not a hex in a page. Each is readable as text on white and the tints. |
|
| A page section's accent colour | `BRAND` and `ACCENTS` in `src/lib/color.ts` | Pages pick from these (`accent: ACCENTS.green`); add a colour there, not a hex in a page. Each is readable as text on white and the tints. |
|
||||||
|
|
|
||||||
12
server/src/migrations/049_request_details.sql
Normal file
12
server/src/migrations/049_request_details.sql
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
-- ═══════════════════════════════════════════════════════════════
|
||||||
|
-- 049 REQUEST DETAILS
|
||||||
|
--
|
||||||
|
-- The Request form's details for the record it's about (a chapter's
|
||||||
|
-- city, website and meeting time, an event's dates...), as one JSON
|
||||||
|
-- object of strings: { "city": "Kansas City", "meets": "..." }. Which
|
||||||
|
-- keys there are is src/data/requestTypes.ts's business; the server
|
||||||
|
-- only checks the shape (routes/requests.js). Forms → Content
|
||||||
|
-- requests shows them and opens the record's editor filled in.
|
||||||
|
-- ═══════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
ALTER TABLE feedback ADD COLUMN details TEXT CHECK (details IS NULL OR json_valid(details));
|
||||||
|
|
@ -30,7 +30,7 @@ const KIND_WHERE = {
|
||||||
content: "feedback_type = 'content'",
|
content: "feedback_type = 'content'",
|
||||||
};
|
};
|
||||||
const COLUMNS = `id, created_at, feedback_type, message, name, email, page_path, section_id,
|
const COLUMNS = `id, created_at, feedback_type, message, name, email, page_path, section_id,
|
||||||
status, admin_note, category, request_action, subject`;
|
status, admin_note, category, request_action, subject, details`;
|
||||||
|
|
||||||
/* Each row with its files (content requests), in one query. */
|
/* Each row with its files (content requests), in one query. */
|
||||||
function withFiles(db, rows) {
|
function withFiles(db, rows) {
|
||||||
|
|
@ -43,6 +43,8 @@ function withFiles(db, rows) {
|
||||||
.all(...rows.map((r) => r.id));
|
.all(...rows.map((r) => r.id));
|
||||||
return rows.map((row) => ({
|
return rows.map((row) => ({
|
||||||
...row,
|
...row,
|
||||||
|
// Stored as JSON text (049); the admin wants the object.
|
||||||
|
details: row.details ? JSON.parse(row.details) : null,
|
||||||
files: files.filter((f) => f.feedback_id === row.id).map(({ feedback_id, ...f }) => f),
|
files: files.filter((f) => f.feedback_id === row.id).map(({ feedback_id, ...f }) => f),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,29 @@ const CATEGORIES = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const LIMITS = { name: 120, email: 254, subject: 200, message: 5000 };
|
const LIMITS = { name: 120, email: 254, subject: 200, message: 5000 };
|
||||||
|
// details (049): at most this many keys, each value this long.
|
||||||
|
const MAX_DETAILS = 30;
|
||||||
|
const MAX_DETAIL = 2000;
|
||||||
|
|
||||||
|
/* The form's details as a JSON object of short strings, or null.
|
||||||
|
Which keys exist is the client's (requestTypes.ts); anything that
|
||||||
|
isn't a plain key with a string value is dropped, as are blanks. */
|
||||||
|
export function cleanDetails(raw) {
|
||||||
|
let parsed;
|
||||||
|
try {
|
||||||
|
parsed = JSON.parse(raw || "null");
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
||||||
|
const out = {};
|
||||||
|
for (const [key, value] of Object.entries(parsed).slice(0, MAX_DETAILS)) {
|
||||||
|
if (!/^[a-z_]{1,40}$/.test(key) || typeof value !== "string") continue;
|
||||||
|
const text = value.trim().slice(0, MAX_DETAIL);
|
||||||
|
if (text) out[key] = text;
|
||||||
|
}
|
||||||
|
return Object.keys(out).length ? out : null;
|
||||||
|
}
|
||||||
const MIN_MESSAGE = 10;
|
const MIN_MESSAGE = 10;
|
||||||
// Where in the shared drive the files go (googleService.js).
|
// Where in the shared drive the files go (googleService.js).
|
||||||
const DRIVE_FOLDER = "Requests";
|
const DRIVE_FOLDER = "Requests";
|
||||||
|
|
@ -87,6 +110,7 @@ requests.post(
|
||||||
const message = field("message", LIMITS.message);
|
const message = field("message", LIMITS.message);
|
||||||
const name = field("name", LIMITS.name);
|
const name = field("name", LIMITS.name);
|
||||||
const email = field("email", LIMITS.email);
|
const email = field("email", LIMITS.email);
|
||||||
|
const details = cleanDetails(field("details", MAX_DETAILS * (MAX_DETAIL + 60)));
|
||||||
const files = [body.files ?? []].flat().filter((f) => f instanceof File && f.size > 0);
|
const files = [body.files ?? []].flat().filter((f) => f instanceof File && f.size > 0);
|
||||||
|
|
||||||
const errors = {};
|
const errors = {};
|
||||||
|
|
@ -122,10 +146,20 @@ requests.post(
|
||||||
db
|
db
|
||||||
.prepare(
|
.prepare(
|
||||||
`INSERT INTO feedback
|
`INSERT INTO feedback
|
||||||
(feedback_type, category, request_action, subject, message, name, email, user_agent, ip_hash)
|
(feedback_type, category, request_action, subject, details, message, name, email, user_agent, ip_hash)
|
||||||
VALUES ('content', ?, ?, ?, ?, ?, ?, ?, ?)`,
|
VALUES ('content', ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||||
|
)
|
||||||
|
.run(
|
||||||
|
category,
|
||||||
|
action,
|
||||||
|
subject,
|
||||||
|
details ? JSON.stringify(details) : null,
|
||||||
|
message,
|
||||||
|
name || null,
|
||||||
|
email,
|
||||||
|
clean(c.req.header("user-agent"), 500) || null,
|
||||||
|
hashIp(clientIp(c)),
|
||||||
)
|
)
|
||||||
.run(category, action, subject, message, name || null, email, clean(c.req.header("user-agent"), 500) || null, hashIp(clientIp(c)))
|
|
||||||
.lastInsertRowid,
|
.lastInsertRowid,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -153,6 +187,7 @@ requests.post(
|
||||||
`${action === "new" ? "New" : "Update"} ${category}: ${subject}`,
|
`${action === "new" ? "New" : "Update"} ${category}: ${subject}`,
|
||||||
`From: ${name ? `${name} <${email}>` : email}`,
|
`From: ${name ? `${name} <${email}>` : email}`,
|
||||||
...(stored.length ? [`Files: ${stored.map((f) => f.name).join(", ")}`] : []),
|
...(stored.length ? [`Files: ${stored.map((f) => f.name).join(", ")}`] : []),
|
||||||
|
...Object.entries(details ?? {}).map(([key, value]) => `${key.replace(/_/g, " ")}: ${value}`),
|
||||||
"",
|
"",
|
||||||
message,
|
message,
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,7 @@ export function FilePicker({
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
if (e.target === dialogRef.current) dialogRef.current?.close();
|
if (e.target === dialogRef.current) dialogRef.current?.close();
|
||||||
}}
|
}}
|
||||||
className="w-[min(48rem,calc(100vw-2rem))] rounded-2xl p-0 backdrop:bg-[#0f2f36]/40"
|
className="m-auto w-[min(48rem,calc(100vw-2rem))] rounded-2xl p-0 backdrop:bg-[#0f2f36]/40"
|
||||||
>
|
>
|
||||||
<div className="flex max-h-[85vh] flex-col">
|
<div className="flex max-h-[85vh] flex-col">
|
||||||
<div className="flex flex-wrap items-center gap-3 border-b border-brand/15 px-5 py-4">
|
<div className="flex flex-wrap items-center gap-3 border-b border-brand/15 px-5 py-4">
|
||||||
|
|
|
||||||
|
|
@ -290,7 +290,7 @@ export function MediaPicker({
|
||||||
// A click on the backdrop lands on the dialog itself.
|
// A click on the backdrop lands on the dialog itself.
|
||||||
if (e.target === dialogRef.current) dialogRef.current?.close();
|
if (e.target === dialogRef.current) dialogRef.current?.close();
|
||||||
}}
|
}}
|
||||||
className="w-[min(56rem,calc(100vw-2rem))] rounded-2xl p-0 backdrop:bg-[#0f2f36]/40"
|
className="m-auto w-[min(56rem,calc(100vw-2rem))] rounded-2xl p-0 backdrop:bg-[#0f2f36]/40"
|
||||||
>
|
>
|
||||||
<div className="flex max-h-[85vh] flex-col">
|
<div className="flex max-h-[85vh] flex-col">
|
||||||
<div className="flex flex-wrap items-center gap-3 border-b border-brand/15 px-5 py-4">
|
<div className="flex flex-wrap items-center gap-3 border-b border-brand/15 px-5 py-4">
|
||||||
|
|
|
||||||
|
|
@ -9,29 +9,230 @@
|
||||||
A link can open the form on one: requestLink("chapter") is
|
A link can open the form on one: requestLink("chapter") is
|
||||||
/request?type=chapter. People, teams and awards have no buttons on
|
/request?type=chapter. People, teams and awards have no buttons on
|
||||||
the site, but are here to pick.
|
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 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;
|
id: string;
|
||||||
label: string;
|
label: string;
|
||||||
hint: string;
|
hint: string;
|
||||||
actions: RequestAction[];
|
actions: RequestAction[];
|
||||||
// What the name field asks, for a new one and for an update.
|
// What the name field asks, for a new one and for an update.
|
||||||
subject: string;
|
subject: string;
|
||||||
}[] = [
|
entity: string;
|
||||||
{ id: "blog", label: "Blog post", hint: "A story or article for the community blog", actions: ["new"], subject: "Its title" },
|
heading: string;
|
||||||
{ id: "event", label: "Event", hint: "A retreat, gathering or calendar event", actions: ["new", "update"], subject: "The event's name" },
|
preset?: Record<string, string>;
|
||||||
{ id: "chapter", label: "Chapter", hint: "A local NGU chapter", actions: ["new", "update"], subject: "The chapter's name" },
|
fields: RequestField[];
|
||||||
{ 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" },
|
const CITY: RequestField = { key: "city", label: "City", to: { path: "locality" } };
|
||||||
{ id: "award", label: "Award", hint: "An award and who received it", actions: ["new", "update"], subject: "The award's name" },
|
const STATE: RequestField = { key: "state", label: "State or province", placeholder: "eg. MO", to: { path: "state_code" } };
|
||||||
{ id: "person", label: "Person", hint: "Someone's profile", actions: ["new", "update"], subject: "Their name" },
|
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}`;
|
export const requestLink = (type: string) => `/request?type=${type}`;
|
||||||
|
|
||||||
const BY_ID = new Map(REQUEST_TYPES.map((t) => [t.id, t.label]));
|
const BY_ID = new Map(REQUEST_TYPES.map((t) => [t.id, t]));
|
||||||
export const requestTypeLabel = (id: string) => BY_ID.get(id) ?? id;
|
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 };
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import { del, get, patch, post, ApiError } from "../../lib/api.ts";
|
||||||
import { isUnauthorized, useAuth } from "../../lib/auth.tsx";
|
import { isUnauthorized, useAuth } from "../../lib/auth.tsx";
|
||||||
import { canWrite as roleCanWrite, canDelete } from "../../lib/roles.ts";
|
import { canWrite as roleCanWrite, canDelete } from "../../lib/roles.ts";
|
||||||
import { feedbackTypeLabel } from "../../data/feedbackTypes.ts";
|
import { feedbackTypeLabel } from "../../data/feedbackTypes.ts";
|
||||||
import { requestTypeLabel } from "../../data/requestTypes.ts";
|
import { fromRequest, requestType, requestTypeLabel } from "../../data/requestTypes.ts";
|
||||||
|
|
||||||
const STATUSES = ["new", "read", "actioned", "archived", "spam"];
|
const STATUSES = ["new", "read", "actioned", "archived", "spam"];
|
||||||
|
|
||||||
|
|
@ -104,6 +104,111 @@ function RequestFiles({ row, canWrite }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* A content request's details (049), labelled from requestTypes.ts;
|
||||||
|
keys it no longer knows are shown as they are. */
|
||||||
|
function RequestDetails({ row }) {
|
||||||
|
const entries = Object.entries(row.details ?? {});
|
||||||
|
if (entries.length === 0) return null;
|
||||||
|
const labels = new Map((requestType(row.category)?.fields ?? []).map((f) => [f.key, f.label]));
|
||||||
|
return (
|
||||||
|
<dl className="mt-4 grid gap-x-6 gap-y-2 text-sm sm:grid-cols-[max-content_1fr]">
|
||||||
|
{entries.map(([key, value]) => (
|
||||||
|
<div key={key} className="contents">
|
||||||
|
<dt className="font-medium text-muted">{labels.get(key) ?? key.replace(/_/g, " ")}</dt>
|
||||||
|
<dd className="whitespace-pre-wrap text-body">{value as string}</dd>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</dl>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The record a request is about, in its editor: a new one filled in
|
||||||
|
from the request, or, for an update, the existing one (picked here,
|
||||||
|
the closest name first) with the requested values beside its own.
|
||||||
|
Nothing is saved until Save in the editor. */
|
||||||
|
function RequestRecord({ row }) {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const type = requestType(row.category);
|
||||||
|
const [candidates, setCandidates] = useState<any[] | null>(null);
|
||||||
|
const [picked, setPicked] = useState("");
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
if (!type) return null;
|
||||||
|
|
||||||
|
const state = { fromRequest: fromRequest(row) };
|
||||||
|
const button =
|
||||||
|
"rounded-full border border-link px-4 py-1.5 text-sm font-semibold text-link transition-colors hover:bg-tint disabled:opacity-60";
|
||||||
|
|
||||||
|
if (row.request_action === "new") {
|
||||||
|
return (
|
||||||
|
<div className="mt-4">
|
||||||
|
<button type="button" className={button} onClick={() => navigate(`/admin/${type.entity}/new`, { state })}>
|
||||||
|
Create {type.label.toLowerCase()} from this
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function find() {
|
||||||
|
if (!type) return;
|
||||||
|
setError(null);
|
||||||
|
try {
|
||||||
|
const params = new URLSearchParams({ limit: "500", ...(type.preset ?? {}) });
|
||||||
|
const { rows } = await get(`/admin/${type.entity}?${params}`, { ttl: 0 });
|
||||||
|
const wanted = String(row.subject ?? "").toLowerCase().trim();
|
||||||
|
const name = (r) => String(r[type.heading] ?? r.id);
|
||||||
|
// The closest name first: exact, then containing, then the rest.
|
||||||
|
const score = (r) => {
|
||||||
|
const n = name(r).toLowerCase();
|
||||||
|
return n === wanted ? 0 : wanted && (n.includes(wanted) || wanted.includes(n)) ? 1 : 2;
|
||||||
|
};
|
||||||
|
const sorted = [...rows].sort((a, b) => score(a) - score(b) || name(a).localeCompare(name(b)));
|
||||||
|
setCandidates(sorted.map((r) => ({ id: r.id, name: name(r) })));
|
||||||
|
setPicked(sorted[0]?.id ?? "");
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof ApiError ? err.message : "Couldn't load the list.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mt-4 flex flex-wrap items-center gap-3">
|
||||||
|
{candidates === null ? (
|
||||||
|
<button type="button" className={button} onClick={find}>
|
||||||
|
Find the {type.label.toLowerCase()} to update
|
||||||
|
</button>
|
||||||
|
) : candidates.length === 0 ? (
|
||||||
|
<span className="text-sm text-muted">No {type.label.toLowerCase()} records yet.</span>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<label htmlFor={`record-${row.id}`} className="sr-only">
|
||||||
|
Which {type.label.toLowerCase()}
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
id={`record-${row.id}`}
|
||||||
|
value={picked}
|
||||||
|
onChange={(e) => setPicked(e.target.value)}
|
||||||
|
className="rounded-lg border border-muted/25 bg-surface px-3 py-1.5 text-sm text-body outline-none focus:border-brand focus:ring-2 focus:ring-brand/25"
|
||||||
|
>
|
||||||
|
{candidates.map((c) => (
|
||||||
|
<option key={c.id} value={c.id}>
|
||||||
|
{c.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={button}
|
||||||
|
disabled={!picked}
|
||||||
|
onClick={() => navigate(`/admin/${type.entity}/${encodeURIComponent(picked)}`, { state })}
|
||||||
|
>
|
||||||
|
Open it with the requested changes
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{error && <span className="text-sm text-danger">{error}</span>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function locationOf(row) {
|
function locationOf(row) {
|
||||||
if (!row.page_path) return "Not page-specific";
|
if (!row.page_path) return "Not page-specific";
|
||||||
return row.section_id ? `${row.page_path} #${row.section_id}` : row.page_path;
|
return row.section_id ? `${row.page_path} #${row.section_id}` : row.page_path;
|
||||||
|
|
@ -170,7 +275,9 @@ function FeedbackCard({ row, onChange, onRemove, canWrite, canRemove }) {
|
||||||
|
|
||||||
{row.subject && <h2 className="mt-4 text-lg font-semibold text-body">{row.subject}</h2>}
|
{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>
|
<p className={`${row.subject ? "mt-2" : "mt-4"} whitespace-pre-wrap text-body`}>{row.message}</p>
|
||||||
|
{row.feedback_type === "content" && <RequestDetails row={row} />}
|
||||||
{row.files?.length > 0 && <RequestFiles row={row} canWrite={canWrite} />}
|
{row.files?.length > 0 && <RequestFiles row={row} canWrite={canWrite} />}
|
||||||
|
{row.feedback_type === "content" && canWrite && <RequestRecord row={row} />}
|
||||||
|
|
||||||
<p className="mt-4 text-sm text-muted">
|
<p className="mt-4 text-sm text-muted">
|
||||||
{row.name || row.email ? (
|
{row.name || row.email ? (
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,10 @@ export default function EntityEdit() {
|
||||||
useWideAdminPage();
|
useWideAdminPage();
|
||||||
|
|
||||||
const isNew = id === "new";
|
const isNew = id === "new";
|
||||||
|
// From Forms → Content requests (requestTypes.ts, fromRequest): a
|
||||||
|
// new record starts filled in with it; an existing one shows it in
|
||||||
|
// RequestedChanges to use value by value.
|
||||||
|
const fromRequest = (useLocation().state as any)?.fromRequest ?? null;
|
||||||
// Editor, unless the entity asks for more (site settings:
|
// Editor, unless the entity asks for more (site settings:
|
||||||
// superadmin), matching the server's writeRole.
|
// superadmin), matching the server's writeRole.
|
||||||
const canWrite = atLeast(user, manifest?.writeRole ?? "editor");
|
const canWrite = atLeast(user, manifest?.writeRole ?? "editor");
|
||||||
|
|
@ -172,8 +176,18 @@ export default function EntityEdit() {
|
||||||
// sending "" would be an explicit value rather than an absence.
|
// sending "" would be an explicit value rather than an absence.
|
||||||
const blank = autoId ? {} : { id: "" };
|
const blank = autoId ? {} : { id: "" };
|
||||||
for (const child of manifest.children ?? []) blank[child.key] = [];
|
for (const child of manifest.children ?? []) blank[child.key] = [];
|
||||||
setForm(blank);
|
// The baseline stays the empty form, so a filled-in one counts
|
||||||
|
// as unsaved until Create.
|
||||||
baseline.current = JSON.stringify(blank);
|
baseline.current = JSON.stringify(blank);
|
||||||
|
let start: any = blank;
|
||||||
|
if (fromRequest) {
|
||||||
|
for (const item of fromRequest.set) start = setPath(start, item.path, item.value);
|
||||||
|
for (const item of fromRequest.add) start = { ...start, [item.child]: [...(start[item.child] ?? []), item.row] };
|
||||||
|
if (!autoId && headingPath) {
|
||||||
|
start = { ...start, id: `${prefixOf(start)}${slugify(getPath(start, headingPath) ?? "")}` };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setForm(start);
|
||||||
} else {
|
} else {
|
||||||
const data = await get(`/admin/${manifest.key}/${id}`, { ttl: 0 });
|
const data = await get(`/admin/${manifest.key}/${id}`, { ttl: 0 });
|
||||||
setForm(data.row);
|
setForm(data.row);
|
||||||
|
|
@ -189,7 +203,8 @@ export default function EntityEdit() {
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, [manifest, id, isNew, autoId, navigate]);
|
// prefixOf and headingPath follow the manifest, already a dependency.
|
||||||
|
}, [manifest, id, isNew, autoId, navigate, fromRequest]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
load();
|
load();
|
||||||
|
|
@ -368,6 +383,15 @@ export default function EntityEdit() {
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<ImportedNote />
|
<ImportedNote />
|
||||||
|
{fromRequest && (
|
||||||
|
<RequestedChanges
|
||||||
|
request={fromRequest}
|
||||||
|
isNew={isNew}
|
||||||
|
form={form}
|
||||||
|
onUse={change}
|
||||||
|
onAdd={(child, row) => setForm((prev) => ({ ...prev, [child]: [...(prev[child] ?? []), row] }))}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Straight in the page, not wrapped: a sticky element only
|
{/* Straight in the page, not wrapped: a sticky element only
|
||||||
travels within its parent, so its parent has to be tall. */}
|
travels within its parent, so its parent has to be tall. */}
|
||||||
|
|
@ -551,3 +575,74 @@ function ImportedNote() {
|
||||||
</p>
|
</p>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* From a content request (Forms → Content requests). A new record
|
||||||
|
is already filled in: this says so. An existing one lists each
|
||||||
|
requested value beside the current one, to use or leave; nothing
|
||||||
|
changes until it's used, and nothing is saved until Save. */
|
||||||
|
function RequestedChanges({ request, isNew, form, onUse, onAdd }: any) {
|
||||||
|
const [done, setDone] = useState<Set<string>>(() => new Set());
|
||||||
|
const mark = (key: string) => setDone((prev) => new Set(prev).add(key));
|
||||||
|
const button = "rounded-full border border-link px-3 py-0.5 text-xs font-semibold text-link transition-colors hover:bg-tint";
|
||||||
|
|
||||||
|
if (isNew) {
|
||||||
|
return (
|
||||||
|
<p role="status" className="mt-4 rounded-xl border border-brand/20 bg-tint px-4 py-3 text-sm text-body">
|
||||||
|
Filled in from content request #{request.request}. Check it, fill in the rest, then Create. It isn't saved yet.
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const items = [
|
||||||
|
...request.set.map((item) => ({ key: `set:${item.path}`, ...item, current: getPath(form, item.path) })),
|
||||||
|
...request.add.map((item, i) => ({ key: `add:${i}`, ...item })),
|
||||||
|
];
|
||||||
|
if (items.length === 0) {
|
||||||
|
return (
|
||||||
|
<p className="mt-4 rounded-xl border border-brand/20 bg-tint px-4 py-3 text-sm text-body">
|
||||||
|
Content request #{request.request} has no details to copy; its message is in Forms → Content requests.
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mt-4 rounded-xl border border-brand/20 bg-tint px-4 py-3 text-sm text-body">
|
||||||
|
<p className="font-semibold">Requested in content request #{request.request}</p>
|
||||||
|
<p className="mt-0.5 text-xs text-muted">Use what should change, then Save changes.</p>
|
||||||
|
<ul className="mt-3 space-y-2">
|
||||||
|
{items.map((item) => (
|
||||||
|
<li key={item.key} className="flex flex-wrap items-baseline gap-x-3 gap-y-1">
|
||||||
|
<span className="font-medium">{item.label}</span>
|
||||||
|
{"path" in item ? (
|
||||||
|
<>
|
||||||
|
<span className="text-muted">
|
||||||
|
now {item.current ? <q>{String(item.current)}</q> : "blank"}, requested <q>{item.value}</q>
|
||||||
|
</span>
|
||||||
|
{done.has(item.key) || String(item.current ?? "") === item.value ? (
|
||||||
|
<span className="text-xs text-muted">in the form</span>
|
||||||
|
) : (
|
||||||
|
<button type="button" className={button} onClick={() => {
|
||||||
|
onUse(item.path, item.value);
|
||||||
|
mark(item.key);
|
||||||
|
}}>
|
||||||
|
Use this
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
) : done.has(item.key) ? (
|
||||||
|
<span className="text-xs text-muted">added below</span>
|
||||||
|
) : (
|
||||||
|
<button type="button" className={button} onClick={() => {
|
||||||
|
onAdd(item.child, item.row);
|
||||||
|
mark(item.key);
|
||||||
|
}}>
|
||||||
|
Add it
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,10 @@
|
||||||
?type=chapter in the address picks one to start with, which is how
|
?type=chapter in the address picks one to start with, which is how
|
||||||
the site's "Request" buttons open it.
|
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
|
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
|
(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.
|
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 [files, setFiles] = useState<File[]>([]);
|
||||||
const [name, setName] = useState("");
|
const [name, setName] = useState("");
|
||||||
const [email, setEmail] = 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 [website, setWebsite] = useState(""); // honeypot
|
||||||
|
|
||||||
const [status, setStatus] = useState<"idle" | "sending" | "sent">("idle");
|
const [status, setStatus] = useState<"idle" | "sending" | "sent">("idle");
|
||||||
|
|
@ -92,6 +98,15 @@ export default function RequestForm() {
|
||||||
form.set("message", message.trim());
|
form.set("message", message.trim());
|
||||||
form.set("name", name.trim());
|
form.set("name", name.trim());
|
||||||
form.set("email", email.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);
|
form.set("website", website);
|
||||||
for (const file of files) form.append("files", file);
|
for (const file of files) form.append("files", file);
|
||||||
|
|
||||||
|
|
@ -111,6 +126,7 @@ export default function RequestForm() {
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
setSubject("");
|
setSubject("");
|
||||||
|
setDetails({});
|
||||||
setMessage("");
|
setMessage("");
|
||||||
setFiles([]);
|
setFiles([]);
|
||||||
setStatus("idle");
|
setStatus("idle");
|
||||||
|
|
@ -204,6 +220,45 @@ export default function RequestForm() {
|
||||||
<FieldError id="request-subject-error">{fieldErrors.subject}</FieldError>
|
<FieldError id="request-subject-error">{fieldErrors.subject}</FieldError>
|
||||||
</div>
|
</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">
|
<div className="mt-8">
|
||||||
<label htmlFor="request-message" className="text-base font-semibold text-body">
|
<label htmlFor="request-message" className="text-base font-semibold text-body">
|
||||||
{action === "update" ? "What should change?" : "Tell us about it"}
|
{action === "update" ? "What should change?" : "Tell us about it"}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue