From 0c99da2eeb5d4425b868f542acde3831c0ea9828 Mon Sep 17 00:00:00 2001 From: DanielS Date: Thu, 27 Aug 2026 00:32:18 +0200 Subject: [PATCH] feat(email): add primaryColor branding param to email templates --- shop/app/api/admin/send-test-email/route.ts | 15 ++++++++++++++- shop/app/api/orders/checkout/route.ts | 5 ++++- shop/lib/actions/email-templates.ts | 13 +++++++------ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/shop/app/api/admin/send-test-email/route.ts b/shop/app/api/admin/send-test-email/route.ts index f7a5fe8..943fbd2 100644 --- a/shop/app/api/admin/send-test-email/route.ts +++ b/shop/app/api/admin/send-test-email/route.ts @@ -43,7 +43,20 @@ export async function POST(request: Request) { const { to, subject, text, html } = await request.json(); try { - const info = await sendMail({ to, subject, text, html }); + const { data: brandData } = await supabase.from('settings').select('primary_color').eq('id', 'branding').maybeSingle(); + const primaryColor = brandData?.primary_color || '#2563eb'; + + const testHtml = html || ` +
+

Test-E-Mail

+

${text || 'Dies ist eine automatische Test-E-Mail.'}

+
+ SMTP-Konfiguration & Branding-Farbe erfolgreich verifiziert. +
+
+ `; + + const info = await sendMail({ to, subject, text, html: testHtml }); return NextResponse.json({ message: 'Email sent', info }); } catch (err) { console.error('Mail error', err); diff --git a/shop/app/api/orders/checkout/route.ts b/shop/app/api/orders/checkout/route.ts index 43b5edb..7e5333d 100644 --- a/shop/app/api/orders/checkout/route.ts +++ b/shop/app/api/orders/checkout/route.ts @@ -295,6 +295,9 @@ export async function POST(request: Request) { const itemsSection = buildEmailItemsSection(items); + const { data: brandData } = await supabase.from('settings').select('primary_color').eq('id', 'branding').maybeSingle(); + const primaryColor = brandData?.primary_color || '#2563eb'; + const emailTemplate = getOrderEmailTemplate({ orderNumber: order.order_number, formattedDate, @@ -303,7 +306,7 @@ export async function POST(request: Request) { totalDetailsHtml, itemsDetailsText: itemsSection.text, itemsDetailsHtml: itemsSection.html - }, `${process.env.NEXT_PUBLIC_SITE_URL || 'https://staging.hephex.de'}`, false); + }, `${process.env.NEXT_PUBLIC_SITE_URL || 'https://staging.hephex.de'}`, false, primaryColor); const { data: bufferData, error: downloadError } = await supabase .storage diff --git a/shop/lib/actions/email-templates.ts b/shop/lib/actions/email-templates.ts index cab0262..9ffb238 100644 --- a/shop/lib/actions/email-templates.ts +++ b/shop/lib/actions/email-templates.ts @@ -14,7 +14,8 @@ interface EmailDetails { export function getOrderEmailTemplate( details: EmailDetails, siteUrl: string, - isUpdate: boolean = false + isUpdate: boolean = false, + primaryColor: string = '#2563eb' ) { const title = isUpdate ? 'Anfrage geändert' : 'Anfrage erhalten' const intro = isUpdate @@ -65,7 +66,7 @@ export function getOrderEmailTemplate( const html = `
-

${title}

+

${title}

Hallo,

${intro}

@@ -90,7 +91,7 @@ export function getOrderEmailTemplate(

Die Bestätigung liegt als PDF im Anhang.

- Anfragebestätigung PDF herunterladen + Anfragebestätigung PDF herunterladen

Viele Grüße,
Dein CASPOS Team

@@ -99,12 +100,12 @@ export function getOrderEmailTemplate( return { text, html } } -export function getStatusEmailTemplate(orderNumber: string, oldLabel: string, newLabel: string) { +export function getStatusEmailTemplate(orderNumber: string, oldLabel: string, newLabel: string, primaryColor: string = '#2563eb') { const text = `Hallo,\n\nder Status deiner Anfrage ${orderNumber} hat sich geändert.\n\nStatus: ${newLabel} (vorher: ${oldLabel})\n\nViele Grüße,\nDein CASPOS Team` const html = `
-

Statusänderung

+

Statusänderung

Hallo,

der Status deiner Anfrage ${orderNumber} wurde aktualisiert.

@@ -119,7 +120,7 @@ export function getStatusEmailTemplate(orderNumber: string, oldLabel: string, ne Aktuell: - ${newLabel} + ${newLabel}