diff --git a/src/lib/email.ts b/src/lib/email.ts index 718b3ba..ea0abc8 100644 --- a/src/lib/email.ts +++ b/src/lib/email.ts @@ -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 = ` + + +
+ + + + `.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