fix chat notification
This commit is contained in:
parent
36b95da09d
commit
22f2a41c89
|
|
@ -48,7 +48,7 @@
|
|||
"react": "19.1.0",
|
||||
"react-dom": "19.1.0",
|
||||
"react-icons": "^5.5.0",
|
||||
"sharp": "^0.34.5",
|
||||
"sharp": "^0.34.3",
|
||||
"tailwind-merge": "^3.3.1",
|
||||
"zod": "^4.3.6"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -150,34 +150,20 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
|
|||
);
|
||||
}
|
||||
} else {
|
||||
// Customer replying to admins
|
||||
const [admins] = await pool.query<RowDataPacket[]>(
|
||||
`SELECT id, email FROM users WHERE role = 'admin'`
|
||||
// Customer replying - send ONE email to CONTACT_EMAIL
|
||||
const adminEmail = process.env.CONTACT_EMAIL || 'info@nordicstorium.se';
|
||||
|
||||
await sendMessageNotification(
|
||||
adminEmail,
|
||||
`Nytt kundmeddelande: ${conversation.subject}`,
|
||||
sender.full_name,
|
||||
sender.email,
|
||||
sender.mobile,
|
||||
sender.personnummer,
|
||||
content,
|
||||
`${process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'}/admin/messages`,
|
||||
'Svara i Adminpanelen'
|
||||
);
|
||||
|
||||
for (const admin of admins) {
|
||||
const [sessions] = await pool.query<RowDataPacket[]>(
|
||||
`SELECT COUNT(*) as count FROM user_sessions
|
||||
WHERE user_id = ? AND expires_at > NOW()`,
|
||||
[admin.id]
|
||||
);
|
||||
|
||||
const isAdminOnline = sessions[0].count > 0;
|
||||
|
||||
if (!isAdminOnline) {
|
||||
await sendMessageNotification(
|
||||
admin.email,
|
||||
`Nytt meddelande: ${conversation.subject}`,
|
||||
sender.full_name,
|
||||
sender.email,
|
||||
sender.mobile,
|
||||
sender.personnummer,
|
||||
content,
|
||||
`${process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'}/admin/messages`,
|
||||
'Svara i Adminpanelen'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
|
|
|
|||
Loading…
Reference in New Issue