fix chat email message

This commit is contained in:
ismail 2026-02-02 20:13:45 +01:00
parent 4d21581c97
commit 2daea21ef4
1 changed files with 52 additions and 14 deletions

View File

@ -179,36 +179,74 @@ export const sendMessageNotification = async (
senderEmail: string,
senderPhone: string | null,
senderPersonnummer: string | null,
senderAddress: string | null,
senderZipCode: string | null,
senderCity: string | null,
messageContent: string,
actionLink: string,
actionText: string
actionText: string,
isCustomerSender: boolean = true
) => {
// Determine labels and values even if null to show clarity
// Format display values with fallbacks
const phoneDisplay = senderPhone || 'Ej angivet';
const personnummerDisplay = senderPersonnummer || 'Ej angivet';
const addressDisplay = senderAddress || 'Ej angivet';
const zipCodeDisplay = senderZipCode || '';
const cityDisplay = senderCity || '';
const fullAddressDisplay = [addressDisplay, zipCodeDisplay, cityDisplay].filter(Boolean).join(', ');
const content = `
<h2 style="font-size: 16px; font-weight: 800; text-transform: uppercase; margin-bottom: 20px; letter-spacing: 1px;">Nytt Meddelande</h2>
// Build customer details section only if sender is a customer
const customerDetailsSection = isCustomerSender ? `
<div style="background: #f7fafc; padding: 25px; border-left: 4px solid #000000; margin-bottom: 30px;">
<h3 style="font-size: 12px; font-weight: 800; text-transform: uppercase; margin: 0 0 20px 0; letter-spacing: 2px; color: #666666;">Avsändarinformation</h3>
<table style="width: 100%; font-size: 14px; border-collapse: collapse;">
<tr>
<td style="padding: 8px 0; width: 140px; font-weight: 700; color: #333333;">Namn:</td>
<td style="padding: 8px 0; color: #000000;">${senderName}</td>
</tr>
<tr>
<td style="padding: 8px 0; font-weight: 700; color: #333333;">E-post:</td>
<td style="padding: 8px 0;"><a href="mailto:${senderEmail}" style="color: #000000; text-decoration: underline;">${senderEmail}</a></td>
</tr>
<tr>
<td style="padding: 8px 0; font-weight: 700; color: #333333;">Telefon:</td>
<td style="padding: 8px 0; color: #000000;">${phoneDisplay}</td>
</tr>
<tr>
<td style="padding: 8px 0; font-weight: 700; color: #333333;">Personnummer:</td>
<td style="padding: 8px 0; color: #000000;">${personnummerDisplay}</td>
</tr>
<tr>
<td style="padding: 8px 0; font-weight: 700; color: #333333;">Adress:</td>
<td style="padding: 8px 0; color: #000000;">${fullAddressDisplay}</td>
</tr>
</table>
</div>
` : `
<div style="background: #f7fafc; padding: 20px; border-left: 4px solid #000000; margin-bottom: 30px;">
<p style="font-size: 14px; margin: 0 0 10px 0;"><strong>Från:</strong> ${senderName}</p>
<p style="font-size: 14px; margin: 0 0 10px 0;"><strong>Email:</strong> <a href="mailto:${senderEmail}" style="color: #000000;">${senderEmail}</a></p>
<p style="font-size: 14px; margin: 0 0 10px 0;"><strong>Telefon:</strong> ${phoneDisplay}</p>
<p style="font-size: 14px; margin: 0;"><strong>Personnummer:</strong> ${personnummerDisplay}</p>
<p style="font-size: 14px; margin: 0;"><strong>Email:</strong> <a href="mailto:${senderEmail}" style="color: #000000;">${senderEmail}</a></p>
</div>
`;
const content = `
<h2 style="font-size: 16px; font-weight: 800; text-transform: uppercase; margin-bottom: 25px; letter-spacing: 1px;">Nytt Meddelande</h2>
<div style="background: #ffffff; padding: 20px; border: 1px solid #e2e8f0; margin-bottom: 30px;">
<h3 style="font-size: 14px; font-weight: 700; text-transform: uppercase; margin: 0 0 15px 0; letter-spacing: 1px;">Meddelande:</h3>
<blockquote style="font-size: 14px; line-height: 1.7; color: #444444; margin: 0; padding-left: 10px; border-left: 3px solid #e2e8f0;">
${messageContent}
</blockquote>
${customerDetailsSection}
<div style="background: #ffffff; padding: 25px; border: 1px solid #e2e8f0; margin-bottom: 30px;">
<h3 style="font-size: 12px; font-weight: 800; text-transform: uppercase; margin: 0 0 15px 0; letter-spacing: 2px; color: #666666;">Meddelande</h3>
<div style="font-size: 14px; line-height: 1.8; color: #333333; padding: 15px; background: #fafafa; border-radius: 4px;">
${messageContent.replace(/\n/g, '<br>')}
</div>
</div>
<a href="${actionLink}" style="display: block; background: #000000; color: #ffffff; text-align: center; padding: 16px; text-decoration: none; font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; border-radius: 4px;">
<a href="${actionLink}" style="display: block; background: #000000; color: #ffffff; text-align: center; padding: 18px; text-decoration: none; font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 2px; border-radius: 4px;">
${actionText}
</a>
<div style="margin-top: 30px; padding-top: 20px; border-top: 1px solid #e2e8f0;">
<p style="font-size: 12px; color: #999999;">
<p style="font-size: 12px; color: #999999; text-align: center;">
Klicka knappen ovan för att svara direkt i portalen.
</p>
</div>