Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | 28x 28x 4x 4x 1x 1x 1x 1x 1x 1x 3x 3x 2x 2x 2x 2x 2x 2x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 3x 3x 3x 1x | // Email template renderer — central switch that maps a `template` string to
// one of the React-Email components in `apps/api/src/emails/`. Extracted from
// email.ts so the dispatcher and createEmailService can evolve independently.
import { render } from "@react-email/render";
import {
BlogApprovalReminderEmail,
type BlogApprovalReminderEmailProps,
} from "../emails/blog-approval-reminder";
import {
BlogApprovalRequestEmail,
type BlogApprovalRequestEmailProps,
} from "../emails/blog-approval-request";
import {
BlogPublishedEmail,
type BlogPublishedEmailProps,
} from "../emails/blog-published";
import { EmailVerificationEmail } from "../emails/email-verification";
import {
EmailVerifiedEmail,
type EmailVerifiedProps,
} from "../emails/email-verified";
import { MagicLinkEmail } from "../emails/magic-link";
import {
NewInquiryEmail,
type NewInquiryEmailProps,
} from "../emails/new-inquiry";
import { PasswordResetEmail } from "../emails/password-reset";
import {
ProAccountStatusEmail,
type ProAccountStatusProps,
} from "../emails/pro-account-status";
import {
ReminderDueEmail,
type ReminderDueEmailProps,
} from "../emails/reminder-due";
import {
TeamInvitationEmail,
type TeamInvitationEmailProps,
} from "../emails/team-invitation";
import {
WebsiteBuildResultEmail,
type WebsiteBuildResultProps,
} from "../emails/website-build-result";
import {
ImportResultEmail,
type ImportResultProps,
} from "../emails/import-result";
import { WelcomeEmail } from "../emails/welcome";
import { escapeHtml } from "./html-escape";
export type RenderedEmailMessage = {
subject: string;
html: string;
};
export async function renderEmailTemplate(params: {
template: string;
props: Record<string, unknown>;
recipientName?: string;
}): Promise<RenderedEmailMessage> {
const { template, props, recipientName } = params;
switch (template) {
case "new-inquiry": {
const html = await render(
NewInquiryEmail({
...(props as Omit<NewInquiryEmailProps, "proName" | "portalUrl">),
proName: recipientName ?? "",
}),
);
return {
subject: `New inquiry from ${escapeHtml(String(props.customerName ?? ""))}`,
html,
};
}
case "password-reset": {
const html = await render(
PasswordResetEmail({
resetLink: props.resetLink as string,
userName: props.userName as string | undefined,
}),
);
return { subject: "Reset your Interioring password", html };
}
case "email-verification": {
const html = await render(
EmailVerificationEmail({
verificationLink: props.verificationLink as string,
userName: props.userName as string | undefined,
}),
);
return { subject: "Verify your Interioring email", html };
}
case "welcome": {
const html = await render(
WelcomeEmail({
userName: props.userName as string,
loginUrl: props.loginUrl as string | undefined,
}),
);
return { subject: "Welcome to Interioring!", html };
}
case "team-invitation": {
const html = await render(TeamInvitationEmail(props as TeamInvitationEmailProps));
return {
subject: `You've been invited to join ${escapeHtml(String(props.proName ?? ""))} on Interioring`,
html,
};
}
case "blog-approval-request": {
const html = await render(
BlogApprovalRequestEmail(props as BlogApprovalRequestEmailProps),
);
return {
subject: `Review Required: ${String(props.blogTitle ?? "")}`,
html,
};
}
case "blog-approval-reminder": {
const html = await render(
BlogApprovalReminderEmail(props as BlogApprovalReminderEmailProps),
);
return {
subject: `Reminder: Blog approval needed - ${String(props.blogTitle ?? "")}`,
html,
};
}
case "blog-published": {
const html = await render(
BlogPublishedEmail({
...(props as Omit<BlogPublishedEmailProps, "proName">),
proName: recipientName ?? "",
}),
);
return {
subject: `Your blog is live: ${String(props.blogTitle ?? "")}`,
html,
};
}
case "email-verified": {
const html = await render(EmailVerifiedEmail(props as EmailVerifiedProps));
return { subject: "Email Verified — You're In!", html };
}
case "pro-account-status": {
const typedProps = props as Omit<ProAccountStatusProps, "proName"> & {
status: ProAccountStatusProps["status"];
};
const html = await render(
ProAccountStatusEmail({
...typedProps,
proName: recipientName ?? "",
}),
);
const subject =
typedProps.status === "published"
? `${typedProps.businessName} is now live on Interioring!`
: "Your Interioring account has been archived";
return { subject, html };
}
case "website-build-result": {
const typedProps = props as Omit<WebsiteBuildResultProps, "proName">;
const html = await render(
WebsiteBuildResultEmail({
...typedProps,
proName: recipientName ?? "",
}),
);
const subject = typedProps.success
? `Your website for ${typedProps.businessName} is live!`
: `Website build failed for ${typedProps.businessName}`;
return { subject, html };
}
case "import-result": {
const typedProps = props as Omit<ImportResultProps, "adminName">;
const html = await render(
ImportResultEmail({
...typedProps,
adminName: recipientName ?? "admin",
}),
);
const statusLabel =
typedProps.status === "completed"
? "ready for review"
: typedProps.status === "failed"
? "failed"
: "cancelled";
const subject = `Pro import for ${typedProps.proName} ${statusLabel}`;
return { subject, html };
}
case "reminder-due": {
const html = await render(ReminderDueEmail(props as ReminderDueEmailProps));
return {
subject: `Reminder due: ${String(props.reminderTitle ?? "")}`,
html,
};
}
case "magic-link": {
const html = await render(
MagicLinkEmail(props as { magicLinkUrl: string }),
);
return { subject: "Sign in to Interioring", html };
}
case "email-otp": {
const greeting = props.userName
? `Hi ${escapeHtml(String(props.userName))},`
: "Hi,";
const html = `
<div style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 480px; margin: 0 auto; padding: 24px;">
<p style="margin: 0 0 16px; color: #333;">${greeting}</p>
<p style="margin: 0 0 16px; color: #333;">Your verification code is:</p>
<div style="background: #f4f4f5; border-radius: 8px; padding: 20px; text-align: center; margin: 0 0 16px;">
<span style="font-size: 32px; font-weight: 700; letter-spacing: 6px; color: #111;">${String(props.code ?? "")}</span>
</div>
<p style="margin: 0 0 16px; color: #666; font-size: 14px;">This code expires in 5 minutes.</p>
<p style="margin: 0; color: #666; font-size: 14px;">If you didn't request this, you can safely ignore this email.</p>
<hr style="border: none; border-top: 1px solid #eee; margin: 24px 0;" />
<p style="margin: 0; color: #999; font-size: 12px;">Interioring — Interior Design Marketplace</p>
</div>
`;
return {
subject: "Your Interioring verification code",
html,
};
}
default:
throw new Error(`Unknown email template: ${template}`);
}
}
|