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 type { SignupErrors, SignupValues } from './signup-form.js'; import type { MoveTarget } from './admin/store.js'; import type { ManageView } from './signup.js'; import { appPath } from './url.js'; const PANTRY_SITE = 'https://hopefoodpantrysc.org'; function asset(config: AppConfig, file: string): string { return appPath(config, file); } export function Layout(props: { config: AppConfig; title: string; path?: string; turnstile?: boolean; account?: { csrf: string } | null; children?: Child; }) { const home = appPath(props.config, '/'); const privacy = appPath(props.config, '/privacy'); const coordinator = appPath(props.config, props.account ? '/admin' : '/login'); 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 (
No upcoming shifts are posted.
> ); } export function EventPage(props: { config: AppConfig; event: PublicEvent; now: string; month?: string; path?: string }) { const description = props.event.description.trim(); return ( <>{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.
) : ({props.shift.event.location}
: null}{description}
: null} {props.notice ? ({props.notice}
) : null} {props.signup ?{props.cancelled ? `${props.name ? `${props.name} is no longer signed up for ` : 'This signup is no longer for '}${props.shift.role}.` : `${props.name ? `${props.name} is signed up for ` : 'This signup is for '}${props.shift.role}.`}
{props.cancelled ? 'A cancellation email is queued. This link still opens the cancelled signup.' : 'A confirmation email is queued. Save this link too, in case the email is delayed. It opens this signup, where you can cancel it or switch it to another open shift.'}
> ) : (If you just signed up, the link stays in this browser for a few minutes. A confirmation email is queued.
)} > ); } 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 ( <>{signup.status === 'confirmed' ? 'Confirmed' : 'Cancelled'}
{signup.eventTitle}
{signup.when.timeLabel} {signup.when.abbreviation}
{signup.location ?{signup.location}
: null}{props.note}
: null} {props.notice ? ({props.notice}
) : null} {props.switches ? ( props.switches.targets.length === 0 ? (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}This signup is cancelled. The spot is open for someone else. A cancellation email is queued.
)}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 ( <>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 ( <>{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 ( <>The link may be out of date, or the shift is not posted.
> ); } export function ProblemPage() { return ( <>The page could not be loaded. Try again in a little while.
> ); } export function WaitPage() { return ( <>Too many attempts. Please wait and try again.
> ); } function monthHref(config: AppConfig, path: string, monthId: string): string { return `${appPath(config, path)}?month=${monthId}`; } 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 MapNo shifts this month.
}
{props.day.weekday} {props.day.day}
{' to '} {shift.when.sameDay ? null : ( )} {shift.when.abbreviation}
); } function Spots(props: { shift: PublicShift }) { return{spotsSentence(props.shift)}
; } function SignupForm(props: { config: AppConfig; shiftId: 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 ( ); } function Field(props: { id: string; label: string; name: string; type: 'text' | 'email' | 'tel'; value: string; error?: string; autoComplete: string; hint?: string; }) { const errorId = `${props.id}-error`; const hintId = `${props.id}-hint`; const describedBy = [props.hint ? hintId : '', props.error ? errorId : ''].filter(Boolean).join(' ') || undefined; return ( ); } function StatusLine(props: { shift: PublicShift }) { if (props.shift.cancelled) returnCancelled. This shift is closed.
; if (props.shift.ended) returnEnded. This shift is closed.
; return ( <> {props.shift.inProgress ?In progress
: null}