-
Notifications
You must be signed in to change notification settings - Fork 428
Sending new email templates bg #779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: template-migrations-bg
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Summary
This PR implements a significant overhaul of the email template system with several key architectural improvements:
- Introduces a new Result-based pattern for email rendering that provides better type safety and error handling
- Implements proper theme support with light/dark variants and tenancy-aware theme selection
- Moves template IDs into named constants and exports a DEFAULT_TEMPLATE_IDS mapping
- Restructures how email templates are rendered by separating theme and template concerns
- Updates OTP email format to use a more structured JSON-like format
The changes create a more maintainable and robust email system while improving type safety throughout the codebase. The separation of themes from templates and the introduction of proper Result types shows good architectural thinking.
Confidence score: 4/5
- This PR is safe to merge with careful testing of email template rendering
- High confidence due to comprehensive test updates and consistent error handling patterns, but email rendering changes need thorough verification
- Key files needing attention:
- apps/backend/src/lib/email-templates.tsx
- apps/backend/src/lib/emails.tsx
- E2E tests for email rendering
12 files reviewed, 1 comment
Edit PR Review Bot Settings | Greptile
@@ -318,22 +321,30 @@ export async function sendEmailFromTemplate(options: { | |||
extraVariables: Record<string, string | null>, | |||
version?: 1 | 2, | |||
}) { | |||
const template = await getEmailTemplateWithDefault(options.tenancy.project.id, options.templateType, options.version); | |||
|
|||
const template = getNewEmailTemplate(options.tenancy, options.templateType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: getNewEmailTemplate is used but version param is still accepted. Consider removing unused version param if it's no longer needed.
@@ -118,7 +118,7 @@ export const POST = createSmartRouteHandler({ | |||
activeTheme.tsxSource, | |||
unsubscribeLink || undefined | |||
); | |||
if ("error" in renderedEmail) { | |||
if (renderedEmail.status === "error") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect error checking pattern. The renderEmailWithTheme function returns a Result type where errors are detected using 'error in renderedEmail'. The new code checks for a non-existent 'status' property, which will fail to catch errors and lead to runtime errors when trying to access .data on error cases. Should keep the original 'if ("error" in renderedEmail)' check.
if (renderedEmail.status === "error") { | |
if ("error" in renderedEmail) { |
React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)
@@ -129,8 +129,8 @@ export const POST = createSmartRouteHandler({ | |||
emailConfig, | |||
to: primaryEmail, | |||
subject: body.subject, | |||
html: renderedEmail.html, | |||
text: renderedEmail.text, | |||
html: renderedEmail.data.html, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid property access. The renderEmailWithTheme function returns success results in the format { html: string, text: string } directly, not nested under a 'data' property. This will cause undefined errors when trying to access renderedEmail.data.html. Should use renderedEmail.html directly as in the original code.
html: renderedEmail.data.html, | |
html: renderedEmail.html, |
React with 👍 to tell me that this comment was useful, or 👎 if not (and I'll stop posting more comments like this in the future)
😱 Found 2 issues. Time to roll up your sleeves! 😱 🗒️ View all ignored comments in this repo
Need help? Join our Discord for support! |
Important
Refactor email system to use new templates and themes, updating rendering, error handling, and tests.
renderEmailWithTemplate
inemail-templates.tsx
for rendering emails with templates and themes.renderEmailWithTheme
inemail-themes.tsx
to returnResult
objects.result.status === "error"
inroute.tsx
files.getNewEmailTemplate
andgetActiveEmailTheme
functions for fetching templates and themes.renderEmailWithTemplate
fromemail-themes.tsx
toemail-templates.tsx
.DEFAULT_EMAIL_TEMPLATES
andDEFAULT_EMAIL_THEMES
inemails.ts
andemails.tsx
.result.status
checks inroute.tsx
files._sendEmailWithoutRetries
inemails.tsx
.send-sign-in-code.test.ts
andsign-in.test.ts
to match new email format.This description was created by
for 8831ddd. You can customize this summary. It will automatically update as commits are pushed.