/** * Email templates — unit E3 (ARCHITECTURE §6.3). * * Pure: no DB, no transport. Rendering happens at **enqueue** time * (`payload_json` is fully merged then, per §4), so what the outbox stores is * exactly what will be sent — auditable and replayable. * * Every interpolated value is HTML-escaped: names, role names and locations are * admin/volunteer-supplied data, and an email client will happily render * injected markup. */ /** Everything one assignment.published email needs, already resolved. */ export interface AssignmentEmailContext { volunteerFirstName: string; roleName: string; serviceName: string; /** e.g. "Sunday, Nov 22" in the church timezone. */ occursOnLabel: string; /** e.g. "9:00 AM". */ startTimeLabel: string; /** e.g. "8:15 AM" — null when the role has no call-time offset. */ callTimeLabel: string | null; location: string; confirmUrl: string; declineUrl: string; } export interface RenderedEmail { subject: string; html: string; text: string; } /** Escape text for safe interpolation into HTML. */ export function escapeHtml(value: string): string { return value .replaceAll("&", "&") .replaceAll("<", "<") .replaceAll(">", ">") .replaceAll('"', """) .replaceAll("'", "'"); } const CALL_TIME_UNSET = "Check the schedule for your call time"; /** The assignment.published email: role, date, call time, confirm/decline. */ export function renderAssignmentPublishedEmail( ctx: AssignmentEmailContext, ): RenderedEmail { return renderAssignmentEmail(ctx, `You're on ${ctx.roleName} — ${ctx.occursOnLabel}`); } /** A reminder for the same assignment (E7): same body, reminder subject. */ export function renderAssignmentReminderEmail( ctx: AssignmentEmailContext, ): RenderedEmail { return renderAssignmentEmail( ctx, `Reminder: ${ctx.roleName} on ${ctx.occursOnLabel}`, ); } export interface EventReminderContext { volunteerFirstName: string; /** "Photographer", "Second shooter" or "Editor". */ roleLabel: string; eventTitle: string; eventType: string; occursOnLabel: string; startTimeLabel: string; location: string; eventUrl: string; /** Days before the event the message is sent — "2" reads "in 2 days". */ leadDays: number; } /** The one-off event reminder (photo shoot): date, time, place, brief link. */ export function renderEventReminderEmail( ctx: EventReminderContext, ): RenderedEmail { const firstName = escapeHtml(ctx.volunteerFirstName); const roleLabel = escapeHtml(ctx.roleLabel); const title = escapeHtml(ctx.eventTitle); const type = escapeHtml(ctx.eventType); const occursOn = escapeHtml(ctx.occursOnLabel); const startTime = escapeHtml(ctx.startTimeLabel); const location = escapeHtml(ctx.location); const eventUrl = escapeHtml(ctx.eventUrl); const lead = ctx.leadDays === 0 ? "today" : ctx.leadDays === 1 ? "tomorrow" : `in ${ctx.leadDays} days`; const subject = `Reminder: ${ctx.eventTitle} — ${ctx.occursOnLabel}`; const html = `
${title} (${type})
${occursOn} at ${startTime}
${location}
You're on as ${roleLabel}.
Check the brief for what to capture and where to deliver the files. If you can no longer make it, tell the team as soon as you can so a replacement can be found.
Media Team Hub · Glenloch
`; const text = [ `${ctx.volunteerFirstName}, you're shooting ${ctx.eventTitle} ${lead}`, "", `${ctx.eventTitle} (${ctx.eventType})`, `${ctx.occursOnLabel} at ${ctx.startTimeLabel}`, ctx.location, `You're on as ${ctx.roleLabel}.`, "", `Brief: ${ctx.eventUrl}`, "", "If you can no longer make it, tell the team so a replacement can be found.", ].join("\n"); return { subject, html, text }; } function renderAssignmentEmail( ctx: AssignmentEmailContext, subject: string, ): RenderedEmail { const callTime = ctx.callTimeLabel ?? CALL_TIME_UNSET; const firstName = escapeHtml(ctx.volunteerFirstName); const roleName = escapeHtml(ctx.roleName); const serviceName = escapeHtml(ctx.serviceName); const occursOn = escapeHtml(ctx.occursOnLabel); const startTime = escapeHtml(ctx.startTimeLabel); const callTimeHtml = escapeHtml(callTime); const location = escapeHtml(ctx.location); const confirmUrl = escapeHtml(ctx.confirmUrl); const declineUrl = escapeHtml(ctx.declineUrl); const html = `
${serviceName}
${occursOn} at ${startTime}
Call time: ${callTimeHtml}
${location}
No login needed — the links above are single-use. If you can't serve, please decline so a coordinator can find cover.
Media Team Hub · Glenloch
`; const text = [ `${ctx.volunteerFirstName}, you're on ${ctx.roleName}`, "", ctx.serviceName, `${ctx.occursOnLabel} at ${ctx.startTimeLabel}`, `Call time: ${callTime}`, ctx.location, "", "Confirm: " + ctx.confirmUrl, "Can't make it: " + ctx.declineUrl, "", "No login needed — the links are single-use.", ].join("\n"); return { subject, html, text }; }