import { Text } from '@react-email/text'; import { EMAIL_ACTION_LINK_COMPONENT, EMAIL_DATE_COMPONENT, EMAIL_LISTING_COMPONENT, EMAIL_USER_NAME_COMPONENT, } from '../extensions'; import type { ActionEmailData, ActionEmailTemplateProps, } from '../components/ActionEmailTemplate'; import { Button } from '../components/Button'; import { EmailContainer } from '../components/EmailContainer'; import { EmailHeading } from '../components/EmailHeading'; import { parseEmailHtml } from '../components/utils'; export const getDefaultOwnerStatementEmailData = ( mode: 'tag' | 'text', args: { appName: string; ownerStatementHref: string; listingName: string; userName: string; month: string; } ): ActionEmailData => { const ownerStatementHref = mode === 'tag' ? EMAIL_ACTION_LINK_COMPONENT : args.ownerStatementHref; const listingName = mode === 'tag' ? EMAIL_LISTING_COMPONENT : args.listingName; const month = mode === 'tag' ? EMAIL_DATE_COMPONENT : args.month; const userName = mode === 'tag' ? EMAIL_USER_NAME_COMPONENT : args.userName; // Owners open the statement by link without a login and viewers log in to // the owner portal, so the text names neither. Subject and preview text are // plain text without tokens, so a saved template must not keep the editor's // sample month and listing. return { subject: mode === 'tag' ? 'Your owner statement is ready' : `Your ${args.month} owner statement for ${args.listingName}`, shortDescription: mode === 'tag' ? 'Your owner statement is ready to view.' : `Your ${args.month} statement for ${args.listingName} is ready to view.`, header: 'Your owner statement is ready', bodyOne: `
Hi ${userName},
${args.appName} published your ${month} owner statement for ${listingName}. Open it with the button below.
`, buttonText: 'View statement', bodyTwo: `If the button doesn't work, copy this link into your browser: ${ownerStatementHref}
`, href: args.ownerStatementHref, }; }; /** * Subject and text of the emails about an owner payment, which a team's saved * statement template does not change: the receipt once Stripe has the money, * and the failed-payment email. */ export const getOwnerPaymentEmailData = ( kind: 'received' | 'failed', args: { appName: string; ownerStatementHref: string; listingName: string; userName: string; month: string; } ): ActionEmailData => ({ subject: kind === 'received' ? `Payment received for your ${args.month} statement for ${args.listingName}` : `Your payment for the ${args.month} statement for ${args.listingName} failed`, shortDescription: kind === 'received' ? `${args.appName} received your payment.` : 'Your bank did not complete your payment.', header: kind === 'received' ? 'Payment received' : 'Your payment failed', bodyOne: kind === 'received' ? `Hi ${args.userName},
${args.appName} received your payment for your ${args.month} owner statement for ${args.listingName}. Thank you.
` : `Hi ${args.userName},
Your bank did not complete your payment for your ${args.month} owner statement for ${args.listingName}. Pay again with the button below.
`, buttonText: 'View statement', bodyTwo: `If the button doesn't work, copy this link into your browser: ${args.ownerStatementHref}
`, href: args.ownerStatementHref, }); const mutedColor = '#737373'; const borderColor = '#e5e7eb'; const paymentColors = { due: { background: '#fef2f2', border: '#fecaca', text: '#991b1b' }, reserveTopUp: { background: '#eff6ff', border: '#bfdbfe', text: '#1e40af' }, failed: { background: '#fef2f2', border: '#fecaca', text: '#991b1b' }, received: { background: '#f0fdf4', border: '#bbf7d0', text: '#166534' }, }; export const OwnerStatementEmailTemplate = ({ data, tenant, themeColors, mode, user, listing, month, unsubscribeHref, renewHref, payment, yearEnd, }: ActionEmailTemplateProps & { /** Requests a new no-login link once the emailed one has expired. */ renewHref?: string; /** * A year-end statement: its eyebrow, the Fiscal year (`month`) and Listings * rows, and the link opening only the year-end statement. */ yearEnd?: { listings?: string }; /** * The owner payment block: what is due with the pay button, a reserve * top-up due when the balance end is not negative, a payment received, or a * payment that failed. */ payment?: { kind: 'due' | 'reserveTopUp' | 'received' | 'failed'; /** Formatted amount, such as `$1,284.50`. */ amount: string; /** Short lines under the amount, such as `Please pay by Oct 16, 2026`. */ details: string[]; /** Opens the payment page. */ payHref?: string; /** How the owner can pay on the payment page. */ methods?: ('ach' | 'card')[]; }; }) => { const parse = (html: string) => parseEmailHtml(html, { href: data.href, userName: user.firstName || '', date: month || '', listingName: listing || '', }); return (| {label} | {value} |