From 322c575fcbe9c3a9e3776af148877871c95b4134 Mon Sep 17 00:00:00 2001 From: blake Date: Mon, 19 Oct 2026 10:43:35 -0500 Subject: [PATCH] fix: clarify the confirmation page and collect first and last names The confirmation told volunteers an email was queued and to open "this signup." It now says the email is on the way and the link cancels or switches shifts. The public form asks for a first and last name so the stored name stays one person. --- README.md | 2 +- public/css/app.css | 16 +++++++++++++-- src/admin-http.tsx | 2 ++ src/pages.tsx | 39 +++++++++++++++++++++++++++-------- src/signup-form.ts | 42 +++++++++++++++++++++++++++++++------- src/signup-http.tsx | 4 +++- tests/cancel.test.ts | 3 ++- tests/mail.test.ts | 3 ++- tests/other-shifts.test.ts | 3 ++- tests/public-pages.test.ts | 4 ++++ tests/signup.test.ts | 34 ++++++++++++++++++++++++++---- 11 files changed, 126 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index cdcf86d..b71e2ef 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ npm run seed Open `/` for the weekly pantry schedule. `/e/weekly-pantry` is the same seeded event. `/privacy` is the unapproved privacy notice. `/healthz` returns `{"ok":true,"database":"ok"}` and nothing else. Volunteer names, emails, and notes are not on the public list. A shift shows how many spots are filled, such as 3/5 spots filled. A shift with space left uses a soft green label. A full shift uses a soft red label. -An open shift has a signup form. It asks for one person. Another person can use the same email and takes another spot. The same person cannot take a second spot. It asks for a parent or guardian when the volunteer is under 18. The form needs JavaScript because of the Turnstile check. Wait a few seconds after the page loads before submitting. The confirmation page shows a private link and says a confirmation email is queued. That page works without JavaScript. Cancel this signup there to open the spot again. A cancellation email is queued, and a confirmation that has not been sent yet is dropped. That person can sign up again once the cancellation is saved. Someone else can use the email while the first signup is still confirmed. A cancelled signup stays on that private page until the link expires. A private link controls only that signup. Use the separate link for each signup. +An open shift has a signup form. It asks for one person. Another person can use the same email and takes another spot. The same person cannot take a second spot. It asks for a parent or guardian when the volunteer is under 18. The form needs JavaScript because of the Turnstile check. Wait a few seconds after the page loads before submitting. The confirmation page shows a private link and says a confirmation email is on the way. That page works without JavaScript. Cancel this signup there to open the spot again. A cancellation email is queued, and a confirmation that has not been sent yet is dropped. That person can sign up again once the cancellation is saved. Someone else can use the email while the first signup is still confirmed. A cancelled signup stays on that private page until the link expires. A private link controls only that signup. Use the separate link for each signup. With `MAIL_DRIVER=console`, the development server tries to send queued mail every 30 seconds and prints each accepted message in its terminal. That is not delivery to a real inbox. `sent` means the driver accepted the message. A lost result is marked uncertain and is not sent again. SMTP2GO is the mail provider. Set `MAIL_DRIVER=smtp2go` and `SMTP2GO_API_KEY` to send through it. Postmark and SES remain available. diff --git a/public/css/app.css b/public/css/app.css index 8c1e458..8562c04 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -872,7 +872,8 @@ article.shift-card { } .spots.is-open, -.spots.is-full { +.spots.is-full, +.status.is-confirmed { display: inline-block; width: fit-content; margin-top: 0.45rem; @@ -881,7 +882,8 @@ article.shift-card { color: var(--hope-ink); } -.spots.is-open { +.spots.is-open, +.status.is-confirmed { background: var(--hope-open); border: 1px solid var(--hope-open-edge); } @@ -962,6 +964,12 @@ article.shift-card { font-size: 1.6rem; } +.name-pair { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 0.95rem; +} + .signup-form label, .signup-form fieldset, .move-form label { @@ -2280,6 +2288,10 @@ button.btn-quiet::before { .desk-range label { max-width: none; } + + .name-pair { + grid-template-columns: 1fr; + } } @media (max-width: 33em) { diff --git a/src/admin-http.tsx b/src/admin-http.tsx index ab70f7d..bf716c8 100644 --- a/src/admin-http.tsx +++ b/src/admin-http.tsx @@ -1519,6 +1519,8 @@ function isAttendanceMark(value: string): value is AttendanceMark { function signupValuesFrom(body: Record): SignupValues { return { name: textField(body, 'name'), + firstName: '', + lastName: '', email: textField(body, 'email'), phone: textField(body, 'phone'), notes: textField(body, 'notes'), diff --git a/src/pages.tsx b/src/pages.tsx index 21fa01b..57309a5 100644 --- a/src/pages.tsx +++ b/src/pages.tsx @@ -288,23 +288,23 @@ export function ConfirmationPage(props: {

{props.cancelled ? 'This signup is cancelled' : "You're signed up"}

{props.cancelled - ? `${props.name ? `${props.name} is no longer signed up for ` : 'This signup is no longer for '}${props.shift.role}.` - : `${props.name ? `${props.name} is signed up for ` : 'This signup is for '}${props.shift.role}.`} + ? `${props.name ? `${props.name} is no longer on the ` : 'This signup is no longer for the '}${props.shift.role} shift.` + : `${props.name ? `${props.name} is on the ` : 'This signup is for the '}${props.shift.role} shift.`}

{props.managePath ? ( <>

{props.cancelled - ? 'A cancellation email is queued. This link still opens the cancelled signup.' - : 'A confirmation email is queued. Save this link too, in case the email is delayed. It opens this signup, where you can cancel it or switch it to another open shift.'} + ? 'A cancellation email is on the way. The link below still opens this cancelled signup.' + : 'A confirmation email is on the way. Save the link below in case the email is late. Use it to cancel or switch to a different shift.'}

- Open this signup + {props.cancelled ? 'View this signup' : 'Cancel or switch shifts'}

) : ( -

If you just signed up, the link stays in this browser for a few minutes. A confirmation email is queued.

+

If you just signed up, the link stays in this browser for a few minutes. A confirmation email is on the way.

)} ); @@ -329,7 +329,7 @@ export function ManagePage(props: { return ( <>

Your signup

-

{signup.status === 'confirmed' ? 'Confirmed' : 'Cancelled'}

+

{signup.status === 'confirmed' ? 'Confirmed' : 'Cancelled'}

{signup.eventTitle}

{signup.role}

@@ -739,7 +739,28 @@ function SignupForm(props: { config: AppConfig; shiftId: number; form: SignupFor - +

+ + +
diff --git a/src/signup-form.ts b/src/signup-form.ts index 8b0c24c..36df51a 100644 --- a/src/signup-form.ts +++ b/src/signup-form.ts @@ -8,6 +8,8 @@ const NOTES_MAX = 500; export type SignupValues = { name: string; + firstName: string; + lastName: string; email: string; phone: string; notes: string; @@ -16,7 +18,9 @@ export type SignupValues = { guardianEmail: string; }; -export type SignupErrors = Partial>; +export type SignupErrors = Partial< + Record<'name' | 'firstName' | 'lastName' | 'email' | 'phone' | 'notes' | 'guardianName' | 'guardianEmail' | 'form', string> +>; export type SignupDraft = { name: string; @@ -32,6 +36,8 @@ export type SignupDraft = { export const EMPTY_SIGNUP: SignupValues = { name: '', + firstName: '', + lastName: '', email: '', phone: '', notes: '', @@ -42,6 +48,15 @@ export const EMPTY_SIGNUP: SignupValues = { const controlChars = /[\u0000-\u001F\u007F]/; +function personPart(raw: string, label: string): { value: string; error?: string } { + const trimmed = raw.normalize('NFC').trim(); + const value = capitalizeName(trimmed); + if (trimmed.length === 0 || value.length === 0) return { value: '', error: `Enter your ${label}.` }; + if (trimmed.length > NAME_MAX || value.length > NAME_MAX) return { value, error: `Use ${NAME_MAX} characters or fewer.` }; + if (controlChars.test(trimmed)) return { value, error: `Enter your ${label} without line breaks.` }; + return { value }; +} + export function parseSignupForm( input: SignupValues, voice: 'volunteer' | 'coordinator' = 'volunteer', @@ -49,6 +64,8 @@ export function parseSignupForm( const parsed = z .object({ name: z.string(), + firstName: z.string(), + lastName: z.string(), email: z.string(), phone: z.string(), notes: z.string(), @@ -59,12 +76,23 @@ export function parseSignupForm( .safeParse(input); if (!parsed.success) return { ok: false, errors: { form: 'Check the signup fields and try again.' } }; const errors: SignupErrors = {}; - const nameRaw = parsed.data.name.normalize('NFC').trim(); - const name = capitalizeName(nameRaw); - const nameLabel = voice === 'coordinator' ? 'their name' : 'your name'; - if (nameRaw.length === 0 || name.length === 0) errors.name = `Enter ${nameLabel}.`; - else if (nameRaw.length > NAME_MAX || name.length > NAME_MAX) errors.name = `Use ${NAME_MAX} characters or fewer.`; - else if (controlChars.test(nameRaw)) errors.name = `Enter ${nameLabel} without line breaks.`; + let name = ''; + if (voice === 'coordinator') { + const nameRaw = parsed.data.name.normalize('NFC').trim(); + name = capitalizeName(nameRaw); + if (nameRaw.length === 0 || name.length === 0) errors.name = 'Enter their name.'; + else if (nameRaw.length > NAME_MAX || name.length > NAME_MAX) errors.name = `Use ${NAME_MAX} characters or fewer.`; + else if (controlChars.test(nameRaw)) errors.name = 'Enter their name without line breaks.'; + } else { + const first = personPart(parsed.data.firstName, 'first name'); + const last = personPart(parsed.data.lastName, 'last name'); + if (first.error) errors.firstName = first.error; + if (last.error) errors.lastName = last.error; + if (!first.error && !last.error && `${first.value} ${last.value}`.length > NAME_MAX) { + errors.lastName = `Use ${NAME_MAX} characters or fewer for the full name.`; + } + name = first.error || last.error || errors.lastName ? '' : `${first.value} ${last.value}`; + } let emailNorm = ''; try { diff --git a/src/signup-http.tsx b/src/signup-http.tsx index c3a51eb..4ebd1bb 100644 --- a/src/signup-http.tsx +++ b/src/signup-http.tsx @@ -277,7 +277,9 @@ function loadShift(services: SignupServices, rawId: string): PublicShift | null function valuesFrom(body: Record): SignupValues { return { - name: textField(body, 'name'), + name: '', + firstName: textField(body, 'first_name'), + lastName: textField(body, 'last_name'), email: textField(body, 'email'), phone: textField(body, 'phone'), notes: textField(body, 'notes'), diff --git a/tests/cancel.test.ts b/tests/cancel.test.ts index 366b12a..f2de987 100644 --- a/tests/cancel.test.ts +++ b/tests/cancel.test.ts @@ -341,7 +341,8 @@ async function postSignup( issuedAt: NOW_MS - 10_000, operationId: randomBytes(16).toString('hex'), }), - name: fields.name, + first_name: fields.name.slice(0, fields.name.indexOf(' ')), + last_name: fields.name.slice(fields.name.indexOf(' ') + 1), email: fields.email, phone: '', notes: '', diff --git a/tests/mail.test.ts b/tests/mail.test.ts index 89e1908..0e587e8 100644 --- a/tests/mail.test.ts +++ b/tests/mail.test.ts @@ -178,7 +178,8 @@ describe('transactional mail', () => { issuedAt: Temporal.Instant.from(NOW).epochMilliseconds - 10_000, operationId: 'mail-http-operation', }), - name: 'Listed Person', + first_name: 'Listed', + last_name: 'Person', email: 'listed@example.invalid', phone: '', notes: '', diff --git a/tests/other-shifts.test.ts b/tests/other-shifts.test.ts index 27e687c..228af71 100644 --- a/tests/other-shifts.test.ts +++ b/tests/other-shifts.test.ts @@ -170,7 +170,8 @@ async function postSignup( issuedAt: NOW_MS - 10_000, operationId: randomBytes(16).toString('hex'), }), - name: fields.name, + first_name: fields.name.slice(0, fields.name.indexOf(' ')), + last_name: fields.name.slice(fields.name.indexOf(' ') + 1), email: fields.email, phone: '', notes: '', diff --git a/tests/public-pages.test.ts b/tests/public-pages.test.ts index 711264b..4e07f83 100644 --- a/tests/public-pages.test.ts +++ b/tests/public-pages.test.ts @@ -113,6 +113,10 @@ describe('public pages', () => { expect(shiftHtml).toContain('1/3 spots filled'); expect(shiftHtml).toContain('spots is-open'); expect(shiftHtml).toContain(' { }); describe('capacity-safe signup', () => { + it('requires a first name and a last name', async () => { + const { app, shiftId } = await buildApp(); + const missingLast = await postSignup(app, shiftId, { firstName: 'Pat', lastName: '', email: 'pat.only@example.invalid' }, { ip: '203.0.113.11' }); + expect(missingLast.status).toBe(400); + const missingLastHtml = await missingLast.text(); + expect(missingLastHtml).toContain('Enter your last name.'); + expect(missingLastHtml).toContain('value="Pat"'); + const missingFirst = await postSignup(app, shiftId, { firstName: ' ', lastName: 'Review', email: 'review.only@example.invalid' }, { ip: '203.0.113.12' }); + expect(missingFirst.status).toBe(400); + expect(await missingFirst.text()).toContain('Enter your first name.'); + }); + it('saves one person, shows a private confirmation link, and does not send mail', async () => { const { app, shiftId, db } = await buildApp(); const response = await postSignup(app, shiftId, { name: 'pat review', email: ' Pat.Review@Example.invalid ', phone: '7125550199', notes: '' }); @@ -38,8 +50,8 @@ describe('capacity-safe signup', () => { const confirmedHtml = await confirmed.text(); expect(confirmed.status).toBe(200); expect(confirmedHtml).toContain('Pat Review'); - expect(confirmedHtml).toContain('A confirmation email is queued'); - expect(confirmedHtml).toContain('where you can cancel it'); + expect(confirmedHtml).toContain('A confirmation email is on the way'); + expect(confirmedHtml).toContain('Cancel or switch shifts'); const managePath = confirmedHtml.match(/href="(\/m\/[^"]+)"/)?.[1]; expect(managePath).toBeTruthy(); expect(cookie).not.toContain(managePath?.slice(3) ?? 'missing-token'); @@ -396,7 +408,18 @@ function insertExtraShift( async function postSignup( app: ReturnType, shiftId: number, - fields: Partial<{ name: string; email: string; phone: string; notes: string; under18: boolean; guardianName: string; guardianEmail: string; company: string }>, + fields: Partial<{ + name: string; + firstName: string; + lastName: string; + email: string; + phone: string; + notes: string; + under18: boolean; + guardianName: string; + guardianEmail: string; + company: string; + }>, options?: { token?: string; issuedAt?: number; ip?: string; origin?: string; forwardedFor?: string; site?: string }, ) { const secret = 'dev-only-change-me-not-for-production-use'; @@ -405,9 +428,12 @@ async function postSignup( issuedAt: options?.issuedAt ?? NOW_MS - 10_000, operationId: randomBytes(16).toString('hex'), }); + const postedName = (fields.name ?? 'Pat Review').trim(); + const splitAt = postedName.indexOf(' '); const body = new URLSearchParams({ form_token: token, - name: fields.name ?? 'Pat Review', + first_name: fields.firstName ?? (splitAt === -1 ? postedName : postedName.slice(0, splitAt)), + last_name: fields.lastName ?? (splitAt === -1 ? '' : postedName.slice(splitAt + 1).trim()), email: fields.email ?? 'pat.review@example.invalid', phone: fields.phone ?? '', notes: fields.notes ?? '',