feat: simplify mails and add reminders
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
import { env } from "@kk/env/server";
|
import { env } from "@kk/env/server";
|
||||||
import nodemailer from "nodemailer";
|
import nodemailer from "nodemailer";
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Transport
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
// Singleton transport — created once per module, reused across all email sends.
|
// Singleton transport — created once per module, reused across all email sends.
|
||||||
// Re-creating it on every call causes EventEmitter listener accumulation in
|
// Re-creating it on every call causes EventEmitter listener accumulation in
|
||||||
// long-lived Cloudflare Worker processes, triggering memory leak warnings.
|
// long-lived Cloudflare Worker processes, triggering memory leak warnings.
|
||||||
@@ -27,46 +31,134 @@ function getTransport(): nodemailer.Transporter | null {
|
|||||||
const from = env.SMTP_FROM ?? "Kunstenkamp <info@kunstenkamp.be>";
|
const from = env.SMTP_FROM ?? "Kunstenkamp <info@kunstenkamp.be>";
|
||||||
const baseUrl = env.BETTER_AUTH_URL ?? "https://kunstenkamp.be";
|
const baseUrl = env.BETTER_AUTH_URL ?? "https://kunstenkamp.be";
|
||||||
|
|
||||||
function registrationConfirmationHtml(params: {
|
// ---------------------------------------------------------------------------
|
||||||
firstName: string;
|
// Primitives
|
||||||
manageUrl: string;
|
// ---------------------------------------------------------------------------
|
||||||
signupUrl: string;
|
|
||||||
wantsToPerform: boolean;
|
|
||||||
artForm?: string | null;
|
|
||||||
giftAmount?: number;
|
|
||||||
drinkCardValue?: number;
|
|
||||||
}) {
|
|
||||||
const role = params.wantsToPerform
|
|
||||||
? `Optreden${params.artForm ? ` — ${params.artForm}` : ""}`
|
|
||||||
: "Toeschouwer";
|
|
||||||
|
|
||||||
const giftCents = params.giftAmount ?? 0;
|
/** Format a cent amount as a Euro string, e.g. 500 → "€5", 550 → "€5,50". */
|
||||||
// drinkCardValue is stored in euros (e.g., 5), giftAmount in cents (e.g., 5000)
|
function formatEuro(cents: number): string {
|
||||||
const drinkCardCents = (params.drinkCardValue ?? 0) * 100;
|
return `€${(cents / 100).toFixed(cents % 100 === 0 ? 0 : 2).replace(".", ",")}`;
|
||||||
const hasPayment = drinkCardCents > 0 || giftCents > 0;
|
}
|
||||||
|
|
||||||
const formatEuro = (cents: number) =>
|
/**
|
||||||
`€${(cents / 100).toFixed(cents % 100 === 0 ? 0 : 2).replace(".", ",")}`;
|
* A shaded info box with a small uppercase label and a bold value.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* infoBox("Jouw rol", "Optreden — Muziek")
|
||||||
|
* infoBox("Inschrijvingen openen", "maandag 16 maart 2026 om 19:00")
|
||||||
|
*/
|
||||||
|
function infoBox(label: string, value: string): string {
|
||||||
|
return `<table width="100%" cellpadding="0" cellspacing="0" style="background:rgba(255,255,255,0.08);border-radius:4px;margin:24px 0;">
|
||||||
|
<tr>
|
||||||
|
<td style="padding:20px 24px;">
|
||||||
|
<p style="margin:0 0 8px;font-size:12px;color:rgba(255,255,255,0.5);text-transform:uppercase;letter-spacing:0.06em;">${label}</p>
|
||||||
|
<p style="margin:0;font-size:18px;color:#ffffff;font-weight:600;">${value}</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>`;
|
||||||
|
}
|
||||||
|
|
||||||
const paymentSummary = hasPayment
|
/**
|
||||||
? `<table width="100%" cellpadding="0" cellspacing="0" style="background:rgba(255,255,255,0.08);border-radius:4px;margin:16px 0;">
|
* A CTA button.
|
||||||
<tr>
|
*
|
||||||
<td style="padding:20px 24px;">
|
* - `"primary"` — white background, teal text (main action)
|
||||||
<p style="margin:0 0 12px;font-size:12px;color:rgba(255,255,255,0.5);text-transform:uppercase;letter-spacing:0.06em;">Betaling</p>
|
* - `"secondary"` — translucent white background, white text (secondary action)
|
||||||
${drinkCardCents > 0 ? `<p style="margin:0 0 8px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.5;">Drinkkaart: <span style="color:#ffffff;font-weight:500;">${formatEuro(drinkCardCents)}</span></p>` : ""}
|
*/
|
||||||
${giftCents > 0 ? `<p style="margin:0 0 8px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.5;">Vrijwillige gift: <span style="color:#ffffff;font-weight:500;">${formatEuro(giftCents)}</span></p>` : ""}
|
function ctaButton(
|
||||||
<p style="margin:16px 0 0;padding-top:12px;border-top:1px solid rgba(255,255,255,0.1);font-size:18px;color:#ffffff;font-weight:600;">Totaal: ${formatEuro(drinkCardCents + giftCents)}</p>
|
href: string,
|
||||||
</td>
|
label: string,
|
||||||
</tr>
|
style: "primary" | "secondary" = "primary",
|
||||||
</table>`
|
): string {
|
||||||
: "";
|
const bg = style === "primary" ? "#ffffff" : "rgba(255,255,255,0.15)";
|
||||||
|
const color = style === "primary" ? "#214e51" : "#ffffff";
|
||||||
|
return `<table cellpadding="0" cellspacing="0">
|
||||||
|
<tr>
|
||||||
|
<td style="border-radius:2px;background:${bg};">
|
||||||
|
<a href="${href}" style="display:inline-block;padding:14px 32px;font-size:16px;font-weight:600;color:${color};text-decoration:none;">
|
||||||
|
${label}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A small muted link line rendered below a CTA button, e.g. "Of kopieer deze link: …"
|
||||||
|
*/
|
||||||
|
function ctaSubtext(text: string): string {
|
||||||
|
return `<p style="margin:16px 0 0;font-size:13px;color:rgba(255,255,255,0.4);">${text}</p>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A standard body paragraph (16 px, 85% white, 1.6 line-height).
|
||||||
|
* Pass raw HTML as the content, e.g. include `<strong>` tags freely.
|
||||||
|
*/
|
||||||
|
function p(content: string): string {
|
||||||
|
return `<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">${content}</p>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payment summary box (drinkcard + gift + total).
|
||||||
|
* Returns an empty string when both amounts are zero.
|
||||||
|
*/
|
||||||
|
function paymentSummaryBox(
|
||||||
|
drinkCardCents: number,
|
||||||
|
giftCents: number,
|
||||||
|
heading = "Betaling",
|
||||||
|
): string {
|
||||||
|
if (drinkCardCents === 0 && giftCents === 0) return "";
|
||||||
|
const total = drinkCardCents + giftCents;
|
||||||
|
return `<table width="100%" cellpadding="0" cellspacing="0" style="background:rgba(255,255,255,0.08);border-radius:4px;margin:16px 0;">
|
||||||
|
<tr>
|
||||||
|
<td style="padding:20px 24px;">
|
||||||
|
<p style="margin:0 0 12px;font-size:12px;color:rgba(255,255,255,0.5);text-transform:uppercase;letter-spacing:0.06em;">${heading}</p>
|
||||||
|
${drinkCardCents > 0 ? `<p style="margin:0 0 8px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.5;">Drinkkaart: <span style="color:#ffffff;font-weight:500;">${formatEuro(drinkCardCents)}</span></p>` : ""}
|
||||||
|
${giftCents > 0 ? `<p style="margin:0 0 8px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.5;">Vrijwillige gift: <span style="color:#ffffff;font-weight:500;">${formatEuro(giftCents)}</span></p>` : ""}
|
||||||
|
<p style="margin:16px 0 0;padding-top:12px;border-top:1px solid rgba(255,255,255,0.1);font-size:18px;color:#ffffff;font-weight:600;">Totaal: ${formatEuro(total)}</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Layout shell
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps content in the full Kunstenkamp email chrome:
|
||||||
|
* outer grey background → teal card → header → body → footer.
|
||||||
|
*
|
||||||
|
* @param title HTML `<title>` value
|
||||||
|
* @param heading Large white `<h1>` in the card header
|
||||||
|
* @param bodyHtml Everything between the header and the footer
|
||||||
|
* @param footerLines Optional extra lines rendered above the default contact
|
||||||
|
* line in the footer (e.g. unsubscribe notice). Pass an
|
||||||
|
* array of plain strings or HTML snippets.
|
||||||
|
* @param headerLabel Small uppercase label above the heading (default: "Kunstenkamp")
|
||||||
|
*/
|
||||||
|
function emailLayout({
|
||||||
|
title,
|
||||||
|
heading,
|
||||||
|
bodyHtml,
|
||||||
|
footerLines = [],
|
||||||
|
headerLabel = "Kunstenkamp",
|
||||||
|
}: {
|
||||||
|
title: string;
|
||||||
|
heading: string;
|
||||||
|
bodyHtml: string;
|
||||||
|
footerLines?: string[];
|
||||||
|
headerLabel?: string;
|
||||||
|
}): string {
|
||||||
|
const extraFooter = footerLines
|
||||||
|
.map((line) => `${line}<br/>`)
|
||||||
|
.join("\n ");
|
||||||
|
|
||||||
return `<!DOCTYPE html>
|
return `<!DOCTYPE html>
|
||||||
<html lang="nl">
|
<html lang="nl">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Bevestiging inschrijving</title>
|
<title>${title}</title>
|
||||||
</head>
|
</head>
|
||||||
<body style="margin:0;padding:0;background:#f4f4f5;font-family:sans-serif;">
|
<body style="margin:0;padding:0;background:#f4f4f5;font-family:sans-serif;">
|
||||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f4f4f5;padding:40px 0;">
|
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f4f4f5;padding:40px 0;">
|
||||||
@@ -76,64 +168,21 @@ function registrationConfirmationHtml(params: {
|
|||||||
<!-- Header -->
|
<!-- Header -->
|
||||||
<tr>
|
<tr>
|
||||||
<td style="padding:40px 48px 32px;">
|
<td style="padding:40px 48px 32px;">
|
||||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.5);letter-spacing:0.08em;text-transform:uppercase;">Kunstenkamp</p>
|
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.5);letter-spacing:0.08em;text-transform:uppercase;">${headerLabel}</p>
|
||||||
<h1 style="margin:12px 0 0;font-size:28px;color:#ffffff;font-weight:700;">Je inschrijving is bevestigd!</h1>
|
<h1 style="margin:12px 0 0;font-size:28px;color:#ffffff;font-weight:700;">${heading}</h1>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<!-- Body -->
|
<!-- Body -->
|
||||||
<tr>
|
<tr>
|
||||||
<td style="padding:0 48px 32px;">
|
<td style="padding:0 48px 32px;">
|
||||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
${bodyHtml}
|
||||||
Hoi ${params.firstName},
|
|
||||||
</p>
|
|
||||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
We hebben je inschrijving voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong> in goede orde ontvangen.
|
|
||||||
</p>
|
|
||||||
<!-- Registration summary -->
|
|
||||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:rgba(255,255,255,0.08);border-radius:4px;margin:24px 0;">
|
|
||||||
<tr>
|
|
||||||
<td style="padding:20px 24px;">
|
|
||||||
<p style="margin:0 0 8px;font-size:12px;color:rgba(255,255,255,0.5);text-transform:uppercase;letter-spacing:0.06em;">Jouw rol</p>
|
|
||||||
<p style="margin:0;font-size:18px;color:#ffffff;font-weight:600;">${role}</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
${paymentSummary}
|
|
||||||
<p style="margin:0 0 24px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
Maak een account aan om je inschrijving te beheren en (voor bezoekers) je Drinkkaart te activeren.
|
|
||||||
</p>
|
|
||||||
<!-- Account creation CTA -->
|
|
||||||
<table cellpadding="0" cellspacing="0" style="margin-bottom:16px;">
|
|
||||||
<tr>
|
|
||||||
<td style="border-radius:2px;background:#ffffff;">
|
|
||||||
<a href="${params.signupUrl}" style="display:inline-block;padding:14px 32px;font-size:16px;font-weight:600;color:#214e51;text-decoration:none;">
|
|
||||||
Account aanmaken
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<p style="margin:0 0 24px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
Wil je je gegevens later nog aanpassen of je inschrijving annuleren? Gebruik dan de knop hieronder. De link is uniek voor jou — deel hem niet.
|
|
||||||
</p>
|
|
||||||
<!-- Manage CTA button -->
|
|
||||||
<table cellpadding="0" cellspacing="0">
|
|
||||||
<tr>
|
|
||||||
<td style="border-radius:2px;background:rgba(255,255,255,0.15);">
|
|
||||||
<a href="${params.manageUrl}" style="display:inline-block;padding:14px 32px;font-size:16px;font-weight:600;color:#ffffff;text-decoration:none;">
|
|
||||||
Beheer mijn inschrijving
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<p style="margin:16px 0 0;font-size:13px;color:rgba(255,255,255,0.4);">
|
|
||||||
Of kopieer deze link: <span style="color:rgba(255,255,255,0.6);">${params.manageUrl}</span>
|
|
||||||
</p>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<!-- Footer -->
|
<!-- Footer -->
|
||||||
<tr>
|
<tr>
|
||||||
<td style="padding:24px 48px;border-top:1px solid rgba(255,255,255,0.1);">
|
<td style="padding:24px 48px;border-top:1px solid rgba(255,255,255,0.1);">
|
||||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.4);line-height:1.6;">
|
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.4);line-height:1.6;">
|
||||||
|
${extraFooter}
|
||||||
Vragen? Mail ons op <a href="mailto:info@kunstenkamp.be" style="color:rgba(255,255,255,0.6);">info@kunstenkamp.be</a><br/>
|
Vragen? Mail ons op <a href="mailto:info@kunstenkamp.be" style="color:rgba(255,255,255,0.6);">info@kunstenkamp.be</a><br/>
|
||||||
Kunstenkamp vzw — Een initiatief voor en door kunstenaars.
|
Kunstenkamp vzw — Een initiatief voor en door kunstenaars.
|
||||||
</p>
|
</p>
|
||||||
@@ -147,6 +196,73 @@ function registrationConfirmationHtml(params: {
|
|||||||
</html>`;
|
</html>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Shared role / payment helpers
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function roleLabel(wantsToPerform: boolean, artForm?: string | null): string {
|
||||||
|
return wantsToPerform
|
||||||
|
? `Optreden${artForm ? ` — ${artForm}` : ""}`
|
||||||
|
: "Toeschouwer";
|
||||||
|
}
|
||||||
|
|
||||||
|
function toCents(
|
||||||
|
drinkCardValue: number | undefined,
|
||||||
|
giftAmount: number | undefined,
|
||||||
|
): { drinkCardCents: number; giftCents: number } {
|
||||||
|
// drinkCardValue is stored in euros (e.g., 5); giftAmount in cents (e.g., 5000)
|
||||||
|
return {
|
||||||
|
drinkCardCents: (drinkCardValue ?? 0) * 100,
|
||||||
|
giftCents: giftAmount ?? 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Email composers
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function registrationConfirmationHtml(params: {
|
||||||
|
firstName: string;
|
||||||
|
manageUrl: string;
|
||||||
|
signupUrl: string;
|
||||||
|
wantsToPerform: boolean;
|
||||||
|
artForm?: string | null;
|
||||||
|
giftAmount?: number;
|
||||||
|
drinkCardValue?: number;
|
||||||
|
}): string {
|
||||||
|
const { drinkCardCents, giftCents } = toCents(
|
||||||
|
params.drinkCardValue,
|
||||||
|
params.giftAmount,
|
||||||
|
);
|
||||||
|
|
||||||
|
const body = [
|
||||||
|
p(`Hoi ${params.firstName},`),
|
||||||
|
p(
|
||||||
|
`We hebben je inschrijving voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong> in goede orde ontvangen.`,
|
||||||
|
),
|
||||||
|
infoBox("Jouw rol", roleLabel(params.wantsToPerform, params.artForm)),
|
||||||
|
paymentSummaryBox(drinkCardCents, giftCents),
|
||||||
|
p(
|
||||||
|
"Maak een account aan om je inschrijving te beheren en (voor bezoekers) je Drinkkaart te activeren.",
|
||||||
|
),
|
||||||
|
ctaButton(params.signupUrl, "Account aanmaken"),
|
||||||
|
`<div style="margin-top:16px;"></div>`,
|
||||||
|
p(
|
||||||
|
"Wil je je gegevens later nog aanpassen of je inschrijving annuleren? Gebruik dan de knop hieronder. De link is uniek voor jou — deel hem niet.",
|
||||||
|
),
|
||||||
|
ctaButton(params.manageUrl, "Beheer mijn inschrijving", "secondary"),
|
||||||
|
ctaSubtext(
|
||||||
|
`Of kopieer deze link: <span style="color:rgba(255,255,255,0.6);">${params.manageUrl}</span>`,
|
||||||
|
),
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
|
return emailLayout({
|
||||||
|
title: "Bevestiging inschrijving",
|
||||||
|
heading: "Je inschrijving is bevestigd!",
|
||||||
|
bodyHtml: body,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function updateConfirmationHtml(params: {
|
function updateConfirmationHtml(params: {
|
||||||
firstName: string;
|
firstName: string;
|
||||||
manageUrl: string;
|
manageUrl: string;
|
||||||
@@ -154,138 +270,199 @@ function updateConfirmationHtml(params: {
|
|||||||
artForm?: string | null;
|
artForm?: string | null;
|
||||||
giftAmount?: number;
|
giftAmount?: number;
|
||||||
drinkCardValue?: number;
|
drinkCardValue?: number;
|
||||||
}) {
|
}): string {
|
||||||
const role = params.wantsToPerform
|
const { drinkCardCents, giftCents } = toCents(
|
||||||
? `Optreden${params.artForm ? ` — ${params.artForm}` : ""}`
|
params.drinkCardValue,
|
||||||
: "Toeschouwer";
|
params.giftAmount,
|
||||||
|
);
|
||||||
|
|
||||||
const giftCents = params.giftAmount ?? 0;
|
const body = [
|
||||||
// drinkCardValue is stored in euros (e.g., 5), giftAmount in cents (e.g., 5000)
|
p(`Hoi ${params.firstName},`),
|
||||||
const drinkCardCents = (params.drinkCardValue ?? 0) * 100;
|
p(
|
||||||
const hasPayment = drinkCardCents > 0 || giftCents > 0;
|
`Je inschrijving voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong> is succesvol bijgewerkt.`,
|
||||||
|
),
|
||||||
|
infoBox("Jouw rol", roleLabel(params.wantsToPerform, params.artForm)),
|
||||||
|
paymentSummaryBox(drinkCardCents, giftCents),
|
||||||
|
ctaButton(params.manageUrl, "Bekijk mijn inschrijving"),
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
const formatEuro = (cents: number) =>
|
return emailLayout({
|
||||||
`€${(cents / 100).toFixed(cents % 100 === 0 ? 0 : 2).replace(".", ",")}`;
|
title: "Inschrijving bijgewerkt",
|
||||||
|
heading: "Inschrijving bijgewerkt",
|
||||||
const paymentSummary = hasPayment
|
bodyHtml: body,
|
||||||
? `<table width="100%" cellpadding="0" cellspacing="0" style="background:rgba(255,255,255,0.08);border-radius:4px;margin:16px 0;">
|
});
|
||||||
<tr>
|
|
||||||
<td style="padding:20px 24px;">
|
|
||||||
<p style="margin:0 0 12px;font-size:12px;color:rgba(255,255,255,0.5);text-transform:uppercase;letter-spacing:0.06em;">Betaling</p>
|
|
||||||
${drinkCardCents > 0 ? `<p style="margin:0 0 8px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.5;">Drinkkaart: <span style="color:#ffffff;font-weight:500;">${formatEuro(drinkCardCents)}</span></p>` : ""}
|
|
||||||
${giftCents > 0 ? `<p style="margin:0 0 8px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.5;">Vrijwillige gift: <span style="color:#ffffff;font-weight:500;">${formatEuro(giftCents)}</span></p>` : ""}
|
|
||||||
<p style="margin:16px 0 0;padding-top:12px;border-top:1px solid rgba(255,255,255,0.1);font-size:18px;color:#ffffff;font-weight:600;">Totaal: ${formatEuro(drinkCardCents + giftCents)}</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>`
|
|
||||||
: "";
|
|
||||||
|
|
||||||
return `<!DOCTYPE html>
|
|
||||||
<html lang="nl">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<title>Inschrijving bijgewerkt</title>
|
|
||||||
</head>
|
|
||||||
<body style="margin:0;padding:0;background:#f4f4f5;font-family:sans-serif;">
|
|
||||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f4f4f5;padding:40px 0;">
|
|
||||||
<tr>
|
|
||||||
<td align="center">
|
|
||||||
<table width="600" cellpadding="0" cellspacing="0" style="background:#214e51;border-radius:4px;overflow:hidden;">
|
|
||||||
<tr>
|
|
||||||
<td style="padding:40px 48px 32px;">
|
|
||||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.5);letter-spacing:0.08em;text-transform:uppercase;">Kunstenkamp</p>
|
|
||||||
<h1 style="margin:12px 0 0;font-size:28px;color:#ffffff;font-weight:700;">Inschrijving bijgewerkt</h1>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td style="padding:0 48px 32px;">
|
|
||||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
Hoi ${params.firstName},
|
|
||||||
</p>
|
|
||||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
Je inschrijving voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong> is succesvol bijgewerkt.
|
|
||||||
</p>
|
|
||||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:rgba(255,255,255,0.08);border-radius:4px;margin:24px 0;">
|
|
||||||
<tr>
|
|
||||||
<td style="padding:20px 24px;">
|
|
||||||
<p style="margin:0 0 8px;font-size:12px;color:rgba(255,255,255,0.5);text-transform:uppercase;letter-spacing:0.06em;">Jouw rol</p>
|
|
||||||
<p style="margin:0;font-size:18px;color:#ffffff;font-weight:600;">${role}</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
${paymentSummary}
|
|
||||||
<table cellpadding="0" cellspacing="0">
|
|
||||||
<tr>
|
|
||||||
<td style="border-radius:2px;background:#ffffff;">
|
|
||||||
<a href="${params.manageUrl}" style="display:inline-block;padding:14px 32px;font-size:16px;font-weight:600;color:#214e51;text-decoration:none;">
|
|
||||||
Bekijk mijn inschrijving
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td style="padding:24px 48px;border-top:1px solid rgba(255,255,255,0.1);">
|
|
||||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.4);">
|
|
||||||
Vragen? Mail ons op <a href="mailto:info@kunstenkamp.be" style="color:rgba(255,255,255,0.6);">info@kunstenkamp.be</a>
|
|
||||||
</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancellationHtml(params: { firstName: string }) {
|
function cancellationHtml(params: { firstName: string }): string {
|
||||||
return `<!DOCTYPE html>
|
const body = [
|
||||||
<html lang="nl">
|
p(`Hoi ${params.firstName},`),
|
||||||
<head>
|
p(
|
||||||
<meta charset="UTF-8" />
|
`Je inschrijving voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong> is geannuleerd.`,
|
||||||
<title>Inschrijving geannuleerd</title>
|
),
|
||||||
</head>
|
p(
|
||||||
<body style="margin:0;padding:0;background:#f4f4f5;font-family:sans-serif;">
|
`Van gedachten veranderd? Je kunt je altijd opnieuw inschrijven via <a href="${baseUrl}/#registration" style="color:#ffffff;">kunstenkamp.be</a>.`,
|
||||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f4f4f5;padding:40px 0;">
|
),
|
||||||
<tr>
|
].join("\n");
|
||||||
<td align="center">
|
|
||||||
<table width="600" cellpadding="0" cellspacing="0" style="background:#214e51;border-radius:4px;overflow:hidden;">
|
return emailLayout({
|
||||||
<tr>
|
title: "Inschrijving geannuleerd",
|
||||||
<td style="padding:40px 48px 32px;">
|
heading: "Inschrijving geannuleerd",
|
||||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.5);letter-spacing:0.08em;text-transform:uppercase;">Kunstenkamp</p>
|
bodyHtml: body,
|
||||||
<h1 style="margin:12px 0 0;font-size:28px;color:#ffffff;font-weight:700;">Inschrijving geannuleerd</h1>
|
});
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td style="padding:0 48px 40px;">
|
|
||||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
Hoi ${params.firstName},
|
|
||||||
</p>
|
|
||||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
Je inschrijving voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong> is geannuleerd.
|
|
||||||
</p>
|
|
||||||
<p style="margin:0;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
Van gedachten veranderd? Je kunt je altijd opnieuw inschrijven via <a href="${baseUrl}/#registration" style="color:#ffffff;">kunstenkamp.be</a>.
|
|
||||||
</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td style="padding:24px 48px;border-top:1px solid rgba(255,255,255,0.1);">
|
|
||||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.4);">
|
|
||||||
Vragen? Mail ons op <a href="mailto:info@kunstenkamp.be" style="color:rgba(255,255,255,0.6);">info@kunstenkamp.be</a>
|
|
||||||
</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reminder24hHtml(params: { firstName?: string | null }): string {
|
||||||
|
const greeting = params.firstName ? `Hoi ${params.firstName},` : "Hoi!";
|
||||||
|
const openDateStr = "maandag 16 maart 2026 om 19:00";
|
||||||
|
const registrationUrl = `${baseUrl}/#registration`;
|
||||||
|
|
||||||
|
const body = [
|
||||||
|
p(greeting),
|
||||||
|
p(
|
||||||
|
`Morgen openen de inschrijvingen voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong>. Zet je wekker!`,
|
||||||
|
),
|
||||||
|
infoBox("Inschrijvingen openen", openDateStr),
|
||||||
|
p("Wees er snel bij — de plaatsen zijn beperkt!"),
|
||||||
|
ctaButton(registrationUrl, "Bekijk de pagina"),
|
||||||
|
ctaSubtext(
|
||||||
|
`Of ga naar: <span style="color:rgba(255,255,255,0.6);">${registrationUrl}</span>`,
|
||||||
|
),
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
|
return emailLayout({
|
||||||
|
title: "Nog 24 uur — inschrijvingen openen morgen!",
|
||||||
|
heading: "Nog 24 uur!",
|
||||||
|
bodyHtml: body,
|
||||||
|
footerLines: [
|
||||||
|
"Je ontvangt dit bericht omdat je een herinnering hebt aangevraagd.",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function reminderHtml(params: { firstName?: string | null }): string {
|
||||||
|
const greeting = params.firstName ? `Hoi ${params.firstName},` : "Hoi!";
|
||||||
|
const openDateStr = "maandag 16 maart 2026 om 19:00";
|
||||||
|
const registrationUrl = `${baseUrl}/#registration`;
|
||||||
|
|
||||||
|
const body = [
|
||||||
|
p(greeting),
|
||||||
|
p(
|
||||||
|
`Over ongeveer <strong style="color:#ffffff;">1 uur</strong> openen de inschrijvingen voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong>.`,
|
||||||
|
),
|
||||||
|
infoBox("Inschrijvingen openen", openDateStr),
|
||||||
|
p("Wees er snel bij — de plaatsen zijn beperkt!"),
|
||||||
|
ctaButton(registrationUrl, "Schrijf je in"),
|
||||||
|
ctaSubtext(
|
||||||
|
`Of ga naar: <span style="color:rgba(255,255,255,0.6);">${registrationUrl}</span>`,
|
||||||
|
),
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
|
return emailLayout({
|
||||||
|
title: "Nog 1 uur — inschrijvingen openen straks!",
|
||||||
|
heading: "Nog 1 uur!",
|
||||||
|
bodyHtml: body,
|
||||||
|
footerLines: [
|
||||||
|
"Je ontvangt dit bericht omdat je een herinnering hebt aangevraagd.",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function subscriptionConfirmationHtml(params: { email: string }): string {
|
||||||
|
const openDateStr = "maandag 16 maart 2026 om 19:00";
|
||||||
|
const registrationUrl = `${baseUrl}/#registration`;
|
||||||
|
|
||||||
|
const body = [
|
||||||
|
p(
|
||||||
|
`We sturen een herinnering naar <strong style="color:#ffffff;">${params.email}</strong> wanneer de inschrijvingen openen.`,
|
||||||
|
),
|
||||||
|
infoBox("Inschrijvingen openen", openDateStr),
|
||||||
|
p(
|
||||||
|
"Je ontvangt twee herinneringen: één 24 uur van tevoren en één 1 uur voor de opening.",
|
||||||
|
),
|
||||||
|
p("Wees er snel bij — de plaatsen zijn beperkt!"),
|
||||||
|
ctaButton(registrationUrl, "Bekijk de pagina"),
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
|
return emailLayout({
|
||||||
|
title: "Herinnering ingepland — Open Mic Night",
|
||||||
|
heading: "Je herinnering is ingepland!",
|
||||||
|
bodyHtml: body,
|
||||||
|
footerLines: [
|
||||||
|
"Je ontvangt dit bericht omdat je een herinnering hebt aangevraagd op kunstenkamp.be.",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function paymentReminderHtml(params: {
|
||||||
|
firstName: string;
|
||||||
|
accountUrl: string;
|
||||||
|
manageUrl: string;
|
||||||
|
drinkCardValue?: number;
|
||||||
|
giftAmount?: number;
|
||||||
|
}): string {
|
||||||
|
const { drinkCardCents, giftCents } = toCents(
|
||||||
|
params.drinkCardValue,
|
||||||
|
params.giftAmount,
|
||||||
|
);
|
||||||
|
const totalCents = drinkCardCents + giftCents;
|
||||||
|
|
||||||
|
const amountLine =
|
||||||
|
totalCents > 0
|
||||||
|
? p(
|
||||||
|
`Je betaling van <strong style="color:#ffffff;">${formatEuro(totalCents)}</strong> staat nog open. Log in op je account om te betalen.`,
|
||||||
|
)
|
||||||
|
: p("Je betaling staat nog open. Log in op je account om te betalen.");
|
||||||
|
|
||||||
|
const body = [
|
||||||
|
p(`Hoi ${params.firstName},`),
|
||||||
|
p(
|
||||||
|
`Je hebt je ingeschreven voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong>, maar we hebben nog geen betaling ontvangen.`,
|
||||||
|
),
|
||||||
|
amountLine,
|
||||||
|
ctaButton(params.accountUrl, "Betaal nu"),
|
||||||
|
ctaSubtext(
|
||||||
|
`Je inschrijving beheren? <a href="${params.manageUrl}" style="color:rgba(255,255,255,0.6);">Klik hier</a>`,
|
||||||
|
),
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
|
return emailLayout({
|
||||||
|
title: "Herinnering: betaling open",
|
||||||
|
heading: "Betaling nog open",
|
||||||
|
bodyHtml: body,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function paymentConfirmationHtml(params: {
|
||||||
|
firstName: string;
|
||||||
|
manageUrl: string;
|
||||||
|
drinkCardValue?: number;
|
||||||
|
giftAmount?: number;
|
||||||
|
}): string {
|
||||||
|
const { drinkCardCents, giftCents } = toCents(
|
||||||
|
params.drinkCardValue,
|
||||||
|
params.giftAmount,
|
||||||
|
);
|
||||||
|
|
||||||
|
const body = [
|
||||||
|
p(`Hoi ${params.firstName},`),
|
||||||
|
p(
|
||||||
|
`We hebben je betaling voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong> in goede orde ontvangen. Tot dan!`,
|
||||||
|
),
|
||||||
|
paymentSummaryBox(drinkCardCents, giftCents, "Betaling ontvangen"),
|
||||||
|
ctaButton(params.manageUrl, "Beheer mijn inschrijving", "secondary"),
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
|
return emailLayout({
|
||||||
|
title: "Betaling ontvangen",
|
||||||
|
heading: "Betaling ontvangen!",
|
||||||
|
bodyHtml: body,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Public send functions
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
export async function sendConfirmationEmail(params: {
|
export async function sendConfirmationEmail(params: {
|
||||||
to: string;
|
to: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
@@ -369,83 +546,39 @@ export async function sendCancellationEmail(params: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function reminderHtml(params: { firstName?: string | null }) {
|
export async function sendSubscriptionConfirmationEmail(params: {
|
||||||
const greeting = params.firstName ? `Hoi ${params.firstName},` : "Hoi!";
|
to: string;
|
||||||
// Registration opens at 2026-03-16T19:00:00+01:00
|
}) {
|
||||||
const openDateStr = "maandag 16 maart 2026 om 19:00";
|
const transport = getTransport();
|
||||||
const registrationUrl = `${baseUrl}/#registration`;
|
if (!transport) {
|
||||||
|
console.warn(
|
||||||
|
"SMTP not configured — skipping subscription confirmation email",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await transport.sendMail({
|
||||||
|
from,
|
||||||
|
to: params.to,
|
||||||
|
subject: "Herinnering ingepland — Open Mic Night",
|
||||||
|
html: subscriptionConfirmationHtml({ email: params.to }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return `<!DOCTYPE html>
|
export async function sendReminder24hEmail(params: {
|
||||||
<html lang="nl">
|
to: string;
|
||||||
<head>
|
firstName?: string | null;
|
||||||
<meta charset="UTF-8" />
|
}) {
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
const transport = getTransport();
|
||||||
<title>Nog 1 uur — inschrijvingen openen straks!</title>
|
if (!transport) {
|
||||||
</head>
|
console.warn("SMTP not configured — skipping 24h reminder email");
|
||||||
<body style="margin:0;padding:0;background:#f4f4f5;font-family:sans-serif;">
|
return;
|
||||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f4f4f5;padding:40px 0;">
|
}
|
||||||
<tr>
|
await transport.sendMail({
|
||||||
<td align="center">
|
from,
|
||||||
<table width="600" cellpadding="0" cellspacing="0" style="background:#214e51;border-radius:4px;overflow:hidden;">
|
to: params.to,
|
||||||
<!-- Header -->
|
subject: "Nog 24 uur — inschrijvingen openen morgen!",
|
||||||
<tr>
|
html: reminder24hHtml({ firstName: params.firstName }),
|
||||||
<td style="padding:40px 48px 32px;">
|
});
|
||||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.5);letter-spacing:0.08em;text-transform:uppercase;">Kunstenkamp</p>
|
|
||||||
<h1 style="margin:12px 0 0;font-size:28px;color:#ffffff;font-weight:700;">Nog 1 uur!</h1>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<!-- Body -->
|
|
||||||
<tr>
|
|
||||||
<td style="padding:0 48px 32px;">
|
|
||||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
${greeting}
|
|
||||||
</p>
|
|
||||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
Over ongeveer <strong style="color:#ffffff;">1 uur</strong> openen de inschrijvingen voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong>.
|
|
||||||
</p>
|
|
||||||
<!-- Time box -->
|
|
||||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:rgba(255,255,255,0.08);border-radius:4px;margin:24px 0;">
|
|
||||||
<tr>
|
|
||||||
<td style="padding:20px 24px;">
|
|
||||||
<p style="margin:0 0 8px;font-size:12px;color:rgba(255,255,255,0.5);text-transform:uppercase;letter-spacing:0.06em;">Inschrijvingen openen</p>
|
|
||||||
<p style="margin:0;font-size:18px;color:#ffffff;font-weight:600;">${openDateStr}</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<p style="margin:0 0 24px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
Wees er snel bij — de plaatsen zijn beperkt!
|
|
||||||
</p>
|
|
||||||
<!-- CTA button -->
|
|
||||||
<table cellpadding="0" cellspacing="0">
|
|
||||||
<tr>
|
|
||||||
<td style="border-radius:2px;background:#ffffff;">
|
|
||||||
<a href="${registrationUrl}" style="display:inline-block;padding:14px 32px;font-size:16px;font-weight:600;color:#214e51;text-decoration:none;">
|
|
||||||
Schrijf je in
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<p style="margin:16px 0 0;font-size:13px;color:rgba(255,255,255,0.4);">
|
|
||||||
Of ga naar: <span style="color:rgba(255,255,255,0.6);">${registrationUrl}</span>
|
|
||||||
</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<!-- Footer -->
|
|
||||||
<tr>
|
|
||||||
<td style="padding:24px 48px;border-top:1px solid rgba(255,255,255,0.1);">
|
|
||||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.4);line-height:1.6;">
|
|
||||||
Je ontvangt dit bericht omdat je een herinnering hebt aangevraagd.<br/>
|
|
||||||
Vragen? Mail ons op <a href="mailto:info@kunstenkamp.be" style="color:rgba(255,255,255,0.6);">info@kunstenkamp.be</a><br/>
|
|
||||||
Kunstenkamp — Een initiatief voor en door kunstenaars.
|
|
||||||
</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendReminderEmail(params: {
|
export async function sendReminderEmail(params: {
|
||||||
@@ -465,87 +598,6 @@ export async function sendReminderEmail(params: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function paymentReminderHtml(params: {
|
|
||||||
firstName: string;
|
|
||||||
accountUrl: string;
|
|
||||||
manageUrl: string;
|
|
||||||
drinkCardValue?: number;
|
|
||||||
giftAmount?: number;
|
|
||||||
}) {
|
|
||||||
const formatEuro = (cents: number) =>
|
|
||||||
`€${(cents / 100).toFixed(cents % 100 === 0 ? 0 : 2).replace(".", ",")}`;
|
|
||||||
|
|
||||||
const giftCents = params.giftAmount ?? 0;
|
|
||||||
const drinkCardCents = (params.drinkCardValue ?? 0) * 100;
|
|
||||||
const totalCents = drinkCardCents + giftCents;
|
|
||||||
const totalStr = totalCents > 0 ? formatEuro(totalCents) : "";
|
|
||||||
|
|
||||||
const amountLine = totalStr
|
|
||||||
? `<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
Je betaling van <strong style="color:#ffffff;">${totalStr}</strong> staat nog open. Log in op je account om te betalen.
|
|
||||||
</p>`
|
|
||||||
: `<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
Je betaling staat nog open. Log in op je account om te betalen.
|
|
||||||
</p>`;
|
|
||||||
|
|
||||||
return `<!DOCTYPE html>
|
|
||||||
<html lang="nl">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>Herinnering: betaling open</title>
|
|
||||||
</head>
|
|
||||||
<body style="margin:0;padding:0;background:#f4f4f5;font-family:sans-serif;">
|
|
||||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f4f4f5;padding:40px 0;">
|
|
||||||
<tr>
|
|
||||||
<td align="center">
|
|
||||||
<table width="600" cellpadding="0" cellspacing="0" style="background:#214e51;border-radius:4px;overflow:hidden;">
|
|
||||||
<tr>
|
|
||||||
<td style="padding:40px 48px 32px;">
|
|
||||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.5);letter-spacing:0.08em;text-transform:uppercase;">Kunstenkamp</p>
|
|
||||||
<h1 style="margin:12px 0 0;font-size:28px;color:#ffffff;font-weight:700;">Betaling nog open</h1>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td style="padding:0 48px 32px;">
|
|
||||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
Hoi ${params.firstName},
|
|
||||||
</p>
|
|
||||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
Je hebt je ingeschreven voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong>, maar we hebben nog geen betaling ontvangen.
|
|
||||||
</p>
|
|
||||||
${amountLine}
|
|
||||||
<!-- Pay CTA -->
|
|
||||||
<table cellpadding="0" cellspacing="0" style="margin-bottom:16px;">
|
|
||||||
<tr>
|
|
||||||
<td style="border-radius:2px;background:#ffffff;">
|
|
||||||
<a href="${params.accountUrl}" style="display:inline-block;padding:14px 32px;font-size:16px;font-weight:600;color:#214e51;text-decoration:none;">
|
|
||||||
Betaal nu
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<p style="margin:16px 0 0;font-size:13px;color:rgba(255,255,255,0.4);">
|
|
||||||
Je inschrijving beheren? <a href="${params.manageUrl}" style="color:rgba(255,255,255,0.6);">Klik hier</a>
|
|
||||||
</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td style="padding:24px 48px;border-top:1px solid rgba(255,255,255,0.1);">
|
|
||||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.4);line-height:1.6;">
|
|
||||||
Vragen? Mail ons op <a href="mailto:info@kunstenkamp.be" style="color:rgba(255,255,255,0.6);">info@kunstenkamp.be</a><br/>
|
|
||||||
Kunstenkamp vzw — Een initiatief voor en door kunstenaars.
|
|
||||||
</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function sendPaymentReminderEmail(params: {
|
export async function sendPaymentReminderEmail(params: {
|
||||||
to: string;
|
to: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
@@ -574,88 +626,6 @@ export async function sendPaymentReminderEmail(params: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function paymentConfirmationHtml(params: {
|
|
||||||
firstName: string;
|
|
||||||
manageUrl: string;
|
|
||||||
drinkCardValue?: number;
|
|
||||||
giftAmount?: number;
|
|
||||||
}) {
|
|
||||||
const formatEuro = (cents: number) =>
|
|
||||||
`€${(cents / 100).toFixed(cents % 100 === 0 ? 0 : 2).replace(".", ",")}`;
|
|
||||||
|
|
||||||
const giftCents = params.giftAmount ?? 0;
|
|
||||||
const drinkCardCents = (params.drinkCardValue ?? 0) * 100;
|
|
||||||
const totalCents = drinkCardCents + giftCents;
|
|
||||||
|
|
||||||
const paymentSummary =
|
|
||||||
totalCents > 0
|
|
||||||
? `<table width="100%" cellpadding="0" cellspacing="0" style="background:rgba(255,255,255,0.08);border-radius:4px;margin:16px 0;">
|
|
||||||
<tr>
|
|
||||||
<td style="padding:20px 24px;">
|
|
||||||
<p style="margin:0 0 12px;font-size:12px;color:rgba(255,255,255,0.5);text-transform:uppercase;letter-spacing:0.06em;">Betaling ontvangen</p>
|
|
||||||
${drinkCardCents > 0 ? `<p style="margin:0 0 8px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.5;">Drinkkaart: <span style="color:#ffffff;font-weight:500;">${formatEuro(drinkCardCents)}</span></p>` : ""}
|
|
||||||
${giftCents > 0 ? `<p style="margin:0 0 8px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.5;">Vrijwillige gift: <span style="color:#ffffff;font-weight:500;">${formatEuro(giftCents)}</span></p>` : ""}
|
|
||||||
<p style="margin:16px 0 0;padding-top:12px;border-top:1px solid rgba(255,255,255,0.1);font-size:18px;color:#ffffff;font-weight:600;">Totaal: ${formatEuro(totalCents)}</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>`
|
|
||||||
: "";
|
|
||||||
|
|
||||||
return `<!DOCTYPE html>
|
|
||||||
<html lang="nl">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>Betaling ontvangen</title>
|
|
||||||
</head>
|
|
||||||
<body style="margin:0;padding:0;background:#f4f4f5;font-family:sans-serif;">
|
|
||||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f4f4f5;padding:40px 0;">
|
|
||||||
<tr>
|
|
||||||
<td align="center">
|
|
||||||
<table width="600" cellpadding="0" cellspacing="0" style="background:#214e51;border-radius:4px;overflow:hidden;">
|
|
||||||
<tr>
|
|
||||||
<td style="padding:40px 48px 32px;">
|
|
||||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.5);letter-spacing:0.08em;text-transform:uppercase;">Kunstenkamp</p>
|
|
||||||
<h1 style="margin:12px 0 0;font-size:28px;color:#ffffff;font-weight:700;">Betaling ontvangen!</h1>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td style="padding:0 48px 32px;">
|
|
||||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
Hoi ${params.firstName},
|
|
||||||
</p>
|
|
||||||
<p style="margin:0 0 16px;font-size:16px;color:rgba(255,255,255,0.85);line-height:1.6;">
|
|
||||||
We hebben je betaling voor <strong style="color:#ffffff;">Open Mic Night — vrijdag 18 april 2026</strong> in goede orde ontvangen. Tot dan!
|
|
||||||
</p>
|
|
||||||
${paymentSummary}
|
|
||||||
<!-- Manage CTA -->
|
|
||||||
<table cellpadding="0" cellspacing="0">
|
|
||||||
<tr>
|
|
||||||
<td style="border-radius:2px;background:rgba(255,255,255,0.15);">
|
|
||||||
<a href="${params.manageUrl}" style="display:inline-block;padding:14px 32px;font-size:16px;font-weight:600;color:#ffffff;text-decoration:none;">
|
|
||||||
Beheer mijn inschrijving
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td style="padding:24px 48px;border-top:1px solid rgba(255,255,255,0.1);">
|
|
||||||
<p style="margin:0;font-size:13px;color:rgba(255,255,255,0.4);line-height:1.6;">
|
|
||||||
Vragen? Mail ons op <a href="mailto:info@kunstenkamp.be" style="color:rgba(255,255,255,0.6);">info@kunstenkamp.be</a><br/>
|
|
||||||
Kunstenkamp vzw — Een initiatief voor en door kunstenaars.
|
|
||||||
</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function sendPaymentConfirmationEmail(params: {
|
export async function sendPaymentConfirmationEmail(params: {
|
||||||
to: string;
|
to: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
|
|||||||
@@ -22,18 +22,26 @@ import {
|
|||||||
sendCancellationEmail,
|
sendCancellationEmail,
|
||||||
sendConfirmationEmail,
|
sendConfirmationEmail,
|
||||||
sendPaymentReminderEmail,
|
sendPaymentReminderEmail,
|
||||||
|
sendReminder24hEmail,
|
||||||
sendReminderEmail,
|
sendReminderEmail,
|
||||||
|
sendSubscriptionConfirmationEmail,
|
||||||
sendUpdateEmail,
|
sendUpdateEmail,
|
||||||
} from "../email";
|
} from "../email";
|
||||||
import { adminProcedure, protectedProcedure, publicProcedure } from "../index";
|
import { adminProcedure, protectedProcedure, publicProcedure } from "../index";
|
||||||
import { generateQrSecret } from "../lib/drinkkaart-utils";
|
import { generateQrSecret } from "../lib/drinkkaart-utils";
|
||||||
import { drinkkaartRouter } from "./drinkkaart";
|
import { drinkkaartRouter } from "./drinkkaart";
|
||||||
|
|
||||||
// Registration opens at this date — reminders fire 1 hour before
|
// Registration opens at this date — reminders fire 24 hours and 1 hour before
|
||||||
const REGISTRATION_OPENS_AT = new Date("2026-03-16T19:00:00+01:00");
|
const REGISTRATION_OPENS_AT = new Date("2026-03-16T19:00:00+01:00");
|
||||||
const REMINDER_WINDOW_START = new Date(
|
const REMINDER_1H_WINDOW_START = new Date(
|
||||||
REGISTRATION_OPENS_AT.getTime() - 60 * 60 * 1000,
|
REGISTRATION_OPENS_AT.getTime() - 60 * 60 * 1000,
|
||||||
);
|
);
|
||||||
|
const REMINDER_24H_WINDOW_START = new Date(
|
||||||
|
REGISTRATION_OPENS_AT.getTime() - 25 * 60 * 60 * 1000,
|
||||||
|
);
|
||||||
|
const REMINDER_24H_WINDOW_END = new Date(
|
||||||
|
REGISTRATION_OPENS_AT.getTime() - 23 * 60 * 60 * 1000,
|
||||||
|
);
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Shared helpers
|
// Shared helpers
|
||||||
@@ -827,9 +835,10 @@ export const appRouter = {
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribe an email address to receive a reminder 1 hour before registration
|
* Subscribe an email address to receive reminders before registration opens:
|
||||||
* opens. Silently deduplicates — if the email is already subscribed, returns
|
* one 24 hours before and one 1 hour before. Silently deduplicates — if the
|
||||||
* ok:true without error. Returns ok:false if registration is already open.
|
* email is already subscribed, returns ok:true without error. Returns
|
||||||
|
* ok:false if registration is already open.
|
||||||
*/
|
*/
|
||||||
subscribeReminder: publicProcedure
|
subscribeReminder: publicProcedure
|
||||||
.input(z.object({ email: z.string().email() }))
|
.input(z.object({ email: z.string().email() }))
|
||||||
@@ -858,6 +867,11 @@ export const appRouter = {
|
|||||||
email: input.email,
|
email: input.email,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Fire-and-forget — don't let a mail failure block the response
|
||||||
|
sendSubscriptionConfirmationEmail({ to: input.email }).catch((err) =>
|
||||||
|
console.error("Failed to send subscription confirmation email:", err),
|
||||||
|
);
|
||||||
|
|
||||||
return { ok: true };
|
return { ok: true };
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@@ -867,8 +881,9 @@ export const appRouter = {
|
|||||||
* header. Should be called by a Cloudflare Cron Trigger at the top of
|
* header. Should be called by a Cloudflare Cron Trigger at the top of
|
||||||
* every hour, or directly via `POST /api/cron/reminders`.
|
* every hour, or directly via `POST /api/cron/reminders`.
|
||||||
*
|
*
|
||||||
* Only sends when the current time is within the 1-hour reminder window
|
* Fires two waves:
|
||||||
* (between REGISTRATION_OPENS_AT - 1h and REGISTRATION_OPENS_AT).
|
* - 24 hours before: window [REGISTRATION_OPENS_AT - 25h, REGISTRATION_OPENS_AT - 23h)
|
||||||
|
* - 1 hour before: window [REGISTRATION_OPENS_AT - 1h, REGISTRATION_OPENS_AT)
|
||||||
*/
|
*/
|
||||||
sendReminders: publicProcedure
|
sendReminders: publicProcedure
|
||||||
.input(z.object({ secret: z.string() }))
|
.input(z.object({ secret: z.string() }))
|
||||||
@@ -879,34 +894,61 @@ export const appRouter = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const windowStart = REMINDER_WINDOW_START.getTime();
|
const in24hWindow =
|
||||||
const windowEnd = REGISTRATION_OPENS_AT.getTime();
|
now >= REMINDER_24H_WINDOW_START.getTime() &&
|
||||||
|
now < REMINDER_24H_WINDOW_END.getTime();
|
||||||
|
const in1hWindow =
|
||||||
|
now >= REMINDER_1H_WINDOW_START.getTime() &&
|
||||||
|
now < REGISTRATION_OPENS_AT.getTime();
|
||||||
|
|
||||||
// Only send during the reminder window
|
if (!in24hWindow && !in1hWindow) {
|
||||||
if (now < windowStart || now >= windowEnd) {
|
|
||||||
return { sent: 0, skipped: true, reason: "outside_window" as const };
|
return { sent: 0, skipped: true, reason: "outside_window" as const };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch all unsent reminders
|
|
||||||
const pending = await db
|
|
||||||
.select()
|
|
||||||
.from(reminder)
|
|
||||||
.where(isNull(reminder.sentAt));
|
|
||||||
|
|
||||||
let sent = 0;
|
let sent = 0;
|
||||||
const errors: string[] = [];
|
const errors: string[] = [];
|
||||||
|
|
||||||
for (const row of pending) {
|
if (in24hWindow) {
|
||||||
try {
|
// Fetch reminders where the 24h email has not been sent yet
|
||||||
await sendReminderEmail({ to: row.email });
|
const pending = await db
|
||||||
await db
|
.select()
|
||||||
.update(reminder)
|
.from(reminder)
|
||||||
.set({ sentAt: new Date() })
|
.where(isNull(reminder.sent24hAt));
|
||||||
.where(eq(reminder.id, row.id));
|
|
||||||
sent++;
|
for (const row of pending) {
|
||||||
} catch (err) {
|
try {
|
||||||
errors.push(`${row.email}: ${String(err)}`);
|
await sendReminder24hEmail({ to: row.email });
|
||||||
console.error(`Failed to send reminder to ${row.email}:`, err);
|
await db
|
||||||
|
.update(reminder)
|
||||||
|
.set({ sent24hAt: new Date() })
|
||||||
|
.where(eq(reminder.id, row.id));
|
||||||
|
sent++;
|
||||||
|
} catch (err) {
|
||||||
|
errors.push(`24h ${row.email}: ${String(err)}`);
|
||||||
|
console.error(`Failed to send 24h reminder to ${row.email}:`, err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in1hWindow) {
|
||||||
|
// Fetch reminders where the 1h email has not been sent yet
|
||||||
|
const pending = await db
|
||||||
|
.select()
|
||||||
|
.from(reminder)
|
||||||
|
.where(isNull(reminder.sentAt));
|
||||||
|
|
||||||
|
for (const row of pending) {
|
||||||
|
try {
|
||||||
|
await sendReminderEmail({ to: row.email });
|
||||||
|
await db
|
||||||
|
.update(reminder)
|
||||||
|
.set({ sentAt: new Date() })
|
||||||
|
.where(eq(reminder.id, row.id));
|
||||||
|
sent++;
|
||||||
|
} catch (err) {
|
||||||
|
errors.push(`1h ${row.email}: ${String(err)}`);
|
||||||
|
console.error(`Failed to send 1h reminder to ${row.email}:`, err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1032,32 +1074,59 @@ export async function runSendReminders(): Promise<{
|
|||||||
errors: string[];
|
errors: string[];
|
||||||
}> {
|
}> {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const windowStart = REMINDER_WINDOW_START.getTime();
|
const in24hWindow =
|
||||||
const windowEnd = REGISTRATION_OPENS_AT.getTime();
|
now >= REMINDER_24H_WINDOW_START.getTime() &&
|
||||||
|
now < REMINDER_24H_WINDOW_END.getTime();
|
||||||
|
const in1hWindow =
|
||||||
|
now >= REMINDER_1H_WINDOW_START.getTime() &&
|
||||||
|
now < REGISTRATION_OPENS_AT.getTime();
|
||||||
|
|
||||||
if (now < windowStart || now >= windowEnd) {
|
if (!in24hWindow && !in1hWindow) {
|
||||||
return { sent: 0, skipped: true, reason: "outside_window", errors: [] };
|
return { sent: 0, skipped: true, reason: "outside_window", errors: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const pending = await db
|
|
||||||
.select()
|
|
||||||
.from(reminder)
|
|
||||||
.where(isNull(reminder.sentAt));
|
|
||||||
|
|
||||||
let sent = 0;
|
let sent = 0;
|
||||||
const errors: string[] = [];
|
const errors: string[] = [];
|
||||||
|
|
||||||
for (const row of pending) {
|
if (in24hWindow) {
|
||||||
try {
|
const pending = await db
|
||||||
await sendReminderEmail({ to: row.email });
|
.select()
|
||||||
await db
|
.from(reminder)
|
||||||
.update(reminder)
|
.where(isNull(reminder.sent24hAt));
|
||||||
.set({ sentAt: new Date() })
|
|
||||||
.where(eq(reminder.id, row.id));
|
for (const row of pending) {
|
||||||
sent++;
|
try {
|
||||||
} catch (err) {
|
await sendReminder24hEmail({ to: row.email });
|
||||||
errors.push(`${row.email}: ${String(err)}`);
|
await db
|
||||||
console.error(`Failed to send reminder to ${row.email}:`, err);
|
.update(reminder)
|
||||||
|
.set({ sent24hAt: new Date() })
|
||||||
|
.where(eq(reminder.id, row.id));
|
||||||
|
sent++;
|
||||||
|
} catch (err) {
|
||||||
|
errors.push(`24h ${row.email}: ${String(err)}`);
|
||||||
|
console.error(`Failed to send 24h reminder to ${row.email}:`, err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in1hWindow) {
|
||||||
|
const pending = await db
|
||||||
|
.select()
|
||||||
|
.from(reminder)
|
||||||
|
.where(isNull(reminder.sentAt));
|
||||||
|
|
||||||
|
for (const row of pending) {
|
||||||
|
try {
|
||||||
|
await sendReminderEmail({ to: row.email });
|
||||||
|
await db
|
||||||
|
.update(reminder)
|
||||||
|
.set({ sentAt: new Date() })
|
||||||
|
.where(eq(reminder.id, row.id));
|
||||||
|
sent++;
|
||||||
|
} catch (err) {
|
||||||
|
errors.push(`1h ${row.email}: ${String(err)}`);
|
||||||
|
console.error(`Failed to send 1h reminder to ${row.email}:`, err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
packages/db/src/migrations/0009_reminder_24h.sql
Normal file
2
packages/db/src/migrations/0009_reminder_24h.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
-- Add sent_24h_at column to track whether the 24-hour-before reminder was sent
|
||||||
|
ALTER TABLE `reminder` ADD `sent_24h_at` integer;
|
||||||
@@ -6,6 +6,9 @@ export const reminder = sqliteTable(
|
|||||||
{
|
{
|
||||||
id: text("id").primaryKey(), // UUID
|
id: text("id").primaryKey(), // UUID
|
||||||
email: text("email").notNull(),
|
email: text("email").notNull(),
|
||||||
|
/** Set when the 24-hours-before reminder has been sent. */
|
||||||
|
sent24hAt: integer("sent_24h_at", { mode: "timestamp_ms" }),
|
||||||
|
/** Set when the 1-hour-before reminder has been sent. */
|
||||||
sentAt: integer("sent_at", { mode: "timestamp_ms" }),
|
sentAt: integer("sent_at", { mode: "timestamp_ms" }),
|
||||||
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
createdAt: integer("created_at", { mode: "timestamp_ms" })
|
||||||
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
.default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export const web = await TanStackStart("web", {
|
|||||||
// Cron secret for protected scheduled endpoints
|
// Cron secret for protected scheduled endpoints
|
||||||
CRON_SECRET: getEnvVar("CRON_SECRET"),
|
CRON_SECRET: getEnvVar("CRON_SECRET"),
|
||||||
},
|
},
|
||||||
// Fire every hour so the reminder check can run at 18:00 on 2026-03-16
|
// Fire every hour so reminder checks can run at 19:00 on 2026-03-15 (24h) and 18:00 on 2026-03-16 (1h)
|
||||||
crons: ["0 * * * *"],
|
crons: ["0 * * * *"],
|
||||||
domains: ["kunstenkamp.be", "www.kunstenkamp.be"],
|
domains: ["kunstenkamp.be", "www.kunstenkamp.be"],
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user