import type { ReactNode } from "react"; import { Layout } from "../components/Layout.js"; import { Button, Footer, Heading, Paragraph, Spacer } from "../components/primitives.js"; export interface TrialReminderEmailCopy { readonly daySingular: string; readonly dayPlural: string; readonly fallbackRecipient: string; readonly preview: (productName: string, daysRemaining: number, dayWord: string) => string; readonly title: (daysRemaining: number, dayWord: string) => string; readonly footerReason: (productName: string) => ReactNode; readonly unsubscribe: string; readonly heading: (daysRemaining: number, dayWord: string) => ReactNode; readonly greeting: (recipientName: string) => ReactNode; readonly intro: (productName: string, daysRemaining: number, dayWord: string) => ReactNode; readonly defaultCta: string; readonly extensionPrompt: ReactNode; } export interface TrialReminderEmailProps { readonly recipientName?: string; readonly productName: string; readonly daysRemaining: number; readonly upgradeUrl: string; readonly unsubscribeUrl: string; readonly copy?: Partial; } const defaultCopy: TrialReminderEmailCopy = { daySingular: "day", dayPlural: "days", fallbackRecipient: "there", preview: (productName, daysRemaining, dayWord) => `Your ${productName} trial ends in ${daysRemaining} ${dayWord}`, title: (daysRemaining, dayWord) => `Trial reminder - ${daysRemaining} ${dayWord} left`, footerReason: (productName) => `Trial reminder from ${productName}.`, unsubscribe: "Unsubscribe", heading: (daysRemaining, dayWord) => `${daysRemaining} ${dayWord} left in your trial`, greeting: (recipientName) => `Hi ${recipientName},`, intro: (productName, daysRemaining, dayWord) => ( <> Your {productName} trial ends in {daysRemaining} {dayWord}. Upgrade now to keep your data, integrations and saved workflows. ), defaultCta: "Upgrade my plan", extensionPrompt: "Need more time? Reply to this email and we will extend your trial - no questions asked.", }; /** * "Trial Expiring" — triggered by `tenant.trial_expiring`. The * sequence schedules 3 steps (7d, 3d, 1d before expiry) with the same * template but different `daysRemaining` values. */ export function TrialReminderEmail({ recipientName, productName, daysRemaining, upgradeUrl, unsubscribeUrl, copy, }: TrialReminderEmailProps) { const resolvedCopy = { ...defaultCopy, ...copy }; const greetingTarget = recipientName?.trim() || resolvedCopy.fallbackRecipient; const dayWord = daysRemaining === 1 ? resolvedCopy.daySingular : resolvedCopy.dayPlural; return ( {resolvedCopy.footerReason(productName)}
{resolvedCopy.unsubscribe} } > {resolvedCopy.heading(daysRemaining, dayWord)} {resolvedCopy.greeting(greetingTarget)} {resolvedCopy.intro(productName, daysRemaining, dayWord)} {resolvedCopy.extensionPrompt}
); }