86 lines
3.4 KiB
TypeScript
86 lines
3.4 KiB
TypeScript
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<TrialReminderEmailCopy>;
|
|
}
|
|
|
|
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 <strong>{daysRemaining} {dayWord}</strong>.
|
|
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 (
|
|
<Layout
|
|
previewText={resolvedCopy.preview(productName, daysRemaining, dayWord)}
|
|
title={resolvedCopy.title(daysRemaining, dayWord)}
|
|
footer={
|
|
<Footer>
|
|
{resolvedCopy.footerReason(productName)}<br />
|
|
<a href={unsubscribeUrl}>{resolvedCopy.unsubscribe}</a>
|
|
</Footer>
|
|
}
|
|
>
|
|
<Heading level={1}>{resolvedCopy.heading(daysRemaining, dayWord)}</Heading>
|
|
<Paragraph>{resolvedCopy.greeting(greetingTarget)}</Paragraph>
|
|
<Paragraph>{resolvedCopy.intro(productName, daysRemaining, dayWord)}</Paragraph>
|
|
<Spacer size="md" />
|
|
<Button href={upgradeUrl}>{resolvedCopy.defaultCta}</Button>
|
|
<Spacer size="md" />
|
|
<Paragraph>{resolvedCopy.extensionPrompt}</Paragraph>
|
|
</Layout>
|
|
);
|
|
}
|