68 lines
2.4 KiB
TypeScript
68 lines
2.4 KiB
TypeScript
type InvitationEmailInput = {
|
|
associationName: string;
|
|
invitationLink: string;
|
|
expiresAt: Date;
|
|
};
|
|
|
|
function formatDate(date: Date) {
|
|
return new Intl.DateTimeFormat("fr-FR", {
|
|
day: "2-digit",
|
|
month: "2-digit",
|
|
year: "numeric",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
}).format(date);
|
|
}
|
|
|
|
function escapeHtml(value: string) {
|
|
return value
|
|
.replaceAll("&", "&")
|
|
.replaceAll("<", "<")
|
|
.replaceAll(">", ">")
|
|
.replaceAll('"', """)
|
|
.replaceAll("'", "'");
|
|
}
|
|
|
|
export function generateAssociationInvitationEmail(input: InvitationEmailInput) {
|
|
const expiryLabel = formatDate(input.expiresAt);
|
|
const associationName = escapeHtml(input.associationName);
|
|
const invitationLink = escapeHtml(input.invitationLink);
|
|
const subject = `Invitation au Portail Associations - ${input.associationName}`;
|
|
|
|
const text = [
|
|
`Bonjour,`,
|
|
``,
|
|
`L'association "${input.associationName}" est invitée à activer son espace sur le Portail Associations.`,
|
|
`Ce lien est personnel, remplace les précédents liens d'invitation et reste valide jusqu'au ${expiryLabel}.`,
|
|
``,
|
|
`${input.invitationLink}`,
|
|
``,
|
|
`Si vous n'êtes pas la bonne personne, merci de transmettre ce message au référent de l'association.`,
|
|
].join("\n");
|
|
|
|
const html = `
|
|
<div style="font-family: Arial, sans-serif; color: #161616; line-height: 1.5;">
|
|
<h2 style="margin: 0 0 16px;">Invitation au Portail Associations</h2>
|
|
<p style="margin: 0 0 12px;">
|
|
L'association <strong>${associationName}</strong> est invitée à activer son espace sur le portail.
|
|
</p>
|
|
<p style="margin: 0 0 20px;">
|
|
Ce lien est personnel, remplace les précédents liens d'invitation et reste valide jusqu'au
|
|
<strong>${expiryLabel}</strong>.
|
|
</p>
|
|
<p style="margin: 0 0 20px;">
|
|
<a href="${invitationLink}" style="display: inline-block; background: #000091; color: white; text-decoration: none; padding: 12px 18px; border-radius: 6px; font-weight: 600;">
|
|
Activer l'espace association
|
|
</a>
|
|
</p>
|
|
<p style="margin: 0 0 8px; font-size: 14px; color: #666;">
|
|
Si le bouton ne fonctionne pas, utilisez ce lien :
|
|
</p>
|
|
<p style="margin: 0; font-size: 14px; word-break: break-all;">
|
|
<a href="${invitationLink}">${invitationLink}</a>
|
|
</p>
|
|
</div>
|
|
`;
|
|
|
|
return { subject, text, html };
|
|
}
|