add new GDPR page and handle account creation email
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
// Code-specific email templates for successful access-code redemption.
|
||||
// Key = the raw access-code value a family enters (e.g. "copppermill03").
|
||||
// Add an entry here and its custom email is sent when that code is used.
|
||||
// If no entry matches, `defaultAccessEmailTemplate` is used.
|
||||
|
||||
export interface AccessEmailVars {
|
||||
famName: string;
|
||||
codeName: string;
|
||||
dashboardUrl: string;
|
||||
}
|
||||
|
||||
export interface AccessEmailTemplate {
|
||||
subject: (vars: AccessEmailVars) => string;
|
||||
html: (vars: AccessEmailVars) => string;
|
||||
}
|
||||
|
||||
const DEFAULT_TEMPLATE: AccessEmailTemplate = {
|
||||
subject: ({ famName }) => `Your ${famName} access is unlocked`,
|
||||
html: ({ famName, codeName, dashboardUrl }) => `
|
||||
<p>Hi${famName ? ` ${famName}` : ' there'}! 🎉</p>
|
||||
<p>Your access code (<strong>${codeName}</strong>) has been applied successfully.</p>
|
||||
<p>Your <strong>${famName}</strong> family on <strong>FamDone</strong> is now unlocked.</p>
|
||||
<p><a href="${dashboardUrl}">Open your family dashboard</a> to add kids, set up chores, and get going.</p>
|
||||
<p>If you have any questions, just reply to this email.</p>
|
||||
<p>Talk soon,<br />The FamDone team</p>
|
||||
`
|
||||
};
|
||||
|
||||
export const accessEmailTemplates: Record<string, AccessEmailTemplate> = {
|
||||
copppermill03: {
|
||||
subject: ({ famName }) => `Save a spot for ${famName} — access unlocked`,
|
||||
html: ({ famName, codeName, dashboardUrl }) => `
|
||||
<p>Hi${famName ? ` ${famName}` : ' there'}! 🎉</p>
|
||||
<p>Your access code (<strong>${codeName}</strong>) has been applied successfully.</p>
|
||||
<p>Your <strong>${famName}</strong> family on <strong>FamDone</strong> is now unlocked.</p>
|
||||
<p><a href="${dashboardUrl}">Open your family dashboard</a> to add kids, set up chores, and get going.</p>
|
||||
<p>If you have any questions, just reply to this email.</p>
|
||||
<p>Talk soon,<br />The FamDone team</p>
|
||||
`
|
||||
}
|
||||
};
|
||||
|
||||
// Resolve the template for a redeemed code, falling back to the default.
|
||||
export function getAccessEmailTemplate(codeValue: string): AccessEmailTemplate {
|
||||
return accessEmailTemplates[codeValue] || DEFAULT_TEMPLATE;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Resend } from 'resend';
|
||||
import { RESEND_API } from '$app/env/private';
|
||||
import { getAccessEmailTemplate } from './email-templates';
|
||||
|
||||
const resend = new Resend(String(RESEND_API));
|
||||
|
||||
@@ -43,3 +44,53 @@ export async function sendParentInviteEmail(opts: {
|
||||
`
|
||||
});
|
||||
}
|
||||
|
||||
export async function sendAccessUnlockedEmail(opts: {
|
||||
to: string;
|
||||
famName: string;
|
||||
codeName: string;
|
||||
codeValue: string;
|
||||
dashboardUrl: string;
|
||||
}) {
|
||||
const { to, famName, codeName, codeValue, dashboardUrl } = opts;
|
||||
|
||||
const template = getAccessEmailTemplate(codeValue);
|
||||
const vars = { famName, codeName, dashboardUrl };
|
||||
|
||||
await resend.emails.send({
|
||||
from: 'no-reply@famchamp.ai',
|
||||
to,
|
||||
subject: template.subject(vars),
|
||||
html: template.html(vars)
|
||||
});
|
||||
}
|
||||
|
||||
export async function sendWelcomeEmail(opts: {
|
||||
to: string;
|
||||
famName: string;
|
||||
dashboardUrl: string;
|
||||
}) {
|
||||
const { to, famName, dashboardUrl } = opts;
|
||||
|
||||
await resend.emails.send({
|
||||
from: 'no-reply@famchamp.ai',
|
||||
to,
|
||||
subject: `Welcome to FamDone${famName ? `, ${famName}` : ''}!`,
|
||||
html: `
|
||||
<p>Hi${famName ? ` ${famName}` : ' there'}! 👋</p>
|
||||
<p>Welcome to <strong>FamDone</strong> — your family chore and pocket-money app.</p>
|
||||
<p>Your family is all set up. Here's how to get going:</p>
|
||||
<ul>
|
||||
<li>Open your <a href="${dashboardUrl}">family dashboard</a>.</li>
|
||||
<li>Add your kids and create join codes from <strong>Family Settings</strong>.</li>
|
||||
<li>Set up chores, rewards, and allowances.</li>
|
||||
</ul>
|
||||
<p>
|
||||
If you haven't already, you can pick a plan and pay from your dashboard to
|
||||
unlock your family.
|
||||
</p>
|
||||
<p>If you have any questions, just reply to this email — we're happy to help.</p>
|
||||
<p>Talk soon,<br />The FamDone team</p>
|
||||
`
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user