🌵 Added email_templates table to support welcome emails design customization#26949
🌵 Added email_templates table to support welcome emails design customization#26949
Conversation
Design for reusable email_templates table to persist email design settings across multiple email types (welcome emails, newsletters)
12-task plan covering: schema, migrations, model, API endpoint, routes, E2E tests, frontend hooks, and modal wiring
- Created email-templates.test.js with browse, read, and edit tests - Added email_template permissions to both production and test fixtures - Added EmailTemplate model seed to fixtures for default template
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
It looks like this PR contains a migration 👀 General requirements
Schema changes
Data changes
|
|
Decision: we're going to go with this approach. Closing this spike PR and starting work on implementing this option properly. |
Summary
Adds design customization persistence for welcome emails by introducing a new
email_templatestable with a foreign key fromautomated_emails. Design settings are stored once in a shared template row, avoiding duplication across free/paid welcome email rows.This is one of two spike branches exploring schema options. This branch takes the normalized approach: a dedicated
email_templatestable thatautomated_emailsreferences via FK.What changed
Database: New
email_templatestable + FKNew table —
email_templates(22 columns):id,name,slugtitle_font_category,title_font_weight,body_font_category,title_alignmentbackground_color,header_background_color,post_title_color,section_title_color,button_color,link_color,divider_colorbutton_style,button_corners,link_style,image_cornersheader_image,show_publication_title,show_badge,footer_contentcreated_at,updated_atModified table —
automated_emails:email_template_id→email_templates.idMigrations (4 files)
email_templatestableemail_template_idFK column toautomated_emailsemail_templateAPI: New
email_templatesendpointGET /email_templates/— browseGET /email_templates/:id— readPUT /email_templates/:id— editFrontend: Modal wired to API
The welcome email customize modal loads the first email template on open and saves design changes back to it.
Architecture
erDiagram email_templates { string id PK string name UK string slug UK string background_color string title_font_category string button_style boolean show_badge text footer_content string header_image } automated_emails { string id PK string email_template_id FK string status string subject text lexical } email_templates ||--o{ automated_emails : "has many"Data flow
sequenceDiagram participant Modal participant Browse as GET /email_templates/ participant Edit as PUT /email_templates/:id participant DB as email_templates table Modal->>Browse: Fetch all templates Browse-->>Modal: [{ id, background_color, ... }] Modal->>Modal: Initialize design state from template[0] Note over Modal: User edits design settings Modal->>Edit: { ...template, ...designSettings, ...generalSettings } Edit->>DB: UPDATE email_templates SET ... WHERE id = ? Edit-->>Modal: Updated template Modal->>Modal: Update query cache + close modalComparison with the other branch (#26948)
flowchart LR subgraph "This branch — Normalized" ET[email_templates] -->|FK| AE1[automated_emails<br/>free] ET -->|FK| AE2[automated_emails<br/>paid] end subgraph "#26948 — Denormalized" AE3[automated_emails<br/>free<br/>+ 18 design columns] AE4[automated_emails<br/>paid<br/>+ 18 design columns] endPUT /email_templates/:id(single edit)PUT /automated_emails/(bulk edit)Files changed
data/schema/schema.jsemail_templatestable + FK onautomated_emailsadd-email-templates-table.jsadd-email-template-id-to-automated-emails.jsadd-email-template-permissions.jsseed-default-email-template.jsmodels/email-template.jsmodels/automated-email.jsbelongsTorelationshipapi/endpoints/email-templates.jsapi/endpoints/index.jsweb/api/endpoints/admin/routes.jsfixtures.json(schema + test)admin-x-framework/.../email-templates.tsadmin-x-framework/.../automated-emails.tsemail_template_idto typewelcome-email-customize-modal.tsxmember-emails.tsxemail_template_idto default objectemail-templates.test.jsTest plan
email_template_id