Skip to content

Email themes UI fixes #768

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

Merged
merged 113 commits into from
Jul 18, 2025
Merged

Email themes UI fixes #768

merged 113 commits into from
Jul 18, 2025

Conversation

BilalG1
Copy link
Contributor

@BilalG1 BilalG1 commented Jul 15, 2025

https://www.loom.com/share/7947d3baf6664b298a5e04214b37c11e


Important

This PR updates email themes and templates, including UI enhancements, backend API routes, and database schema changes, to improve email customization capabilities.

  • Database Changes:
    • Remove role column from ThreadMessage table and drop ThreadMessageRole enum in migration.sql.
  • Backend API:
    • Add GET route in email-templates/route.tsx to fetch email templates.
    • Add GET, PATCH, and POST routes in email-themes/[id]/route.tsx and email-themes/chat/route.tsx for email theme management.
  • Dashboard UI:
    • Add new components in vibe-coding for email template and theme editing, including VibeCodeEditor, VibeAssistantChat, and VibePreviewPanel.
    • Update email-templates-new and email-themes pages to use new components for editing and previewing.
  • Schema and Config:
    • Update schema.prisma to remove ThreadMessageRole enum.
    • Add emailTemplateListSchema to schema-fields.ts for email template validation.
    • Update config/schema.ts to include templateList in email configuration.
  • Miscellaneous:
    • Add default email templates in helpers/emails.ts.
    • Update admin-interface.ts and admin-app-impl.ts to support new email template and theme functionalities.

This description was created by Ellipsis for 6fb7614. You can customize this summary. It will automatically update as commits are pushed.

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 significant changes to the email themes UI and its underlying architecture. The key changes include:

  1. Migration from role-based thread messages to a more flexible message format by removing the ThreadMessageRole enum and role column
  2. Implementing proper message persistence with new save/load functionality
  3. Improving the email theme preview system with better async handling and loading states
  4. Enhancing the UI with a new grid-based theme selection layout and improved navigation
  5. Adding support for raw HTML rendering in email previews
  6. Implementing proper chat message history and tool call handling

These changes collectively improve the email themes system's robustness and user experience, particularly around theme previews and AI assistant interactions.

Confidence score: 3 /5

  1. This PR is moderately safe to merge but requires careful testing of the chat and preview functionality
  2. The score is 3 because while most changes are well-structured, the removal of ThreadMessageRole is a breaking change that could affect existing data
  3. Files needing attention:
    • apps/backend/prisma/migrations/20250715181353_remove_msg_role/migration.sql (data loss risk)
    • apps/dashboard/src/app/(main)/(protected)/projects/[projectId]/email-templates/[type]/new/page.tsx (type safety issues)

18 files reviewed, 12 comments
Edit PR Review Bot Settings | Greptile

Copy link

recurseml bot commented Jul 15, 2025

✨ No issues found! Your code is sparkling clean! ✨

🗒️ View all ignored comments in this repo
  • The constraint 'TokenStoreType extends string' is too restrictive. It should likely be 'TokenStoreType extends string | object' to match the condition check in line 113 where TokenStoreType is checked against {}
  • Return type mismatch - the interface declares useUsers() returning ServerUser[] but the Team interface that this extends declares useUsers() returning TeamUser[]
  • There is a syntax error in the super constructor call due to the ellipsis operator used incorrectly. Objects aren't being merged correctly. This syntax usage can lead to runtime errors when trying to pass the merged object to 'super()'. Verify that the intended alterations to the object occur before or outside of the super() call if needed.
  • Throwing an error when no active span is found is too aggressive. The log function should gracefully fallback to console.log or another logging mechanism when there's no active span, since not all execution contexts will have an active span. This makes the code less resilient and could break functionality in non-traced environments.

📚 Relevant Docs

  • Function sets backendContext with a new configuration but doesn't pass 'defaultProjectKeys'. Since defaultProjectKeys is required in the type definition and cannot be updated (throws error if tried to set), this will cause a type error.
  • The schema is using array syntax for pick() which is incorrect for Yup schemas. The pick() method in Yup expects individual arguments, not an array. Should be changed to: emailConfigSchema.pick('type', 'host', 'port', 'username', 'sender_name', 'sender_email')

📚 Relevant Docs

  • Creating a refresh token with current timestamp as expiration means it expires immediately. Should set a future date for token expiration.
  • The 'tools' object is initialized as an empty object, even though 'tools' is presumably expected to contain tool definitions. This could cause the server capabilities to lack necessary tool configurations, thus potentially impacting functionalities that depend on certain tool setups.

📚 Relevant Docs

  • 'STACK_SECRET_SERVER_KEY' is potentially being included in every request header without checking its existence again here. Although it's checked during initialization, this could lead to security issues as it's exposed in all communications where the header is logged or captured.

📚 Relevant Docs

  • When adding 'use client' directive at the beginning, it doesn't check if file.text already contains the 'use client' directive. This could lead to duplicate 'use client' directives if the file already has one.

📚 Relevant Docs

⚠️ Only 5 files were analyzed due to processing limits.

Need help? Join our Discord for support!
https://discord.gg/qEjHQk64Z9

Base automatically changed from vibe-coding-themes to dev July 15, 2025 19:06
@BilalG1 BilalG1 assigned N2D4 and unassigned BilalG1 Jul 15, 2025
Copy link
Contributor

@N2D4 N2D4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing to add besides the AI changes!

@N2D4 N2D4 assigned BilalG1 and unassigned N2D4 Jul 16, 2025
N2D4 and others added 10 commits July 16, 2025 04:33
https://www.loom.com/share/b43b8fc7dfc947ab88d3cf709d2a167e?sid=d6e635ce-ab0f-4e86-887b-373632996cea
<!--

Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md

-->

<!-- ELLIPSIS_HIDDEN -->

----

> [!IMPORTANT]
> Refactor vibe coding components and add basic email template
configurations, including new components and schema updates.
> 
>   - **Email Templates**:
> - Adds `route.tsx` in `api/latest/internal/email-templates` to handle
GET requests for email templates.
> - Introduces `useNewEmailTemplates()` in `admin-app-impl.ts` to fetch
new email templates.
> - Adds `listInternalEmailTemplatesNew()` in `admin-interface.ts` to
list new email templates.
>   - **Components**:
> - Adds `VibeCodeEditor`, `VibePreviewPanel`, `VibeAssistantChat`, and
`VibeCodeEditorLayout` in `vibe-coding` for email template editing and
preview.
> - Refactors `page-client.tsx` in `email-templates-new` to use new
components for template editing.
> - Updates `page-client.tsx` in `email-themes` to use new vibe coding
components.
>   - **Schema and Config**:
> - Adds `emailTemplateListSchema` in `schema-fields.ts` for email
template validation.
>     - Updates `emails.ts` to include `DEFAULT_EMAIL_TEMPLATES`.
> - Modifies `schema.ts` to include `templateList` in email
configurations.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup>
for 18fdae9. You can
[customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>

<!-- ELLIPSIS_HIDDEN -->

---------

Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
BilalG1 and others added 4 commits July 18, 2025 09:56
https://www.loom.com/share/acaea08979274fc194357a5359f0938a?sid=6b5a2ac0-1f87-4311-8b40-0c2e22cd965d
<!--

Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md

-->

<!-- ELLIPSIS_HIDDEN -->


----

> [!IMPORTANT]
> This PR adds support for email templates, refactors chat handling, and
updates UI components for enhanced email and chat functionalities.
> 
>   - **Behavior**:
> - Adds support for rendering emails with either `theme_id` or
`template_id` in `render-email/route.tsx`.
> - Introduces `ai-chat/[threadId]/route.tsx` for handling chat messages
with context types `email-theme` and `email-template`.
> - Adds PATCH and GET routes for
`email-templates/[templateId]/route.tsx` to update and retrieve email
templates.
>   - **Adapters**:
> - Adds `emailTemplateAdapter` and `emailThemeAdapter` in
`adapter-registry.ts` for chat context handling.
> - Implements `renderEmailWithTemplate` in `email-themes.tsx` for
rendering emails with templates.
>   - **UI Components**:
> - Updates `page-client.tsx` for email templates and themes to use
`VibeCodeLayout` with `AssistantChat` and `CodeEditor`.
> - Adds `ThemePreview` component to handle email preview rendering with
error boundaries.
>   - **Misc**:
> - Renames `OPENAI_API_KEY` to `STACK_OPENAI_API_KEY` in
`.env.development`.
> - Refactors `chat-adapters.ts` to handle tool calls and chat message
history.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup>
for df210b8. You can
[customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this
summary. It will automatically update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->

---------

Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
@N2D4 N2D4 merged commit c5c67de into dev Jul 18, 2025
15 of 17 checks passed
@N2D4 N2D4 deleted the email-themes-ui-fixes branch July 18, 2025 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants