From 04b28e762005dafc74096f34f504bb67ca9fc1b7 Mon Sep 17 00:00:00 2001 From: Vadym Samoilenko Date: Wed, 3 Jun 2026 16:26:56 +0100 Subject: [PATCH] feat(email): Ukrainian source labels, full lead details in email (guests, date, message) --- src/app/api/leads/route.ts | 4 ++ src/emails/LeadAlert.tsx | 119 +++++++++++++++++++++++++++++-------- src/lib/resend.ts | 20 ++++++- 3 files changed, 116 insertions(+), 27 deletions(-) diff --git a/src/app/api/leads/route.ts b/src/app/api/leads/route.ts index ad31f62..04d6214 100644 --- a/src/app/api/leads/route.ts +++ b/src/app/api/leads/route.ts @@ -86,6 +86,10 @@ export async function POST(req: NextRequest): Promise { phone: data.phone, email: data.email, formSource: data.formSource, + groupSize: data.groupSize, + preferredDate: data.preferredDate, + message: data.message, + packageSlug: data.packageSlug, utmSource: data.utmSource, } diff --git a/src/emails/LeadAlert.tsx b/src/emails/LeadAlert.tsx index f051bc6..0b20a0f 100644 --- a/src/emails/LeadAlert.tsx +++ b/src/emails/LeadAlert.tsx @@ -3,6 +3,7 @@ import { Container, Head, Heading, + Hr, Html, Preview, Section, @@ -14,54 +15,120 @@ interface LeadAlertEmailProps { phone: string email?: string formSource: string + formSourceLabel: string + groupSize?: number + preferredDate?: string + message?: string + packageSlug?: string utmSource?: string submittedAt: string } +function Row({ label, value, bold }: { label: string; value: string; bold?: boolean }) { + return ( + + {label}:  + {value} + + ) +} + export function LeadAlertEmail({ name, phone, email, - formSource, + formSourceLabel, + groupSize, + preferredDate, + message, + packageSlug, utmSource, submittedAt, }: LeadAlertEmailProps) { + const hasDetails = groupSize ?? preferredDate ?? packageSlug ?? message + return ( - Новий лід: {name} - + + {formSourceLabel}: {name} — {phone} + + - Новий лід з сайту Shumiland -
- - Ім'я: {name} - - - Телефон: {phone} - - {email && ( - - Email: {email} + {/* Header */} +
+ + 🌿 Нова заявка — {formSourceLabel} + +
+ + {/* Contact */} +
+ + Контактні дані + + + + {email ? : null} +
+ + {/* Details */} + {hasDetails ? ( + <> +
+
+ + Деталі заявки + + {groupSize ? : null} + {preferredDate ? : null} + {packageSlug ? : null} + {message ? : null} +
+ + ) : null} + + {/* Footer */} +
+
+ {utmSource ? ( + + Джерело трафіку: {utmSource} - )} - - Форма: {formSource} + ) : null} + + Отримано: {submittedAt} - {utmSource && ( - - UTM Source: {utmSource} - - )} - Отримано: {submittedAt}
diff --git a/src/lib/resend.ts b/src/lib/resend.ts index bba5b53..b0b4f02 100644 --- a/src/lib/resend.ts +++ b/src/lib/resend.ts @@ -12,11 +12,26 @@ function getResend() { const FROM = process.env['RESEND_FROM'] ?? 'noreply@shumiland.ua' const MANAGER_EMAILS = (process.env['MANAGER_EMAILS'] ?? '').split(',').filter(Boolean) +const SOURCE_LABELS: Record = { + 'birthday-booking': 'Дні народження', + 'group-request': 'Групові відвідування', + 'ticket-purchase': 'Купівля квитків', + general: 'Загальна заявка', +} + +function sourceLabel(formSource: string): string { + return SOURCE_LABELS[formSource] ?? formSource +} + export type LeadAlertData = { name: string phone: string email?: string formSource: string + groupSize?: number + preferredDate?: string + message?: string + packageSlug?: string utmSource?: string } @@ -26,9 +41,12 @@ export async function sendLeadAlert(lead: LeadAlertData): Promise { return } + const label = sourceLabel(lead.formSource) + const html = await render( LeadAlertEmail({ ...lead, + formSourceLabel: label, submittedAt: new Date().toLocaleString('uk-UA', { timeZone: 'Europe/Kyiv' }), }) ) @@ -43,7 +61,7 @@ export async function sendLeadAlert(lead: LeadAlertData): Promise { await resend.emails.send({ from: FROM, to: MANAGER_EMAILS, - subject: `Новий лід: ${lead.name} (${lead.formSource})`, + subject: `Нова заявка — ${label}: ${lead.name} (${lead.phone})`, html, }) } catch (err) {