feat: open the next three months of Wednesday shifts on the public list
Volunteers can see who is signed up, and a full shift stays closed. Coordinators can see a contact's current and past shifts.
This commit is contained in:
1 parent
e7c99a788e
commit
1a8959c86a
26 files changed
+1402
-192
No files matched your search
@@ -91,6 +91,7 @@ import {
|
||||
parseContactSkips,
|
||||
removeContact,
|
||||
saveManualContact,
|
||||
contactSignupShifts,
|
||||
walkInFromContact,
|
||||
type ContactImportSummary,
|
||||
type ContactManualErrors,
|
||||
@@ -474,6 +475,7 @@ function showContact(
|
||||
config={services.config}
|
||||
csrf={session.csrf}
|
||||
contact={contact}
|
||||
signedUp={contactSignupShifts(services.db, contact, services.now())}
|
||||
shifts={listOpenShiftsForPerson(services.db, { email: contact.email, name: contact.name }, services.now())}
|
||||
form={state?.form ?? blankWalkIn(services, contact.id)}
|
||||
shiftId={state?.shiftId ?? ''}
|
||||
|
||||
+140
-91
@@ -12,6 +12,7 @@ import {
|
||||
type ContactImportSummary,
|
||||
type ContactManualErrors,
|
||||
type ContactManualValues,
|
||||
type ContactShift,
|
||||
} from './contacts.js';
|
||||
import type { SignupErrors, SignupValues } from './signup-form.js';
|
||||
import { addLocalDays, formatInstantInZone, todayInZone } from './time.js';
|
||||
@@ -458,6 +459,19 @@ function contactListHref(config: AppConfig, query: string, shown: number): strin
|
||||
return `${appPath(config, '/admin/contacts')}?${params.toString()}#contact-more`;
|
||||
}
|
||||
|
||||
function ContactShiftList(props: { config: AppConfig; shifts: ContactShift[]; empty: string }) {
|
||||
if (props.shifts.length === 0) return <p class="empty">{props.empty}</p>;
|
||||
return (
|
||||
<ul class="contact-shift-list">
|
||||
{props.shifts.map((shift) => (
|
||||
<li key={shift.signupId}>
|
||||
<a href={appPath(props.config, `/admin/shifts/${shift.shiftId}`)}>{shift.label}</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
export function ContactsPage(props: {
|
||||
config: AppConfig;
|
||||
csrf: string;
|
||||
@@ -482,6 +496,8 @@ export function ContactsPage(props: {
|
||||
: `${props.total} people`;
|
||||
const hiddenSkips = props.summary ? Math.max(0, props.summary.skipped - props.summary.skips.length) : 0;
|
||||
const moreHref = contactListHref(props.config, props.query, props.limit + CONTACT_LIST_PAGE);
|
||||
const addOpen = Object.keys(manual.errors).length > 0;
|
||||
const importOpen = Boolean(props.importError);
|
||||
return (
|
||||
<>
|
||||
<Crumb items={[{ href: appPath(props.config, '/admin'), label: 'Coordinator' }, { label: 'Contacts' }]} />
|
||||
@@ -495,42 +511,11 @@ export function ContactsPage(props: {
|
||||
</ul>
|
||||
) : 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 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} />
|
||||
<h2>Add a contact</h2>
|
||||
<p>This saves one person. It does not sign them up and does not send email. The same name and email updates that person. A different name is saved separately, even with the same email. Names are capitalized. A 10-digit phone is saved with dashes, like 712-555-0100.</p>
|
||||
<WalkInField id="contact-first" label="First name" name="first_name" type="text" value={manual.values.firstName} error={manual.errors.firstName} />
|
||||
<WalkInField id="contact-last" label="Last name" name="last_name" type="text" value={manual.values.lastName} error={manual.errors.lastName} />
|
||||
<WalkInField id="contact-email" label="Email" name="email" type="email" value={manual.values.email} error={manual.errors.email} />
|
||||
<WalkInField id="contact-phone" label="Phone" name="phone" type="tel" value={manual.values.phone} error={manual.errors.phone} required />
|
||||
<button type="submit">Save this contact</button>
|
||||
</form>
|
||||
<form method="post" action={appPath(props.config, '/admin/contacts/import')} class="signup-form desk-download" enctype="multipart/form-data">
|
||||
<input type="hidden" name="csrf" value={props.csrf} />
|
||||
<h2>Import a contact list</h2>
|
||||
<p>
|
||||
Use a spreadsheet with First Name, Last Name, Email, and Phone. The SignUpGenius people export works. Address 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 row without a phone is skipped. Names are capitalized. A 10-digit phone is saved with dashes, like 712-555-0100. Email addresses are stored in lowercase. The file has to be under 64 KB.
|
||||
</p>
|
||||
{props.importError ? <p class="error">{props.importError}</p> : null}
|
||||
<label>
|
||||
Spreadsheet
|
||||
<input name="file" type="file" accept=".csv,text/csv,text/plain" required />
|
||||
</label>
|
||||
<button type="submit">Import this list</button>
|
||||
</form>
|
||||
<form method="post" action={appPath(props.config, '/admin/contacts/export')} class="signup-form desk-download">
|
||||
<input type="hidden" name="csrf" value={props.csrf} />
|
||||
<h2>Download contacts</h2>
|
||||
<p>A downloaded copy stays on your computer. This app does not delete it later. The Address column is blank. A cell that would be a spreadsheet formula is saved as text.</p>
|
||||
<button type="submit">Download contacts</button>
|
||||
</form>
|
||||
<section class="desk-events" aria-labelledby="contacts-heading">
|
||||
<h2 id="contacts-heading">{heading}</h2>
|
||||
<div class="contact-toolbar">
|
||||
{props.total > 0 ? (
|
||||
<form method="get" action={appPath(props.config, '/admin/contacts')} class="signup-form desk-download">
|
||||
<form method="get" action={appPath(props.config, '/admin/contacts')} class="signup-form desk-download contact-find">
|
||||
<div class="desk-range">
|
||||
<label>
|
||||
Find
|
||||
@@ -542,6 +527,53 @@ export function ContactsPage(props: {
|
||||
) : (
|
||||
<p class="empty">No contacts yet.</p>
|
||||
)}
|
||||
<div class="contact-actions">
|
||||
<details class="contact-menu" name="contact-tools" open={addOpen ? true : undefined}>
|
||||
<summary>
|
||||
Add a contact
|
||||
<span class="edit-chevron" aria-hidden="true" />
|
||||
</summary>
|
||||
<form method="post" action={appPath(props.config, '/admin/contacts/new')} class="signup-form">
|
||||
<input type="hidden" name="csrf" value={props.csrf} />
|
||||
<p>This saves one person. It does not sign them up and does not send email. The same name and email updates that person. A different name is saved separately, even with the same email. Names are capitalized. A 10-digit phone is saved with dashes, like 712-555-0100.</p>
|
||||
<WalkInField id="contact-first" label="First name" name="first_name" type="text" value={manual.values.firstName} error={manual.errors.firstName} />
|
||||
<WalkInField id="contact-last" label="Last name" name="last_name" type="text" value={manual.values.lastName} error={manual.errors.lastName} />
|
||||
<WalkInField id="contact-email" label="Email" name="email" type="email" value={manual.values.email} error={manual.errors.email} />
|
||||
<WalkInField id="contact-phone" label="Phone" name="phone" type="tel" value={manual.values.phone} error={manual.errors.phone} required />
|
||||
<button type="submit">Save this contact</button>
|
||||
</form>
|
||||
</details>
|
||||
<details class="contact-menu" name="contact-tools" open={importOpen ? true : undefined}>
|
||||
<summary>
|
||||
Import
|
||||
<span class="edit-chevron" aria-hidden="true" />
|
||||
</summary>
|
||||
<form method="post" action={appPath(props.config, '/admin/contacts/import')} class="signup-form" enctype="multipart/form-data">
|
||||
<input type="hidden" name="csrf" value={props.csrf} />
|
||||
<p>
|
||||
Use a spreadsheet with First Name, Last Name, Email, and Phone. The SignUpGenius people export works. Address 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 row without a phone is skipped. Names are capitalized. A 10-digit phone is saved with dashes, like 712-555-0100. Email addresses are stored in lowercase. The file has to be under 64 KB.
|
||||
</p>
|
||||
{props.importError ? <p class="error">{props.importError}</p> : null}
|
||||
<label>
|
||||
Spreadsheet
|
||||
<input name="file" type="file" accept=".csv,text/csv,text/plain" required />
|
||||
</label>
|
||||
<button type="submit">Import this list</button>
|
||||
</form>
|
||||
</details>
|
||||
<details class="contact-menu" name="contact-tools">
|
||||
<summary>
|
||||
Download
|
||||
<span class="edit-chevron" aria-hidden="true" />
|
||||
</summary>
|
||||
<form method="post" action={appPath(props.config, '/admin/contacts/export')} class="signup-form">
|
||||
<input type="hidden" name="csrf" value={props.csrf} />
|
||||
<p>A downloaded copy stays on your computer. This app does not delete it later. The Address column is blank. A cell that would be a spreadsheet formula is saved as text.</p>
|
||||
<button type="submit">Download contacts</button>
|
||||
</form>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
{props.total > 0 && props.people.length === 0 ? <p class="empty">No contacts match.</p> : null}
|
||||
{props.people.length > 0 ? (
|
||||
<ul class="contact-list" id="contacts-list">
|
||||
@@ -580,6 +612,7 @@ export function ContactPage(props: {
|
||||
config: AppConfig;
|
||||
csrf: string;
|
||||
contact: Contact;
|
||||
signedUp: { current: ContactShift[]; past: ContactShift[] };
|
||||
shifts: MoveTarget[];
|
||||
form: WalkInState;
|
||||
shiftId: string;
|
||||
@@ -599,6 +632,8 @@ export function ContactPage(props: {
|
||||
},
|
||||
errors: {},
|
||||
};
|
||||
const editOpen = Object.keys(correction.errors).length > 0;
|
||||
const addOpen = Boolean(props.error || props.form.message || errorEntries.length > 0 || props.shiftId);
|
||||
return (
|
||||
<>
|
||||
<Crumb
|
||||
@@ -612,62 +647,76 @@ export function ContactPage(props: {
|
||||
<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.
|
||||
</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"
|
||||
name="phone"
|
||||
type="tel"
|
||||
value={correction.values.phone}
|
||||
error={correction.errors.phone}
|
||||
required
|
||||
/>
|
||||
<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>
|
||||
{props.shifts.length > 0 ? (
|
||||
<form method="post" action={appPath(props.config, `/admin/contacts/${props.contact.id}/add`)} class="signup-form">
|
||||
{props.form.message ? <p class="error">{props.form.message}</p> : null}
|
||||
{errorEntries.length > 0 ? (
|
||||
<div class="error" role="alert">
|
||||
<p>Check these fields:</p>
|
||||
<ul>
|
||||
{errorEntries.map(([field, message]) => (
|
||||
<li key={field}>{message}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
) : null}
|
||||
<h2>Signed up for</h2>
|
||||
<ContactShiftList config={props.config} shifts={props.signedUp.current} empty="Not signed up for a shift." />
|
||||
<h2>Past shifts</h2>
|
||||
<ContactShiftList config={props.config} shifts={props.signedUp.past} empty="No past shifts." />
|
||||
<div class="contact-actions">
|
||||
<details class="contact-menu" name="contact-action" open={editOpen ? true : undefined}>
|
||||
<summary>
|
||||
Edit contact
|
||||
<span class="edit-chevron" aria-hidden="true" />
|
||||
</summary>
|
||||
<form method="post" action={appPath(props.config, `/admin/contacts/${props.contact.id}`)} class="signup-form">
|
||||
<input type="hidden" name="csrf" value={props.csrf} />
|
||||
<input type="hidden" name="form_token" value={props.form.token} />
|
||||
<label for="add-shift">
|
||||
Shift
|
||||
<select id="add-shift" name="shift" required>
|
||||
<ShiftTargetOptions targets={props.shifts} selectedId={props.shiftId} />
|
||||
</select>
|
||||
</label>
|
||||
<label for="add-notes">
|
||||
Notes (optional)
|
||||
<textarea id="add-notes" name="notes" aria-invalid={errors.notes ? 'true' : undefined}>
|
||||
{values.notes}
|
||||
</textarea>
|
||||
{errors.notes ? <span class="field-error">{errors.notes}</span> : null}
|
||||
</label>
|
||||
<button type="submit">Add to this shift</button>
|
||||
<p>This changes the saved person. It does not change a signup, take a spot, or send email.</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"
|
||||
name="phone"
|
||||
type="tel"
|
||||
value={correction.values.phone}
|
||||
error={correction.errors.phone}
|
||||
required
|
||||
/>
|
||||
<button type="submit">Save contact</button>
|
||||
</form>
|
||||
) : (
|
||||
<p class="empty">No open shift is available.</p>
|
||||
)}
|
||||
</details>
|
||||
<details class="contact-menu" name="contact-action" open={addOpen ? true : undefined}>
|
||||
<summary>
|
||||
Add to a shift
|
||||
<span class="edit-chevron" aria-hidden="true" />
|
||||
</summary>
|
||||
{props.error ? <p class="error">{props.error}</p> : null}
|
||||
{props.shifts.length > 0 ? (
|
||||
<form method="post" action={appPath(props.config, `/admin/contacts/${props.contact.id}/add`)} class="signup-form">
|
||||
<p>This uses their saved name, email, and phone. It takes one spot and queues a confirmation email.</p>
|
||||
{props.form.message ? <p class="error">{props.form.message}</p> : null}
|
||||
{errorEntries.length > 0 ? (
|
||||
<div class="error" role="alert">
|
||||
<p>Check these fields:</p>
|
||||
<ul>
|
||||
{errorEntries.map(([field, message]) => (
|
||||
<li key={field}>{message}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
) : null}
|
||||
<input type="hidden" name="csrf" value={props.csrf} />
|
||||
<input type="hidden" name="form_token" value={props.form.token} />
|
||||
<label for="add-shift">
|
||||
Shift
|
||||
<select id="add-shift" name="shift" required>
|
||||
<ShiftTargetOptions targets={props.shifts} selectedId={props.shiftId} />
|
||||
</select>
|
||||
</label>
|
||||
<label for="add-notes">
|
||||
Notes (optional)
|
||||
<textarea id="add-notes" name="notes" aria-invalid={errors.notes ? 'true' : undefined}>
|
||||
{values.notes}
|
||||
</textarea>
|
||||
{errors.notes ? <span class="field-error">{errors.notes}</span> : null}
|
||||
</label>
|
||||
<button type="submit">Add to this shift</button>
|
||||
</form>
|
||||
) : (
|
||||
<p class="empty">No open shift is available.</p>
|
||||
)}
|
||||
</details>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1195,7 +1244,7 @@ function ShiftList(props: { config: AppConfig; event: AdminEvent; csrf: string;
|
||||
<details class="help-tip">
|
||||
<summary aria-label="About upcoming shifts">?</summary>
|
||||
<p>
|
||||
Shifts show on the public list when this event is public, the shift is not cancelled, and it has not ended. Repeating shifts add dates for the next eight weeks. Add weekly shifts fills those dates. Shifts already on the schedule stay as they are, including cancelled ones.
|
||||
Shifts show on the public list when this event is public, the shift is not cancelled, and it has not ended. Repeating shifts add dates for the next three months. Add weekly shifts fills those dates. Shifts already on the schedule stay as they are, including cancelled ones.
|
||||
</p>
|
||||
</details>
|
||||
</div>
|
||||
@@ -1374,7 +1423,7 @@ function WeeklyTemplates(props: { config: AppConfig; event: AdminEvent; csrf: st
|
||||
<div>
|
||||
<h2 id="templates-heading">Repeating shifts</h2>
|
||||
<p class="event-panel-note">
|
||||
Each one adds 8 weeks ahead.{' '}
|
||||
Each one adds three months ahead.{' '}
|
||||
<button type="submit" class="text-action" form="add-weekly">
|
||||
Add weekly shifts
|
||||
</button>
|
||||
@@ -1603,7 +1652,7 @@ function WalkInForm(props: { config: AppConfig; csrf: string; shiftId: number; f
|
||||
return (
|
||||
<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>
|
||||
<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 stays off the public list.</p>
|
||||
<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>
|
||||
{props.form.message ? <p class="error">{props.form.message}</p> : null}
|
||||
{errorEntries.length > 0 ? (
|
||||
<div class="error" role="alert">
|
||||
@@ -1890,7 +1939,7 @@ const NOTICES: Record<string, string> = {
|
||||
'no-show': 'Marked as a no-show.',
|
||||
'attendance-cleared': 'The attendance mark is cleared.',
|
||||
moved: 'They are on this shift. A change email is queued.',
|
||||
generated: 'Weekly shifts for the next eight weeks are on the schedule. Existing shifts were left as they are.',
|
||||
generated: 'Weekly shifts for the next three months are on the schedule. Existing shifts were left as they are.',
|
||||
'no-template': 'There is no active weekly template.',
|
||||
'template-saved': 'The weekly template is saved. Shifts already on the schedule were not changed.',
|
||||
'template-ended': 'This weekly template has ended. Shifts already on the schedule stay.',
|
||||
|
||||
+25
-4
@@ -7,6 +7,7 @@ import { cancelPendingConfirmations, cancelPendingReminders, queueCancellation,
|
||||
import type { MailShift } from '../mail/templates.js';
|
||||
import type { MailIdentity } from '../mail/types.js';
|
||||
import { confirmedPersonOnShift, confirmedPersonShiftIds, reserveSignup, type ReserveInput, type ReserveResult } from '../signup.js';
|
||||
import { isWithinSignupWindow } from '../signup-window.js';
|
||||
import { isUniqueConstraint } from '../sqlite-error.js';
|
||||
import { addLocalDays, assertSameDayShift, assertValidTimeZone, formatInstantInZone, formatUtc, localShiftToUtc, LocalTimeError, todayInZone } from '../time.js';
|
||||
|
||||
@@ -1006,7 +1007,7 @@ export function listMoveTargets(
|
||||
eventId: number,
|
||||
shiftId: number,
|
||||
now: string,
|
||||
options?: { publishedOnly?: boolean; excludePerson?: { email: string; name: string } },
|
||||
options?: { publishedOnly?: boolean; excludePerson?: { email: string; name: string }; signupWindow?: boolean },
|
||||
): MoveTarget[] {
|
||||
const blocked = new Set<number>();
|
||||
if (options?.excludePerson) {
|
||||
@@ -1042,6 +1043,7 @@ export function listMoveTargets(
|
||||
if (Number(row.occupied) >= Number(row.capacity)) return [];
|
||||
const start = formatInstantInZone(row.starts_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 [];
|
||||
return [{
|
||||
id: row.id,
|
||||
date: start.date,
|
||||
@@ -1197,14 +1199,23 @@ function relocate(
|
||||
if (destinationShiftId === source.shift_id) return { ok: false, error: transferError(options.audience, 'same'), shiftId: source.shift_id };
|
||||
const destination = db
|
||||
.prepare(
|
||||
`SELECT s.id AS id, s.event_id AS event_id, s.cancelled AS cancelled, s.ends_at_utc AS ends_at_utc,
|
||||
s.capacity AS capacity, e.published AS published
|
||||
`SELECT s.id AS id, s.event_id AS event_id, s.cancelled AS cancelled, s.starts_at_utc AS starts_at_utc,
|
||||
s.ends_at_utc AS ends_at_utc, s.capacity AS capacity, e.published AS published, e.tz AS tz
|
||||
FROM shifts s
|
||||
JOIN events e ON e.id = s.event_id
|
||||
WHERE s.id = ?`,
|
||||
)
|
||||
.get(destinationShiftId) as
|
||||
| { id: number; event_id: number; cancelled: number; ends_at_utc: string; capacity: number; published: number }
|
||||
| {
|
||||
id: number;
|
||||
event_id: number;
|
||||
cancelled: number;
|
||||
starts_at_utc: string;
|
||||
ends_at_utc: string;
|
||||
capacity: number;
|
||||
published: number;
|
||||
tz: string;
|
||||
}
|
||||
| undefined;
|
||||
if (!destination) return { ok: false, error: transferError(options.audience, 'missing'), shiftId: source.shift_id };
|
||||
if (destination.event_id !== source.event_id) return { ok: false, error: transferError(options.audience, 'event'), shiftId: source.shift_id };
|
||||
@@ -1214,6 +1225,13 @@ function relocate(
|
||||
if (destination.cancelled === 1 || destination.ends_at_utc <= now) {
|
||||
return { ok: false, error: transferError(options.audience, 'closed'), shiftId: source.shift_id };
|
||||
}
|
||||
if (options.audience === 'volunteer') {
|
||||
const start = formatInstantInZone(destination.starts_at_utc, destination.tz);
|
||||
const today = todayInZone(destination.tz, Temporal.Instant.from(now));
|
||||
if (!isWithinSignupWindow(start.date, today)) {
|
||||
return { ok: false, error: transferError(options.audience, 'early'), shiftId: source.shift_id };
|
||||
}
|
||||
}
|
||||
if (confirmedPersonOnShift(db, destination.id, source.email_norm, source.name)) {
|
||||
return { ok: false, error: transferError(options.audience, 'duplicate'), shiftId: source.shift_id };
|
||||
}
|
||||
@@ -1308,6 +1326,7 @@ function transferError(audience: TransferOptions['audience'], code: TransferErro
|
||||
missing: 'That shift is not available.',
|
||||
event: 'Choose a shift in this event.',
|
||||
closed: 'That shift is closed.',
|
||||
early: 'That shift is not open for sign-up yet.',
|
||||
duplicate: 'That person is already signed up for this shift.',
|
||||
full: 'That shift is full.',
|
||||
used: 'This form was already used for a different signup. Submit it again.',
|
||||
@@ -1322,6 +1341,7 @@ function transferError(audience: TransferOptions['audience'], code: TransferErro
|
||||
missing: 'That shift is not available.',
|
||||
event: 'Choose a shift in this event.',
|
||||
closed: 'That shift is closed.',
|
||||
early: 'Sign-up for that shift opens three months before the date.',
|
||||
duplicate: 'You are already signed up for that shift.',
|
||||
full: 'That shift is full.',
|
||||
used: 'This form was already used. Open the link from your email.',
|
||||
@@ -1339,6 +1359,7 @@ type TransferError =
|
||||
| 'missing'
|
||||
| 'event'
|
||||
| 'closed'
|
||||
| 'early'
|
||||
| 'duplicate'
|
||||
| 'full'
|
||||
| 'used'
|
||||
|
||||
+2
-2
@@ -72,7 +72,7 @@ export function createApp(
|
||||
db,
|
||||
at,
|
||||
`${event.title} · Hope Volunteer`,
|
||||
<EventPage config={config} event={event} now={at} month={c.req.query('month')} path="/" />,
|
||||
<EventPage config={config} event={event} now={at} month={c.req.query('month')} view={c.req.query('view')} path="/" />,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -96,7 +96,7 @@ export function createApp(
|
||||
db,
|
||||
at,
|
||||
`${event.title} · Hope Volunteer`,
|
||||
<EventPage config={config} event={event} now={at} month={c.req.query('month')} />,
|
||||
<EventPage config={config} event={event} now={at} month={c.req.query('month')} view={c.req.query('view')} />,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { csvCell, csvImportedCell } from './export.js';
|
||||
import { capitalizeName, formatPhone } from './person-format.js';
|
||||
import type { SignupValues } from './signup-form.js';
|
||||
import { isUniqueConstraint } from './sqlite-error.js';
|
||||
import { formatInstantInZone, isUtcInstant } from './time.js';
|
||||
|
||||
const MAX_ROWS = 2000;
|
||||
export const CONTACT_LIST_PAGE = 20;
|
||||
@@ -34,6 +35,12 @@ export type ContactImportSummary = {
|
||||
skips: ContactSkip[];
|
||||
};
|
||||
|
||||
export type ContactShift = {
|
||||
signupId: number;
|
||||
shiftId: number;
|
||||
label: string;
|
||||
};
|
||||
|
||||
export type Contact = {
|
||||
id: number;
|
||||
firstName: string;
|
||||
@@ -207,6 +214,41 @@ export function loadContacts(db: Database.Database, query: string): { total: num
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Shifts this saved person signed up for.
|
||||
* Current means a confirmed signup whose shift has not ended.
|
||||
* Past means the shift has ended, including a cancelled signup.
|
||||
*/
|
||||
export function contactSignupShifts(
|
||||
db: Database.Database,
|
||||
person: Pick<Contact, 'firstName' | 'lastName' | 'email'>,
|
||||
now: string,
|
||||
): { current: ContactShift[]; past: ContactShift[] } {
|
||||
if (!isUtcInstant(now)) return { current: [], past: [] };
|
||||
const rows = db
|
||||
.prepare(
|
||||
`SELECT su.id AS signup_id, su.status AS status,
|
||||
s.id AS id, s.role AS role, s.starts_at_utc AS starts_at_utc, s.ends_at_utc AS ends_at_utc,
|
||||
s.cancelled AS cancelled, e.title AS title, e.tz AS tz, e.published AS published
|
||||
FROM signups su
|
||||
JOIN shifts s ON s.id = su.shift_id
|
||||
JOIN events e ON e.id = s.event_id
|
||||
WHERE su.anonymized_at IS NULL AND su.name IS NOT NULL AND su.email_norm IS NOT NULL
|
||||
AND su.email_norm = ? AND su.name = ? COLLATE NOCASE
|
||||
ORDER BY s.starts_at_utc, s.id, su.id`,
|
||||
)
|
||||
.all(person.email, contactSignupName(person)) as ContactShiftRow[];
|
||||
const current: ContactShift[] = [];
|
||||
const past: ContactShift[] = [];
|
||||
for (const row of rows) {
|
||||
const shift = { signupId: row.signup_id, shiftId: row.id, label: contactShiftLabel(row) };
|
||||
if (row.ends_at_utc > now && row.status === 'confirmed' && row.cancelled === 0) current.push(shift);
|
||||
else if (row.ends_at_utc <= now) past.push(shift);
|
||||
}
|
||||
past.reverse();
|
||||
return { current, past };
|
||||
}
|
||||
|
||||
export function getContact(db: Database.Database, id: number): Contact | null {
|
||||
if (!Number.isSafeInteger(id) || id < 1) return null;
|
||||
const row = db.prepare('SELECT id, first_name, last_name, email, phone FROM contacts WHERE id = ?').get(id) as ContactRow | undefined;
|
||||
@@ -341,6 +383,34 @@ function present(row: ContactRow): Contact {
|
||||
};
|
||||
}
|
||||
|
||||
type ContactShiftRow = {
|
||||
signup_id: number;
|
||||
status: string;
|
||||
id: number;
|
||||
role: string;
|
||||
starts_at_utc: string;
|
||||
ends_at_utc: string;
|
||||
cancelled: number;
|
||||
title: string;
|
||||
tz: string;
|
||||
published: number;
|
||||
};
|
||||
|
||||
/** A signup with no space is saved with a hyphen as the last name. The signup itself keeps the single name. */
|
||||
function contactSignupName(person: Pick<Contact, 'firstName' | 'lastName'>): string {
|
||||
return person.lastName === '-' ? person.firstName : `${person.firstName} ${person.lastName}`;
|
||||
}
|
||||
|
||||
function contactShiftLabel(row: ContactShiftRow): string {
|
||||
const start = formatInstantInZone(row.starts_at_utc, row.tz);
|
||||
const end = formatInstantInZone(row.ends_at_utc, row.tz);
|
||||
const comma = start.dateLabel.indexOf(', ');
|
||||
const date = comma === -1 ? start.dateLabel : start.dateLabel.slice(comma + 2);
|
||||
const publicity = row.published === 1 ? '' : ' (not on the public list)';
|
||||
const state = row.status === 'cancelled' ? ' (cancelled)' : row.cancelled === 1 ? ' (shift cancelled)' : '';
|
||||
return `${row.title}: ${row.role}, ${date}, ${start.timeLabel} to ${end.timeLabel} ${end.abbreviation}${publicity}${state}`;
|
||||
}
|
||||
|
||||
function columnIndex(cells: string[]): { first: number; last: number; email: number; phone: number } | null {
|
||||
const names = cells.map((cell) => csvImportedCell(cell).toLowerCase());
|
||||
const first = names.indexOf('first name');
|
||||
|
||||
+1
-1
@@ -107,7 +107,7 @@ export async function runSeedCli(env: NodeJS.ProcessEnv = process.env): Promise<
|
||||
`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('The weekly template is stored. Starting the app adds its shifts for the next eight weeks.');
|
||||
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.');
|
||||
} finally {
|
||||
db.close();
|
||||
|
||||
@@ -59,7 +59,7 @@ export function startDailyExpansionRunner(db: Database.Database, now: () => stri
|
||||
try {
|
||||
const result = runDueTemplateExpansion(db, now());
|
||||
if (result.created > 0) {
|
||||
console.log(`Added ${result.created} weekly shifts for the next eight weeks.`);
|
||||
console.log(`Added ${result.created} weekly shifts for the next three months.`);
|
||||
}
|
||||
for (const skip of result.skipped) console.error(skip);
|
||||
} catch (err) {
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ async function main(): Promise<void> {
|
||||
}
|
||||
const expanded = expandTemplates(database, startedAt);
|
||||
if (expanded.created > 0) {
|
||||
console.log(`Added ${expanded.created} weekly shifts for the next eight weeks.`);
|
||||
console.log(`Added ${expanded.created} weekly shifts for the next three months.`);
|
||||
}
|
||||
for (const skip of expanded.skipped) console.error(skip);
|
||||
runRetention(database, startedAt);
|
||||
|
||||
+165
-5
@@ -1,7 +1,8 @@
|
||||
import type { Child } from 'hono/jsx';
|
||||
import type { AppConfig } from './config.js';
|
||||
import { WEEKDAY_SHORT, calendarMonth, calendarToday, chooseCalendarMonth, monthStep, type CalendarDay } from './calendar.js';
|
||||
import { 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 type { SignupErrors, SignupValues } from './signup-form.js';
|
||||
import type { MoveTarget } from './admin/store.js';
|
||||
import { ShiftTargetOptions } from './shift-options.js';
|
||||
@@ -100,7 +101,7 @@ export function Layout(props: {
|
||||
<main id="content" tabIndex={-1}>
|
||||
<div class="session-bar">
|
||||
<a href={home} aria-current={props.path === home ? 'page' : undefined}>
|
||||
Calendar
|
||||
Sign Up
|
||||
</a>
|
||||
<a href={coordinator} class={props.account ? undefined : 'session-entry'} aria-current={coordinatorHere ? 'page' : undefined}>
|
||||
Coordinator
|
||||
@@ -224,7 +225,14 @@ export function EmptySchedulePage() {
|
||||
);
|
||||
}
|
||||
|
||||
export function EventPage(props: { config: AppConfig; event: PublicEvent; now: string; month?: string; path?: string }) {
|
||||
export function EventPage(props: {
|
||||
config: AppConfig;
|
||||
event: PublicEvent;
|
||||
now: string;
|
||||
month?: string;
|
||||
view?: string;
|
||||
path?: string;
|
||||
}) {
|
||||
const description = props.event.description.trim();
|
||||
return (
|
||||
<>
|
||||
@@ -235,11 +243,12 @@ export function EventPage(props: { config: AppConfig; event: PublicEvent; now: s
|
||||
{props.event.shifts.length === 0 ? (
|
||||
<p class="empty">No upcoming shifts are posted for this event.</p>
|
||||
) : (
|
||||
<ShiftCalendar
|
||||
<PublicSchedule
|
||||
config={props.config}
|
||||
event={props.event}
|
||||
now={props.now}
|
||||
month={props.month}
|
||||
view={props.view}
|
||||
path={props.path ?? `/e/${encodeURIComponent(props.event.slug)}`}
|
||||
/>
|
||||
)}
|
||||
@@ -485,8 +494,149 @@ export function WaitPage() {
|
||||
);
|
||||
}
|
||||
|
||||
function scheduleHref(config: AppConfig, path: string, view?: 'calendar', monthId?: string): string {
|
||||
const base = appPath(config, path);
|
||||
if (view !== 'calendar') return base;
|
||||
const params = new URLSearchParams({ view: 'calendar' });
|
||||
if (monthId) params.set('month', monthId);
|
||||
return `${base}?${params.toString()}`;
|
||||
}
|
||||
|
||||
function monthHref(config: AppConfig, path: string, monthId: string): string {
|
||||
return `${appPath(config, path)}?month=${monthId}`;
|
||||
return scheduleHref(config, path, 'calendar', monthId);
|
||||
}
|
||||
|
||||
function signupWindowSentence(timeZone: string, now: string): string {
|
||||
return `Sign-up is open through ${signupDeadlineLabel(calendarToday(timeZone, now))}.`;
|
||||
}
|
||||
|
||||
function PublicSchedule(props: {
|
||||
config: AppConfig;
|
||||
event: PublicEvent;
|
||||
now: string;
|
||||
month?: string;
|
||||
view?: string;
|
||||
path: string;
|
||||
}) {
|
||||
const calendarView = props.view === 'calendar';
|
||||
return (
|
||||
<div class="signup-board">
|
||||
<div class="schedule-bar">
|
||||
<details class="view-menu">
|
||||
<summary>
|
||||
<span class="view-menu-kicker">View</span>
|
||||
<span>{calendarView ? 'Calendar' : 'List'}</span>
|
||||
</summary>
|
||||
<div class="view-menu-list">
|
||||
<a href={scheduleHref(props.config, props.path)} aria-current={calendarView ? undefined : 'page'}>
|
||||
List
|
||||
</a>
|
||||
<a href={scheduleHref(props.config, props.path, 'calendar')} aria-current={calendarView ? 'page' : undefined}>
|
||||
Calendar
|
||||
</a>
|
||||
</div>
|
||||
</details>
|
||||
<p class="window-note">{signupWindowSentence(props.event.timeZone, props.now)}</p>
|
||||
</div>
|
||||
{calendarView ? (
|
||||
<ShiftCalendar config={props.config} event={props.event} now={props.now} month={props.month} path={props.path} />
|
||||
) : (
|
||||
<WednesdayBoard config={props.config} event={props.event} now={props.now} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
type WednesdayGroup = {
|
||||
date: string;
|
||||
heading: string;
|
||||
shifts: PublicShift[];
|
||||
};
|
||||
|
||||
function wednesdayGroups(shifts: PublicShift[]): WednesdayGroup[] {
|
||||
const groups: WednesdayGroup[] = [];
|
||||
for (const shift of shifts) {
|
||||
if (shift.when.weekday !== WEDNESDAY) continue;
|
||||
const last = groups.at(-1);
|
||||
if (last && last.date === shift.when.date) {
|
||||
last.shifts.push(shift);
|
||||
} else {
|
||||
const comma = shift.when.dateLabel.indexOf(', ');
|
||||
groups.push({
|
||||
date: shift.when.date,
|
||||
heading: comma === -1 ? shift.when.dateLabel : shift.when.dateLabel.slice(comma + 2),
|
||||
shifts: [shift],
|
||||
});
|
||||
}
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
function WednesdayBoard(props: { config: AppConfig; event: PublicEvent; now: string }) {
|
||||
const today = calendarToday(props.event.timeZone, props.now);
|
||||
const days = wednesdayGroups(props.event.shifts);
|
||||
if (days.length === 0) {
|
||||
return <p class="empty">No Wednesday shifts are posted. The calendar lists shifts on other days.</p>;
|
||||
}
|
||||
return (
|
||||
<ol class="day-board">
|
||||
{days.map((day) => (
|
||||
<li key={day.date}>
|
||||
<article class="day-card" aria-current={day.date === today ? 'date' : undefined}>
|
||||
<header class="day-card-head">
|
||||
<p class="day-card-dow">Wednesday</p>
|
||||
<h2>
|
||||
<time dateTime={day.date}>{day.heading}</time>
|
||||
</h2>
|
||||
{day.date === today ? <span class="today-flag">Today</span> : null}
|
||||
</header>
|
||||
<div class="day-card-shifts">
|
||||
{day.shifts.map((shift) => (
|
||||
<ShiftPane key={shift.id} config={props.config} shift={shift} />
|
||||
))}
|
||||
</div>
|
||||
</article>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
);
|
||||
}
|
||||
|
||||
function ShiftPane(props: { config: AppConfig; shift: PublicShift }) {
|
||||
const shift = props.shift;
|
||||
const closed = shift.full || shift.cancelled || shift.ended;
|
||||
const action = closed ? 'View shift' : 'Sign up';
|
||||
return (
|
||||
<section class="shift-pane">
|
||||
<div class="shift-pane-body">
|
||||
<h3>{shift.role}</h3>
|
||||
<ShiftWhen shift={shift} />
|
||||
{shift.inProgress ? <p class="status">In progress</p> : null}
|
||||
<Spots shift={shift} />
|
||||
<h4 class="roster-label">Volunteers</h4>
|
||||
{shift.volunteers.length === 0 ? (
|
||||
<p class="roster-empty">No one signed up yet.</p>
|
||||
) : (
|
||||
<ul class="roster-names">
|
||||
{shift.volunteers.map((name, index) => (
|
||||
<li key={`${shift.id}-${index}`}>{name}</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
{shift.full ? (
|
||||
<p class="btn-card is-static">
|
||||
<span class="shift-full-label">Full</span>
|
||||
<span>Not accepting more signups</span>
|
||||
</p>
|
||||
) : (
|
||||
<a class="btn-card" href={appPath(props.config, `/s/${shift.id}`)}>
|
||||
{action}
|
||||
<img src={asset(props.config, '/img/icons/right-arrow.svg')} alt="" />
|
||||
</a>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function MonthArrow(props: { config: AppConfig; path: string; monthId: string; direction: 'prev' | 'next' }) {
|
||||
@@ -661,6 +811,7 @@ function CalendarShift(props: { config: AppConfig; shift: PublicShift }) {
|
||||
{action} for {shift.role} on {shift.when.dateLabel}, {shift.when.startLabel} to {shift.when.endLabel}{' '}
|
||||
{shift.when.abbreviation}. {spotsSentence(shift)}
|
||||
{shift.inProgress ? ' In progress.' : ''}
|
||||
{shift.volunteers.length > 0 ? ` Volunteers: ${shift.volunteers.join(', ')}.` : ' No one signed up yet.'}
|
||||
</span>
|
||||
<div class="cal-detail" aria-hidden="true">
|
||||
<span class="cal-hold" aria-hidden="true"></span>
|
||||
@@ -673,6 +824,7 @@ function CalendarShift(props: { config: AppConfig; shift: PublicShift }) {
|
||||
</span>
|
||||
{shift.inProgress ? <span class="status">In progress</span> : null}
|
||||
<Spots shift={shift} />
|
||||
<span class="cal-names">{shift.volunteers.length > 0 ? shift.volunteers.join(', ') : 'No one signed up yet.'}</span>
|
||||
<span class="cal-action">{action}</span>
|
||||
</div>
|
||||
</a>
|
||||
@@ -822,6 +974,14 @@ function Field(props: {
|
||||
function StatusLine(props: { shift: PublicShift }) {
|
||||
if (props.shift.cancelled) return <p class="status">Cancelled. This shift is closed.</p>;
|
||||
if (props.shift.ended) return <p class="status">Ended. This shift is closed.</p>;
|
||||
if (props.shift.tooEarly) {
|
||||
return (
|
||||
<>
|
||||
<p class="status">{SIGNUP_TOO_EARLY}</p>
|
||||
<Spots shift={props.shift} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<>
|
||||
{props.shift.inProgress ? <p class="status">In progress</p> : null}
|
||||
|
||||
+3
-5
@@ -1,10 +1,8 @@
|
||||
import { Temporal } from '@js-temporal/polyfill';
|
||||
import type Database from 'better-sqlite3';
|
||||
import { writeAudit } from './auth/audit.js';
|
||||
import { LocalTimeError, addLocalDays, localShiftToUtc, todayInZone } from './time.js';
|
||||
|
||||
/** How far ahead an active template fills the schedule, counted in local days. */
|
||||
export const TEMPLATE_HORIZON_DAYS = 56;
|
||||
import { signupDeadline } from './signup-window.js';
|
||||
import { LocalTimeError, localShiftToUtc, todayInZone } from './time.js';
|
||||
|
||||
export type ExpandResult = {
|
||||
created: number;
|
||||
@@ -88,7 +86,7 @@ function expandOne(
|
||||
if (err instanceof LocalTimeError) return { created: 0, skipped: [err.message] };
|
||||
throw err;
|
||||
}
|
||||
const windowEnd = addLocalDays(today, TEMPLATE_HORIZON_DAYS);
|
||||
const windowEnd = signupDeadline(today);
|
||||
const dates = occurrenceDates(template, today, windowEnd);
|
||||
const insert = db.prepare(
|
||||
`INSERT OR IGNORE INTO shifts (
|
||||
|
||||
+48
-4
@@ -1,5 +1,12 @@
|
||||
import { Temporal } from '@js-temporal/polyfill';
|
||||
import type Database from 'better-sqlite3';
|
||||
import { formatInstantInZone } from './time.js';
|
||||
import { isWithinSignupWindow } from './signup-window.js';
|
||||
import { formatInstantInZone, todayInZone } from './time.js';
|
||||
|
||||
/** Weekday 0 is Sunday, matching the zoned clock. The public sign-up cards use Wednesday. */
|
||||
export const WEDNESDAY = 3;
|
||||
|
||||
const WEEKDAY_LABELS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] as const;
|
||||
|
||||
export type PublicShift = {
|
||||
id: number;
|
||||
@@ -13,6 +20,9 @@ export type PublicShift = {
|
||||
cancelled: boolean;
|
||||
ended: boolean;
|
||||
inProgress: boolean;
|
||||
/** The shift starts more than three months from today in the event time zone. */
|
||||
tooEarly: boolean;
|
||||
volunteers: string[];
|
||||
event: {
|
||||
id: number;
|
||||
slug: string;
|
||||
@@ -29,6 +39,8 @@ export type PublicShift = {
|
||||
startLabel: string;
|
||||
endLabel: string;
|
||||
abbreviation: string;
|
||||
weekday: number;
|
||||
weekdayLabel: string;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -107,6 +119,7 @@ export function getPublishedEvent(db: Database.Database, slug: string, now: stri
|
||||
ORDER BY s.starts_at_utc, s.role, s.id`,
|
||||
)
|
||||
.all(event.id, now) as ShiftRow[];
|
||||
const names = volunteerNamesByShift(db, rows.map((row) => row.id));
|
||||
return {
|
||||
id: event.id,
|
||||
slug: event.slug,
|
||||
@@ -114,7 +127,9 @@ export function getPublishedEvent(db: Database.Database, slug: string, now: stri
|
||||
description: event.description,
|
||||
location: event.location,
|
||||
timeZone: event.tz,
|
||||
shifts: rows.map((row) => presentShift(row, now)),
|
||||
shifts: rows
|
||||
.map((row) => presentShift(row, now, names.get(row.id) ?? []))
|
||||
.filter((shift) => !shift.tooEarly),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -127,7 +142,9 @@ export function getPublicShift(db: Database.Database, id: number, now: string):
|
||||
GROUP BY s.id`,
|
||||
)
|
||||
.get(id) as ShiftRow | undefined;
|
||||
return row ? presentShift(row, now) : null;
|
||||
if (!row) return null;
|
||||
const names = volunteerNamesByShift(db, [row.id]);
|
||||
return presentShift(row, now, names.get(row.id) ?? []);
|
||||
}
|
||||
|
||||
export function spotsSentence(shift: Pick<PublicShift, 'occupied' | 'capacity'>): string {
|
||||
@@ -135,7 +152,7 @@ export function spotsSentence(shift: Pick<PublicShift, 'occupied' | 'capacity'>)
|
||||
return `${filled}/${shift.capacity} spots filled`;
|
||||
}
|
||||
|
||||
function presentShift(row: ShiftRow, now: string): PublicShift {
|
||||
function presentShift(row: ShiftRow, now: string, volunteers: string[]): PublicShift {
|
||||
const start = formatInstantInZone(row.starts_at_utc, row.tz);
|
||||
const end = formatInstantInZone(row.ends_at_utc, row.tz);
|
||||
const occupied = Number(row.occupied);
|
||||
@@ -144,6 +161,8 @@ function presentShift(row: ShiftRow, now: string): PublicShift {
|
||||
const cancelled = row.cancelled === 1;
|
||||
const ended = row.ends_at_utc <= now;
|
||||
const inProgress = !cancelled && !ended && row.starts_at_utc <= now;
|
||||
const today = todayInZone(row.tz, Temporal.Instant.from(now));
|
||||
const tooEarly = !isWithinSignupWindow(start.date, today);
|
||||
return {
|
||||
id: row.id,
|
||||
role: row.role,
|
||||
@@ -156,6 +175,8 @@ function presentShift(row: ShiftRow, now: string): PublicShift {
|
||||
cancelled,
|
||||
ended,
|
||||
inProgress,
|
||||
tooEarly,
|
||||
volunteers,
|
||||
event: {
|
||||
id: row.event_id,
|
||||
slug: row.slug,
|
||||
@@ -172,6 +193,29 @@ function presentShift(row: ShiftRow, now: string): PublicShift {
|
||||
startLabel: start.timeLabel,
|
||||
endLabel: end.timeLabel,
|
||||
abbreviation: start.abbreviation,
|
||||
weekday: start.weekday,
|
||||
weekdayLabel: WEEKDAY_LABELS[start.weekday] ?? 'Day',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function volunteerNamesByShift(db: Database.Database, shiftIds: number[]): Map<number, string[]> {
|
||||
const names = new Map<number, string[]>();
|
||||
if (shiftIds.length === 0) return names;
|
||||
const marks = shiftIds.map(() => '?').join(', ');
|
||||
const rows = db
|
||||
.prepare(
|
||||
`SELECT shift_id AS shift_id, name AS name
|
||||
FROM signups
|
||||
WHERE status = 'confirmed' AND anonymized_at IS NULL AND name IS NOT NULL
|
||||
AND shift_id IN (${marks})
|
||||
ORDER BY name COLLATE NOCASE, id`,
|
||||
)
|
||||
.all(...shiftIds) as { shift_id: number; name: string }[];
|
||||
for (const row of rows) {
|
||||
const listed = names.get(row.shift_id);
|
||||
if (listed) listed.push(row.name);
|
||||
else names.set(row.shift_id, [row.name]);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
+6
-2
@@ -26,6 +26,7 @@ import {
|
||||
} from './pages.js';
|
||||
import { recordInvalidManageToken, recordSignupEmail, recordSignupIp, recordSwitchAttempt } from './rate-limit.js';
|
||||
import { getPublicShift, type PublicShift } from './schedule.js';
|
||||
import { SIGNUP_TOO_EARLY } from './signup-window.js';
|
||||
import { EMPTY_SIGNUP, parseSignupForm, type SignupErrors, type SignupValues } from './signup-form.js';
|
||||
import type { MailIdentity } from './mail/types.js';
|
||||
import { disableReminders } from './reminders.js';
|
||||
@@ -106,6 +107,7 @@ async function submitSignup(c: Context, services: SignupServices): Promise<Respo
|
||||
const now = services.now();
|
||||
const shift = loadShift(services, c.req.param('id') ?? '');
|
||||
if (!shift) return html(c, services, 'That page is not available · Hope Volunteer', <NotFoundPage />, 404);
|
||||
if (shift.tooEarly) return shiftResponse(c, services, shift, 400, null, SIGNUP_TOO_EARLY);
|
||||
const ip = clientAddress(config.trustProxy, peerAddress(c, services.clientIp), c.req.header('x-forwarded-for'));
|
||||
if (!originAllowed(c, config.baseUrl)) {
|
||||
return shiftResponse(c, services, shift, 403, formFor(services, shift, EMPTY_SIGNUP, {}, null), ORIGIN);
|
||||
@@ -168,6 +170,7 @@ async function submitSignup(c: Context, services: SignupServices): Promise<Respo
|
||||
if (reserved.ok) return redirectConfirmed(c, services, shift.id, reserved.manageToken ? { signupId: reserved.signupId, token: reserved.manageToken } : null);
|
||||
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 === '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 === 'duplicate') {
|
||||
return shiftResponse(c, services, shift, 409, formFor(services, shift, values, {}, null), ALREADY_SIGNED_UP);
|
||||
@@ -210,7 +213,7 @@ function shiftResponse(
|
||||
) {
|
||||
if (retryAfter !== undefined) c.header('Retry-After', String(retryAfter));
|
||||
const current = loadShift(services, String(shift.id)) ?? shift;
|
||||
const showForm = signup !== null && !current.cancelled && !current.ended && !current.full;
|
||||
const showForm = signup !== null && !current.cancelled && !current.ended && !current.full && !current.tooEarly;
|
||||
return html(
|
||||
c,
|
||||
services,
|
||||
@@ -222,7 +225,7 @@ function shiftResponse(
|
||||
}
|
||||
|
||||
function blankForm(services: SignupServices, shift: PublicShift): SignupFormView | null {
|
||||
if (shift.cancelled || shift.ended || shift.full) return null;
|
||||
if (shift.cancelled || shift.ended || shift.full || shift.tooEarly) return null;
|
||||
return formFor(services, shift, EMPTY_SIGNUP, {}, null);
|
||||
}
|
||||
|
||||
@@ -400,6 +403,7 @@ function switchForm(services: SignupServices, token: string, signup: { status: '
|
||||
if (signup.status !== 'confirmed') return null;
|
||||
const targets = listMoveTargets(services.db, signup.eventId, signup.shiftId, services.now(), {
|
||||
publishedOnly: true,
|
||||
signupWindow: true,
|
||||
});
|
||||
if (targets.length === 0) return { action: '', token: '', formToken: '', targets };
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Temporal } from '@js-temporal/polyfill';
|
||||
|
||||
/** How far ahead a volunteer can join a shift, counted from today in the event's time zone. */
|
||||
export const SIGNUP_WINDOW_MONTHS = 3;
|
||||
|
||||
export const SIGNUP_TOO_EARLY = 'Sign-up opens three months before this shift.';
|
||||
|
||||
const MONTHS = [
|
||||
'January',
|
||||
'February',
|
||||
'March',
|
||||
'April',
|
||||
'May',
|
||||
'June',
|
||||
'July',
|
||||
'August',
|
||||
'September',
|
||||
'October',
|
||||
'November',
|
||||
'December',
|
||||
] as const;
|
||||
|
||||
/** Last local date, inclusive, that is open for signup on `today`. */
|
||||
export function signupDeadline(today: string): string {
|
||||
return Temporal.PlainDate.from(today).add({ months: SIGNUP_WINDOW_MONTHS }).toString();
|
||||
}
|
||||
|
||||
export function isWithinSignupWindow(date: string, today: string): boolean {
|
||||
return date <= signupDeadline(today);
|
||||
}
|
||||
|
||||
export function signupDeadlineLabel(today: string): string {
|
||||
const date = Temporal.PlainDate.from(signupDeadline(today));
|
||||
const month = MONTHS[date.month - 1];
|
||||
if (!month) throw new Error(`${today} is not a date.`);
|
||||
return `${month} ${date.day}, ${date.year}`;
|
||||
}
|
||||
+8
-2
@@ -5,7 +5,8 @@ import { rememberSignupContact } from './contacts.js';
|
||||
import { normalizeEmail } from './email.js';
|
||||
import { queueCancellation, queueConfirmation, cancelPendingConfirmations, cancelPendingReminders } from './mail/queue.js';
|
||||
import type { MailIdentity } from './mail/types.js';
|
||||
import { formatInstantInZone, formatUtc, type ZonedClock } from './time.js';
|
||||
import { isWithinSignupWindow } from './signup-window.js';
|
||||
import { formatInstantInZone, formatUtc, todayInZone, type ZonedClock } from './time.js';
|
||||
|
||||
const MANAGE_TOKEN_TTL_HOURS = 24 * 7;
|
||||
|
||||
@@ -25,7 +26,7 @@ export type ReserveInput = {
|
||||
|
||||
export type ReserveResult =
|
||||
| { ok: true; signupId: number; manageToken: string | null; replay: boolean }
|
||||
| { ok: false; reason: 'not_found' | 'closed' | 'full' | 'duplicate' | 'conflict' };
|
||||
| { ok: false; reason: 'not_found' | 'closed' | 'early' | 'full' | 'duplicate' | 'conflict' };
|
||||
|
||||
export type ManageView = {
|
||||
signupId: number;
|
||||
@@ -167,6 +168,11 @@ function placeReservation(db: Database.Database, input: ReserveInput, emailNorm:
|
||||
const coordinator = input.audience === 'coordinator';
|
||||
if (!shift || (!coordinator && shift.published !== 1)) return { ok: false, reason: 'not_found' };
|
||||
if (shift.cancelled === 1 || shift.ends_at_utc <= input.now) return { ok: false, reason: 'closed' };
|
||||
if (!coordinator) {
|
||||
const start = formatInstantInZone(shift.starts_at_utc, shift.tz);
|
||||
const today = todayInZone(shift.tz, Temporal.Instant.from(input.now));
|
||||
if (!isWithinSignupWindow(start.date, today)) return { ok: false, reason: 'early' };
|
||||
}
|
||||
|
||||
const existing = findOperation(db, operationKey);
|
||||
if (existing) {
|
||||
|
||||
Reference in new issue
Block a user