feat: email notifications via Resend on new incident

This commit is contained in:
2026-07-10 13:24:44 +08:00
parent 3f8da5bd91
commit 2239b6e2df
6 changed files with 254 additions and 38 deletions
@@ -0,0 +1,45 @@
export function newIncidentTemplate(params: {
reference_no: string
incident_type: string
site_name: string
reporter_name: string
reported_at: string
site_url: string
incident_id: string
}): { subject: string; html: string; text: string } {
const typeLabel = params.incident_type.replace(/_/g, ' ')
const subject = `[IMS] New incident ${params.reference_no}${typeLabel} at ${params.site_name}`
const link = `${params.site_url}/hse/incidents/${params.incident_id}`
const text = `
New incident report received.
Reference: ${params.reference_no}
Type: ${typeLabel}
Site: ${params.site_name}
Reported by: ${params.reporter_name}
Time: ${params.reported_at}
View incident: ${link}
`.trim()
const html = `
<div style="font-family:sans-serif;max-width:600px;margin:0 auto">
<h2 style="color:#1e293b">New Incident Report</h2>
<table style="border-collapse:collapse;width:100%">
<tr><td style="padding:6px 0;color:#64748b">Reference</td><td style="padding:6px 0;font-weight:600">${params.reference_no}</td></tr>
<tr><td style="padding:6px 0;color:#64748b">Type</td><td style="padding:6px 0">${typeLabel}</td></tr>
<tr><td style="padding:6px 0;color:#64748b">Site</td><td style="padding:6px 0">${params.site_name}</td></tr>
<tr><td style="padding:6px 0;color:#64748b">Reported by</td><td style="padding:6px 0">${params.reporter_name}</td></tr>
<tr><td style="padding:6px 0;color:#64748b">Time</td><td style="padding:6px 0">${params.reported_at}</td></tr>
</table>
<p style="margin-top:20px">
<a href="${link}" style="background:#2563eb;color:#fff;padding:10px 18px;text-decoration:none;border-radius:6px;display:inline-block">
View Incident
</a>
</p>
</div>
`.trim()
return { subject, html, text }
}