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
+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.';
|
||||
|
||||
Reference in new issue
Block a user