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.
This commit is contained in:
1 parent
03da30dbbc
commit
322c575fcb
11 files changed
+126
-26
No files matched your search
@@ -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.
|
||||
|
||||
|
||||
+14
-2
@@ -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) {
|
||||
|
||||
@@ -1519,6 +1519,8 @@ function isAttendanceMark(value: string): value is AttendanceMark {
|
||||
function signupValuesFrom(body: Record<string, unknown>): SignupValues {
|
||||
return {
|
||||
name: textField(body, 'name'),
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
email: textField(body, 'email'),
|
||||
phone: textField(body, 'phone'),
|
||||
notes: textField(body, 'notes'),
|
||||
|
||||
+31
-8
@@ -288,23 +288,23 @@ export function ConfirmationPage(props: {
|
||||
<h1>{props.cancelled ? 'This signup is cancelled' : "You're signed up"}</h1>
|
||||
<p>
|
||||
{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.`}
|
||||
</p>
|
||||
<ShiftWhen shift={props.shift} />
|
||||
{props.managePath ? (
|
||||
<>
|
||||
<p>
|
||||
{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.'}
|
||||
</p>
|
||||
<p>
|
||||
<a href={props.managePath}>Open this signup</a>
|
||||
<a href={props.managePath}>{props.cancelled ? 'View this signup' : 'Cancel or switch shifts'}</a>
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<p>If you just signed up, the link stays in this browser for a few minutes. A confirmation email is queued.</p>
|
||||
<p>If you just signed up, the link stays in this browser for a few minutes. A confirmation email is on the way.</p>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
@@ -329,7 +329,7 @@ export function ManagePage(props: {
|
||||
return (
|
||||
<>
|
||||
<h1>Your signup</h1>
|
||||
<p class="status">{signup.status === 'confirmed' ? 'Confirmed' : 'Cancelled'}</p>
|
||||
<p class={signup.status === 'confirmed' ? 'status is-confirmed' : 'status'}>{signup.status === 'confirmed' ? 'Confirmed' : 'Cancelled'}</p>
|
||||
<p>{signup.eventTitle}</p>
|
||||
<h2>{signup.role}</h2>
|
||||
<p class="when">
|
||||
@@ -739,7 +739,28 @@ function SignupForm(props: { config: AppConfig; shiftId: number; form: SignupFor
|
||||
<input name="company_website" type="text" tabindex={-1} autocomplete="off" value="" />
|
||||
</label>
|
||||
</div>
|
||||
<Field id="signup-name" label="Name" name="name" type="text" value={form.values.name} error={errors.name} autoComplete="name" />
|
||||
<div class="name-pair">
|
||||
<Field
|
||||
id="signup-firstName"
|
||||
label="First name"
|
||||
name="first_name"
|
||||
type="text"
|
||||
value={form.values.firstName}
|
||||
error={errors.firstName}
|
||||
autoComplete="given-name"
|
||||
required
|
||||
/>
|
||||
<Field
|
||||
id="signup-lastName"
|
||||
label="Last name"
|
||||
name="last_name"
|
||||
type="text"
|
||||
value={form.values.lastName}
|
||||
error={errors.lastName}
|
||||
autoComplete="family-name"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<Field id="signup-email" label="Email" name="email" type="email" value={form.values.email} error={errors.email} autoComplete="email" />
|
||||
<Field
|
||||
id="signup-phone"
|
||||
@@ -803,6 +824,7 @@ function Field(props: {
|
||||
error?: string;
|
||||
autoComplete: string;
|
||||
hint?: string;
|
||||
required?: boolean;
|
||||
}) {
|
||||
const errorId = `${props.id}-error`;
|
||||
const hintId = `${props.id}-hint`;
|
||||
@@ -816,6 +838,7 @@ function Field(props: {
|
||||
type={props.type}
|
||||
value={props.value}
|
||||
autocomplete={props.autoComplete}
|
||||
required={props.required ? true : undefined}
|
||||
aria-invalid={props.error ? 'true' : undefined}
|
||||
aria-describedby={describedBy}
|
||||
/>
|
||||
|
||||
+35
-7
@@ -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<Record<'name' | 'email' | 'phone' | 'notes' | 'guardianName' | 'guardianEmail' | 'form', string>>;
|
||||
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 {
|
||||
|
||||
+3
-1
@@ -277,7 +277,9 @@ function loadShift(services: SignupServices, rawId: string): PublicShift | null
|
||||
|
||||
function valuesFrom(body: Record<string, unknown>): 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'),
|
||||
|
||||
@@ -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: '',
|
||||
|
||||
+2
-1
@@ -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: '',
|
||||
|
||||
@@ -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: '',
|
||||
|
||||
@@ -113,6 +113,10 @@ describe('public pages', () => {
|
||||
expect(shiftHtml).toContain('1/3 spots filled');
|
||||
expect(shiftHtml).toContain('spots is-open');
|
||||
expect(shiftHtml).toContain('<form');
|
||||
expect(shiftHtml).toContain('name="first_name"');
|
||||
expect(shiftHtml).toContain('name="last_name"');
|
||||
expect(shiftHtml).toContain('First name');
|
||||
expect(shiftHtml).toContain('Last name');
|
||||
expect(shiftHtml).toContain('We will not text you');
|
||||
expect(shiftHtml).toContain('https://challenges.cloudflare.com/turnstile/v0/api.js');
|
||||
expect(shiftHtml).toContain('data-under-18');
|
||||
|
||||
+30
-4
@@ -26,6 +26,18 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
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: '<script>alert(1)</script>' });
|
||||
@@ -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<typeof createApp>,
|
||||
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 ?? '',
|
||||
|
||||
Reference in new issue
Block a user