Files
NextChair/src/services/notifications/templates/shared.ts
T
2026-08-03 21:15:24 +01:00

38 lines
1.3 KiB
TypeScript

import { escapeHtml } from "./layout";
export interface BusinessEmailInfo {
name: string;
logoUrl?: string;
address?: string;
phone?: string;
cancellationPolicy?: string;
}
/** Absolute URL — email clients can't resolve a relative path, unlike a browser looking at the current origin. */
export function absoluteUrl(path: string): string {
const base = process.env.NEXT_PUBLIC_APP_URL ?? "http://localhost:3000";
return path.startsWith("http") ? path : `${base}${path.startsWith("/") ? "" : "/"}${path}`;
}
export function footerNoteHtml(business: BusinessEmailInfo): string | undefined {
const parts: string[] = [];
if (business.address) parts.push(business.address);
if (business.phone) parts.push(business.phone);
if (business.cancellationPolicy) parts.push(business.cancellationPolicy);
return parts.length > 0 ? parts.map((p) => `<span>${escapeHtml(p)}</span>`).join("<br/>") : undefined;
}
export function footerNoteText(business: BusinessEmailInfo): string | undefined {
const parts: string[] = [];
if (business.address) parts.push(business.address);
if (business.phone) parts.push(business.phone);
if (business.cancellationPolicy) parts.push(business.cancellationPolicy);
return parts.length > 0 ? parts.join("\n") : undefined;
}
export interface RenderedEmail {
subject: string;
html: string;
text: string;
}