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 { WEDNESDAY, spotsSentence, type PublicEvent, type PublicShift } from './schedule.js';
import { SIGNUP_TOO_EARLY, signupDeadlineLabel } from './signup-window.js';
import { partyChoiceLabel, partyChoices, type SignupErrors, type 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 { assetHref } from './static-assets.js';
import { appPath } from './url.js';
const PANTRY_SITE = 'https://hopefoodpantrysc.org';
function asset(config: AppConfig, file: string): string {
return assetHref(config, file);
}
function pathIs(path: string | undefined, target: string): boolean {
if (!path) return false;
return path === target || path.startsWith(`${target}/`);
}
export function Layout(props: {
config: AppConfig;
title: string;
path?: string;
turnstile?: boolean;
account?: { csrf: string } | null;
children?: Child;
}) {
const home = appPath(props.config, '/');
const coordinator = appPath(props.config, props.account ? '/admin' : '/login');
const coordinatorHere = pathIs(props.path, coordinator);
const volunteeringCurrent = props.path === home ? 'page' : undefined;
const logo = asset(props.config, '/img/logo.png');
const menu = asset(props.config, '/img/icons/menu.svg');
const close = asset(props.config, '/img/icons/close.svg');
const facebook = asset(props.config, '/img/icons/facebook.svg');
const instagram = asset(props.config, '/img/icons/instagram.svg');
const wave = asset(props.config, '/img/wave-secondary.svg');
return (
{props.title}
Skip to content
{props.children}
{props.turnstile ? : null}
);
}
export function EmptySchedulePage() {
return (
<>
Weekly pantry
No upcoming shifts are posted.
>
);
}
export function EventPage(props: {
config: AppConfig;
event: PublicEvent;
now: string;
month?: string;
view?: string;
path?: string;
}) {
const description = props.event.description.trim();
return (
<>
{props.event.title}
{props.event.location ? {props.event.location}
: null}
{props.event.slug === 'weekly-pantry' ? null : Times are shown in {props.event.timeZone}.
}
{description ? {description}
: null}
{props.event.shifts.length === 0 ? (
No upcoming shifts are posted for this event.
) : (
)}
>
);
}
export type SignupFormView = {
token: string;
siteKey: string;
values: SignupValues;
errors: SignupErrors;
};
export function ShiftPage(props: {
config: AppConfig;
shift: PublicShift;
signup?: SignupFormView | null;
notice?: string;
}) {
const description = props.shift.event.description.trim();
return (
<>
{props.shift.role}
{props.shift.event.location ? {props.shift.event.location}
: null}
{description ? {description}
: null}
{props.notice ? (
{props.notice}
) : null}
{props.signup ? (
) : null}
>
);
}
export function ConfirmationPage(props: {
config: AppConfig;
shift: PublicShift;
name: string | null;
managePath: string | null;
groupSize?: number;
cancelled?: boolean;
}) {
const shift = props.shift;
const cancelled = Boolean(props.cancelled);
const summary = cancelled
? `${props.name ? `${props.name} is no longer on the ` : 'This signup is no longer for the '}${shift.role} shift.`
: `${props.name ? `${props.name} is on the ` : 'This signup is for the '}${shift.role} shift.`;
const note = props.managePath
? cancelled
? '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.'
: 'If you just signed up, the link stays in this browser for a few minutes. A confirmation email is on the way.';
const location = shift.event.location.trim();
return (
Shift information
{shift.role}
{shift.when.dateLabel}
{shift.when.startLabel}
{' to '}
{shift.when.sameDay ? null : {shift.when.endDateLabel} }
{shift.when.endLabel} {shift.when.abbreviation}
{location ?
{location}
: null}
{note}
{props.managePath ? (
{`${props.config.baseUrl}${props.managePath}`}
) : null}
);
}
export type SwitchForm = {
action: string;
token: string;
formToken: string;
targets: MoveTarget[];
};
export function ManagePage(props: {
signup: ManageView;
cancel: { action: string; token: string } | null;
switches: SwitchForm | null;
reminders?: { action: string; token: string } | 'off' | null;
notice?: string;
note?: string;
}) {
const signup = props.signup;
return (
<>
Your signup
{signup.status === 'confirmed' ? 'Confirmed' : 'Cancelled'}
{signup.eventTitle}
{signup.role}
{signup.when.dateLabel} {signup.when.timeLabel} {signup.when.abbreviation}
{signup.location ? {signup.location}
: null}
Name
{signup.name}
People
{signup.groupSize}
Email
{signup.email}
{signup.phone ? (
Phone
{signup.phone}
) : null}
{signup.notes ? (
Notes
{signup.notes}
) : null}
{props.note ? {props.note}
: null}
{props.notice ? (
{props.notice}
) : null}
{props.switches ? (
props.switches.targets.length === 0 ? (
{signup.groupSize > 1
? 'There is no other open shift with room for everyone on this signup.'
: 'There is no other open shift you can switch to.'}
) : (
)
) : null}
{props.reminders === 'off' ? (
Reminder emails for this signup are off. The signup stays. Confirmation, change, and cancellation emails still arrive.
) : null}
{props.reminders && props.reminders !== 'off' ? (
) : null}
{props.cancel ? (
) : (
{signup.groupSize > 1
? `This signup is cancelled. The ${signup.groupSize} spots it held are open for someone else. A cancellation email is queued.`
: 'This signup is cancelled. The spot is open for someone else. A cancellation email is queued.'}
)}
>
);
}
// TODO(D3): The pantry still has to approve this wording, including retention and copies.
// A blank setting keeps the unapproved message. Saved wording is shown as written, escaped, and is not a policy by itself.
export function PrivacyPage(props: { paragraphs: string[] }) {
return (
<>
Privacy
{props.paragraphs.length === 0 ? (
<>
Hope Volunteer does not have an approved privacy notice yet.
When the pantry approves the wording, it will appear on this page. This page is not a privacy policy.
>
) : (
props.paragraphs.map((paragraph, index) => {paragraph}
)
)}
>
);
}
export function SwitchAlreadyPage() {
return (
<>
Your signup
This signup was already switched. Use the link in the email.
>
);
}
export function ReminderOffPage(props: { config: AppConfig; token: string; replyTo: string; off: boolean; error?: string }) {
return (
<>
Reminder emails
{props.error ? (
{props.error}
) : null}
{props.off ? (
Reminder emails for this signup are off. The signup stays. Confirmation, change, and cancellation emails still arrive.
) : (
)}
>
);
}
export function NotFoundPage() {
return (
<>
That page is not available
The link may be out of date, or the shift is not posted.
>
);
}
export function ProblemPage() {
return (
<>
Something went wrong
The page could not be loaded. Try again in a little while.
>
);
}
export function WaitPage() {
return (
<>
Please wait
Too many attempts. Please wait and try again.
>
);
}
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 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 (
{signupWindowSentence(props.event.timeZone, props.now)}
{calendarView ? (
) : (
)}
);
}
function SignupDialog(props: { config: AppConfig }) {
return (
<>
>
);
}
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 No Wednesday shifts are posted. The calendar lists shifts on other days.
;
}
return (
{days.map((day) => (
Wednesday
{day.heading}
{day.date === today ? Today : null}
{day.shifts.map((shift) => (
))}
))}
);
}
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 (
{shift.role}
{shift.inProgress ?
In progress
: null}
Volunteers
{shift.full ? (
Full
Not accepting more signups
) : (
{action}
)}
);
}
function MonthArrow(props: { config: AppConfig; path: string; monthId: string; direction: 'prev' | 'next' }) {
const next = props.direction === 'next';
return (
{next ? 'Next month' : 'Previous month'}
);
}
function ShiftCalendar(props: {
config: AppConfig;
event: PublicEvent;
now: string;
month?: string;
path: string;
}) {
const today = calendarToday(props.event.timeZone, props.now);
const dates = props.event.shifts.map((shift) => shift.when.date);
const monthId = chooseCalendarMonth(props.month, dates, today);
const month = calendarMonth(monthId);
const step = monthStep(monthId, dates);
const shiftsByDate = new Map();
for (const shift of props.event.shifts) {
if (shift.when.date.slice(0, 7) !== month.id) continue;
const listed = shiftsByDate.get(shift.when.date);
if (listed) listed.push(shift);
else shiftsByDate.set(shift.when.date, [shift]);
}
const titleId = `month-${props.event.id}-${month.id}`;
const shiftsThisMonth = [...shiftsByDate.values()].some((listed) => listed.length > 0);
return (
{step.previous ? (
) : (
)}
{month.label}
{step.next ? (
) : (
)}
{WEEKDAY_SHORT.map((weekday) => (
{weekday}
))}
{month.weeks.map((week) => {
const weekStart = week[0];
if (!weekStart) return null;
return (
{week.map((day) => (
))}
);
})}
{shiftsThisMonth ? null : No shifts this month.
}
);
}
function CalendarDayCell(props: { config: AppConfig; day: CalendarDay; today: string; weekName: string; shifts: PublicShift[] }) {
if (!props.day.inMonth) return ;
const today = props.day.date === props.today;
const className = ['cal-day', today ? 'is-today' : '', props.day.date < props.today ? 'is-past' : '', props.shifts.length > 0 ? 'has-shifts' : 'is-empty']
.filter(Boolean)
.join(' ');
return (
{today ? (
Today
) : null}
{props.shifts.length > 0 ? (
{today ? (
Today
) : null}
Show shifts
) : null}
{props.shifts.length > 0 ? (
{props.day.weekday} {props.day.day}
) : null}
);
}
function DayStamp(props: { day: CalendarDay; today: boolean }) {
return (
{props.today ? `Today, ${props.day.label}` : props.day.label}
{props.day.weekday}
{props.day.day}
);
}
function ShiftList(props: { config: AppConfig; shifts: PublicShift[]; className: string }) {
return (
{props.shifts.map((shift) => (
))}
);
}
function CalendarShift(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 (
{shift.when.startLabel} {shift.role}
{'. '}
{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.'}
{shift.role}
{shift.when.startLabel}
{' to '}
{shift.when.sameDay ? null : {shift.when.endDateLabel} }
{shift.when.endLabel} {shift.when.abbreviation}
{shift.inProgress ? In progress : null}
{shift.volunteers.length > 0 ? shift.volunteers.join(', ') : 'No one signed up yet.'}
{action}
);
}
function RosterNames(props: { config: AppConfig; shiftId: number; names: string[] }) {
if (props.names.length === 0) {
return No one signed up yet.
;
}
return (
{props.names.map((name, index) => (
{name}
))}
);
}
function ShiftWhen(props: { shift: PublicShift }) {
const shift = props.shift;
return (
{shift.when.startLabel}
{' to '}
{shift.when.sameDay ? null : (
{shift.when.endDateLabel}
)}
{shift.when.endLabel} {shift.when.abbreviation}
);
}
function Spots(props: { shift: PublicShift }) {
return {spotsSentence(props.shift)}
;
}
function SignupForm(props: { config: AppConfig; shiftId: number; remaining: number; form: SignupFormView }) {
const form = props.form;
const errors = form.errors;
const errorEntries = Object.entries(errors).filter((entry): entry is [string, string] => Boolean(entry[1]));
return (
);
}
export function PartySizeField(props: { idPrefix: string; value: string; error?: string; remaining: number }) {
const id = `${props.idPrefix}-partySize`;
const hintId = `${id}-hint`;
const errorId = `${id}-error`;
return (
How many people?
{partyChoices(props.remaining).map((count) => (
{partyChoiceLabel(count)}
))}
Including you. This signup holds that many spots. You don't need to add their names.
{props.error ? (
{props.error}
) : null}
);
}
function Field(props: {
id: string;
label: string;
name: string;
type: 'text' | 'email' | 'tel';
value: string;
error?: string;
autoComplete: string;
hint?: string;
required?: boolean;
}) {
const errorId = `${props.id}-error`;
const hintId = `${props.id}-hint`;
const describedBy = [props.hint ? hintId : '', props.error ? errorId : ''].filter(Boolean).join(' ') || undefined;
return (
{props.label}
{props.hint ? (
{props.hint}
) : null}
{props.error ? (
{props.error}
) : null}
);
}
function StatusLine(props: { shift: PublicShift }) {
if (props.shift.cancelled) return Cancelled. This shift is closed.
;
if (props.shift.ended) return Ended. This shift is closed.
;
if (props.shift.tooEarly) {
return (
<>
{SIGNUP_TOO_EARLY}
>
);
}
return (
<>
{props.shift.inProgress ? In progress
: null}
>
);
}