feat: show the private signup address and let coordinators correct contacts
The confirmation page prints the full manage URL so it can be copied before the browser drops it. A saved contact can be corrected in place, and shift menus group choices by date.
This commit is contained in:
1 parent
322c575fcb
commit
5e0e4a55a8
14 files changed
+439
-36
No files matched your search
@@ -103,7 +103,7 @@ A reminder is queued at each saved time before a confirmed signup, while the shi
|
||||
|
||||
**Download this roster**, on a shift, and **Download this event**, on an event, save a spreadsheet of the signups. **Download this date range**, on the coordinator page, uses each event's local shift date. The file includes cancelled signups and attendance. A cell that would be a spreadsheet formula is saved as text. The download is not cached. A copy on a coordinator's computer is outside this app, and the app does not delete it later.
|
||||
|
||||
**Contacts**, on the coordinator page, keeps a list of people. A confirmed signup is saved on this list. The name is split at the last space. A signup name with no space is saved with a hyphen as the last name. A different name is a separate contact, even when the email matches. The same name and email updates that contact. Cancelling the signup does not remove the contact. Saving someone here does not sign them up for a shift. **Import this list** reads a spreadsheet with First Name, Last Name, Email, and Phone, including the SignUpGenius people export. An Address column is ignored. The same name and email updates that person. A different name stays a separate person, even when the email matches. A different email stays a separate person, even when the name matches. A blank phone does not erase a phone already saved. Names are capitalized. A word that already mixes upper and lower case stays as written. A phone number with ten digits is saved with dashes, like 712-555-0100. A leading 1 is left off. Email addresses are stored in lowercase. Importing does not take a spot and does not send email. **Download contacts** saves that list. A cell that would be a spreadsheet formula is saved as text. A downloaded copy stays on the coordinator's computer. The signup retention job does not clear this list. The list is the contacts table in `app.db`. The list shows 20 people. **See more** shows the next 20 on this page, without returning to the top, and keeps a search. **Choose a name**, then choose the shift from **Shift**. That takes one spot and queues a confirmation email. A full, cancelled, or ended shift is not in that list, and a shift they are already on is not in that list. A shift that is not on the public list can still be chosen. **Remove** deletes that person from the list only. On an open shift, **Saved contact** fills a walk-in. The walk-in still takes one spot and queues a confirmation email. **Add a contact** saves one person who has not signed up. It does not take a spot and does not send email. The same name and email updates that person. A different name is saved separately, even with the same email. Typing a walk-in who is not on the list saves them here too.
|
||||
**Contacts**, on the coordinator page, keeps a list of people. A confirmed signup is saved on this list. The name is split at the last space. A signup name with no space is saved with a hyphen as the last name. A different name is a separate contact, even when the email matches. The same name and email updates that contact. Cancelling the signup does not remove the contact. Saving someone here does not sign them up for a shift. **Import this list** reads a spreadsheet with First Name, Last Name, Email, and Phone, including the SignUpGenius people export. An Address column is ignored. The same name and email updates that person. A different name stays a separate person, even when the email matches. A different email stays a separate person, even when the name matches. A blank phone does not erase a phone already saved. Names are capitalized. A word that already mixes upper and lower case stays as written. A phone number with ten digits is saved with dashes, like 712-555-0100. A leading 1 is left off. Email addresses are stored in lowercase. Importing does not take a spot and does not send email. **Download contacts** saves that list. A cell that would be a spreadsheet formula is saved as text. A downloaded copy stays on the coordinator's computer. The signup retention job does not clear this list. The list is the contacts table in `app.db`. The list shows 20 people. **See more** shows the next 20 on this page, without returning to the top, and keeps a search. **Choose a name**, then choose the shift from **Shift**. That takes one spot and queues a confirmation email. A full, cancelled, or ended shift is not in that list, and a shift they are already on is not in that list. A shift that is not on the public list can still be chosen. **Correct this contact**, on that page, saves a corrected name, email, or phone on the same person. A phone typo can be replaced. A hyphen saved as the last name can be replaced with the real last name. Changing the name does not create a second person, even when the email stays the same. A blank phone removes the saved number. It does not change a signup, take a spot, or send email. **Remove** deletes that person from the list only. On an open shift, **Saved contact** fills a walk-in. The walk-in still takes one spot and queues a confirmation email. **Add a contact** saves one person who has not signed up. It does not take a spot and does not send email. The same name and email updates that person. A different name is saved separately, even with the same email. Typing a walk-in who is not on the list saves them here too.
|
||||
|
||||
**Settings**, on the coordinator page, saves the two reminder times, the reply-to address, the privacy-page wording, and how many months to keep a signup after the shift ends. The defaults are 48 hours, 2 hours, the reply-to address from the server configuration, a blank privacy notice, and 24 months. The two reminder times have to be different whole hours from 1 to 336. The month count is a whole number from 1 to 120. A blank privacy notice leaves the public page saying a notice is not approved yet. Saved wording is shown on `/privacy` as written. Saving it does not by itself make that wording an approved privacy policy. New mail uses the saved reply-to address. Mail already queued keeps the address it was given. The sending address stays in the server configuration.
|
||||
|
||||
|
||||
@@ -446,6 +446,16 @@ main a:hover {
|
||||
color: var(--hope-ink-2);
|
||||
}
|
||||
|
||||
.saved-link {
|
||||
margin: 0.85rem 0 0.2rem;
|
||||
overflow-wrap: anywhere;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.saved-link a {
|
||||
user-select: all;
|
||||
}
|
||||
|
||||
.shift-calendar {
|
||||
margin-top: 1.25rem;
|
||||
}
|
||||
@@ -2228,6 +2238,11 @@ button.btn-quiet::before {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.event-page .desk-actions .btn,
|
||||
.event-page .desk-actions .desk-inline {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.event-page .desk-actions .btn,
|
||||
.event-page .desk-actions .desk-inline,
|
||||
.desk-actions .desk-inline button,
|
||||
|
||||
+37
-2
@@ -79,6 +79,7 @@ import type { MailIdentity } from './mail/types.js';
|
||||
import { issueFormToken, newOperationId, readFormToken } from './form-token.js';
|
||||
import {
|
||||
contactListLimit,
|
||||
correctContact,
|
||||
exportContacts,
|
||||
formatContactSkips,
|
||||
getContact,
|
||||
@@ -149,6 +150,7 @@ export function registerAdmin(app: Hono, services: AdminServices): void {
|
||||
app.post(appPath(config, '/admin/contacts/:id/remove'), (c) => submitRemoveContact(c, services));
|
||||
app.post(appPath(config, '/admin/contacts/:id/add'), (c) => submitAddContactToShift(c, services));
|
||||
app.get(appPath(config, '/admin/contacts/:id'), (c) => showContact(c, services));
|
||||
app.post(appPath(config, '/admin/contacts/:id'), (c) => submitCorrectContact(c, services));
|
||||
app.get(appPath(config, '/admin/events/new'), (c) => showNewEvent(c, services));
|
||||
app.post(appPath(config, '/admin/events'), (c) => submitNewEvent(c, services));
|
||||
app.get(appPath(config, '/admin/events/:id/remove'), (c) => showRemoveEvent(c, services));
|
||||
@@ -440,7 +442,13 @@ function showRemoveContact(c: Context, services: AdminServices, error?: string,
|
||||
function showContact(
|
||||
c: Context,
|
||||
services: AdminServices,
|
||||
state?: { error?: string; status?: 200 | 400; form?: WalkInState; shiftId?: string },
|
||||
state?: {
|
||||
error?: string;
|
||||
status?: 200 | 400;
|
||||
form?: WalkInState;
|
||||
shiftId?: string;
|
||||
correction?: { values: ContactManualValues; errors: ContactManualErrors };
|
||||
},
|
||||
) {
|
||||
const session = requireSession(c, services);
|
||||
if (session instanceof Response) return session;
|
||||
@@ -457,12 +465,37 @@ function showContact(
|
||||
shifts={listOpenShiftsForPerson(services.db, { email: contact.email, name: contact.name }, services.now())}
|
||||
form={state?.form ?? blankWalkIn(services, contact.id)}
|
||||
shiftId={state?.shiftId ?? ''}
|
||||
notice={state?.status === 400 ? undefined : knownNotice(c.req.query('notice'))}
|
||||
correction={state?.correction}
|
||||
error={state?.error}
|
||||
/>,
|
||||
{ account: session, status: state?.status ?? 200 },
|
||||
);
|
||||
}
|
||||
|
||||
async function submitCorrectContact(c: Context, services: AdminServices): Promise<Response> {
|
||||
const session = await postedSession(c, services);
|
||||
if (session instanceof Response) return session;
|
||||
const id = idFrom(c);
|
||||
const values = {
|
||||
firstName: textField(session.body, 'first_name'),
|
||||
lastName: textField(session.body, 'last_name'),
|
||||
email: textField(session.body, 'email'),
|
||||
phone: textField(session.body, 'phone'),
|
||||
};
|
||||
try {
|
||||
const saved = correctContact(services.db, session.coordinatorId, id, values, services.now());
|
||||
if (!saved.ok) {
|
||||
if ('missing' in saved) return missing(c, services);
|
||||
return showContact(c, services, { status: 400, correction: { values, errors: saved.errors } });
|
||||
}
|
||||
const notice = saved.status === 'changed' ? 'contact-corrected' : 'contact-same';
|
||||
return c.redirect(appPath(services.config, `/admin/contacts/${id}?notice=${notice}`), 303);
|
||||
} catch (err) {
|
||||
return saveFailed(c, services, session, err);
|
||||
}
|
||||
}
|
||||
|
||||
function contactShiftUnavailable(c: Context, services: AdminServices, email: string, name: string, shiftId: number, form: WalkInState) {
|
||||
const already = shiftId > 0 && confirmedPersonOnShift(services.db, shiftId, email, name);
|
||||
return showContact(c, services, {
|
||||
@@ -1484,7 +1517,9 @@ function knownNotice(value: string | undefined): string | undefined {
|
||||
value === 'contact-removed' ||
|
||||
value === 'contact-saved' ||
|
||||
value === 'contact-updated' ||
|
||||
value === 'contact-matched'
|
||||
value === 'contact-matched' ||
|
||||
value === 'contact-corrected' ||
|
||||
value === 'contact-same'
|
||||
) {
|
||||
return value;
|
||||
}
|
||||
|
||||
+38
-15
@@ -15,6 +15,7 @@ import {
|
||||
} from './contacts.js';
|
||||
import type { SignupErrors, SignupValues } from './signup-form.js';
|
||||
import { addLocalDays, todayInZone } from './time.js';
|
||||
import { ShiftTargetOptions } from './shift-options.js';
|
||||
import { appPath } from './url.js';
|
||||
|
||||
export type WalkInState = {
|
||||
@@ -353,7 +354,7 @@ export function ContactsPage(props: {
|
||||
) : null}
|
||||
{hiddenSkips > 0 ? <p class="panel-note">{hiddenSkips === 1 ? '1 more row was skipped.' : `${hiddenSkips} more rows were skipped.`}</p> : null}
|
||||
<p>
|
||||
Someone who signs up is saved here. Cancelling that signup does not remove them. A different name is a separate contact, even when the email matches. To add someone who has not signed up, import a spreadsheet or save them below. That does not take a spot and does not send email. Choose a name to add that person to an open shift. Old signups lose their details after the retention period. This list stays until you remove someone.
|
||||
Someone who signs up is saved here. Cancelling that signup does not remove them. A different name is a separate contact, even when the email matches. To add someone who has not signed up, import a spreadsheet or save them below. That does not take a spot and does not send email. Choose a name to correct that person or add them to an open shift. Old signups lose their details after the retention period. This list stays until you remove someone.
|
||||
</p>
|
||||
<form method="post" action={appPath(props.config, '/admin/contacts/new')} class="signup-form desk-download">
|
||||
<input type="hidden" name="csrf" value={props.csrf} />
|
||||
@@ -440,11 +441,22 @@ export function ContactPage(props: {
|
||||
shifts: MoveTarget[];
|
||||
form: WalkInState;
|
||||
shiftId: string;
|
||||
notice?: string;
|
||||
correction?: { values: ContactManualValues; errors: ContactManualErrors };
|
||||
error?: string;
|
||||
}) {
|
||||
const values = props.form.values;
|
||||
const errors = props.form.errors;
|
||||
const errorEntries = Object.entries(errors).filter((entry): entry is [string, string] => Boolean(entry[1]));
|
||||
const correction = props.correction ?? {
|
||||
values: {
|
||||
firstName: props.contact.firstName,
|
||||
lastName: props.contact.lastName,
|
||||
email: props.contact.email,
|
||||
phone: props.contact.phone ?? '',
|
||||
},
|
||||
errors: {},
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<p>
|
||||
@@ -453,6 +465,27 @@ export function ContactPage(props: {
|
||||
<h1>{props.contact.name}</h1>
|
||||
<p>{props.contact.email}</p>
|
||||
{props.contact.phone ? <p>{props.contact.phone}</p> : null}
|
||||
<Notice notice={props.notice} />
|
||||
<form method="post" action={appPath(props.config, `/admin/contacts/${props.contact.id}`)} class="signup-form">
|
||||
<input type="hidden" name="csrf" value={props.csrf} />
|
||||
<h2>Correct this contact</h2>
|
||||
<p>
|
||||
This changes the saved person. A different name stays this contact and does not create a second person. It does not change a signup, take a spot, or send email. Names are capitalized. A 10-digit phone is saved with dashes, like 712-555-0100. A blank phone removes the saved number.
|
||||
</p>
|
||||
<WalkInField id="correct-first" label="First name" name="first_name" type="text" value={correction.values.firstName} error={correction.errors.firstName} />
|
||||
<WalkInField id="correct-last" label="Last name" name="last_name" type="text" value={correction.values.lastName} error={correction.errors.lastName} />
|
||||
<WalkInField id="correct-email" label="Email" name="email" type="email" value={correction.values.email} error={correction.errors.email} />
|
||||
<WalkInField
|
||||
id="correct-phone"
|
||||
label="Phone (optional)"
|
||||
name="phone"
|
||||
type="tel"
|
||||
value={correction.values.phone}
|
||||
error={correction.errors.phone}
|
||||
hint="We will not text them"
|
||||
/>
|
||||
<button type="submit">Save this correction</button>
|
||||
</form>
|
||||
{props.error ? <p class="error">{props.error}</p> : null}
|
||||
<h2>Add to a shift</h2>
|
||||
<p>Choose an open shift. This uses their saved name, email, and phone. It takes one spot and queues a confirmation email. Their name stays off the public list. Full, cancelled, and ended shifts are left off this list, and so is a shift they are already on.</p>
|
||||
@@ -474,14 +507,7 @@ export function ContactPage(props: {
|
||||
<label for="add-shift">
|
||||
Shift
|
||||
<select id="add-shift" name="shift" required>
|
||||
<option value="" selected={props.shiftId === '' ? true : undefined}>
|
||||
Choose a shift
|
||||
</option>
|
||||
{props.shifts.map((shift) => (
|
||||
<option value={String(shift.id)} key={shift.id} selected={props.shiftId === String(shift.id) ? true : undefined}>
|
||||
{shift.label}
|
||||
</option>
|
||||
))}
|
||||
<ShiftTargetOptions targets={props.shifts} selectedId={props.shiftId} />
|
||||
</select>
|
||||
</label>
|
||||
<label for="add-notes">
|
||||
@@ -1479,12 +1505,7 @@ function Roster(props: { config: AppConfig; csrf: string; people: RosterPerson[]
|
||||
<label for={`move-${person.id}`}>
|
||||
Move to
|
||||
<select id={`move-${person.id}`} name="destination" required>
|
||||
<option value="">Choose a shift</option>
|
||||
{props.moves.targets.map((target) => (
|
||||
<option value={String(target.id)} key={target.id}>
|
||||
{target.label}
|
||||
</option>
|
||||
))}
|
||||
<ShiftTargetOptions targets={props.moves.targets} />
|
||||
</select>
|
||||
</label>
|
||||
<button type="submit">Move</button>
|
||||
@@ -1614,6 +1635,8 @@ const NOTICES: Record<string, string> = {
|
||||
'contact-saved': 'That contact is saved.',
|
||||
'contact-updated': 'That contact is updated.',
|
||||
'contact-matched': 'That email is already on the contact list.',
|
||||
'contact-corrected': 'That contact is corrected.',
|
||||
'contact-same': 'That contact already matches.',
|
||||
};
|
||||
|
||||
const WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] as const;
|
||||
|
||||
+16
-2
@@ -121,6 +121,10 @@ export type EventRemoval = {
|
||||
|
||||
export type MoveTarget = {
|
||||
id: number;
|
||||
/** Local start date, YYYY-MM-DD. Menus group choices that share this date. */
|
||||
date: string;
|
||||
/** Local date heading, such as Tuesday, October 20, 2026. */
|
||||
dateLabel: string;
|
||||
label: string;
|
||||
};
|
||||
|
||||
@@ -929,6 +933,12 @@ export function findSignupShift(db: Database.Database, signupId: number): number
|
||||
return row ? row.shift_id : null;
|
||||
}
|
||||
|
||||
/** "Tuesday, October 20, 2026" becomes "October 20, 2026". The weekday stays on the menu group. */
|
||||
function dateWithoutWeekday(dateLabel: string): string {
|
||||
const comma = dateLabel.indexOf(', ');
|
||||
return comma === -1 ? dateLabel : dateLabel.slice(comma + 2);
|
||||
}
|
||||
|
||||
/** Other open shifts in this event that still have a spot. Full, cancelled, and ended shifts are omitted. */
|
||||
export function listMoveTargets(
|
||||
db: Database.Database,
|
||||
@@ -973,7 +983,9 @@ export function listMoveTargets(
|
||||
const end = formatInstantInZone(row.ends_at_utc, row.tz);
|
||||
return [{
|
||||
id: row.id,
|
||||
label: `${row.role}, ${start.dateLabel}, ${start.timeLabel} to ${end.timeLabel} ${end.abbreviation}`,
|
||||
date: start.date,
|
||||
dateLabel: start.dateLabel,
|
||||
label: `${row.role}, ${dateWithoutWeekday(start.dateLabel)}, ${start.timeLabel} to ${end.timeLabel} ${end.abbreviation}`,
|
||||
}];
|
||||
});
|
||||
}
|
||||
@@ -1016,7 +1028,9 @@ export function listOpenShiftsForPerson(
|
||||
const publicity = row.published === 1 ? '' : ' (not on the public list)';
|
||||
return [{
|
||||
id: row.id,
|
||||
label: `${row.title}: ${row.role}, ${start.dateLabel}, ${start.timeLabel} to ${end.timeLabel} ${end.abbreviation}${publicity}`,
|
||||
date: start.date,
|
||||
dateLabel: start.dateLabel,
|
||||
label: `${row.title}: ${row.role}, ${dateWithoutWeekday(start.dateLabel)}, ${start.timeLabel} to ${end.timeLabel} ${end.abbreviation}${publicity}`,
|
||||
}];
|
||||
});
|
||||
}
|
||||
|
||||
@@ -265,6 +265,49 @@ export function saveManualContact(
|
||||
return { ok: true, status };
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the name, email, and phone on one saved contact.
|
||||
* A different name stays this contact. A blank phone removes the saved number.
|
||||
*/
|
||||
export function correctContact(
|
||||
db: Database.Database,
|
||||
coordinatorId: number,
|
||||
id: number,
|
||||
values: ContactManualValues,
|
||||
now: string,
|
||||
): { ok: true; status: 'changed' | 'unchanged' } | { ok: false; missing: true } | { ok: false; errors: ContactManualErrors } {
|
||||
const parsed = manualContact(values);
|
||||
if (!parsed.ok) return parsed;
|
||||
const person = parsed.person;
|
||||
return db.transaction(() => {
|
||||
const current = getContact(db, id);
|
||||
if (!current) return { ok: false as const, missing: true as const };
|
||||
if (
|
||||
person.firstName === current.firstName &&
|
||||
person.lastName === current.lastName &&
|
||||
person.email === current.email &&
|
||||
person.phone === current.phone
|
||||
) {
|
||||
return { ok: true as const, status: 'unchanged' as const };
|
||||
}
|
||||
try {
|
||||
const updated = db
|
||||
.prepare(
|
||||
`UPDATE contacts
|
||||
SET first_name = ?, last_name = ?, email = ?, email_norm = ?, phone = ?, updated_at = ?
|
||||
WHERE id = ?`,
|
||||
)
|
||||
.run(person.firstName, person.lastName, person.email, person.email, person.phone, now, id);
|
||||
if (updated.changes !== 1) return { ok: false as const, missing: true as const };
|
||||
} catch (err) {
|
||||
if (!isUniqueConstraint(err)) throw err;
|
||||
return { ok: false as const, errors: { email: 'That name and email are already saved as another contact.' } };
|
||||
}
|
||||
writeAudit(db, coordinatorId, 'contacts.correct', { id }, now);
|
||||
return { ok: true as const, status: 'changed' as const };
|
||||
})();
|
||||
}
|
||||
|
||||
/** Blank name, email, or phone on the form keeps the saved contact's value. */
|
||||
export function walkInFromContact(contact: Contact, values: SignupValues): SignupValues {
|
||||
return {
|
||||
|
||||
+6
-10
@@ -4,6 +4,7 @@ import { WEEKDAY_SHORT, calendarMonth, calendarToday, chooseCalendarMonth, month
|
||||
import { spotsSentence, type PublicEvent, type PublicShift } from './schedule.js';
|
||||
import type { SignupErrors, SignupValues } from './signup-form.js';
|
||||
import type { MoveTarget } from './admin/store.js';
|
||||
import { ShiftTargetOptions } from './shift-options.js';
|
||||
import type { ManageView } from './signup.js';
|
||||
import { appPath } from './url.js';
|
||||
|
||||
@@ -296,11 +297,11 @@ export function ConfirmationPage(props: {
|
||||
<>
|
||||
<p>
|
||||
{props.cancelled
|
||||
? 'A cancellation email is on the way. The link below still opens this cancelled signup.'
|
||||
: 'A confirmation email is on the way. Save the link below in case the email is late. Use it to cancel or switch to a different shift.'}
|
||||
? 'A cancellation email is on the way. The address below still opens this cancelled signup.'
|
||||
: 'A confirmation email is on the way. Save the address below in case the email is late. This browser keeps it for a few minutes. Use it to cancel or switch to a different shift.'}
|
||||
</p>
|
||||
<p>
|
||||
<a href={props.managePath}>{props.cancelled ? 'View this signup' : 'Cancel or switch shifts'}</a>
|
||||
<p class="saved-link">
|
||||
<a href={props.managePath}>{`${props.config.baseUrl}${props.managePath}`}</a>
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
@@ -384,12 +385,7 @@ export function ManagePage(props: {
|
||||
<label for="switch-to">
|
||||
Switch to
|
||||
<select id="switch-to" name="destination" required>
|
||||
<option value="">Choose a shift</option>
|
||||
{props.switches.targets.map((target) => (
|
||||
<option value={String(target.id)} key={target.id}>
|
||||
{target.label}
|
||||
</option>
|
||||
))}
|
||||
<ShiftTargetOptions targets={props.switches.targets} />
|
||||
</select>
|
||||
</label>
|
||||
<button type="submit">Switch</button>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import type { MoveTarget } from './admin/store.js';
|
||||
|
||||
export type ShiftDateGroup = {
|
||||
date: string;
|
||||
dateLabel: string;
|
||||
targets: MoveTarget[];
|
||||
};
|
||||
|
||||
/** Groups a date-sorted shift list. The same date later in the list stays its own group so menu order matches the list. */
|
||||
export function groupShiftTargets(targets: readonly MoveTarget[]): ShiftDateGroup[] {
|
||||
const groups: ShiftDateGroup[] = [];
|
||||
for (const target of targets) {
|
||||
const current = groups.at(-1);
|
||||
if (current?.date === target.date) current.targets.push(target);
|
||||
else groups.push({ date: target.date, dateLabel: target.dateLabel, targets: [target] });
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
export function ShiftTargetOptions(props: { targets: MoveTarget[]; selectedId?: string }) {
|
||||
const selected = props.selectedId ?? '';
|
||||
return (
|
||||
<>
|
||||
<option value="" selected={selected === '' ? true : undefined}>
|
||||
Choose a shift
|
||||
</option>
|
||||
{groupShiftTargets(props.targets).map((group, index) => (
|
||||
<optgroup label={group.dateLabel} key={`${group.date}-${index}`}>
|
||||
{group.targets.map((target) => (
|
||||
<option value={String(target.id)} key={target.id} selected={selected === String(target.id) ? true : undefined}>
|
||||
{target.label}
|
||||
</option>
|
||||
))}
|
||||
</optgroup>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
+2
-1
@@ -35,7 +35,8 @@ import { appPath, cookiePath } from './url.js';
|
||||
|
||||
const COULD_NOT_SAVE =
|
||||
'This signup could not be saved. If this shift is already in your confirmation, use that link.';
|
||||
const ALREADY_SIGNED_UP = 'That person is already signed up for this shift.';
|
||||
const ALREADY_SIGNED_UP =
|
||||
'That person is already signed up for this shift. Use the link in the confirmation email.';
|
||||
const TOO_FAST = 'Please wait a few seconds and submit the form again.';
|
||||
const CHECK_AGAIN = 'The check did not finish. Please try again.';
|
||||
const CHECK_UNAVAILABLE = 'The check could not be reached. Please try again in a little while.';
|
||||
|
||||
@@ -520,6 +520,8 @@ describe('coordinator screens', () => {
|
||||
const page = await app.request(`/admin/shifts/${sourceId}`, { headers: { cookie } });
|
||||
const html = await page.text();
|
||||
expect(optionValues(html, 'destination')).toEqual([String(destinationId)]);
|
||||
expect(html).toContain('<optgroup label="Friday, October 23, 2026">');
|
||||
expect(html).toContain('>Distribution, October 23, 2026, 9:00 AM to 12:00 PM CDT<');
|
||||
const moved = await postMove(app, cookie, signupId, html, String(destinationId));
|
||||
expect(moved.status).toBe(303);
|
||||
expect(moved.headers.get('location')).toBe(`/admin/shifts/${destinationId}?notice=moved`);
|
||||
|
||||
@@ -170,6 +170,8 @@ describe('manage-link switch', () => {
|
||||
const html = await before.text();
|
||||
expect(before.status).toBe(200);
|
||||
expect(optionValues(html)).toEqual([String(destinationId)]);
|
||||
expect(html).toContain('<optgroup label="Saturday, October 17, 2026">');
|
||||
expect(html).toContain('>Distribution, October 17, 2026, 9:00 AM to 12:00 PM CDT<');
|
||||
expect(html).toContain('>Switch<');
|
||||
expect(db.prepare('SELECT status, shift_id FROM signups').get()).toEqual({ status: 'confirmed', shift_id: shiftId });
|
||||
|
||||
@@ -285,6 +287,31 @@ describe('manage-link switch', () => {
|
||||
});
|
||||
expect(db.prepare("SELECT COUNT(*) AS n FROM audit WHERE action = 'signup.switch'").get()).toEqual({ n: 0 });
|
||||
});
|
||||
|
||||
it('groups switch choices under each date', async () => {
|
||||
const { app, db, shiftId } = await buildApp();
|
||||
const eventId = Number((db.prepare('SELECT id AS id FROM events').get() as { id: number }).id);
|
||||
const morningId = insertShift(db, eventId, 'Intake', '2026-10-17T14:00:00.000Z', '2026-10-17T16:00:00.000Z', 2);
|
||||
const afternoonId = insertShift(db, eventId, 'Distribution', '2026-10-17T19:00:00.000Z', '2026-10-17T21:00:00.000Z', 2);
|
||||
const tuesdayId = insertShift(db, eventId, 'Packing', '2026-10-20T14:00:00.000Z', '2026-10-20T17:00:00.000Z', 2);
|
||||
const { managePath } = await openManage(app, shiftId, 'date.switch@example.invalid', '203.0.113.45');
|
||||
const html = await (await app.request(managePath)).text();
|
||||
const select = /<select\b[^>]*\bid="switch-to"[^>]*>([\s\S]*?)<\/select>/.exec(html)?.[1] ?? '';
|
||||
const saturday = select.indexOf('<optgroup label="Saturday, October 17, 2026">');
|
||||
const tuesday = select.indexOf('<optgroup label="Tuesday, October 20, 2026">');
|
||||
const morning = select.indexOf(`<option value="${morningId}">`);
|
||||
const afternoon = select.indexOf(`<option value="${afternoonId}">`);
|
||||
const later = select.indexOf(`<option value="${tuesdayId}">`);
|
||||
expect(saturday).toBeGreaterThanOrEqual(0);
|
||||
expect(morning).toBeGreaterThan(saturday);
|
||||
expect(afternoon).toBeGreaterThan(morning);
|
||||
expect(tuesday).toBeGreaterThan(afternoon);
|
||||
expect(later).toBeGreaterThan(tuesday);
|
||||
expect(select).toContain('>Intake, October 17, 2026, 9:00 AM to 11:00 AM CDT<');
|
||||
expect(select).toContain('>Distribution, October 17, 2026, 2:00 PM to 4:00 PM CDT<');
|
||||
expect(select).toContain('>Packing, October 20, 2026, 9:00 AM to 12:00 PM CDT<');
|
||||
expect(select.match(/<optgroup/g)).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
async function buildApp(options?: { capacity?: number }) {
|
||||
|
||||
+181
-2
@@ -385,8 +385,15 @@ describe('contact pages', () => {
|
||||
expect(personHtml).toContain('555-0100');
|
||||
expect(personHtml).toContain('id="add-shift"');
|
||||
expect(personHtml).toContain('Choose a shift');
|
||||
expect(personHtml).toContain(`<option value="${openId}">`);
|
||||
expect(personHtml).toContain(`<option value="${unpublishedId}">`);
|
||||
const addMenu = /<select\b[^>]*\bid="add-shift"[^>]*>([\s\S]*?)<\/select>/.exec(personHtml)?.[1] ?? '';
|
||||
const wednesday = addMenu.indexOf('<optgroup label="Wednesday, October 21, 2026">');
|
||||
const thursday = addMenu.indexOf('<optgroup label="Thursday, October 22, 2026">');
|
||||
expect(wednesday).toBeGreaterThanOrEqual(0);
|
||||
expect(addMenu.indexOf(`<option value="${openId}">`)).toBeGreaterThan(wednesday);
|
||||
expect(thursday).toBeGreaterThan(wednesday);
|
||||
expect(addMenu.indexOf(`<option value="${unpublishedId}">`)).toBeGreaterThan(thursday);
|
||||
expect(addMenu).toContain('>Weekly pantry: Sorting, October 21, 2026, 9:00 AM to 12:00 PM CDT<');
|
||||
expect(addMenu).toContain('>Soup kitchen: Serving, October 22, 2026, 9:00 AM to 12:00 PM CDT (not on the public list)<');
|
||||
expect(personHtml).toContain('Serving');
|
||||
expect(personHtml).toContain('(not on the public list)');
|
||||
expect(personHtml).not.toContain('Closing');
|
||||
@@ -512,6 +519,157 @@ describe('contact pages', () => {
|
||||
expect(count(db, 'SELECT COUNT(*) AS n FROM contacts')).toBe(2);
|
||||
expect(await (await app.request('/')).text()).not.toContain('ada@example.invalid');
|
||||
});
|
||||
|
||||
it('corrects a saved name, email, or phone without creating another person', async () => {
|
||||
const { app, db } = await buildApp();
|
||||
const cookie = await signIn(app, db);
|
||||
const openId = insertShift(db);
|
||||
await postFile(
|
||||
app,
|
||||
cookie,
|
||||
'First Name,Last Name,Email,Phone\nPat,-,pat@example.invalid,7125550101\nPat,Other,pat@example.invalid,222\n',
|
||||
);
|
||||
const contactId = (db.prepare(`SELECT id AS id FROM contacts WHERE last_name = '-'`).get() as { id: number }).id;
|
||||
const otherId = (db.prepare(`SELECT id AS id FROM contacts WHERE last_name = 'Other'`).get() as { id: number }).id;
|
||||
|
||||
const person = await app.request(`/admin/contacts/${contactId}`, { headers: { cookie } });
|
||||
const personHtml = await person.text();
|
||||
expect(person.status).toBe(200);
|
||||
expect(personHtml).toContain('Correct this contact');
|
||||
expect(personHtml).toContain('Save this correction');
|
||||
expect(personHtml).toContain('value="Pat"');
|
||||
expect(personHtml).toContain('value="-"');
|
||||
expect(personHtml).toContain('value="pat@example.invalid"');
|
||||
expect(personHtml).toContain('value="712-555-0101"');
|
||||
expect(personHtml).toContain('Add to this shift');
|
||||
|
||||
const loggedOut = await app.request(`/admin/contacts/${contactId}`, { method: 'POST' });
|
||||
expect(loggedOut.status).toBe(303);
|
||||
expect(db.prepare('SELECT last_name, phone FROM contacts WHERE id = ?').get(contactId)).toEqual({
|
||||
last_name: '-',
|
||||
phone: '712-555-0101',
|
||||
});
|
||||
|
||||
const stale = await postCorrect(app, cookie, contactId, {
|
||||
firstName: 'Pat',
|
||||
lastName: 'Review',
|
||||
email: 'pat@example.invalid',
|
||||
phone: '7125550199',
|
||||
csrf: 'nope',
|
||||
});
|
||||
expect(stale.status).toBe(403);
|
||||
expect(db.prepare('SELECT last_name FROM contacts WHERE id = ?').get(contactId)).toEqual({ last_name: '-' });
|
||||
|
||||
const corrected = await postCorrect(app, cookie, contactId, {
|
||||
firstName: 'pat',
|
||||
lastName: 'review',
|
||||
email: 'Pat@Example.invalid',
|
||||
phone: '7125550199',
|
||||
});
|
||||
expect(corrected.status).toBe(303);
|
||||
expect(corrected.headers.get('location')).toBe(`/admin/contacts/${contactId}?notice=contact-corrected`);
|
||||
const after = await app.request(corrected.headers.get('location') ?? '', { headers: { cookie } });
|
||||
const afterHtml = await after.text();
|
||||
expect(afterHtml).toContain('That contact is corrected.');
|
||||
expect(afterHtml).toContain('Pat Review');
|
||||
expect(afterHtml).toContain('value="Review"');
|
||||
expect(afterHtml).toContain('value="712-555-0199"');
|
||||
expect(db.prepare('SELECT id, first_name, last_name, email, phone FROM contacts ORDER BY id').all()).toEqual([
|
||||
{ id: contactId, first_name: 'Pat', last_name: 'Review', email: 'pat@example.invalid', phone: '712-555-0199' },
|
||||
{ id: otherId, first_name: 'Pat', last_name: 'Other', email: 'pat@example.invalid', phone: '222' },
|
||||
]);
|
||||
const correctAudit = db.prepare(`SELECT detail_json AS detail_json FROM audit WHERE action = 'contacts.correct'`).get() as {
|
||||
detail_json: string;
|
||||
};
|
||||
expect(correctAudit.detail_json).toBe(`{"id":${contactId}}`);
|
||||
expect(correctAudit.detail_json).not.toContain('@');
|
||||
expect(count(db, 'SELECT COUNT(*) AS n FROM signups')).toBe(0);
|
||||
expect(count(db, `SELECT COUNT(*) AS n FROM outbox WHERE kind = 'confirmation'`)).toBe(0);
|
||||
|
||||
const added = await postContactShift(app, cookie, contactId, openId, afterHtml, {});
|
||||
expect(added.status).toBe(303);
|
||||
expect(db.prepare(`SELECT name AS name, phone AS phone FROM signups WHERE email_norm = 'pat@example.invalid'`).get()).toEqual({
|
||||
name: 'Pat Review',
|
||||
phone: '712-555-0199',
|
||||
});
|
||||
expect(count(db, 'SELECT COUNT(*) AS n FROM contacts')).toBe(2);
|
||||
|
||||
const same = await postCorrect(app, cookie, contactId, {
|
||||
firstName: 'Pat',
|
||||
lastName: 'Review',
|
||||
email: 'pat@example.invalid',
|
||||
phone: '712-555-0199',
|
||||
});
|
||||
expect(same.headers.get('location')).toBe(`/admin/contacts/${contactId}?notice=contact-same`);
|
||||
expect(count(db, `SELECT COUNT(*) AS n FROM audit WHERE action = 'contacts.correct'`)).toBe(1);
|
||||
|
||||
const renamedEmail = await postCorrect(app, cookie, contactId, {
|
||||
firstName: 'Pat',
|
||||
lastName: 'Review',
|
||||
email: 'Patrick@Example.invalid',
|
||||
phone: '712-555-0199',
|
||||
});
|
||||
expect(renamedEmail.headers.get('location')).toBe(`/admin/contacts/${contactId}?notice=contact-corrected`);
|
||||
expect(db.prepare('SELECT email, phone FROM contacts WHERE id = ?').get(contactId)).toEqual({
|
||||
email: 'patrick@example.invalid',
|
||||
phone: '712-555-0199',
|
||||
});
|
||||
expect(db.prepare('SELECT email FROM contacts WHERE id = ?').get(otherId)).toEqual({ email: 'pat@example.invalid' });
|
||||
|
||||
const taken = await postCorrect(app, cookie, contactId, {
|
||||
firstName: 'Pat',
|
||||
lastName: 'Other',
|
||||
email: 'pat@example.invalid',
|
||||
phone: '712-555-0199',
|
||||
});
|
||||
expect(taken.status).toBe(400);
|
||||
const takenHtml = await taken.text();
|
||||
expect(takenHtml).toContain('That name and email are already saved as another contact.');
|
||||
expect(takenHtml).toContain('value="Other"');
|
||||
expect(db.prepare('SELECT first_name, last_name, email FROM contacts WHERE id = ?').get(contactId)).toEqual({
|
||||
first_name: 'Pat',
|
||||
last_name: 'Review',
|
||||
email: 'patrick@example.invalid',
|
||||
});
|
||||
expect(count(db, 'SELECT COUNT(*) AS n FROM contacts')).toBe(2);
|
||||
|
||||
const cleared = await postCorrect(app, cookie, contactId, {
|
||||
firstName: 'Pat',
|
||||
lastName: 'Review',
|
||||
email: 'patrick@example.invalid',
|
||||
phone: '',
|
||||
});
|
||||
expect(cleared.status).toBe(303);
|
||||
expect(db.prepare('SELECT phone FROM contacts WHERE id = ?').get(contactId)).toEqual({ phone: null });
|
||||
expect(db.prepare(`SELECT phone AS phone FROM signups WHERE email_norm = 'pat@example.invalid'`).get()).toEqual({
|
||||
phone: '712-555-0199',
|
||||
});
|
||||
|
||||
const invalid = await postCorrect(app, cookie, contactId, {
|
||||
firstName: '',
|
||||
lastName: 'Review',
|
||||
email: 'not-an-email',
|
||||
phone: '7125550199',
|
||||
});
|
||||
expect(invalid.status).toBe(400);
|
||||
const invalidHtml = await invalid.text();
|
||||
expect(invalidHtml).toContain('Enter a first name.');
|
||||
expect(invalidHtml).toContain('Enter an email address.');
|
||||
expect(db.prepare('SELECT first_name, email, phone FROM contacts WHERE id = ?').get(contactId)).toEqual({
|
||||
first_name: 'Pat',
|
||||
email: 'patrick@example.invalid',
|
||||
phone: null,
|
||||
});
|
||||
|
||||
const missing = await postCorrect(app, cookie, 999, {
|
||||
firstName: 'Pat',
|
||||
lastName: 'Review',
|
||||
email: 'patrick@example.invalid',
|
||||
phone: '',
|
||||
});
|
||||
expect(missing.status).toBe(404);
|
||||
expect(count(db, `SELECT COUNT(*) AS n FROM audit WHERE action = 'contacts.correct'`)).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
async function openDb() {
|
||||
@@ -670,6 +828,27 @@ async function postContactShift(
|
||||
});
|
||||
}
|
||||
|
||||
async function postCorrect(
|
||||
app: Awaited<ReturnType<typeof buildApp>>['app'],
|
||||
cookie: string,
|
||||
contactId: number,
|
||||
fields: { firstName: string; lastName: string; email: string; phone?: string; csrf?: string },
|
||||
) {
|
||||
const current = await app.request('/admin/contacts', { headers: { cookie } });
|
||||
const token = fields.csrf ?? (/name="csrf" value="([^"]*)"/.exec(await current.text())?.[1] ?? '');
|
||||
return app.request(`/admin/contacts/${contactId}`, {
|
||||
method: 'POST',
|
||||
headers: { origin: ORIGIN, 'content-type': 'application/x-www-form-urlencoded', cookie },
|
||||
body: new URLSearchParams({
|
||||
csrf: token,
|
||||
first_name: fields.firstName,
|
||||
last_name: fields.lastName,
|
||||
email: fields.email,
|
||||
phone: fields.phone ?? '',
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
async function postManual(
|
||||
app: Awaited<ReturnType<typeof buildApp>>['app'],
|
||||
cookie: string,
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { groupShiftTargets } from '../src/shift-options.js';
|
||||
import type { MoveTarget } from '../src/admin/store.js';
|
||||
|
||||
function target(id: number, date: string, dateLabel: string): MoveTarget {
|
||||
return { id, date, dateLabel, label: `Shift ${id}` };
|
||||
}
|
||||
|
||||
describe('shift menu groups', () => {
|
||||
it('keeps same-day shifts together and leaves a later repeat of that date in place', () => {
|
||||
const groups = groupShiftTargets([
|
||||
target(1, '2026-10-20', 'Tuesday, October 20, 2026'),
|
||||
target(2, '2026-10-20', 'Tuesday, October 20, 2026'),
|
||||
target(3, '2026-10-21', 'Wednesday, October 21, 2026'),
|
||||
target(4, '2026-10-20', 'Tuesday, October 20, 2026'),
|
||||
]);
|
||||
expect(groups.map((group) => group.targets.map((item) => item.id))).toEqual([[1, 2], [3], [4]]);
|
||||
expect(groups.map((group) => group.dateLabel)).toEqual([
|
||||
'Tuesday, October 20, 2026',
|
||||
'Wednesday, October 21, 2026',
|
||||
'Tuesday, October 20, 2026',
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -51,9 +51,11 @@ describe('capacity-safe signup', () => {
|
||||
expect(confirmed.status).toBe(200);
|
||||
expect(confirmedHtml).toContain('Pat Review');
|
||||
expect(confirmedHtml).toContain('A confirmation email is on the way');
|
||||
expect(confirmedHtml).toContain('Cancel or switch shifts');
|
||||
expect(confirmedHtml).toContain('Save the address below');
|
||||
expect(confirmedHtml).toContain('This browser keeps it for a few minutes');
|
||||
const managePath = confirmedHtml.match(/href="(\/m\/[^"]+)"/)?.[1];
|
||||
expect(managePath).toBeTruthy();
|
||||
expect(confirmedHtml).toContain(`>http://127.0.0.1:3000${managePath}<`);
|
||||
expect(cookie).not.toContain(managePath?.slice(3) ?? 'missing-token');
|
||||
const manage = await app.request(managePath ?? '/m/missing');
|
||||
const manageHtml = await manage.text();
|
||||
@@ -81,9 +83,11 @@ describe('capacity-safe signup', () => {
|
||||
const again = await postSignup(app, shiftId, { name: 'Pat Review', email: 'pat.review@example.invalid' }, { ip: '203.0.113.21' });
|
||||
expect(again.status).toBe(409);
|
||||
const againHtml = await again.text();
|
||||
expect(againHtml).toContain('That person is already signed up for this shift.');
|
||||
expect(againHtml).toContain('That person is already signed up for this shift. Use the link in the confirmation email.');
|
||||
expect(againHtml).not.toContain('already registered');
|
||||
expect(againHtml).not.toContain('duplicate');
|
||||
expect(againHtml).not.toContain(managePath ?? '/m/');
|
||||
expect(againHtml).not.toContain('/m/');
|
||||
|
||||
expect(db.prepare("SELECT COUNT(*) AS n FROM signups WHERE status = 'confirmed'").get()).toEqual({ n: 1 });
|
||||
});
|
||||
@@ -105,7 +109,9 @@ describe('capacity-safe signup', () => {
|
||||
]);
|
||||
const again = await postSignup(app, shiftId, { name: 'sam review', email: 'home@example.invalid' }, { ip: '203.0.113.93' });
|
||||
expect(again.status).toBe(409);
|
||||
expect(await again.text()).toContain('That person is already signed up for this shift.');
|
||||
const againHtml = await again.text();
|
||||
expect(againHtml).toContain('That person is already signed up for this shift. Use the link in the confirmation email.');
|
||||
expect(againHtml).not.toContain('/m/');
|
||||
expect(db.prepare("SELECT COUNT(*) AS n FROM signups WHERE status = 'confirmed'").get()).toEqual({ n: 2 });
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user