Skip to content

[Core]: Fix EmailTemplateType enum — document types, not field types #667

Open

Description

@nielsdrost7

Modules/Core/Enums/EmailTemplateType.php currently declares TEXT/NUMBER/DATE/BOOLEAN with labels like "Single Line Text" and "Date Picker" — custom-field types pasted into the email-template enum. The intended domain (//'invoice', 'quote', 'payment', 'reminder') survives only as a comment. Every consumer that must filter templates by document type (#164 quote templates, #400 auto-send, #480 reminders, status-aware selection) is blocked; today InvoiceService::resolveEmailDefaults() works around it by matching on the magic title invoice_sent.

v1 spec: email_template_type column with values invoice/quote, filtered in application/modules/mailer/controllers/Mailer.php:83,141.

Specific

  • Enum cases become INVOICE='invoice', QUOTE='quote', PAYMENT='payment', REMINDER='reminder' with sensible labels/colors.
  • Data migration maps existing rows: seeded titles invoice_sent→invoice, quote_sent→quote, payment_received→payment, user_invitation→ nullable/system (decide: add SYSTEM case or leave type nullable).
  • EmailTemplateForm type select and EmailTemplatesTable badge use the new cases.
  • InvoiceService::resolveEmailDefaults() filters type = INVOICE (keeping title fallback for back-compat this release).

Measurable

No code path references TEXT/NUMBER/DATE/BOOLEAN on email templates; template pickers list only same-type templates.

Achievable

Enum + migration + two Filament touch points + one service filter; EmailTemplateFactory/seeder updated in the same PR (factory-schema contract).

Relevant

Prerequisite for the entire typed-template roadmap (#164, #400, #480, #235/#239/#230).

Time-Bound

Small; schedule before #164.

Arrange

Seeded templates for one company; an invoice for that company.

Act

Run migration; open EmailTemplateForm; call resolveEmailDefaults().

Assert

  • email_templates.type values are in invoice|quote|payment|reminder (or null) after migration
  • Type select shows the four document types
  • resolveEmailDefaults() picks the invoice-typed template without relying on the title
  • EmailTemplateFactory produces valid typed rows (suite green)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refinedRefined with SMART plan / test suggestions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions