Compare commits
2 Commits
4d21581c97
...
ca0a4c6968
| Author | SHA1 | Date |
|---|---|---|
|
|
ca0a4c6968 | |
|
|
2daea21ef4 |
|
|
@ -115,7 +115,7 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
|
|||
|
||||
// Fetch sender's expanded details for the email
|
||||
const [senderDetails] = await pool.query<RowDataPacket[]>(
|
||||
`SELECT full_name, email, mobile, personnummer FROM users WHERE id = ?`,
|
||||
`SELECT full_name, email, mobile, personnummer, address, zip_code, city FROM users WHERE id = ?`,
|
||||
[user.userId]
|
||||
);
|
||||
const sender = senderDetails[0];
|
||||
|
|
@ -144,9 +144,13 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
|
|||
process.env.SMTP_FROM || 'info@nordicstorium.se',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
content,
|
||||
`${process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'}/messages`,
|
||||
'Se konversation'
|
||||
'Se konversation',
|
||||
false // Admin is sender, not customer
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -160,9 +164,13 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
|
|||
sender.email,
|
||||
sender.mobile,
|
||||
sender.personnummer,
|
||||
sender.address,
|
||||
sender.zip_code,
|
||||
sender.city,
|
||||
content,
|
||||
`${process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'}/admin/messages`,
|
||||
'Svara i Adminpanelen'
|
||||
'Svara i Adminpanelen',
|
||||
true // Customer is sender
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -248,16 +256,28 @@ export async function PATCH(request: NextRequest, { params }: RouteParams) {
|
|||
);
|
||||
|
||||
// Send resolution email to customer
|
||||
const resolveContent = `
|
||||
<div style="font-family: 'Inter', -apple-system, sans-serif; max-width: 600px; margin: 40px auto; border: 1px solid #000000; color: #000000; background: #ffffff; overflow: hidden;">
|
||||
<div style="background: linear-gradient(135deg, #0a192f 0%, #020c1b 100%); padding: 40px; text-align: center; border-bottom: 1px solid #000000;">
|
||||
<h1 style="font-size: 16px; font-weight: 900; text-transform: uppercase; letter-spacing: 4px; margin: 0; color: #ffffff;">Nordic Storium</h1>
|
||||
</div>
|
||||
<div style="padding: 50px 40px;">
|
||||
<h2 style="font-size: 16px; font-weight: 800; text-transform: uppercase; margin-bottom: 25px; letter-spacing: 1px;">Ärende Avslutat</h2>
|
||||
<p style="font-size: 14px; line-height: 1.7; color: #444444; margin-bottom: 20px;">Hej ${conversation.user_name || 'kund'},</p>
|
||||
<p style="font-size: 14px; line-height: 1.7; color: #444444; margin-bottom: 20px;">Vi har markerat ditt ärende "<strong>${conversation.subject}</strong>" som löst.</p>
|
||||
<p style="font-size: 14px; line-height: 1.7; color: #444444; margin-bottom: 30px;">Om du fortfarande har frågor eller känner att ärendet inte är helt löst, tveka inte att kontakta oss igen.</p>
|
||||
<a href="${process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'}/messages" 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;">Öppna Mina Meddelanden</a>
|
||||
<p style="font-size: 14px; line-height: 1.7; color: #666666; margin-top: 30px;">Med vänliga hälsningar,<br><strong>Nordic Storium Support</strong></p>
|
||||
</div>
|
||||
<div style="background: linear-gradient(135deg, #0a192f 0%, #020c1b 100%); padding: 40px; border-top: 1px solid #000000; text-align: center;">
|
||||
<div style="font-size: 10px; color: #ffffff; text-transform: uppercase; letter-spacing: 2px; font-weight: 900;">© ${new Date().getFullYear()} Nordic Storium — Stockholm, Sweden.</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
await sendEmail(
|
||||
conversation.user_email,
|
||||
`Ärende löst: ${conversation.subject}`,
|
||||
`
|
||||
<h2>Ditt ärende har markerats som löst</h2>
|
||||
<p>Hej ${conversation.user_name || 'kund'},</p>
|
||||
<p>Vi har markerat ditt ärende "<strong>${conversation.subject}</strong>" som löst.</p>
|
||||
<p>Om du fortfarande har frågor eller känner att ärendet inte är helt löst, tveka inte att kontakta oss igen.</p>
|
||||
<p>Med vänliga hälsningar,<br/>Nordic Storium Support</p>
|
||||
`
|
||||
resolveContent
|
||||
);
|
||||
|
||||
return NextResponse.json({ success: true, message: 'Conversation resolved' });
|
||||
|
|
|
|||
|
|
@ -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 på knappen ovan för att svara direkt i portalen.
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue