From 63748d464a0ec08b74bbd5c61beaac7bcc1de600 Mon Sep 17 00:00:00 2001 From: blake Date: Wed, 28 Oct 2026 12:08:00 -0500 Subject: [PATCH] feat: let one signup cover a party of spots Capacity, mail, and the roster count each person in the group. Today's calendar shifts are a light wash on the yellow day, and the signup dialog scrolls inside its panel. --- migrations/008_party_size.sql | 105 ++++++++++++++++++++++++++++++++++ public/css/app.css | 79 ++++++++++++++++++++----- public/js/signup-dialog.js | 21 +++++-- src/admin-http.tsx | 20 ++++++- src/admin-pages.tsx | 25 ++++++-- src/admin/store.ts | 40 +++++++++---- src/db.ts | 10 ++++ src/dev/seed.ts | 4 +- src/mail/queue.ts | 4 ++ src/mail/templates.ts | 22 +++++-- src/pages.tsx | 72 ++++++++++++++++++++--- src/reminders.ts | 4 +- src/schedule.ts | 14 +++-- src/signup-form.ts | 44 +++++++++++++- src/signup-http.tsx | 22 ++++++- src/signup.ts | 22 +++++-- tests/db.test.ts | 50 +++++++++++++++- tests/signup.test.ts | 95 ++++++++++++++++++++++++++++++ 18 files changed, 585 insertions(+), 68 deletions(-) create mode 100644 migrations/008_party_size.sql diff --git a/migrations/008_party_size.sql b/migrations/008_party_size.sql new file mode 100644 index 0000000..11a4985 --- /dev/null +++ b/migrations/008_party_size.sql @@ -0,0 +1,105 @@ +-- foreign-keys: off +-- Rebuilding signups drops the table. outbox and reminders_sent reference it, so foreign keys are off for this file. +-- group_size is how many spots this one signup holds. Names for the extra people are not stored. + +CREATE TABLE signups_next ( + id INTEGER PRIMARY KEY, + shift_id INTEGER NOT NULL REFERENCES shifts (id) ON DELETE NO ACTION, + name TEXT NULL, + email TEXT NULL, + email_norm TEXT NULL, + phone TEXT NULL, + is_minor INTEGER NOT NULL DEFAULT 0 CHECK (is_minor IN (0, 1)), + guardian_name TEXT NULL, + guardian_email TEXT NULL, + group_size INTEGER NOT NULL DEFAULT 1 CHECK (group_size >= 1 AND group_size <= 20), + notes TEXT NULL, + status TEXT NOT NULL CHECK (status IN ('confirmed', 'cancelled')), + manage_token_hash TEXT NULL UNIQUE, + token_expires_at TEXT NULL CHECK ( + token_expires_at IS NULL + OR token_expires_at GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9]Z' + ), + reminders_off INTEGER NOT NULL DEFAULT 0 CHECK (reminders_off IN (0, 1)), + created_at TEXT NOT NULL CHECK ( + created_at GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9]Z' + ), + updated_at TEXT NOT NULL CHECK ( + updated_at GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9]Z' + ), + anonymized_at TEXT NULL CHECK ( + anonymized_at IS NULL + OR anonymized_at GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9]Z' + ), + operation_key TEXT NULL, + CHECK ( + ( + anonymized_at IS NULL + AND name IS NOT NULL + AND length(trim(name)) > 0 + AND email IS NOT NULL + AND email_norm IS NOT NULL + ) + OR ( + anonymized_at IS NOT NULL + AND name IS NULL + AND email IS NULL + AND email_norm IS NULL + AND phone IS NULL + AND guardian_name IS NULL + AND guardian_email IS NULL + AND notes IS NULL + AND manage_token_hash IS NULL + AND token_expires_at IS NULL + ) + ), + CHECK ( + anonymized_at IS NOT NULL + OR is_minor = 0 + OR ( + guardian_name IS NOT NULL + AND length(trim(guardian_name)) > 0 + AND guardian_email IS NOT NULL + AND length(trim(guardian_email)) > 0 + ) + ), + CHECK ( + email_norm IS NULL + OR ( + email_norm = lower(email_norm) + AND instr(email_norm, ' ') = 0 + AND instr(email_norm, '@') > 1 + AND instr(email_norm, char(10)) = 0 + AND instr(email_norm, char(13)) = 0 + ) + ) +); + +INSERT INTO signups_next ( + id, shift_id, name, email, email_norm, phone, is_minor, guardian_name, guardian_email, + group_size, notes, status, manage_token_hash, token_expires_at, reminders_off, + created_at, updated_at, anonymized_at, operation_key +) +SELECT + id, shift_id, name, email, email_norm, phone, is_minor, guardian_name, guardian_email, + group_size, notes, status, manage_token_hash, token_expires_at, reminders_off, + created_at, updated_at, anonymized_at, operation_key +FROM signups; + +DROP TABLE signups; + +ALTER TABLE signups_next RENAME TO signups; + +CREATE INDEX signups_by_shift ON signups (shift_id, status); + +CREATE INDEX signups_by_email_norm + ON signups (email_norm) + WHERE email_norm IS NOT NULL; + +CREATE UNIQUE INDEX signups_one_confirmed_person_per_shift + ON signups (shift_id, email_norm, name COLLATE NOCASE) + WHERE status = 'confirmed' AND email_norm IS NOT NULL AND name IS NOT NULL; + +CREATE UNIQUE INDEX signups_operation_key + ON signups (operation_key) + WHERE operation_key IS NOT NULL; diff --git a/public/css/app.css b/public/css/app.css index ff435ed..3054743 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -37,6 +37,10 @@ --hope-open-edge: #c5d7b4; --hope-full: #f6e2de; --hope-full-edge: #e4c4be; + --hope-scrollbar-size: 14px; + --hope-scrollbar-thumb: var(--hope-gold); + --hope-scrollbar-thumb-hover: color-mix(in srgb, var(--hope-gold) 72%, var(--hope-ink)); + --hope-scrollbar-track: color-mix(in srgb, var(--hope-border) 48%, var(--hope-blue-100)); } *, @@ -59,6 +63,49 @@ body { overflow-x: hidden; } +/* Gold pill on a soft track, the same family as the buttons. */ +html { + scrollbar-width: thin; + scrollbar-color: var(--hope-scrollbar-thumb) var(--hope-scrollbar-track); +} + +@supports selector(::-webkit-scrollbar) { + html { + scrollbar-width: auto; + scrollbar-color: auto; + } + + *::-webkit-scrollbar { + width: var(--hope-scrollbar-size); + height: var(--hope-scrollbar-size); + } + + *::-webkit-scrollbar-button { + display: none; + width: 0; + height: 0; + } + + *::-webkit-scrollbar-track { + background: var(--hope-scrollbar-track); + border-radius: 999px; + } + + *::-webkit-scrollbar-thumb { + background: var(--hope-yellow); + border: 2px solid var(--hope-gold); + border-radius: 999px; + } + + *::-webkit-scrollbar-thumb:hover { + background: var(--hope-yellow-hover); + } + + *::-webkit-scrollbar-corner { + background: transparent; + } +} + body { display: flex; flex-direction: column; @@ -939,7 +986,7 @@ main a:hover { } .cal-day.is-today .cal-line { - background: var(--hope-gold); + background: rgb(255 255 255 / 0.45); } .cal-hold { @@ -1629,28 +1676,30 @@ html:has(#signup-dialog[open]) { } .signup-dialog-panel { - display: grid; + display: flex; + flex-direction: column; width: 100%; max-height: calc(100dvh - 2rem - 2.7rem); + overflow: hidden; + background: transparent; +} + +.signup-dialog-scroll { + flex: 1 1 auto; + min-height: 0; overflow: auto; overscroll-behavior: contain; - background: transparent; - scrollbar-width: thin; - scrollbar-color: rgb(34 34 34 / 0.45) transparent; } -.signup-dialog-panel::-webkit-scrollbar { - width: 10px; +.signup-dialog-scroll::-webkit-scrollbar-track, +.event-dialog .signup-form::-webkit-scrollbar-track { + margin-top: 0.45rem; + margin-bottom: 0.85rem; } -.signup-dialog-panel::-webkit-scrollbar-track { - background: transparent; -} - -.signup-dialog-panel::-webkit-scrollbar-thumb { - background: rgb(34 34 34 / 0.35); - border: 2px solid var(--hope-blue-100); - border-radius: 999px; +/* The new-event form scrolls as one piece, with the close control over its corner. */ +.event-dialog .signup-form::-webkit-scrollbar-track { + margin-top: 3.55rem; } .signup-dialog-summary { diff --git a/public/js/signup-dialog.js b/public/js/signup-dialog.js index eee1140..c0ed5e5 100644 --- a/public/js/signup-dialog.js +++ b/public/js/signup-dialog.js @@ -69,7 +69,7 @@ note.className = 'signup-dialog-note'; note.setAttribute('role', 'status'); note.textContent = 'Loading the signup form.'; - panel.appendChild(note); + panelScroll(panel).appendChild(note); body.replaceChildren(panel); } @@ -84,7 +84,7 @@ link.href = href; link.textContent = 'Open the shift page'; note.appendChild(link); - panel.appendChild(note); + panelScroll(panel).appendChild(note); body.replaceChildren(panel); if (closeButton) closeButton.focus(); } @@ -116,6 +116,7 @@ var notice = main.querySelector('p.error'); if (notice && (!form || !form.contains(notice))) summary.appendChild(document.importNode(notice, true)); panel.appendChild(summary); + var scroll = attachScroll(panel); if (!form) { var closed = document.createElement('p'); closed.className = 'signup-dialog-note'; @@ -125,14 +126,14 @@ } else { closed.textContent = 'This shift is not open for signup.'; } - panel.appendChild(closed); + scroll.appendChild(closed); body.replaceChildren(panel); if (closeButton) closeButton.focus(); return; } var liveForm = document.importNode(form, true); liveForm.querySelectorAll('noscript').forEach(function (node) { node.remove(); }); - panel.appendChild(liveForm); + scroll.appendChild(liveForm); body.replaceChildren(panel); bindForm(liveForm); mountTurnstile(liveForm); @@ -245,9 +246,21 @@ title.textContent = text; summary.appendChild(title); panel.appendChild(summary); + attachScroll(panel); return panel; } + function attachScroll(panel) { + var scroll = document.createElement('div'); + scroll.className = 'signup-dialog-scroll'; + panel.appendChild(scroll); + return scroll; + } + + function panelScroll(panel) { + return panel.querySelector('.signup-dialog-scroll') || panel; + } + function appendFrom(parent, root, selector) { var node = root.querySelector(selector); if (node) parent.appendChild(document.importNode(node, true)); diff --git a/src/admin-http.tsx b/src/admin-http.tsx index ecb3490..385f2ce 100644 --- a/src/admin-http.tsx +++ b/src/admin-http.tsx @@ -108,7 +108,7 @@ import { } from './settings.js'; import { expandTemplates } from './recurrence.js'; import { Layout } from './pages.js'; -import { EMPTY_SIGNUP, parseSignupForm, type SignupValues } from './signup-form.js'; +import { EMPTY_SIGNUP, parseSignupForm, spotsLeftMessage, type SignupValues } from './signup-form.js'; import { confirmedPersonOnShift } from './signup.js'; import { recordInvalidLoginToken, recordLoginEmail, recordLoginIp } from './rate-limit.js'; import { isBusy } from './sqlite-error.js'; @@ -562,6 +562,7 @@ async function submitAddContactToShift(c: Context, services: AdminServices): Pro email: parsed.draft.emailNorm, phone: parsed.draft.phone, notes: parsed.draft.notes, + groupSize: parsed.draft.groupSize, operationId: token.claims.operationId, now: services.now(), mail: mailIdentity(services.db, services.config), @@ -1308,13 +1309,27 @@ async function submitWalkIn(c: Context, services: AdminServices): Promise 0) { + return showShift(c, services, undefined, 400, { + token: textField(session.body, 'form_token'), + values: filled.values, + errors: { partySize: spotsLeftMessage(left) }, + contactId, + }); + } + return showShift(c, services, undefined, 400); + } if (saved.reason === 'duplicate') { return showShift(c, services, undefined, 400, { token: textField(session.body, 'form_token'), @@ -1623,6 +1638,7 @@ function signupValuesFrom(body: Record): SignupValues { email: textField(body, 'email'), phone: textField(body, 'phone'), notes: textField(body, 'notes'), + partySize: textField(body, 'party_size'), }; } diff --git a/src/admin-pages.tsx b/src/admin-pages.tsx index 45f47c7..288145f 100644 --- a/src/admin-pages.tsx +++ b/src/admin-pages.tsx @@ -15,6 +15,7 @@ import { type ContactShift, } from './contacts.js'; import type { SignupErrors, SignupValues } from './signup-form.js'; +import { PartySizeField } from './pages.js'; import { addLocalDays, formatInstantInZone, todayInZone } from './time.js'; import { ShiftTargetOptions } from './shift-options.js'; import type { AdminAccount, AdminErrors, AdminForm } from './admins.js'; @@ -974,7 +975,7 @@ export function ShiftRoster(props: { ) : null}

Cancelling a signup emails them. Their old private link stops working, and the email includes a new one.

-

Moving a confirmed signup opens this spot and queues a change email. Their old private link stops working.

+

Moving a confirmed signup opens the spots it holds and queues a change email. Their old private link stops working.

{props.moves && props.moves.targets.length === 0 ?

No other open shift in this event has room.

: null} {props.shift.people.length === 0 ? (

No one has signed up.

@@ -984,7 +985,14 @@ export function ShiftRoster(props: { {props.walkIn ? (
- +
) : props.walkInNote ? (

{props.walkInNote}

@@ -1643,7 +1651,14 @@ function ShiftEditorForm(props: { config: AppConfig; csrf: string; shift: AdminS ); } -function WalkInForm(props: { config: AppConfig; csrf: string; shiftId: number; form: WalkInState; contacts: Contact[] }) { +function WalkInForm(props: { + config: AppConfig; + csrf: string; + shiftId: number; + spotsLeft: number; + form: WalkInState; + contacts: Contact[]; +}) { const values = props.form.values; const errors = props.form.errors; const errorEntries = Object.entries(errors).filter((entry): entry is [string, string] => Boolean(entry[1])); @@ -1651,7 +1666,7 @@ function WalkInForm(props: { config: AppConfig; csrf: string; shiftId: number; f return (