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.
This commit is contained in:
1 parent
1f451dc830
commit
63748d464a
18 files changed
+585
-68
No files matched your search
@@ -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;
|
||||||
+64
-15
@@ -37,6 +37,10 @@
|
|||||||
--hope-open-edge: #c5d7b4;
|
--hope-open-edge: #c5d7b4;
|
||||||
--hope-full: #f6e2de;
|
--hope-full: #f6e2de;
|
||||||
--hope-full-edge: #e4c4be;
|
--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;
|
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 {
|
body {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -939,7 +986,7 @@ main a:hover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.cal-day.is-today .cal-line {
|
.cal-day.is-today .cal-line {
|
||||||
background: var(--hope-gold);
|
background: rgb(255 255 255 / 0.45);
|
||||||
}
|
}
|
||||||
|
|
||||||
.cal-hold {
|
.cal-hold {
|
||||||
@@ -1629,28 +1676,30 @@ html:has(#signup-dialog[open]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.signup-dialog-panel {
|
.signup-dialog-panel {
|
||||||
display: grid;
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-height: calc(100dvh - 2rem - 2.7rem);
|
max-height: calc(100dvh - 2rem - 2.7rem);
|
||||||
|
overflow: hidden;
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.signup-dialog-scroll {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-height: 0;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
overscroll-behavior: contain;
|
overscroll-behavior: contain;
|
||||||
background: transparent;
|
|
||||||
scrollbar-width: thin;
|
|
||||||
scrollbar-color: rgb(34 34 34 / 0.45) transparent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.signup-dialog-panel::-webkit-scrollbar {
|
.signup-dialog-scroll::-webkit-scrollbar-track,
|
||||||
width: 10px;
|
.event-dialog .signup-form::-webkit-scrollbar-track {
|
||||||
|
margin-top: 0.45rem;
|
||||||
|
margin-bottom: 0.85rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.signup-dialog-panel::-webkit-scrollbar-track {
|
/* The new-event form scrolls as one piece, with the close control over its corner. */
|
||||||
background: transparent;
|
.event-dialog .signup-form::-webkit-scrollbar-track {
|
||||||
}
|
margin-top: 3.55rem;
|
||||||
|
|
||||||
.signup-dialog-panel::-webkit-scrollbar-thumb {
|
|
||||||
background: rgb(34 34 34 / 0.35);
|
|
||||||
border: 2px solid var(--hope-blue-100);
|
|
||||||
border-radius: 999px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.signup-dialog-summary {
|
.signup-dialog-summary {
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
note.className = 'signup-dialog-note';
|
note.className = 'signup-dialog-note';
|
||||||
note.setAttribute('role', 'status');
|
note.setAttribute('role', 'status');
|
||||||
note.textContent = 'Loading the signup form.';
|
note.textContent = 'Loading the signup form.';
|
||||||
panel.appendChild(note);
|
panelScroll(panel).appendChild(note);
|
||||||
body.replaceChildren(panel);
|
body.replaceChildren(panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@
|
|||||||
link.href = href;
|
link.href = href;
|
||||||
link.textContent = 'Open the shift page';
|
link.textContent = 'Open the shift page';
|
||||||
note.appendChild(link);
|
note.appendChild(link);
|
||||||
panel.appendChild(note);
|
panelScroll(panel).appendChild(note);
|
||||||
body.replaceChildren(panel);
|
body.replaceChildren(panel);
|
||||||
if (closeButton) closeButton.focus();
|
if (closeButton) closeButton.focus();
|
||||||
}
|
}
|
||||||
@@ -116,6 +116,7 @@
|
|||||||
var notice = main.querySelector('p.error');
|
var notice = main.querySelector('p.error');
|
||||||
if (notice && (!form || !form.contains(notice))) summary.appendChild(document.importNode(notice, true));
|
if (notice && (!form || !form.contains(notice))) summary.appendChild(document.importNode(notice, true));
|
||||||
panel.appendChild(summary);
|
panel.appendChild(summary);
|
||||||
|
var scroll = attachScroll(panel);
|
||||||
if (!form) {
|
if (!form) {
|
||||||
var closed = document.createElement('p');
|
var closed = document.createElement('p');
|
||||||
closed.className = 'signup-dialog-note';
|
closed.className = 'signup-dialog-note';
|
||||||
@@ -125,14 +126,14 @@
|
|||||||
} else {
|
} else {
|
||||||
closed.textContent = 'This shift is not open for signup.';
|
closed.textContent = 'This shift is not open for signup.';
|
||||||
}
|
}
|
||||||
panel.appendChild(closed);
|
scroll.appendChild(closed);
|
||||||
body.replaceChildren(panel);
|
body.replaceChildren(panel);
|
||||||
if (closeButton) closeButton.focus();
|
if (closeButton) closeButton.focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var liveForm = document.importNode(form, true);
|
var liveForm = document.importNode(form, true);
|
||||||
liveForm.querySelectorAll('noscript').forEach(function (node) { node.remove(); });
|
liveForm.querySelectorAll('noscript').forEach(function (node) { node.remove(); });
|
||||||
panel.appendChild(liveForm);
|
scroll.appendChild(liveForm);
|
||||||
body.replaceChildren(panel);
|
body.replaceChildren(panel);
|
||||||
bindForm(liveForm);
|
bindForm(liveForm);
|
||||||
mountTurnstile(liveForm);
|
mountTurnstile(liveForm);
|
||||||
@@ -245,9 +246,21 @@
|
|||||||
title.textContent = text;
|
title.textContent = text;
|
||||||
summary.appendChild(title);
|
summary.appendChild(title);
|
||||||
panel.appendChild(summary);
|
panel.appendChild(summary);
|
||||||
|
attachScroll(panel);
|
||||||
return 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) {
|
function appendFrom(parent, root, selector) {
|
||||||
var node = root.querySelector(selector);
|
var node = root.querySelector(selector);
|
||||||
if (node) parent.appendChild(document.importNode(node, true));
|
if (node) parent.appendChild(document.importNode(node, true));
|
||||||
|
|||||||
+18
-2
@@ -108,7 +108,7 @@ import {
|
|||||||
} from './settings.js';
|
} from './settings.js';
|
||||||
import { expandTemplates } from './recurrence.js';
|
import { expandTemplates } from './recurrence.js';
|
||||||
import { Layout } from './pages.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 { confirmedPersonOnShift } from './signup.js';
|
||||||
import { recordInvalidLoginToken, recordLoginEmail, recordLoginIp } from './rate-limit.js';
|
import { recordInvalidLoginToken, recordLoginEmail, recordLoginIp } from './rate-limit.js';
|
||||||
import { isBusy } from './sqlite-error.js';
|
import { isBusy } from './sqlite-error.js';
|
||||||
@@ -562,6 +562,7 @@ async function submitAddContactToShift(c: Context, services: AdminServices): Pro
|
|||||||
email: parsed.draft.emailNorm,
|
email: parsed.draft.emailNorm,
|
||||||
phone: parsed.draft.phone,
|
phone: parsed.draft.phone,
|
||||||
notes: parsed.draft.notes,
|
notes: parsed.draft.notes,
|
||||||
|
groupSize: parsed.draft.groupSize,
|
||||||
operationId: token.claims.operationId,
|
operationId: token.claims.operationId,
|
||||||
now: services.now(),
|
now: services.now(),
|
||||||
mail: mailIdentity(services.db, services.config),
|
mail: mailIdentity(services.db, services.config),
|
||||||
@@ -1308,13 +1309,27 @@ async function submitWalkIn(c: Context, services: AdminServices): Promise<Respon
|
|||||||
email: parsed.draft.emailNorm,
|
email: parsed.draft.emailNorm,
|
||||||
phone: parsed.draft.phone,
|
phone: parsed.draft.phone,
|
||||||
notes: parsed.draft.notes,
|
notes: parsed.draft.notes,
|
||||||
|
groupSize: parsed.draft.groupSize,
|
||||||
operationId: token.claims.operationId,
|
operationId: token.claims.operationId,
|
||||||
now: services.now(),
|
now: services.now(),
|
||||||
mail: mailIdentity(services.db, services.config),
|
mail: mailIdentity(services.db, services.config),
|
||||||
});
|
});
|
||||||
if (saved.ok) return c.redirect(appPath(services.config, `/admin/shifts/${id}?notice=walk-in`), 303);
|
if (saved.ok) return c.redirect(appPath(services.config, `/admin/shifts/${id}?notice=walk-in`), 303);
|
||||||
if (saved.reason === 'not_found') return missing(c, services);
|
if (saved.reason === 'not_found') return missing(c, services);
|
||||||
if (saved.reason === 'closed' || saved.reason === 'full') return showShift(c, services, undefined, 400);
|
if (saved.reason === 'closed') return showShift(c, services, undefined, 400);
|
||||||
|
if (saved.reason === 'full') {
|
||||||
|
const current = getAdminShift(services.db, id);
|
||||||
|
const left = current ? current.capacity - current.occupied : 0;
|
||||||
|
if (left > 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') {
|
if (saved.reason === 'duplicate') {
|
||||||
return showShift(c, services, undefined, 400, {
|
return showShift(c, services, undefined, 400, {
|
||||||
token: textField(session.body, 'form_token'),
|
token: textField(session.body, 'form_token'),
|
||||||
@@ -1623,6 +1638,7 @@ function signupValuesFrom(body: Record<string, unknown>): SignupValues {
|
|||||||
email: textField(body, 'email'),
|
email: textField(body, 'email'),
|
||||||
phone: textField(body, 'phone'),
|
phone: textField(body, 'phone'),
|
||||||
notes: textField(body, 'notes'),
|
notes: textField(body, 'notes'),
|
||||||
|
partySize: textField(body, 'party_size'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+21
-4
@@ -15,6 +15,7 @@ import {
|
|||||||
type ContactShift,
|
type ContactShift,
|
||||||
} from './contacts.js';
|
} from './contacts.js';
|
||||||
import type { SignupErrors, SignupValues } from './signup-form.js';
|
import type { SignupErrors, SignupValues } from './signup-form.js';
|
||||||
|
import { PartySizeField } from './pages.js';
|
||||||
import { addLocalDays, formatInstantInZone, todayInZone } from './time.js';
|
import { addLocalDays, formatInstantInZone, todayInZone } from './time.js';
|
||||||
import { ShiftTargetOptions } from './shift-options.js';
|
import { ShiftTargetOptions } from './shift-options.js';
|
||||||
import type { AdminAccount, AdminErrors, AdminForm } from './admins.js';
|
import type { AdminAccount, AdminErrors, AdminForm } from './admins.js';
|
||||||
@@ -974,7 +975,7 @@ export function ShiftRoster(props: {
|
|||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
<p class="panel-note">Cancelling a signup emails them. Their old private link stops working, and the email includes a new one.</p>
|
<p class="panel-note">Cancelling a signup emails them. Their old private link stops working, and the email includes a new one.</p>
|
||||||
<p class="panel-note">Moving a confirmed signup opens this spot and queues a change email. Their old private link stops working.</p>
|
<p class="panel-note">Moving a confirmed signup opens the spots it holds and queues a change email. Their old private link stops working.</p>
|
||||||
{props.moves && props.moves.targets.length === 0 ? <p class="panel-note">No other open shift in this event has room.</p> : null}
|
{props.moves && props.moves.targets.length === 0 ? <p class="panel-note">No other open shift in this event has room.</p> : null}
|
||||||
{props.shift.people.length === 0 ? (
|
{props.shift.people.length === 0 ? (
|
||||||
<p class="empty">No one has signed up.</p>
|
<p class="empty">No one has signed up.</p>
|
||||||
@@ -984,7 +985,14 @@ export function ShiftRoster(props: {
|
|||||||
</section>
|
</section>
|
||||||
{props.walkIn ? (
|
{props.walkIn ? (
|
||||||
<section class="desk-events" aria-labelledby="walkin-heading">
|
<section class="desk-events" aria-labelledby="walkin-heading">
|
||||||
<WalkInForm config={props.config} csrf={props.csrf} shiftId={props.shift.id} form={props.walkIn} contacts={props.contacts ?? []} />
|
<WalkInForm
|
||||||
|
config={props.config}
|
||||||
|
csrf={props.csrf}
|
||||||
|
shiftId={props.shift.id}
|
||||||
|
spotsLeft={Math.max(0, props.shift.capacity - props.shift.occupied)}
|
||||||
|
form={props.walkIn}
|
||||||
|
contacts={props.contacts ?? []}
|
||||||
|
/>
|
||||||
</section>
|
</section>
|
||||||
) : props.walkInNote ? (
|
) : props.walkInNote ? (
|
||||||
<p class="panel-note">{props.walkInNote}</p>
|
<p class="panel-note">{props.walkInNote}</p>
|
||||||
@@ -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 values = props.form.values;
|
||||||
const errors = props.form.errors;
|
const errors = props.form.errors;
|
||||||
const errorEntries = Object.entries(errors).filter((entry): entry is [string, string] => Boolean(entry[1]));
|
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 (
|
return (
|
||||||
<form method="post" action={appPath(props.config, `/admin/shifts/${props.shiftId}/walk-in`)} class="signup-form event-details-form">
|
<form method="post" action={appPath(props.config, `/admin/shifts/${props.shiftId}/walk-in`)} class="signup-form event-details-form">
|
||||||
<h2 id="walkin-heading">Add a walk-in</h2>
|
<h2 id="walkin-heading">Add a walk-in</h2>
|
||||||
<p>This is one person who is here. It takes one spot and queues a confirmation email. Another person can use the same email. Their name is listed on the public sign-up page when this shift is posted there. Email and notes stay off that page.</p>
|
<p>Choose how many people are here, including the person named below. This signup holds that many spots and queues one confirmation email. Another person can use the same email. The name is listed on the public sign-up page when this shift is posted there. Email and notes stay off that page.</p>
|
||||||
{props.form.message ? <p class="error">{props.form.message}</p> : null}
|
{props.form.message ? <p class="error">{props.form.message}</p> : null}
|
||||||
{errorEntries.length > 0 ? (
|
{errorEntries.length > 0 ? (
|
||||||
<div class="error" role="alert">
|
<div class="error" role="alert">
|
||||||
@@ -1695,6 +1710,7 @@ function WalkInForm(props: { config: AppConfig; csrf: string; shiftId: number; f
|
|||||||
<WalkInField id="walkin-name" label="Name" name="name" type="text" value={values.name} error={errors.name} />
|
<WalkInField id="walkin-name" label="Name" name="name" type="text" value={values.name} error={errors.name} />
|
||||||
<WalkInField id="walkin-email" label="Email" name="email" type="email" value={values.email} error={errors.email} />
|
<WalkInField id="walkin-email" label="Email" name="email" type="email" value={values.email} error={errors.email} />
|
||||||
<WalkInField id="walkin-phone" label="Phone" name="phone" type="tel" value={values.phone} error={errors.phone} required />
|
<WalkInField id="walkin-phone" label="Phone" name="phone" type="tel" value={values.phone} error={errors.phone} required />
|
||||||
|
<PartySizeField idPrefix="walkin" value={values.partySize} error={errors.partySize} remaining={props.spotsLeft} />
|
||||||
<label for="walkin-notes">
|
<label for="walkin-notes">
|
||||||
Notes (optional)
|
Notes (optional)
|
||||||
<textarea id="walkin-notes" name="notes" aria-invalid={errors.notes ? 'true' : undefined} aria-describedby={errors.notes ? 'walkin-notes-error' : undefined}>
|
<textarea id="walkin-notes" name="notes" aria-invalid={errors.notes ? 'true' : undefined} aria-describedby={errors.notes ? 'walkin-notes-error' : undefined}>
|
||||||
@@ -1765,6 +1781,7 @@ function Roster(props: { config: AppConfig; csrf: string; people: RosterPerson[]
|
|||||||
) : null}
|
) : null}
|
||||||
<strong>{person.name}</strong>
|
<strong>{person.name}</strong>
|
||||||
</p>
|
</p>
|
||||||
|
{person.groupSize > 1 ? <p>Holds {person.groupSize} spots</p> : null}
|
||||||
<p>{person.email}</p>
|
<p>{person.email}</p>
|
||||||
{person.phone ? <p>{person.phone}</p> : null}
|
{person.phone ? <p>{person.phone}</p> : null}
|
||||||
{person.notes ? <p>Note: {person.notes}</p> : null}
|
{person.notes ? <p>Note: {person.notes}</p> : null}
|
||||||
|
|||||||
+28
-12
@@ -87,6 +87,7 @@ export type RosterPerson = {
|
|||||||
email: string;
|
email: string;
|
||||||
phone: string | null;
|
phone: string | null;
|
||||||
notes: string | null;
|
notes: string | null;
|
||||||
|
groupSize: number;
|
||||||
status: 'confirmed' | 'cancelled';
|
status: 'confirmed' | 'cancelled';
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -291,7 +292,7 @@ export function getAdminShift(db: Database.Database, id: number): AdminShift | n
|
|||||||
if (!row) return null;
|
if (!row) return null;
|
||||||
const people = db
|
const people = db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT id, name, email, phone, notes, status
|
`SELECT id, name, email, phone, notes, status, group_size
|
||||||
FROM signups
|
FROM signups
|
||||||
WHERE shift_id = ? AND anonymized_at IS NULL AND name IS NOT NULL AND email IS NOT NULL
|
WHERE shift_id = ? AND anonymized_at IS NULL AND name IS NOT NULL AND email IS NOT NULL
|
||||||
ORDER BY CASE status WHEN 'confirmed' THEN 0 ELSE 1 END, id`,
|
ORDER BY CASE status WHEN 'confirmed' THEN 0 ELSE 1 END, id`,
|
||||||
@@ -303,6 +304,7 @@ export function getAdminShift(db: Database.Database, id: number): AdminShift | n
|
|||||||
phone: string | null;
|
phone: string | null;
|
||||||
notes: string | null;
|
notes: string | null;
|
||||||
status: string;
|
status: string;
|
||||||
|
group_size: number;
|
||||||
}>;
|
}>;
|
||||||
return {
|
return {
|
||||||
...presentShift(row, row.tz),
|
...presentShift(row, row.tz),
|
||||||
@@ -318,6 +320,7 @@ export function getAdminShift(db: Database.Database, id: number): AdminShift | n
|
|||||||
email: person.email,
|
email: person.email,
|
||||||
phone: person.phone,
|
phone: person.phone,
|
||||||
notes: person.notes,
|
notes: person.notes,
|
||||||
|
groupSize: Number(person.group_size),
|
||||||
status: person.status,
|
status: person.status,
|
||||||
}];
|
}];
|
||||||
}),
|
}),
|
||||||
@@ -962,7 +965,7 @@ export function listMoveTargets(
|
|||||||
eventId: number,
|
eventId: number,
|
||||||
shiftId: number,
|
shiftId: number,
|
||||||
now: string,
|
now: string,
|
||||||
options?: { publishedOnly?: boolean; excludePerson?: { email: string; name: string }; signupWindow?: boolean },
|
options?: { publishedOnly?: boolean; excludePerson?: { email: string; name: string }; signupWindow?: boolean; spotsNeeded?: number },
|
||||||
): MoveTarget[] {
|
): MoveTarget[] {
|
||||||
const blocked = new Set<number>();
|
const blocked = new Set<number>();
|
||||||
if (options?.excludePerson) {
|
if (options?.excludePerson) {
|
||||||
@@ -995,7 +998,8 @@ export function listMoveTargets(
|
|||||||
return rows.flatMap((row) => {
|
return rows.flatMap((row) => {
|
||||||
if (options?.publishedOnly && row.published !== 1) return [];
|
if (options?.publishedOnly && row.published !== 1) return [];
|
||||||
if (blocked.has(row.id)) return [];
|
if (blocked.has(row.id)) return [];
|
||||||
if (Number(row.occupied) >= Number(row.capacity)) return [];
|
const needed = options?.spotsNeeded && options.spotsNeeded > 0 ? options.spotsNeeded : 1;
|
||||||
|
if (Number(row.occupied) + needed > Number(row.capacity)) return [];
|
||||||
const start = formatInstantInZone(row.starts_at_utc, row.tz);
|
const start = formatInstantInZone(row.starts_at_utc, row.tz);
|
||||||
const end = formatInstantInZone(row.ends_at_utc, row.tz);
|
const end = formatInstantInZone(row.ends_at_utc, row.tz);
|
||||||
if (options?.signupWindow && !isWithinSignupWindow(start.date, todayInZone(row.tz, Temporal.Instant.from(now)))) return [];
|
if (options?.signupWindow && !isWithinSignupWindow(start.date, todayInZone(row.tz, Temporal.Instant.from(now)))) return [];
|
||||||
@@ -1058,8 +1062,8 @@ export type MoveResult =
|
|||||||
| { ok: false; error: string; shiftId?: number };
|
| { ok: false; error: string; shiftId?: number };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves one confirmed person onto another open shift in the same event.
|
* Moves one confirmed signup onto another open shift in the same event.
|
||||||
* The cancellation and the new signup commit together. A failed move leaves the original signup confirmed.
|
* Every spot the signup holds moves with it. A failed move leaves the original signup confirmed.
|
||||||
*/
|
*/
|
||||||
export function moveSignup(
|
export function moveSignup(
|
||||||
db: Database.Database,
|
db: Database.Database,
|
||||||
@@ -1196,8 +1200,11 @@ function relocate(
|
|||||||
FROM signups WHERE shift_id = ? AND status = 'confirmed'`,
|
FROM signups WHERE shift_id = ? AND status = 'confirmed'`,
|
||||||
)
|
)
|
||||||
.get(destination.id) as { occupied: number };
|
.get(destination.id) as { occupied: number };
|
||||||
if (Number(occupied.occupied) + 1 > destination.capacity) {
|
const groupSize = Number(source.group_size);
|
||||||
return { ok: false, error: transferError(options.audience, 'full'), shiftId: source.shift_id };
|
const taken = Number(occupied.occupied);
|
||||||
|
if (taken + groupSize > destination.capacity) {
|
||||||
|
const code = groupSize > 1 && taken < destination.capacity ? 'room' : 'full';
|
||||||
|
return { ok: false, error: transferError(options.audience, code), shiftId: source.shift_id };
|
||||||
}
|
}
|
||||||
|
|
||||||
const retired = issueManageToken(destination.ends_at_utc);
|
const retired = issueManageToken(destination.ends_at_utc);
|
||||||
@@ -1219,7 +1226,7 @@ function relocate(
|
|||||||
shift_id, name, email, email_norm, phone, is_minor, guardian_name, guardian_email,
|
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,
|
group_size, notes, status, manage_token_hash, token_expires_at, reminders_off,
|
||||||
created_at, updated_at, operation_key
|
created_at, updated_at, operation_key
|
||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1, ?, 'confirmed', ?, ?, ?, ?, ?, ?)`,
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'confirmed', ?, ?, ?, ?, ?, ?)`,
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
destination.id,
|
destination.id,
|
||||||
@@ -1230,6 +1237,7 @@ function relocate(
|
|||||||
source.is_minor,
|
source.is_minor,
|
||||||
source.is_minor === 1 ? source.guardian_name : null,
|
source.is_minor === 1 ? source.guardian_name : null,
|
||||||
source.is_minor === 1 ? source.guardian_email : null,
|
source.is_minor === 1 ? source.guardian_email : null,
|
||||||
|
groupSize,
|
||||||
source.notes,
|
source.notes,
|
||||||
issued.hash,
|
issued.hash,
|
||||||
issued.expiresAt,
|
issued.expiresAt,
|
||||||
@@ -1250,6 +1258,7 @@ function relocate(
|
|||||||
token: issued.token,
|
token: issued.token,
|
||||||
volunteerName: source.name,
|
volunteerName: source.name,
|
||||||
volunteerEmail: source.email_norm,
|
volunteerEmail: source.email_norm,
|
||||||
|
groupSize,
|
||||||
shift: shift.facts,
|
shift: shift.facts,
|
||||||
mail,
|
mail,
|
||||||
now,
|
now,
|
||||||
@@ -1284,6 +1293,7 @@ function transferError(audience: TransferOptions['audience'], code: TransferErro
|
|||||||
early: 'That shift is not open for sign-up yet.',
|
early: 'That shift is not open for sign-up yet.',
|
||||||
duplicate: 'That person is already signed up for this shift.',
|
duplicate: 'That person is already signed up for this shift.',
|
||||||
full: 'That shift is full.',
|
full: 'That shift is full.',
|
||||||
|
room: 'That shift does not have room for everyone on this signup.',
|
||||||
used: 'This form was already used for a different signup. Submit it again.',
|
used: 'This form was already used for a different signup. Submit it again.',
|
||||||
foreign: 'That signup is not on this page.',
|
foreign: 'That signup is not on this page.',
|
||||||
already: 'That signup is already cancelled.',
|
already: 'That signup is already cancelled.',
|
||||||
@@ -1299,6 +1309,7 @@ function transferError(audience: TransferOptions['audience'], code: TransferErro
|
|||||||
early: 'Sign-up for that shift opens three months before the date.',
|
early: 'Sign-up for that shift opens three months before the date.',
|
||||||
duplicate: 'You are already signed up for that shift.',
|
duplicate: 'You are already signed up for that shift.',
|
||||||
full: 'That shift is full.',
|
full: 'That shift is full.',
|
||||||
|
room: 'That shift does not have room for everyone on this signup.',
|
||||||
used: 'This form was already used. Open the link from your email.',
|
used: 'This form was already used. Open the link from your email.',
|
||||||
foreign: 'That signup is not on this page.',
|
foreign: 'That signup is not on this page.',
|
||||||
already: 'That signup is already cancelled.',
|
already: 'That signup is already cancelled.',
|
||||||
@@ -1317,6 +1328,7 @@ type TransferError =
|
|||||||
| 'early'
|
| 'early'
|
||||||
| 'duplicate'
|
| 'duplicate'
|
||||||
| 'full'
|
| 'full'
|
||||||
|
| 'room'
|
||||||
| 'used'
|
| 'used'
|
||||||
| 'foreign'
|
| 'foreign'
|
||||||
| 'already';
|
| 'already';
|
||||||
@@ -1327,7 +1339,7 @@ function loadMoveSource(db: Database.Database, signupId: number): MoveSource | n
|
|||||||
`SELECT su.id AS id, su.shift_id AS shift_id, s.event_id AS event_id, su.name AS name, su.email AS email,
|
`SELECT su.id AS id, su.shift_id AS shift_id, s.event_id AS event_id, su.name AS name, su.email AS email,
|
||||||
su.email_norm AS email_norm, su.phone AS phone, su.notes AS notes, su.is_minor AS is_minor,
|
su.email_norm AS email_norm, su.phone AS phone, su.notes AS notes, su.is_minor AS is_minor,
|
||||||
su.guardian_name AS guardian_name, su.guardian_email AS guardian_email, su.reminders_off AS reminders_off,
|
su.guardian_name AS guardian_name, su.guardian_email AS guardian_email, su.reminders_off AS reminders_off,
|
||||||
su.status AS status
|
su.group_size AS group_size, su.status AS status
|
||||||
FROM signups su
|
FROM signups su
|
||||||
JOIN shifts s ON s.id = su.shift_id
|
JOIN shifts s ON s.id = su.shift_id
|
||||||
WHERE su.id = ? AND su.anonymized_at IS NULL`,
|
WHERE su.id = ? AND su.anonymized_at IS NULL`,
|
||||||
@@ -1351,7 +1363,7 @@ function findMoveOperation(
|
|||||||
return row ?? null;
|
return row ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** One named person, one spot, same capacity and person rules as public signup. */
|
/** One named signup. groupSize reserves that many spots, with the same rules as public signup. */
|
||||||
export function addWalkIn(
|
export function addWalkIn(
|
||||||
db: Database.Database,
|
db: Database.Database,
|
||||||
coordinatorId: number,
|
coordinatorId: number,
|
||||||
@@ -1385,7 +1397,7 @@ function bumpAndNotify(db: Database.Database, shiftId: number, now: string, mail
|
|||||||
if (!shift) return 0;
|
if (!shift) return 0;
|
||||||
const people = db
|
const people = db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT id, name, email_norm, shift_id, status
|
`SELECT id, name, email_norm, shift_id, status, group_size
|
||||||
FROM signups
|
FROM signups
|
||||||
WHERE shift_id = ? AND status = 'confirmed' AND anonymized_at IS NULL AND name IS NOT NULL AND email_norm IS NOT NULL`,
|
WHERE shift_id = ? AND status = 'confirmed' AND anonymized_at IS NULL AND name IS NOT NULL AND email_norm IS NOT NULL`,
|
||||||
)
|
)
|
||||||
@@ -1401,6 +1413,7 @@ function bumpAndNotify(db: Database.Database, shiftId: number, now: string, mail
|
|||||||
token,
|
token,
|
||||||
volunteerName: person.name,
|
volunteerName: person.name,
|
||||||
volunteerEmail: person.email_norm,
|
volunteerEmail: person.email_norm,
|
||||||
|
groupSize: Number(person.group_size),
|
||||||
shift: shift.facts,
|
shift: shift.facts,
|
||||||
mail,
|
mail,
|
||||||
now,
|
now,
|
||||||
@@ -1413,7 +1426,7 @@ function bumpAndNotify(db: Database.Database, shiftId: number, now: string, mail
|
|||||||
function cancelConfirmedOnShift(db: Database.Database, shiftId: number, now: string, mail: MailIdentity): number {
|
function cancelConfirmedOnShift(db: Database.Database, shiftId: number, now: string, mail: MailIdentity): number {
|
||||||
const people = db
|
const people = db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT id, name, email_norm, shift_id, status
|
`SELECT id, name, email_norm, shift_id, status, group_size
|
||||||
FROM signups
|
FROM signups
|
||||||
WHERE shift_id = ? AND status = 'confirmed' AND anonymized_at IS NULL AND name IS NOT NULL AND email_norm IS NOT NULL`,
|
WHERE shift_id = ? AND status = 'confirmed' AND anonymized_at IS NULL AND name IS NOT NULL AND email_norm IS NOT NULL`,
|
||||||
)
|
)
|
||||||
@@ -1446,6 +1459,7 @@ function cancelConfirmedPerson(db: Database.Database, person: PersonRow, now: st
|
|||||||
token: issued.token,
|
token: issued.token,
|
||||||
volunteerName: person.name,
|
volunteerName: person.name,
|
||||||
volunteerEmail: person.email_norm,
|
volunteerEmail: person.email_norm,
|
||||||
|
groupSize: Number(person.group_size),
|
||||||
shift: shift.facts,
|
shift: shift.facts,
|
||||||
mail,
|
mail,
|
||||||
now,
|
now,
|
||||||
@@ -1658,6 +1672,7 @@ type PersonRow = {
|
|||||||
email_norm: string | null;
|
email_norm: string | null;
|
||||||
shift_id: number;
|
shift_id: number;
|
||||||
status: string;
|
status: string;
|
||||||
|
group_size: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
type MoveSource = {
|
type MoveSource = {
|
||||||
@@ -1673,5 +1688,6 @@ type MoveSource = {
|
|||||||
guardian_name: string | null;
|
guardian_name: string | null;
|
||||||
guardian_email: string | null;
|
guardian_email: string | null;
|
||||||
reminders_off: number;
|
reminders_off: number;
|
||||||
|
group_size: number;
|
||||||
status: string;
|
status: string;
|
||||||
};
|
};
|
||||||
@@ -123,18 +123,28 @@ export async function applyMigrations(
|
|||||||
}
|
}
|
||||||
const applied: string[] = [];
|
const applied: string[] = [];
|
||||||
for (const file of pending) {
|
for (const file of pending) {
|
||||||
|
const relaxForeignKeys = file.sql.split('\n').some((line) => line.trim() === '-- foreign-keys: off');
|
||||||
const apply = db.transaction(() => {
|
const apply = db.transaction(() => {
|
||||||
db.exec(file.sql);
|
db.exec(file.sql);
|
||||||
|
if (relaxForeignKeys) {
|
||||||
|
const broken = db.pragma('foreign_key_check');
|
||||||
|
if (Array.isArray(broken) && broken.length > 0) {
|
||||||
|
throw new Error('foreign key check failed');
|
||||||
|
}
|
||||||
|
}
|
||||||
db.prepare('INSERT INTO schema_migrations (name, checksum, applied_at) VALUES (?, ?, ?)').run(
|
db.prepare('INSERT INTO schema_migrations (name, checksum, applied_at) VALUES (?, ?, ?)').run(
|
||||||
file.name,
|
file.name,
|
||||||
file.checksum,
|
file.checksum,
|
||||||
options.now ?? nowUtc(),
|
options.now ?? nowUtc(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
if (relaxForeignKeys) db.pragma('foreign_keys = OFF');
|
||||||
try {
|
try {
|
||||||
apply();
|
apply();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new MigrationError(`Startup aborted. Migration ${file.name} failed: ${messageOf(err)}`);
|
throw new MigrationError(`Startup aborted. Migration ${file.name} failed: ${messageOf(err)}`);
|
||||||
|
} finally {
|
||||||
|
if (relaxForeignKeys) db.pragma('foreign_keys = ON');
|
||||||
}
|
}
|
||||||
applied.push(file.name);
|
applied.push(file.name);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -106,7 +106,7 @@ export async function runSeedCli(env: NodeJS.ProcessEnv = process.env): Promise<
|
|||||||
console.log(
|
console.log(
|
||||||
`Event ${result.slug}: ${result.shiftIds.length} one-off shifts and ${result.signupIds.length} fake signups.`,
|
`Event ${result.slug}: ${result.shiftIds.length} one-off shifts and ${result.signupIds.length} fake signups.`,
|
||||||
);
|
);
|
||||||
console.log('Each signup is one person. Another person can use the same email. Group size is fixed at 1.');
|
console.log('A signup can hold more than one person. The count reserves that many spots under one name.');
|
||||||
console.log('The weekly template is stored. Starting the app adds its shifts for the next three months.');
|
console.log('The weekly template is stored. Starting the app adds its shifts for the next three months.');
|
||||||
console.log('No coordinator account was created.');
|
console.log('No coordinator account was created.');
|
||||||
} finally {
|
} finally {
|
||||||
@@ -115,7 +115,7 @@ export async function runSeedCli(env: NodeJS.ProcessEnv = process.env): Promise<
|
|||||||
}
|
}
|
||||||
|
|
||||||
function insertFakeSignups(db: Database.Database, shiftId: number, createdAt: string): number[] {
|
function insertFakeSignups(db: Database.Database, shiftId: number, createdAt: string): number[] {
|
||||||
// TODO(D2): These rows are individual signups. Do not invent group reservations here.
|
// Seed rows stay one person each. A signup can hold more, but these fixtures do not.
|
||||||
// TODO(D4): Seed data does not create coordinator accounts.
|
// TODO(D4): Seed data does not create coordinator accounts.
|
||||||
const people = [
|
const people = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export type QueuedSignup = {
|
|||||||
token: string;
|
token: string;
|
||||||
volunteerName: string;
|
volunteerName: string;
|
||||||
volunteerEmail: string;
|
volunteerEmail: string;
|
||||||
|
groupSize?: number;
|
||||||
shift: MailShift;
|
shift: MailShift;
|
||||||
mail: MailIdentity;
|
mail: MailIdentity;
|
||||||
now: string;
|
now: string;
|
||||||
@@ -23,6 +24,7 @@ export function queueConfirmation(db: Database.Database, input: QueuedSignup): v
|
|||||||
shift: input.shift,
|
shift: input.shift,
|
||||||
manageUrl: manageUrl(input),
|
manageUrl: manageUrl(input),
|
||||||
replyTo: input.mail.replyTo,
|
replyTo: input.mail.replyTo,
|
||||||
|
groupSize: input.groupSize,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,6 +35,7 @@ export function queueCancellation(db: Database.Database, input: QueuedSignup): v
|
|||||||
manageUrl: manageUrl(input),
|
manageUrl: manageUrl(input),
|
||||||
replyTo: input.mail.replyTo,
|
replyTo: input.mail.replyTo,
|
||||||
linkNote: input.linkNote,
|
linkNote: input.linkNote,
|
||||||
|
groupSize: input.groupSize,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +46,7 @@ export function queueChanged(db: Database.Database, input: QueuedSignup, reason:
|
|||||||
shift: input.shift,
|
shift: input.shift,
|
||||||
manageUrl: manageUrl(input),
|
manageUrl: manageUrl(input),
|
||||||
replyTo: input.mail.replyTo,
|
replyTo: input.mail.replyTo,
|
||||||
|
groupSize: input.groupSize,
|
||||||
};
|
};
|
||||||
if (reason === 'move') return renderMoved(letter);
|
if (reason === 'move') return renderMoved(letter);
|
||||||
if (reason === 'switch') return renderSwitched(letter);
|
if (reason === 'switch') return renderSwitched(letter);
|
||||||
|
|||||||
+17
-5
@@ -23,12 +23,13 @@ export function renderConfirmation(input: {
|
|||||||
shift: MailShift;
|
shift: MailShift;
|
||||||
manageUrl: string;
|
manageUrl: string;
|
||||||
replyTo: string;
|
replyTo: string;
|
||||||
|
groupSize?: number;
|
||||||
}): RenderedMail {
|
}): RenderedMail {
|
||||||
const role = singleLine(input.shift.role);
|
const role = singleLine(input.shift.role);
|
||||||
const name = singleLine(input.volunteerName);
|
const name = singleLine(input.volunteerName);
|
||||||
return render({
|
return render({
|
||||||
subject: `You're signed up for ${role}`,
|
subject: `You're signed up for ${role}`,
|
||||||
hello: `You are signed up for ${role}.`,
|
hello: `You are signed up for ${role}.${partyNote(input.groupSize)}`,
|
||||||
greeting: `Hello ${name},`,
|
greeting: `Hello ${name},`,
|
||||||
shift: input.shift,
|
shift: input.shift,
|
||||||
linkLabel: 'Open this signup',
|
linkLabel: 'Open this signup',
|
||||||
@@ -44,12 +45,14 @@ export function renderCancellation(input: {
|
|||||||
manageUrl: string;
|
manageUrl: string;
|
||||||
replyTo: string;
|
replyTo: string;
|
||||||
linkNote?: string;
|
linkNote?: string;
|
||||||
|
groupSize?: number;
|
||||||
}): RenderedMail {
|
}): RenderedMail {
|
||||||
const role = singleLine(input.shift.role);
|
const role = singleLine(input.shift.role);
|
||||||
const name = singleLine(input.volunteerName);
|
const name = singleLine(input.volunteerName);
|
||||||
|
const spots = input.groupSize && input.groupSize > 1 ? `The ${input.groupSize} spots this signup held are open for someone else.` : 'The spot is open for someone else.';
|
||||||
return render({
|
return render({
|
||||||
subject: `Your signup for ${role} is cancelled`,
|
subject: `Your signup for ${role} is cancelled`,
|
||||||
hello: `Your signup for ${role} is cancelled. The spot is open for someone else.`,
|
hello: `Your signup for ${role} is cancelled. ${spots}`,
|
||||||
greeting: `Hello ${name},`,
|
greeting: `Hello ${name},`,
|
||||||
shift: input.shift,
|
shift: input.shift,
|
||||||
linkLabel: 'Open this signup',
|
linkLabel: 'Open this signup',
|
||||||
@@ -64,6 +67,7 @@ export function renderChanged(input: {
|
|||||||
shift: MailShift;
|
shift: MailShift;
|
||||||
manageUrl: string;
|
manageUrl: string;
|
||||||
replyTo: string;
|
replyTo: string;
|
||||||
|
groupSize?: number;
|
||||||
}): RenderedMail {
|
}): RenderedMail {
|
||||||
const role = singleLine(input.shift.role);
|
const role = singleLine(input.shift.role);
|
||||||
return changedLetter(input, `Your ${role} shift has changed`, `The time or place for your ${role} shift has changed.`);
|
return changedLetter(input, `Your ${role} shift has changed`, `The time or place for your ${role} shift has changed.`);
|
||||||
@@ -74,6 +78,7 @@ export function renderMoved(input: {
|
|||||||
shift: MailShift;
|
shift: MailShift;
|
||||||
manageUrl: string;
|
manageUrl: string;
|
||||||
replyTo: string;
|
replyTo: string;
|
||||||
|
groupSize?: number;
|
||||||
}): RenderedMail {
|
}): RenderedMail {
|
||||||
const role = singleLine(input.shift.role);
|
const role = singleLine(input.shift.role);
|
||||||
return changedLetter(input, `Your signup was moved to ${role}`, 'A coordinator moved your signup to a different shift.');
|
return changedLetter(input, `Your signup was moved to ${role}`, 'A coordinator moved your signup to a different shift.');
|
||||||
@@ -84,20 +89,21 @@ export function renderSwitched(input: {
|
|||||||
shift: MailShift;
|
shift: MailShift;
|
||||||
manageUrl: string;
|
manageUrl: string;
|
||||||
replyTo: string;
|
replyTo: string;
|
||||||
|
groupSize?: number;
|
||||||
}): RenderedMail {
|
}): RenderedMail {
|
||||||
const role = singleLine(input.shift.role);
|
const role = singleLine(input.shift.role);
|
||||||
return changedLetter(input, `Your signup was switched to ${role}`, 'You switched this signup to a different shift.');
|
return changedLetter(input, `Your signup was switched to ${role}`, 'You switched this signup to a different shift.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function changedLetter(
|
function changedLetter(
|
||||||
input: { volunteerName: string; shift: MailShift; manageUrl: string; replyTo: string },
|
input: { volunteerName: string; shift: MailShift; manageUrl: string; replyTo: string; groupSize?: number },
|
||||||
subject: string,
|
subject: string,
|
||||||
hello: string,
|
hello: string,
|
||||||
): RenderedMail {
|
): RenderedMail {
|
||||||
const name = singleLine(input.volunteerName);
|
const name = singleLine(input.volunteerName);
|
||||||
return render({
|
return render({
|
||||||
subject,
|
subject,
|
||||||
hello,
|
hello: `${hello}${partyNote(input.groupSize)}`,
|
||||||
greeting: `Hello ${name},`,
|
greeting: `Hello ${name},`,
|
||||||
shift: input.shift,
|
shift: input.shift,
|
||||||
linkLabel: 'Open this signup',
|
linkLabel: 'Open this signup',
|
||||||
@@ -112,11 +118,12 @@ export function renderReminder(input: {
|
|||||||
shift: MailShift;
|
shift: MailShift;
|
||||||
unsubscribeUrl: string;
|
unsubscribeUrl: string;
|
||||||
replyTo: string;
|
replyTo: string;
|
||||||
|
groupSize?: number;
|
||||||
}): RenderedMail {
|
}): RenderedMail {
|
||||||
const role = singleLine(input.shift.role);
|
const role = singleLine(input.shift.role);
|
||||||
const name = singleLine(input.volunteerName);
|
const name = singleLine(input.volunteerName);
|
||||||
const subject = `Reminder: ${role}`;
|
const subject = `Reminder: ${role}`;
|
||||||
const hello = `You are still signed up for ${role}.`;
|
const hello = `You are still signed up for ${role}.${partyNote(input.groupSize)}`;
|
||||||
const cancelNote = 'To cancel, use the link in your confirmation email.';
|
const cancelNote = 'To cancel, use the link in your confirmation email.';
|
||||||
const stopNote = `To stop reminder emails for this signup, open ${input.unsubscribeUrl}. The pantry reads mail sent to ${input.replyTo}. Stopping reminders does not cancel the signup. Confirmation, change, and cancellation emails still arrive.`;
|
const stopNote = `To stop reminder emails for this signup, open ${input.unsubscribeUrl}. The pantry reads mail sent to ${input.replyTo}. Stopping reminders does not cancel the signup. Confirmation, change, and cancellation emails still arrive.`;
|
||||||
const greeting = `Hello ${name},`;
|
const greeting = `Hello ${name},`;
|
||||||
@@ -179,6 +186,11 @@ export function renderMagicLink(input: { signInUrl: string; replyTo: string }):
|
|||||||
return { subject, text, html };
|
return { subject, text, html };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function partyNote(groupSize: number | undefined): string {
|
||||||
|
if (!groupSize || groupSize <= 1) return '';
|
||||||
|
return ` This signup holds ${groupSize} spots.`;
|
||||||
|
}
|
||||||
|
|
||||||
function render(input: {
|
function render(input: {
|
||||||
subject: string;
|
subject: string;
|
||||||
greeting: string;
|
greeting: string;
|
||||||
|
|||||||
+64
-8
@@ -3,7 +3,7 @@ import type { AppConfig } from './config.js';
|
|||||||
import { WEEKDAY_SHORT, calendarMonth, calendarToday, chooseCalendarMonth, monthStep, type CalendarDay } from './calendar.js';
|
import { WEEKDAY_SHORT, calendarMonth, calendarToday, chooseCalendarMonth, monthStep, type CalendarDay } from './calendar.js';
|
||||||
import { WEDNESDAY, spotsSentence, type PublicEvent, type PublicShift } from './schedule.js';
|
import { WEDNESDAY, spotsSentence, type PublicEvent, type PublicShift } from './schedule.js';
|
||||||
import { SIGNUP_TOO_EARLY, signupDeadlineLabel } from './signup-window.js';
|
import { SIGNUP_TOO_EARLY, signupDeadlineLabel } from './signup-window.js';
|
||||||
import type { SignupErrors, SignupValues } from './signup-form.js';
|
import { partyChoiceLabel, partyChoices, type SignupErrors, type SignupValues } from './signup-form.js';
|
||||||
import type { MoveTarget } from './admin/store.js';
|
import type { MoveTarget } from './admin/store.js';
|
||||||
import { ShiftTargetOptions } from './shift-options.js';
|
import { ShiftTargetOptions } from './shift-options.js';
|
||||||
import type { ManageView } from './signup.js';
|
import type { ManageView } from './signup.js';
|
||||||
@@ -282,7 +282,9 @@ export function ShiftPage(props: {
|
|||||||
{props.notice}
|
{props.notice}
|
||||||
</p>
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
{props.signup ? <SignupForm config={props.config} shiftId={props.shift.id} form={props.signup} /> : null}
|
{props.signup ? (
|
||||||
|
<SignupForm config={props.config} shiftId={props.shift.id} remaining={props.shift.remaining} form={props.signup} />
|
||||||
|
) : null}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -292,6 +294,7 @@ export function ConfirmationPage(props: {
|
|||||||
shift: PublicShift;
|
shift: PublicShift;
|
||||||
name: string | null;
|
name: string | null;
|
||||||
managePath: string | null;
|
managePath: string | null;
|
||||||
|
groupSize?: number;
|
||||||
cancelled?: boolean;
|
cancelled?: boolean;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
@@ -302,6 +305,7 @@ export function ConfirmationPage(props: {
|
|||||||
? `${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 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.name ? `${props.name} is on the ` : 'This signup is for the '}${props.shift.role} shift.`}
|
||||||
</p>
|
</p>
|
||||||
|
{props.groupSize && props.groupSize > 1 ? <p>This signup holds {props.groupSize} spots.</p> : null}
|
||||||
<ShiftWhen shift={props.shift} />
|
<ShiftWhen shift={props.shift} />
|
||||||
{props.managePath ? (
|
{props.managePath ? (
|
||||||
<>
|
<>
|
||||||
@@ -352,6 +356,10 @@ export function ManagePage(props: {
|
|||||||
<dt>Name</dt>
|
<dt>Name</dt>
|
||||||
<dd>{signup.name}</dd>
|
<dd>{signup.name}</dd>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt>People</dt>
|
||||||
|
<dd>{signup.groupSize}</dd>
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<dt>Email</dt>
|
<dt>Email</dt>
|
||||||
<dd>{signup.email}</dd>
|
<dd>{signup.email}</dd>
|
||||||
@@ -377,10 +385,18 @@ export function ManagePage(props: {
|
|||||||
) : null}
|
) : null}
|
||||||
{props.switches ? (
|
{props.switches ? (
|
||||||
props.switches.targets.length === 0 ? (
|
props.switches.targets.length === 0 ? (
|
||||||
<p>There is no other open shift you can switch to.</p>
|
<p>
|
||||||
|
{signup.groupSize > 1
|
||||||
|
? 'There is no other open shift with room for everyone on this signup.'
|
||||||
|
: 'There is no other open shift you can switch to.'}
|
||||||
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<form class="move-form" method="post" action={props.switches.action}>
|
<form class="move-form" method="post" action={props.switches.action}>
|
||||||
<p>Switch to another shift in this event. This opens your spot here and queues a change email. This link stops working, and the next page has the new one.</p>
|
<p>
|
||||||
|
{signup.groupSize > 1
|
||||||
|
? `Switch to another shift in this event. This opens the ${signup.groupSize} spots here and queues a change email. This link stops working, and the next page has the new one.`
|
||||||
|
: 'Switch to another shift in this event. This opens your spot here and queues a change email. This link stops working, and the next page has the new one.'}
|
||||||
|
</p>
|
||||||
<input type="hidden" name="switch_token" value={props.switches.token} />
|
<input type="hidden" name="switch_token" value={props.switches.token} />
|
||||||
<input type="hidden" name="form_token" value={props.switches.formToken} />
|
<input type="hidden" name="form_token" value={props.switches.formToken} />
|
||||||
<label for="switch-to">
|
<label for="switch-to">
|
||||||
@@ -406,12 +422,20 @@ export function ManagePage(props: {
|
|||||||
) : null}
|
) : null}
|
||||||
{props.cancel ? (
|
{props.cancel ? (
|
||||||
<form class="cancel-form" method="post" action={props.cancel.action}>
|
<form class="cancel-form" method="post" action={props.cancel.action}>
|
||||||
<p>Cancel this signup to open the spot for someone else. A cancellation email is queued when you cancel.</p>
|
<p>
|
||||||
|
{signup.groupSize > 1
|
||||||
|
? `Cancel this signup to open these ${signup.groupSize} spots for someone else. A cancellation email is queued when you cancel.`
|
||||||
|
: 'Cancel this signup to open the spot for someone else. A cancellation email is queued when you cancel.'}
|
||||||
|
</p>
|
||||||
<input type="hidden" name="cancel_token" value={props.cancel.token} />
|
<input type="hidden" name="cancel_token" value={props.cancel.token} />
|
||||||
<button type="submit">Cancel this signup</button>
|
<button type="submit">Cancel this signup</button>
|
||||||
</form>
|
</form>
|
||||||
) : (
|
) : (
|
||||||
<p>This signup is cancelled. The spot is open for someone else. A cancellation email is queued.</p>
|
<p>
|
||||||
|
{signup.groupSize > 1
|
||||||
|
? `This signup is cancelled. The ${signup.groupSize} spots it held are open for someone else. A cancellation email is queued.`
|
||||||
|
: 'This signup is cancelled. The spot is open for someone else. A cancellation email is queued.'}
|
||||||
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
@@ -874,14 +898,14 @@ function Spots(props: { shift: PublicShift }) {
|
|||||||
return <p class={props.shift.full ? 'spots is-full' : 'spots is-open'}>{spotsSentence(props.shift)}</p>;
|
return <p class={props.shift.full ? 'spots is-full' : 'spots is-open'}>{spotsSentence(props.shift)}</p>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function SignupForm(props: { config: AppConfig; shiftId: number; form: SignupFormView }) {
|
function SignupForm(props: { config: AppConfig; shiftId: number; remaining: number; form: SignupFormView }) {
|
||||||
const form = props.form;
|
const form = props.form;
|
||||||
const errors = form.errors;
|
const errors = form.errors;
|
||||||
const errorEntries = Object.entries(errors).filter((entry): entry is [string, string] => Boolean(entry[1]));
|
const errorEntries = Object.entries(errors).filter((entry): entry is [string, string] => Boolean(entry[1]));
|
||||||
return (
|
return (
|
||||||
<form class="signup-form" method="post" action={appPath(props.config, `/s/${props.shiftId}`)}>
|
<form class="signup-form" method="post" action={appPath(props.config, `/s/${props.shiftId}`)}>
|
||||||
<h2>Sign up</h2>
|
<h2>Sign up</h2>
|
||||||
<p>Each signup is for one person and takes one spot. Another person can use the same email address.</p>
|
<p>Choose how many people are coming, including you. This signup holds that many spots under your name. Another person can use the same email address.</p>
|
||||||
<noscript>
|
<noscript>
|
||||||
<p class="error">Signing up needs JavaScript for the abuse check. The pantry has not published a contact method for help with signup.</p>
|
<p class="error">Signing up needs JavaScript for the abuse check. The pantry has not published a contact method for help with signup.</p>
|
||||||
</noscript>
|
</noscript>
|
||||||
@@ -926,6 +950,7 @@ function SignupForm(props: { config: AppConfig; shiftId: number; form: SignupFor
|
|||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<PartySizeField idPrefix="signup" value={form.values.partySize} error={errors.partySize} remaining={props.remaining} />
|
||||||
<Field id="signup-email" label="Email" name="email" type="email" value={form.values.email} error={errors.email} autoComplete="email" />
|
<Field id="signup-email" label="Email" name="email" type="email" value={form.values.email} error={errors.email} autoComplete="email" />
|
||||||
<Field
|
<Field
|
||||||
id="signup-phone"
|
id="signup-phone"
|
||||||
@@ -955,6 +980,37 @@ function SignupForm(props: { config: AppConfig; shiftId: number; form: SignupFor
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function PartySizeField(props: { idPrefix: string; value: string; error?: string; remaining: number }) {
|
||||||
|
const id = `${props.idPrefix}-partySize`;
|
||||||
|
const hintId = `${id}-hint`;
|
||||||
|
const errorId = `${id}-error`;
|
||||||
|
return (
|
||||||
|
<label for={id}>
|
||||||
|
How many people?
|
||||||
|
<select
|
||||||
|
id={id}
|
||||||
|
name="party_size"
|
||||||
|
aria-invalid={props.error ? 'true' : undefined}
|
||||||
|
aria-describedby={props.error ? `${hintId} ${errorId}` : hintId}
|
||||||
|
>
|
||||||
|
{partyChoices(props.remaining).map((count) => (
|
||||||
|
<option key={count} value={String(count)} selected={props.value === String(count) ? true : undefined}>
|
||||||
|
{partyChoiceLabel(count)}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<span class="hint" id={hintId}>
|
||||||
|
Including you. This signup holds that many spots. You don't need to add their names.
|
||||||
|
</span>
|
||||||
|
{props.error ? (
|
||||||
|
<span class="field-error" id={errorId}>
|
||||||
|
{props.error}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</label>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function Field(props: {
|
function Field(props: {
|
||||||
id: string;
|
id: string;
|
||||||
label: string;
|
label: string;
|
||||||
|
|||||||
+3
-1
@@ -22,6 +22,7 @@ type DueSignup = {
|
|||||||
location: string;
|
location: string;
|
||||||
tz: string;
|
tz: string;
|
||||||
shift_id: number;
|
shift_id: number;
|
||||||
|
group_size: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,7 +38,7 @@ export function queueDueReminders(db: Database.Database, mail: MailIdentity, sec
|
|||||||
const activeMail = { ...mail, replyTo: readReplyTo(db, mail.replyTo) };
|
const activeMail = { ...mail, replyTo: readReplyTo(db, mail.replyTo) };
|
||||||
const rows = db
|
const rows = db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT su.id AS id, su.name AS name, su.email_norm AS email_norm,
|
`SELECT su.id AS id, su.name AS name, su.email_norm AS email_norm, su.group_size AS group_size,
|
||||||
su.shift_id AS shift_id, s.version AS version, s.starts_at_utc AS starts_at_utc,
|
su.shift_id AS shift_id, s.version AS version, s.starts_at_utc AS starts_at_utc,
|
||||||
s.ends_at_utc AS ends_at_utc, s.role AS role,
|
s.ends_at_utc AS ends_at_utc, s.role AS role,
|
||||||
e.title AS title, e.location AS location, e.tz AS tz
|
e.title AS title, e.location AS location, e.tz AS tz
|
||||||
@@ -156,6 +157,7 @@ function insertOutbox(
|
|||||||
shift: shiftFacts(row),
|
shift: shiftFacts(row),
|
||||||
unsubscribeUrl,
|
unsubscribeUrl,
|
||||||
replyTo: mail.replyTo,
|
replyTo: mail.replyTo,
|
||||||
|
groupSize: Number(row.group_size),
|
||||||
})
|
})
|
||||||
: { subject: 'Reminder not sent', text: 'This reminder was not sent.', html: '<p>This reminder was not sent.</p>' };
|
: { subject: 'Reminder not sent', text: 'This reminder was not sent.', html: '<p>This reminder was not sent.</p>' };
|
||||||
const saved = db
|
const saved = db
|
||||||
|
|||||||
+10
-4
@@ -152,6 +152,11 @@ export function spotsSentence(shift: Pick<PublicShift, 'occupied' | 'capacity'>)
|
|||||||
return `${filled}/${shift.capacity} spots filled`;
|
return `${filled}/${shift.capacity} spots filled`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** One roster line. A signup that holds several spots stays one name, with the count beside it. */
|
||||||
|
export function partyRosterLabel(name: string, groupSize: number): string {
|
||||||
|
return groupSize > 1 ? `${name} (${groupSize} people)` : name;
|
||||||
|
}
|
||||||
|
|
||||||
function presentShift(row: ShiftRow, now: string, volunteers: string[]): PublicShift {
|
function presentShift(row: ShiftRow, now: string, volunteers: string[]): PublicShift {
|
||||||
const start = formatInstantInZone(row.starts_at_utc, row.tz);
|
const start = formatInstantInZone(row.starts_at_utc, row.tz);
|
||||||
const end = formatInstantInZone(row.ends_at_utc, row.tz);
|
const end = formatInstantInZone(row.ends_at_utc, row.tz);
|
||||||
@@ -205,17 +210,18 @@ function volunteerNamesByShift(db: Database.Database, shiftIds: number[]): Map<n
|
|||||||
const marks = shiftIds.map(() => '?').join(', ');
|
const marks = shiftIds.map(() => '?').join(', ');
|
||||||
const rows = db
|
const rows = db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT shift_id AS shift_id, name AS name
|
`SELECT shift_id AS shift_id, name AS name, group_size AS group_size
|
||||||
FROM signups
|
FROM signups
|
||||||
WHERE status = 'confirmed' AND anonymized_at IS NULL AND name IS NOT NULL
|
WHERE status = 'confirmed' AND anonymized_at IS NULL AND name IS NOT NULL
|
||||||
AND shift_id IN (${marks})
|
AND shift_id IN (${marks})
|
||||||
ORDER BY name COLLATE NOCASE, id`,
|
ORDER BY name COLLATE NOCASE, id`,
|
||||||
)
|
)
|
||||||
.all(...shiftIds) as { shift_id: number; name: string }[];
|
.all(...shiftIds) as { shift_id: number; name: string; group_size: number }[];
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
|
const label = partyRosterLabel(row.name, Number(row.group_size));
|
||||||
const listed = names.get(row.shift_id);
|
const listed = names.get(row.shift_id);
|
||||||
if (listed) listed.push(row.name);
|
if (listed) listed.push(label);
|
||||||
else names.set(row.shift_id, [row.name]);
|
else names.set(row.shift_id, [label]);
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
+42
-2
@@ -6,6 +6,9 @@ const NAME_MAX = 80;
|
|||||||
const PHONE_MAX = 40;
|
const PHONE_MAX = 40;
|
||||||
const NOTES_MAX = 500;
|
const NOTES_MAX = 500;
|
||||||
|
|
||||||
|
/** One signup can hold this many spots. The database check uses the same bound. */
|
||||||
|
export const MAX_PARTY_SIZE = 20;
|
||||||
|
|
||||||
export type SignupValues = {
|
export type SignupValues = {
|
||||||
name: string;
|
name: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
@@ -13,10 +16,11 @@ export type SignupValues = {
|
|||||||
email: string;
|
email: string;
|
||||||
phone: string;
|
phone: string;
|
||||||
notes: string;
|
notes: string;
|
||||||
|
partySize: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SignupErrors = Partial<
|
export type SignupErrors = Partial<
|
||||||
Record<'name' | 'firstName' | 'lastName' | 'email' | 'phone' | 'notes' | 'form', string>
|
Record<'name' | 'firstName' | 'lastName' | 'email' | 'phone' | 'notes' | 'partySize' | 'form', string>
|
||||||
>;
|
>;
|
||||||
|
|
||||||
export type SignupDraft = {
|
export type SignupDraft = {
|
||||||
@@ -25,6 +29,7 @@ export type SignupDraft = {
|
|||||||
emailNorm: string;
|
emailNorm: string;
|
||||||
phone: string;
|
phone: string;
|
||||||
notes: string | null;
|
notes: string | null;
|
||||||
|
groupSize: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const EMPTY_SIGNUP: SignupValues = {
|
export const EMPTY_SIGNUP: SignupValues = {
|
||||||
@@ -34,8 +39,24 @@ export const EMPTY_SIGNUP: SignupValues = {
|
|||||||
email: '',
|
email: '',
|
||||||
phone: '',
|
phone: '',
|
||||||
notes: '',
|
notes: '',
|
||||||
|
partySize: '1',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Choices for the people control. Never offers more than the spots still open, or more than the stored maximum. */
|
||||||
|
export function partyChoices(remaining: number): number[] {
|
||||||
|
const room = Math.max(0, Math.floor(remaining));
|
||||||
|
const cap = Math.min(MAX_PARTY_SIZE, room);
|
||||||
|
return Array.from({ length: cap }, (_, index) => index + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function partyChoiceLabel(count: number): string {
|
||||||
|
return count === 1 ? '1 person' : `${count} people`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function spotsLeftMessage(remaining: number): string {
|
||||||
|
return remaining === 1 ? 'This shift has 1 spot left.' : `This shift has ${remaining} spots left.`;
|
||||||
|
}
|
||||||
|
|
||||||
const controlChars = /[\u0000-\u001F\u007F]/;
|
const controlChars = /[\u0000-\u001F\u007F]/;
|
||||||
|
|
||||||
function personPart(raw: string, label: string): { value: string; error?: string } {
|
function personPart(raw: string, label: string): { value: string; error?: string } {
|
||||||
@@ -59,6 +80,7 @@ export function parseSignupForm(
|
|||||||
email: z.string(),
|
email: z.string(),
|
||||||
phone: z.string(),
|
phone: z.string(),
|
||||||
notes: z.string(),
|
notes: z.string(),
|
||||||
|
partySize: z.string(),
|
||||||
})
|
})
|
||||||
.safeParse(input);
|
.safeParse(input);
|
||||||
if (!parsed.success) return { ok: false, errors: { form: 'Check the signup fields and try again.' } };
|
if (!parsed.success) return { ok: false, errors: { form: 'Check the signup fields and try again.' } };
|
||||||
@@ -99,7 +121,12 @@ export function parseSignupForm(
|
|||||||
if (notes.length > NOTES_MAX) errors.notes = `Use ${NOTES_MAX} characters or fewer.`;
|
if (notes.length > NOTES_MAX) errors.notes = `Use ${NOTES_MAX} characters or fewer.`;
|
||||||
else if (controlChars.test(notes)) errors.notes = 'Enter notes without control characters.';
|
else if (controlChars.test(notes)) errors.notes = 'Enter notes without control characters.';
|
||||||
|
|
||||||
if (Object.keys(errors).length > 0 || emailNorm.length === 0 || phone.length === 0) return { ok: false, errors };
|
const party = readPartySize(parsed.data.partySize, voice);
|
||||||
|
if (party.error) errors.partySize = party.error;
|
||||||
|
|
||||||
|
if (Object.keys(errors).length > 0 || emailNorm.length === 0 || phone.length === 0 || party.error) {
|
||||||
|
return { ok: false, errors };
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
ok: true,
|
ok: true,
|
||||||
draft: {
|
draft: {
|
||||||
@@ -108,6 +135,19 @@ export function parseSignupForm(
|
|||||||
emailNorm,
|
emailNorm,
|
||||||
phone,
|
phone,
|
||||||
notes: notes.length === 0 ? null : notes,
|
notes: notes.length === 0 ? null : notes,
|
||||||
|
groupSize: party.value,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readPartySize(raw: string, voice: 'volunteer' | 'coordinator'): { value: number; error?: string } {
|
||||||
|
const trimmed = raw.trim();
|
||||||
|
if (trimmed.length === 0) return { value: 1 };
|
||||||
|
const label = voice === 'coordinator' ? 'Choose how many people are here.' : 'Choose how many people are coming.';
|
||||||
|
if (!/^[1-9]\d*$/.test(trimmed)) return { value: 1, error: label };
|
||||||
|
const value = Number(trimmed);
|
||||||
|
if (!Number.isSafeInteger(value) || value < 1 || value > MAX_PARTY_SIZE) {
|
||||||
|
return { value: 1, error: `Choose ${MAX_PARTY_SIZE} people or fewer.` };
|
||||||
|
}
|
||||||
|
return { value };
|
||||||
|
}
|
||||||
+19
-3
@@ -27,7 +27,7 @@ import {
|
|||||||
import { recordInvalidManageToken, recordSignupEmail, recordSignupIp, recordSwitchAttempt } from './rate-limit.js';
|
import { recordInvalidManageToken, recordSignupEmail, recordSignupIp, recordSwitchAttempt } from './rate-limit.js';
|
||||||
import { getPublicShift, type PublicShift } from './schedule.js';
|
import { getPublicShift, type PublicShift } from './schedule.js';
|
||||||
import { SIGNUP_TOO_EARLY } from './signup-window.js';
|
import { SIGNUP_TOO_EARLY } from './signup-window.js';
|
||||||
import { EMPTY_SIGNUP, parseSignupForm, type SignupErrors, type SignupValues } from './signup-form.js';
|
import { EMPTY_SIGNUP, parseSignupForm, spotsLeftMessage, type SignupErrors, type SignupValues } from './signup-form.js';
|
||||||
import type { MailIdentity } from './mail/types.js';
|
import type { MailIdentity } from './mail/types.js';
|
||||||
import { disableReminders } from './reminders.js';
|
import { disableReminders } from './reminders.js';
|
||||||
import { cancelSignup, confirmedOperationShift, findSignupByOperation, readManageSignup, reserveSignup } from './signup.js';
|
import { cancelSignup, confirmedOperationShift, findSignupByOperation, readManageSignup, reserveSignup } from './signup.js';
|
||||||
@@ -90,6 +90,7 @@ export function registerPublicSignup(app: Hono, services: SignupServices): void
|
|||||||
shift={shift}
|
shift={shift}
|
||||||
name={matches && manage ? manage.name : null}
|
name={matches && manage ? manage.name : null}
|
||||||
managePath={matches && seal ? appPath(config, `/m/${seal.token}`) : null}
|
managePath={matches && seal ? appPath(config, `/m/${seal.token}`) : null}
|
||||||
|
groupSize={matches && manage ? manage.groupSize : undefined}
|
||||||
cancelled={cancelled}
|
cancelled={cancelled}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
@@ -163,6 +164,7 @@ async function submitSignup(c: Context, services: SignupServices): Promise<Respo
|
|||||||
email: parsed.draft.emailNorm,
|
email: parsed.draft.emailNorm,
|
||||||
phone: parsed.draft.phone,
|
phone: parsed.draft.phone,
|
||||||
notes: parsed.draft.notes,
|
notes: parsed.draft.notes,
|
||||||
|
groupSize: parsed.draft.groupSize,
|
||||||
operationId: tokenResult.claims.operationId,
|
operationId: tokenResult.claims.operationId,
|
||||||
now,
|
now,
|
||||||
mail: mailIdentity(db, config),
|
mail: mailIdentity(db, config),
|
||||||
@@ -171,7 +173,19 @@ async function submitSignup(c: Context, services: SignupServices): Promise<Respo
|
|||||||
if (reserved.reason === 'not_found') return html(c, services, 'That page is not available · Hope Volunteer', <NotFoundPage />, 404);
|
if (reserved.reason === 'not_found') return html(c, services, 'That page is not available · Hope Volunteer', <NotFoundPage />, 404);
|
||||||
if (reserved.reason === 'closed') return shiftResponse(c, services, loadShift(services, String(shift.id)) ?? shift, 400, null, CLOSED);
|
if (reserved.reason === 'closed') return shiftResponse(c, services, loadShift(services, String(shift.id)) ?? shift, 400, null, CLOSED);
|
||||||
if (reserved.reason === 'early') return shiftResponse(c, services, loadShift(services, String(shift.id)) ?? shift, 400, null, SIGNUP_TOO_EARLY);
|
if (reserved.reason === 'early') return shiftResponse(c, services, loadShift(services, String(shift.id)) ?? shift, 400, null, SIGNUP_TOO_EARLY);
|
||||||
if (reserved.reason === 'full') return shiftResponse(c, services, loadShift(services, String(shift.id)) ?? shift, 409, null, FULL);
|
if (reserved.reason === 'full') {
|
||||||
|
const current = loadShift(services, String(shift.id)) ?? shift;
|
||||||
|
if (current.remaining > 0) {
|
||||||
|
return shiftResponse(
|
||||||
|
c,
|
||||||
|
services,
|
||||||
|
current,
|
||||||
|
409,
|
||||||
|
formFor(services, shift, values, { partySize: spotsLeftMessage(current.remaining) }, textField(body, 'form_token')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return shiftResponse(c, services, current, 409, null, FULL);
|
||||||
|
}
|
||||||
if (reserved.reason === 'duplicate') {
|
if (reserved.reason === 'duplicate') {
|
||||||
return shiftResponse(c, services, shift, 409, formFor(services, shift, values, {}, null), ALREADY_SIGNED_UP);
|
return shiftResponse(c, services, shift, 409, formFor(services, shift, values, {}, null), ALREADY_SIGNED_UP);
|
||||||
}
|
}
|
||||||
@@ -277,6 +291,7 @@ function valuesFrom(body: Record<string, unknown>): SignupValues {
|
|||||||
email: textField(body, 'email'),
|
email: textField(body, 'email'),
|
||||||
phone: textField(body, 'phone'),
|
phone: textField(body, 'phone'),
|
||||||
notes: textField(body, 'notes'),
|
notes: textField(body, 'notes'),
|
||||||
|
partySize: textField(body, 'party_size'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,11 +414,12 @@ function switchedAlready(c: Context, services: SignupServices, token: string, bo
|
|||||||
return html(c, services, 'Your signup · Hope Volunteer', <SwitchAlreadyPage />);
|
return html(c, services, 'Your signup · Hope Volunteer', <SwitchAlreadyPage />);
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchForm(services: SignupServices, token: string, signup: { status: 'confirmed' | 'cancelled'; shiftId: number; eventId: number; name: string; email: string }): SwitchForm | null {
|
function switchForm(services: SignupServices, token: string, signup: { status: 'confirmed' | 'cancelled'; shiftId: number; eventId: number; name: string; email: string; groupSize: number }): SwitchForm | null {
|
||||||
if (signup.status !== 'confirmed') return null;
|
if (signup.status !== 'confirmed') return null;
|
||||||
const targets = listMoveTargets(services.db, signup.eventId, signup.shiftId, services.now(), {
|
const targets = listMoveTargets(services.db, signup.eventId, signup.shiftId, services.now(), {
|
||||||
publishedOnly: true,
|
publishedOnly: true,
|
||||||
signupWindow: true,
|
signupWindow: true,
|
||||||
|
spotsNeeded: signup.groupSize,
|
||||||
});
|
});
|
||||||
if (targets.length === 0) return { action: '', token: '', formToken: '', targets };
|
if (targets.length === 0) return { action: '', token: '', formToken: '', targets };
|
||||||
return {
|
return {
|
||||||
|
|||||||
+18
-4
@@ -5,6 +5,7 @@ import { rememberSignupContact } from './contacts.js';
|
|||||||
import { normalizeEmail } from './email.js';
|
import { normalizeEmail } from './email.js';
|
||||||
import { queueCancellation, queueConfirmation, cancelPendingConfirmations, cancelPendingReminders } from './mail/queue.js';
|
import { queueCancellation, queueConfirmation, cancelPendingConfirmations, cancelPendingReminders } from './mail/queue.js';
|
||||||
import type { MailIdentity } from './mail/types.js';
|
import type { MailIdentity } from './mail/types.js';
|
||||||
|
import { MAX_PARTY_SIZE } from './signup-form.js';
|
||||||
import { isWithinSignupWindow } from './signup-window.js';
|
import { isWithinSignupWindow } from './signup-window.js';
|
||||||
import { formatInstantInZone, formatUtc, todayInZone, type ZonedClock } from './time.js';
|
import { formatInstantInZone, formatUtc, todayInZone, type ZonedClock } from './time.js';
|
||||||
|
|
||||||
@@ -16,6 +17,8 @@ export type ReserveInput = {
|
|||||||
email: string;
|
email: string;
|
||||||
phone: string | null;
|
phone: string | null;
|
||||||
notes: string | null;
|
notes: string | null;
|
||||||
|
/** Spots this one signup holds, including the person named on it. Omitted means 1. */
|
||||||
|
groupSize?: number;
|
||||||
operationId: string;
|
operationId: string;
|
||||||
now: string;
|
now: string;
|
||||||
mail: MailIdentity;
|
mail: MailIdentity;
|
||||||
@@ -34,6 +37,7 @@ export type ManageView = {
|
|||||||
email: string;
|
email: string;
|
||||||
phone: string | null;
|
phone: string | null;
|
||||||
notes: string | null;
|
notes: string | null;
|
||||||
|
groupSize: number;
|
||||||
status: 'confirmed' | 'cancelled';
|
status: 'confirmed' | 'cancelled';
|
||||||
remindersOff: boolean;
|
remindersOff: boolean;
|
||||||
emailNorm: string;
|
emailNorm: string;
|
||||||
@@ -46,7 +50,7 @@ export type ManageView = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes one spot only when the published shift still has room.
|
* Takes groupSize spots when the published shift still has room for all of them.
|
||||||
* The immediate transaction is the capacity lock and also queues confirmation mail.
|
* The immediate transaction is the capacity lock and also queues confirmation mail.
|
||||||
* A later send failure does not undo the reservation.
|
* A later send failure does not undo the reservation.
|
||||||
*/
|
*/
|
||||||
@@ -104,6 +108,7 @@ export function readManageSignup(db: Database.Database, token: string, now: stri
|
|||||||
su.email AS email,
|
su.email AS email,
|
||||||
su.phone AS phone,
|
su.phone AS phone,
|
||||||
su.notes AS notes,
|
su.notes AS notes,
|
||||||
|
su.group_size AS group_size,
|
||||||
su.status AS status,
|
su.status AS status,
|
||||||
su.reminders_off AS reminders_off,
|
su.reminders_off AS reminders_off,
|
||||||
su.email_norm AS email_norm,
|
su.email_norm AS email_norm,
|
||||||
@@ -130,6 +135,7 @@ export function readManageSignup(db: Database.Database, token: string, now: stri
|
|||||||
email: row.email,
|
email: row.email,
|
||||||
phone: row.phone,
|
phone: row.phone,
|
||||||
notes: row.notes,
|
notes: row.notes,
|
||||||
|
groupSize: Number(row.group_size),
|
||||||
status: row.status,
|
status: row.status,
|
||||||
remindersOff: row.reminders_off === 1,
|
remindersOff: row.reminders_off === 1,
|
||||||
emailNorm: row.email_norm,
|
emailNorm: row.email_norm,
|
||||||
@@ -183,6 +189,9 @@ function placeReservation(db: Database.Database, input: ReserveInput, emailNorm:
|
|||||||
}
|
}
|
||||||
if (confirmedPersonOnShift(db, input.shiftId, emailNorm, input.name)) return { ok: false, reason: 'duplicate' };
|
if (confirmedPersonOnShift(db, input.shiftId, emailNorm, input.name)) return { ok: false, reason: 'duplicate' };
|
||||||
|
|
||||||
|
const groupSize = input.groupSize ?? 1;
|
||||||
|
if (!Number.isInteger(groupSize) || groupSize < 1 || groupSize > MAX_PARTY_SIZE) return { ok: false, reason: 'conflict' };
|
||||||
|
|
||||||
const occupied = db
|
const occupied = db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT COALESCE(SUM(group_size), 0) AS occupied
|
`SELECT COALESCE(SUM(group_size), 0) AS occupied
|
||||||
@@ -190,7 +199,7 @@ function placeReservation(db: Database.Database, input: ReserveInput, emailNorm:
|
|||||||
WHERE shift_id = ? AND status = 'confirmed'`,
|
WHERE shift_id = ? AND status = 'confirmed'`,
|
||||||
)
|
)
|
||||||
.get(input.shiftId) as { occupied: number };
|
.get(input.shiftId) as { occupied: number };
|
||||||
if (Number(occupied.occupied) + 1 > shift.capacity) return { ok: false, reason: 'full' };
|
if (Number(occupied.occupied) + groupSize > shift.capacity) return { ok: false, reason: 'full' };
|
||||||
|
|
||||||
const manageToken = randomBytes(32).toString('base64url');
|
const manageToken = randomBytes(32).toString('base64url');
|
||||||
const expiresAt = formatUtc(Temporal.Instant.from(shift.ends_at_utc).add({ hours: MANAGE_TOKEN_TTL_HOURS }));
|
const expiresAt = formatUtc(Temporal.Instant.from(shift.ends_at_utc).add({ hours: MANAGE_TOKEN_TTL_HOURS }));
|
||||||
@@ -200,7 +209,7 @@ function placeReservation(db: Database.Database, input: ReserveInput, emailNorm:
|
|||||||
shift_id, name, email, email_norm, phone, is_minor, guardian_name, guardian_email,
|
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,
|
group_size, notes, status, manage_token_hash, token_expires_at, reminders_off,
|
||||||
created_at, updated_at, operation_key
|
created_at, updated_at, operation_key
|
||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1, ?, 'confirmed', ?, ?, 0, ?, ?, ?)`,
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'confirmed', ?, ?, 0, ?, ?, ?)`,
|
||||||
)
|
)
|
||||||
.run(
|
.run(
|
||||||
input.shiftId,
|
input.shiftId,
|
||||||
@@ -211,6 +220,7 @@ function placeReservation(db: Database.Database, input: ReserveInput, emailNorm:
|
|||||||
0,
|
0,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
groupSize,
|
||||||
input.notes,
|
input.notes,
|
||||||
sha256(manageToken),
|
sha256(manageToken),
|
||||||
expiresAt,
|
expiresAt,
|
||||||
@@ -226,6 +236,7 @@ function placeReservation(db: Database.Database, input: ReserveInput, emailNorm:
|
|||||||
token: manageToken,
|
token: manageToken,
|
||||||
volunteerName: input.name,
|
volunteerName: input.name,
|
||||||
volunteerEmail: emailNorm,
|
volunteerEmail: emailNorm,
|
||||||
|
groupSize,
|
||||||
shift: shiftFacts(shift).facts,
|
shift: shiftFacts(shift).facts,
|
||||||
mail: input.mail,
|
mail: input.mail,
|
||||||
now: input.now,
|
now: input.now,
|
||||||
@@ -275,7 +286,7 @@ function cancelConfirmed(db: Database.Database, hash: string, token: string, now
|
|||||||
const row = db
|
const row = db
|
||||||
.prepare(
|
.prepare(
|
||||||
`SELECT su.id AS id, su.status AS status, su.token_expires_at AS token_expires_at, su.anonymized_at AS anonymized_at,
|
`SELECT su.id AS id, su.status AS status, su.token_expires_at AS token_expires_at, su.anonymized_at AS anonymized_at,
|
||||||
su.name AS name, su.email_norm AS email_norm, su.shift_id AS shift_id
|
su.name AS name, su.email_norm AS email_norm, su.shift_id AS shift_id, su.group_size AS group_size
|
||||||
FROM signups su
|
FROM signups su
|
||||||
WHERE su.manage_token_hash = ?`,
|
WHERE su.manage_token_hash = ?`,
|
||||||
)
|
)
|
||||||
@@ -288,6 +299,7 @@ function cancelConfirmed(db: Database.Database, hash: string, token: string, now
|
|||||||
name: string | null;
|
name: string | null;
|
||||||
email_norm: string | null;
|
email_norm: string | null;
|
||||||
shift_id: number;
|
shift_id: number;
|
||||||
|
group_size: number;
|
||||||
}
|
}
|
||||||
| undefined;
|
| undefined;
|
||||||
if (!row || row.anonymized_at || !row.token_expires_at || row.token_expires_at <= now) {
|
if (!row || row.anonymized_at || !row.token_expires_at || row.token_expires_at <= now) {
|
||||||
@@ -314,6 +326,7 @@ function cancelConfirmed(db: Database.Database, hash: string, token: string, now
|
|||||||
token,
|
token,
|
||||||
volunteerName: row.name,
|
volunteerName: row.name,
|
||||||
volunteerEmail: row.email_norm,
|
volunteerEmail: row.email_norm,
|
||||||
|
groupSize: Number(row.group_size),
|
||||||
shift: shift.facts,
|
shift: shift.facts,
|
||||||
mail,
|
mail,
|
||||||
now,
|
now,
|
||||||
@@ -396,6 +409,7 @@ type ManageRow = {
|
|||||||
email_norm: string | null;
|
email_norm: string | null;
|
||||||
phone: string | null;
|
phone: string | null;
|
||||||
notes: string | null;
|
notes: string | null;
|
||||||
|
group_size: number;
|
||||||
status: string;
|
status: string;
|
||||||
reminders_off: number;
|
reminders_off: number;
|
||||||
token_expires_at: string | null;
|
token_expires_at: string | null;
|
||||||
|
|||||||
+48
-2
@@ -200,7 +200,49 @@ describe('database startup', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('signup and shift constraints', () => {
|
describe('signup and shift constraints', () => {
|
||||||
it('enforces capacity, individual signups, duplicates, anonymization, and history', async () => {
|
it('keeps existing signups when one signup can hold several spots', async () => {
|
||||||
|
const root = makeDir();
|
||||||
|
const migrations = path.join(root, 'migrations');
|
||||||
|
const dataDir = path.join(root, 'data');
|
||||||
|
mkdirSync(migrations);
|
||||||
|
const real = defaultMigrationsDir();
|
||||||
|
for (const name of readdirSync(real)) {
|
||||||
|
if (name.startsWith('008')) continue;
|
||||||
|
copyFileSync(path.join(real, name), path.join(migrations, name));
|
||||||
|
}
|
||||||
|
const config = loadConfig(devEnv({ DATA_DIR: dataDir }));
|
||||||
|
const first = await openAppDatabase(config, { migrationsDir: migrations });
|
||||||
|
const parents = insertParents(first);
|
||||||
|
insertSignup(first, parents.shiftId, { email: 'ada@example.invalid', emailNorm: 'ada@example.invalid' });
|
||||||
|
const signupId = Number((first.prepare('SELECT id AS id FROM signups').get() as { id: number }).id);
|
||||||
|
first
|
||||||
|
.prepare(
|
||||||
|
`INSERT INTO outbox (
|
||||||
|
dedupe_key, signup_id, shift_id, kind, to_email, subject, body_text, body_html, send_after, status, created_at
|
||||||
|
) VALUES ('keep', ?, ?, 'confirmation', 'ada@example.invalid', 'Hi', 'Hi', '<p>Hi</p>', ?, 'pending', ?)`,
|
||||||
|
)
|
||||||
|
.run(signupId, parents.shiftId, INSTANT, INSTANT);
|
||||||
|
first.close();
|
||||||
|
|
||||||
|
copyFileSync(path.join(real, '008_party_size.sql'), path.join(migrations, '008_party_size.sql'));
|
||||||
|
const second = await openAppDatabase(config, { migrationsDir: migrations });
|
||||||
|
try {
|
||||||
|
expect(second.pragma('foreign_keys', { simple: true })).toBe(1);
|
||||||
|
expect(second.prepare('PRAGMA foreign_key_check').all()).toEqual([]);
|
||||||
|
expect(second.prepare('SELECT name, group_size FROM signups WHERE id = ?').get(signupId)).toEqual({
|
||||||
|
name: 'Fake Person',
|
||||||
|
group_size: 1,
|
||||||
|
});
|
||||||
|
expect(second.prepare('SELECT signup_id AS signup_id FROM outbox WHERE dedupe_key = ?').get('keep')).toEqual({
|
||||||
|
signup_id: signupId,
|
||||||
|
});
|
||||||
|
expect(second.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'signups_next'").get()).toBeUndefined();
|
||||||
|
} finally {
|
||||||
|
second.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('enforces capacity, party size, duplicates, anonymization, and history', async () => {
|
||||||
const dataDir = path.join(makeDir(), 'data');
|
const dataDir = path.join(makeDir(), 'data');
|
||||||
const db = await openAppDatabase(loadConfig(devEnv({ DATA_DIR: dataDir })));
|
const db = await openAppDatabase(loadConfig(devEnv({ DATA_DIR: dataDir })));
|
||||||
try {
|
try {
|
||||||
@@ -246,8 +288,12 @@ describe('signup and shift constraints', () => {
|
|||||||
status: 'cancelled',
|
status: 'cancelled',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
insertSignup(db, parents.shiftId, { email: 'ben@example.invalid', emailNorm: 'ben@example.invalid', groupSize: 2 });
|
||||||
expect(() =>
|
expect(() =>
|
||||||
insertSignup(db, parents.shiftId, { email: 'ben@example.invalid', emailNorm: 'ben@example.invalid', groupSize: 2 }),
|
insertSignup(db, parents.shiftId, { email: 'zero@example.invalid', emailNorm: 'zero@example.invalid', groupSize: 0 }),
|
||||||
|
).toThrow(/CHECK/);
|
||||||
|
expect(() =>
|
||||||
|
insertSignup(db, parents.shiftId, { email: 'many@example.invalid', emailNorm: 'many@example.invalid', groupSize: 21 }),
|
||||||
).toThrow(/CHECK/);
|
).toThrow(/CHECK/);
|
||||||
expect(() =>
|
expect(() =>
|
||||||
insertSignup(db, parents.shiftId, {
|
insertSignup(db, parents.shiftId, {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { loadConfig } from '../src/config.js';
|
|||||||
import { openAppDatabase } from '../src/db.js';
|
import { openAppDatabase } from '../src/db.js';
|
||||||
import { issueFormToken, MIN_FILL_MS } from '../src/form-token.js';
|
import { issueFormToken, MIN_FILL_MS } from '../src/form-token.js';
|
||||||
import { SIGNUP_EMAIL_LIMIT, SIGNUP_IP_LIMIT } from '../src/rate-limit.js';
|
import { SIGNUP_EMAIL_LIMIT, SIGNUP_IP_LIMIT } from '../src/rate-limit.js';
|
||||||
|
import { switchSignup } from '../src/admin/store.js';
|
||||||
import type { ReserveInput } from '../src/signup.js';
|
import type { ReserveInput } from '../src/signup.js';
|
||||||
import { verifyTurnstile, type TurnstileVerdict } from '../src/turnstile.js';
|
import { verifyTurnstile, type TurnstileVerdict } from '../src/turnstile.js';
|
||||||
import { devEnv } from './env.js';
|
import { devEnv } from './env.js';
|
||||||
@@ -286,6 +287,98 @@ describe('capacity-safe signup', () => {
|
|||||||
expect(db.prepare("SELECT COALESCE(SUM(group_size), 0) AS n FROM signups WHERE status = 'confirmed'").get()).toEqual({ n: 3 });
|
expect(db.prepare("SELECT COALESCE(SUM(group_size), 0) AS n FROM signups WHERE status = 'confirmed'").get()).toEqual({ n: 3 });
|
||||||
}, 30_000);
|
}, 30_000);
|
||||||
|
|
||||||
|
it('holds several spots under one name', async () => {
|
||||||
|
const { app, db, shiftId } = await buildApp({ capacity: 4 });
|
||||||
|
const form = await app.request(`/s/${shiftId}`);
|
||||||
|
const formHtml = await form.text();
|
||||||
|
expect(formHtml).toContain('How many people?');
|
||||||
|
expect(formHtml).toContain('This signup holds that many spots.');
|
||||||
|
expect(formHtml).toContain('value="4"');
|
||||||
|
|
||||||
|
const saved = await postSignup(
|
||||||
|
app,
|
||||||
|
shiftId,
|
||||||
|
{ name: 'Pat Review', email: 'pat.party@example.invalid', partySize: '3' },
|
||||||
|
{ ip: '203.0.113.71' },
|
||||||
|
);
|
||||||
|
expect(saved.status).toBe(303);
|
||||||
|
expect(db.prepare('SELECT name, group_size, status FROM signups').get()).toEqual({
|
||||||
|
name: 'Pat Review',
|
||||||
|
group_size: 3,
|
||||||
|
status: 'confirmed',
|
||||||
|
});
|
||||||
|
const letter = db.prepare("SELECT body_text FROM outbox WHERE kind = 'confirmation'").get() as { body_text: string };
|
||||||
|
expect(letter.body_text).toContain('This signup holds 3 spots.');
|
||||||
|
const confirmed = await app.request(locationOf(saved), { headers: { cookie: cookiePair(saved.headers.get('set-cookie') ?? '') } });
|
||||||
|
const confirmedHtml = await confirmed.text();
|
||||||
|
expect(confirmedHtml).toContain('This signup holds 3 spots.');
|
||||||
|
const managePath = confirmedHtml.match(/href="(\/m\/[^"]+)"/)?.[1] ?? '';
|
||||||
|
const manageHtml = await (await app.request(managePath)).text();
|
||||||
|
expect(manageHtml).toContain('People');
|
||||||
|
expect(manageHtml).toContain('>3<');
|
||||||
|
const shiftHtml = await (await app.request(`/s/${shiftId}`)).text();
|
||||||
|
expect(shiftHtml).toContain('3/4 spots filled');
|
||||||
|
const board = await (await app.request('/?view=calendar')).text();
|
||||||
|
expect(board).toContain('Pat Review (3 people)');
|
||||||
|
expect(board).not.toContain('Pat Review (3 people), Pat Review');
|
||||||
|
|
||||||
|
const tooMany = await postSignup(
|
||||||
|
app,
|
||||||
|
shiftId,
|
||||||
|
{ name: 'Sam Review', email: 'sam.party@example.invalid', partySize: '2' },
|
||||||
|
{ ip: '203.0.113.72' },
|
||||||
|
);
|
||||||
|
expect(tooMany.status).toBe(409);
|
||||||
|
const tooManyHtml = await tooMany.text();
|
||||||
|
expect(tooManyHtml).toContain('This shift has 1 spot left.');
|
||||||
|
expect(tooManyHtml).toContain('How many people?');
|
||||||
|
expect(tooManyHtml).not.toContain('This shift is full.');
|
||||||
|
|
||||||
|
const nonsense = await postSignup(
|
||||||
|
app,
|
||||||
|
shiftId,
|
||||||
|
{ name: 'Ada Review', email: 'ada.party@example.invalid', partySize: '0' },
|
||||||
|
{ ip: '203.0.113.73' },
|
||||||
|
);
|
||||||
|
expect(nonsense.status).toBe(400);
|
||||||
|
expect(await nonsense.text()).toContain('Choose how many people are coming.');
|
||||||
|
expect(db.prepare("SELECT COUNT(*) AS n FROM signups WHERE status = 'confirmed'").get()).toEqual({ n: 1 });
|
||||||
|
|
||||||
|
const eventId = Number((db.prepare('SELECT event_id AS event_id FROM shifts WHERE id = ?').get(shiftId) as { event_id: number }).event_id);
|
||||||
|
const tight = insertExtraShift(db, {
|
||||||
|
capacity: 2,
|
||||||
|
starts: '2026-10-16T14:00:00.000Z',
|
||||||
|
ends: '2026-10-16T17:00:00.000Z',
|
||||||
|
});
|
||||||
|
const signupId = Number((db.prepare('SELECT id AS id FROM signups').get() as { id: number }).id);
|
||||||
|
const mail = {
|
||||||
|
baseUrl: 'http://127.0.0.1:3000',
|
||||||
|
basePath: '',
|
||||||
|
from: 'Hope Volunteer <signup@example.invalid>',
|
||||||
|
replyTo: 'signup@example.invalid',
|
||||||
|
};
|
||||||
|
const blocked = switchSignup(db, signupId, tight, 'switch-tight', NOW, mail);
|
||||||
|
expect(blocked.ok).toBe(false);
|
||||||
|
if (!blocked.ok) expect(blocked.error).toContain('does not have room');
|
||||||
|
expect(db.prepare("SELECT status FROM signups WHERE id = ?").get(signupId)).toEqual({ status: 'confirmed' });
|
||||||
|
|
||||||
|
const wide = insertExtraShift(db, {
|
||||||
|
capacity: 4,
|
||||||
|
starts: '2026-10-17T14:00:00.000Z',
|
||||||
|
ends: '2026-10-17T17:00:00.000Z',
|
||||||
|
});
|
||||||
|
const moved = switchSignup(db, signupId, wide, 'switch-wide', NOW, mail);
|
||||||
|
expect(moved.ok).toBe(true);
|
||||||
|
expect(db.prepare("SELECT group_size, status FROM signups WHERE shift_id = ? AND status = 'confirmed'").get(wide)).toEqual({
|
||||||
|
group_size: 3,
|
||||||
|
status: 'confirmed',
|
||||||
|
});
|
||||||
|
expect(db.prepare("SELECT COALESCE(SUM(group_size), 0) AS n FROM signups WHERE shift_id = ? AND status = 'confirmed'").get(shiftId)).toEqual({ n: 0 });
|
||||||
|
const changed = db.prepare("SELECT body_text FROM outbox WHERE kind = 'changed'").get() as { body_text: string };
|
||||||
|
expect(changed.body_text).toContain('This signup holds 3 spots.');
|
||||||
|
expect(eventId).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
it('treats an invalid or expired manage link as unavailable', async () => {
|
it('treats an invalid or expired manage link as unavailable', async () => {
|
||||||
const { app, db, shiftId } = await buildApp();
|
const { app, db, shiftId } = await buildApp();
|
||||||
const saved = await postSignup(app, shiftId, { email: 'link@example.invalid' }, { ip: '203.0.113.81' });
|
const saved = await postSignup(app, shiftId, { email: 'link@example.invalid' }, { ip: '203.0.113.81' });
|
||||||
@@ -376,6 +469,7 @@ async function postSignup(
|
|||||||
phone: string;
|
phone: string;
|
||||||
notes: string;
|
notes: string;
|
||||||
company: string;
|
company: string;
|
||||||
|
partySize: string;
|
||||||
}>,
|
}>,
|
||||||
options?: { token?: string; issuedAt?: number; ip?: string; origin?: string; forwardedFor?: string; site?: string },
|
options?: { token?: string; issuedAt?: number; ip?: string; origin?: string; forwardedFor?: string; site?: string },
|
||||||
) {
|
) {
|
||||||
@@ -394,6 +488,7 @@ async function postSignup(
|
|||||||
email: fields.email ?? 'pat.review@example.invalid',
|
email: fields.email ?? 'pat.review@example.invalid',
|
||||||
phone: fields.phone ?? '712-555-0100',
|
phone: fields.phone ?? '712-555-0100',
|
||||||
notes: fields.notes ?? '',
|
notes: fields.notes ?? '',
|
||||||
|
party_size: fields.partySize ?? '',
|
||||||
company_website: fields.company ?? '',
|
company_website: fields.company ?? '',
|
||||||
'cf-turnstile-response': 'widget-token',
|
'cf-turnstile-response': 'widget-token',
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user