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
|
|
@ -39,6 +39,29 @@ const CATEGORIES = {
|
|||
};
|
||||
|
||||
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;
|
||||
// Where in the shared drive the files go (googleService.js).
|
||||
const DRIVE_FOLDER = "Requests";
|
||||
|
|
@ -87,6 +110,7 @@ requests.post(
|
|||
const message = field("message", LIMITS.message);
|
||||
const name = field("name", LIMITS.name);
|
||||
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 errors = {};
|
||||
|
|
@ -122,10 +146,20 @@ requests.post(
|
|||
db
|
||||
.prepare(
|
||||
`INSERT INTO feedback
|
||||
(feedback_type, category, request_action, subject, message, name, email, user_agent, ip_hash)
|
||||
VALUES ('content', ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
(feedback_type, category, request_action, subject, details, message, name, email, user_agent, ip_hash)
|
||||
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,
|
||||
);
|
||||
|
||||
|
|
@ -153,6 +187,7 @@ requests.post(
|
|||
`${action === "new" ? "New" : "Update"} ${category}: ${subject}`,
|
||||
`From: ${name ? `${name} <${email}>` : email}`,
|
||||
...(stored.length ? [`Files: ${stored.map((f) => f.name).join(", ")}`] : []),
|
||||
...Object.entries(details ?? {}).map(([key, value]) => `${key.replace(/_/g, " ")}: ${value}`),
|
||||
"",
|
||||
message,
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue