60 lines
2.3 KiB
TypeScript
60 lines
2.3 KiB
TypeScript
'use server';
|
|
|
|
import { Resend } from 'resend';
|
|
|
|
const resend = new Resend(process.env.RESEND_API_KEY);
|
|
|
|
export async function submitAwariaForm(data: {
|
|
isUrgent: boolean;
|
|
brand: string;
|
|
model: string;
|
|
errorCode: string;
|
|
problemType: string;
|
|
description: string;
|
|
warranty: string;
|
|
lastService: string;
|
|
name: string;
|
|
phone: string;
|
|
city: string;
|
|
preferredDate: string;
|
|
preferredTime: string;
|
|
}) {
|
|
try {
|
|
await resend.emails.send({
|
|
from: process.env.RESEND_FROM_EMAIL || '[email protected]',
|
|
to: process.env.RESEND_TO_EMAIL || '[email protected]',
|
|
subject: `${data.isUrgent ? '🚨 PILNE — ' : ''}Zgłoszenie serwisowe: ${data.brand} — ${data.city}`,
|
|
html: `
|
|
<div style="font-family:Arial,sans-serif;max-width:600px;margin:0 auto;">
|
|
<div style="background:${data.isUrgent ? '#ef4444' : '#0F2A47'};padding:20px;text-align:center;">
|
|
<h1 style="color:#fff;margin:0;font-size:20px;">
|
|
${data.isUrgent ? '🚨 PILNE — ' : ''}Zgłoszenie serwisowe ThermCool
|
|
</h1>
|
|
</div>
|
|
<div style="padding:24px;">
|
|
<h2 style="font-size:16px;margin-top:0;">Dane klienta</h2>
|
|
<p><strong>Imię:</strong> ${data.name}</p>
|
|
<p><strong>Telefon:</strong> <a href="tel:${data.phone}">${data.phone}</a></p>
|
|
<p><strong>Miasto:</strong> ${data.city}</p>
|
|
${data.preferredDate ? `<p><strong>Preferowany termin:</strong> ${data.preferredDate} ${data.preferredTime || ''}</p>` : ''}
|
|
|
|
<h2 style="font-size:16px;">Urządzenie</h2>
|
|
<p><strong>Marka:</strong> ${data.brand}</p>
|
|
${data.model ? `<p><strong>Model:</strong> ${data.model}</p>` : ''}
|
|
${data.warranty ? `<p><strong>Gwarancja:</strong> ${data.warranty}</p>` : ''}
|
|
${data.lastService ? `<p><strong>Ostatni serwis:</strong> ${data.lastService}</p>` : ''}
|
|
|
|
<h2 style="font-size:16px;">Problem</h2>
|
|
<p><strong>Typ problemu:</strong> ${data.problemType}</p>
|
|
${data.errorCode ? `<p><strong>Kod błędu:</strong> ${data.errorCode}</p>` : ''}
|
|
${data.description ? `<p><strong>Opis:</strong> ${data.description}</p>` : ''}
|
|
</div>
|
|
</div>
|
|
`,
|
|
});
|
|
return { success: true };
|
|
} catch {
|
|
return { success: false };
|
|
}
|
|
}
|