feat(email): mentor-onboarding email template + sender (§D)

One-shot email sent when a user is first granted the MENTOR role.
Subject: 'Welcome to MOPC mentoring'. Includes a CTA to /mentor and
a hint about the Switch View pill for multi-role users.

Idempotency lives at the call site (User.mentorOnboardingSentAt
checked in user.bulkUpdateRoles / user.updateRoles).

Plan: docs/superpowers/plans/2026-04-28-pr6-multi-role-and-workspace-previews.md
This commit is contained in:
Matt
2026-04-28 15:58:17 +02:00
parent 75c8829c3f
commit cedd188328

View File

@@ -2494,3 +2494,76 @@ export async function sendNotificationEmail(
const template = getNotificationEmailTemplate(name, subject, body, ensureAbsoluteUrl(linkUrl))
await sendEmail({ to: email, subject: template.subject, text: template.text, html: template.html })
}
// =============================================================================
// Mentor onboarding (one-shot, on first MENTOR role grant)
// =============================================================================
function getMentorOnboardingTemplate(name: string, baseUrl: string): EmailTemplate {
const mentorUrl = `${baseUrl.replace(/\/$/, '')}/mentor`
const subject = 'Welcome to MOPC mentoring'
const text = [
`Hi ${name || 'there'},`,
'',
'You have been added as a mentor for the Monaco Ocean Protection Challenge.',
'',
'As a mentor, you will:',
' • Be matched with one or more shortlisted projects',
' • Communicate with project teams in a private workspace',
' • Share files, comments, and milestone feedback',
' • Help projects sharpen their submissions before the live final',
'',
`Your mentor dashboard: ${mentorUrl}`,
'',
'If you also have other roles on the platform (e.g. juror), look for the',
'"Switch View" pill in the top-right of any page to move between dashboards.',
'',
'The MOPC team',
].join('\n')
const html = `
<!DOCTYPE html>
<html>
<body style="margin:0;padding:0;background:#f6f8fa;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif;color:#0f172a;">
<div style="max-width:560px;margin:32px auto;background:#fff;border-radius:8px;overflow:hidden;box-shadow:0 1px 3px rgba(0,0,0,0.06);">
<div style="background:#053d57;padding:24px 28px;color:#fefefe;">
<h1 style="margin:0;font-size:20px;font-weight:600;">Welcome to MOPC mentoring</h1>
</div>
<div style="padding:24px 28px;line-height:1.5;font-size:14px;">
<p style="margin-top:0;">Hi ${name || 'there'},</p>
<p>You have been added as a mentor for the Monaco Ocean Protection Challenge.</p>
<p>As a mentor, you will:</p>
<ul style="padding-left:20px;">
<li>Be matched with one or more shortlisted projects</li>
<li>Communicate with project teams in a private workspace</li>
<li>Share files, comments, and milestone feedback</li>
<li>Help projects sharpen their submissions before the live final</li>
</ul>
<p style="margin-top:24px;">
<a href="${mentorUrl}" style="display:inline-block;padding:10px 20px;background:#de0f1e;color:#fff;text-decoration:none;border-radius:6px;font-weight:600;">Open Mentor Dashboard</a>
</p>
<p style="margin-top:24px;color:#64748b;font-size:12px;">
If you also have other roles on the platform, use the "Switch View" pill in the top-right of any page to move between dashboards.
</p>
</div>
<div style="padding:16px 28px;background:#f1f5f9;color:#64748b;font-size:12px;text-align:center;">
Monaco Ocean Protection Challenge
</div>
</div>
</body>
</html>
`.trim()
return { subject, text, html }
}
/**
* Send mentor onboarding email. Idempotency is enforced at the call site
* (see user.bulkUpdateRoles / user.updateRoles) by checking
* User.mentorOnboardingSentAt.
*/
export async function sendMentorOnboardingEmail(email: string, name: string | null): Promise<void> {
const baseUrl = process.env.NEXTAUTH_URL || 'https://monaco-opc.com'
const template = getMentorOnboardingTemplate(name || '', baseUrl)
await sendEmail({ to: email, subject: template.subject, text: template.text, html: template.html })
}