NestJS + Prisma/Postgres API shared by the site, admin and attendee app. Ports the site's D1 application flow and review, stores every inquiry form, sells tickets with discount codes (manual payment confirmation), and runs booth/startup/mystery-investee QR scans with derived points and raffles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
289 lines
12 KiB
TypeScript
289 lines
12 KiB
TypeScript
import type { Mail } from "../common/mail.js";
|
||
import type { InquiryIntent, InquiryPayload } from "./inquiry.js";
|
||
import { boothSizes } from "./exhibit.js";
|
||
import { site } from "./site.js";
|
||
import { ADMIN_URL, SITE_URL } from "../common/env.js";
|
||
|
||
type Content = Omit<Mail, "to" | "replyTo">;
|
||
type Row = [label: string, value: string | undefined];
|
||
|
||
const FONT = "-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif";
|
||
const GREEN = "#30614c";
|
||
const DARK = "#1a4034";
|
||
const MINT = "#e8f2ec";
|
||
|
||
export function escapeHtml(value: string) {
|
||
return value
|
||
.replace(/&/g, "&")
|
||
.replace(/</g, "<")
|
||
.replace(/>/g, ">")
|
||
.replace(/"/g, """)
|
||
.replace(/'/g, "'");
|
||
}
|
||
|
||
const isUrl = (value: string) => /^https?:\/\/\S+$/i.test(value);
|
||
|
||
function rowsHtml(rows: Row[]) {
|
||
return rows
|
||
.filter((row): row is [string, string] => Boolean(row[1]?.trim()))
|
||
.map(([label, value]) => {
|
||
const safe = escapeHtml(value.trim());
|
||
const body = isUrl(value.trim())
|
||
? `<a href="${safe}" style="color:${GREEN};word-break:break-all;">${safe}</a>`
|
||
: safe.replace(/\n/g, "<br>");
|
||
return `<tr>
|
||
<td style="padding:12px 12px 12px 0;border-bottom:1px solid ${MINT};width:34%;vertical-align:top;font-size:11px;letter-spacing:0.12em;text-transform:uppercase;color:${GREEN};font-weight:700;">${escapeHtml(label)}</td>
|
||
<td style="padding:12px 0;border-bottom:1px solid ${MINT};vertical-align:top;font-size:15px;line-height:1.6;color:${DARK};">${body}</td>
|
||
</tr>`;
|
||
})
|
||
.join("");
|
||
}
|
||
|
||
function rowsText(rows: Row[]) {
|
||
return rows
|
||
.filter(([, value]) => value?.trim())
|
||
.map(([label, value]) => `${label}: ${value!.trim()}`)
|
||
.join("\n");
|
||
}
|
||
|
||
/** One branded, table-based layout for every GRV email. All dynamic text is escaped here. */
|
||
function layout(opts: {
|
||
subject: string;
|
||
kicker: string;
|
||
title: string;
|
||
paragraphs: string[];
|
||
rows?: Row[];
|
||
cta?: { label: string; href: string };
|
||
}): Content {
|
||
const { subject, kicker, title, paragraphs, rows = [], cta } = opts;
|
||
const html = `<!doctype html>
|
||
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${escapeHtml(subject)}</title></head>
|
||
<body style="margin:0;padding:0;background:#f4f7f5;font-family:${FONT};">
|
||
<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="background:#f4f7f5;padding:24px 12px;">
|
||
<tr><td align="center">
|
||
<table role="presentation" width="600" cellspacing="0" cellpadding="0" style="width:100%;max-width:600px;background:#ffffff;border-radius:16px;overflow:hidden;">
|
||
<tr><td style="padding:24px 32px;border-bottom:1px solid ${MINT};">
|
||
<img src="${SITE_URL}/GRVLogo.png" width="160" alt="GRV Summit" style="display:block;width:160px;max-width:50%;height:auto;border:0;">
|
||
</td></tr>
|
||
<tr><td style="padding:32px 32px 28px;background:${DARK};">
|
||
<p style="margin:0 0 8px;font-size:11px;letter-spacing:0.22em;text-transform:uppercase;color:#b9d8c9;font-weight:700;">${escapeHtml(kicker)}</p>
|
||
<h1 style="margin:0;font-size:26px;line-height:1.3;color:#ffffff;font-weight:700;">${escapeHtml(title)}</h1>
|
||
</td></tr>
|
||
<tr><td style="padding:28px 32px 8px;">
|
||
${paragraphs.map((p) => `<p style="margin:0 0 16px;font-size:15px;line-height:1.7;color:${DARK};">${escapeHtml(p)}</p>`).join("")}
|
||
${rows.length ? `<table role="presentation" width="100%" cellspacing="0" cellpadding="0" style="margin:8px 0 16px;">${rowsHtml(rows)}</table>` : ""}
|
||
${
|
||
cta
|
||
? `<p style="margin:8px 0 24px;"><a href="${escapeHtml(cta.href)}" style="display:inline-block;background:${GREEN};color:#ffffff;text-decoration:none;font-weight:700;font-size:15px;padding:12px 24px;border-radius:999px;">${escapeHtml(cta.label)}</a></p>`
|
||
: ""
|
||
}
|
||
</td></tr>
|
||
<tr><td style="padding:20px 32px 28px;background:${MINT};">
|
||
<p style="margin:0;font-size:12px;line-height:1.7;color:${GREEN};">
|
||
${escapeHtml(site.name)} · ${escapeHtml(site.dates.label)} · ${escapeHtml(site.venue.name)}<br>
|
||
Presented by the Ethiopian Diaspora Trust Fund · <a href="${SITE_URL}" style="color:${GREEN};">${SITE_URL.replace(/^https?:\/\//, "")}</a>
|
||
</p>
|
||
</td></tr>
|
||
</table>
|
||
</td></tr>
|
||
</table>
|
||
</body></html>`;
|
||
|
||
const text = [
|
||
kicker.toUpperCase(),
|
||
title,
|
||
"",
|
||
...paragraphs,
|
||
rows.length ? `\n${rowsText(rows)}` : "",
|
||
cta ? `\n${cta.label}: ${cta.href}` : "",
|
||
`\n— ${site.name} · ${SITE_URL}`,
|
||
].join("\n");
|
||
|
||
return { subject, html, text };
|
||
}
|
||
|
||
const intentCopy: Record<InquiryIntent, { label: string; thanks: string }> = {
|
||
general: { label: "General inquiry", thanks: "Thanks for reaching out. Our team will reply within two working days." },
|
||
sales: { label: "Sales inquiry", thanks: "Thanks for reaching out. Our team will reply within two working days." },
|
||
press: { label: "Press inquiry", thanks: "Thanks for your interest in covering GRV Summit. Our media team will be in touch." },
|
||
partnership: {
|
||
label: "Partnership request",
|
||
thanks: "Thanks for your interest in partnering with GRV Summit. We'll send partnership information and next steps shortly.",
|
||
},
|
||
sponsor: {
|
||
label: "Sponsorship inquiry",
|
||
thanks: "Thanks for your interest in sponsoring GRV Summit. Our partnerships team will follow up with packages and availability.",
|
||
},
|
||
exhibitor: {
|
||
label: "Booth request",
|
||
thanks: "Thanks for requesting a booth. We'll confirm availability, pricing and the floor plan with you shortly.",
|
||
},
|
||
startup_referral: {
|
||
label: "Startup recommendation",
|
||
thanks: "Thanks for championing a startup. Our programming team reviews every recommendation.",
|
||
},
|
||
newsletter: {
|
||
label: "Newsletter signup",
|
||
thanks: "You're on the list. We'll share speaker announcements, programme updates and pitch competition news.",
|
||
},
|
||
};
|
||
|
||
function inquiryRows(data: InquiryPayload): Row[] {
|
||
const booth = boothSizes.find((size) => size.value === data.boothSize)?.label ?? data.boothSize;
|
||
return [
|
||
["Name", data.name],
|
||
["Email", data.email],
|
||
["Phone", data.phone],
|
||
["Company", data.company],
|
||
["Booth package", booth],
|
||
["Startup", data.startupName],
|
||
["Startup website", data.startupWebsite],
|
||
["Sector", data.startupSector],
|
||
["Message", data.message],
|
||
];
|
||
}
|
||
|
||
export function inquiryStaffEmail(data: InquiryPayload): Content {
|
||
const { label } = intentCopy[data.intent];
|
||
const who = data.company ? `${data.name} (${data.company})` : data.name;
|
||
return layout({
|
||
subject: `[GRV] ${label}: ${data.startupName ?? who}`,
|
||
kicker: "New website submission",
|
||
title: label,
|
||
paragraphs: [`${who} submitted the ${label.toLowerCase()} form. Reply to this email to answer them directly.`],
|
||
rows: inquiryRows(data),
|
||
});
|
||
}
|
||
|
||
export function inquiryConfirmationEmail(data: InquiryPayload): Content {
|
||
const { label, thanks } = intentCopy[data.intent];
|
||
return layout({
|
||
subject: `We received your ${label.toLowerCase()} · GRV Summit`,
|
||
kicker: label,
|
||
title: `Thank you, ${data.firstName ?? data.name.split(" ")[0]}`,
|
||
paragraphs: [thanks, "Here's a copy of what you sent:"],
|
||
rows: inquiryRows(data).filter(([key]) => key !== "Email"),
|
||
});
|
||
}
|
||
|
||
const resumeUrl = (token: string) => `${SITE_URL}/apply?token=${encodeURIComponent(token)}`;
|
||
|
||
export function applyResumeEmail(name: string, token: string): Content {
|
||
return layout({
|
||
subject: "Continue your GRV Summit application",
|
||
kicker: "Pitch competition",
|
||
title: `Your application is saved, ${name.split(" ")[0]}`,
|
||
paragraphs: [
|
||
"Use the link below to continue on any device. Your answers save after each step.",
|
||
"Anyone with this link can edit your draft, so keep it private.",
|
||
],
|
||
cta: { label: "Continue application", href: resumeUrl(token) },
|
||
});
|
||
}
|
||
|
||
export function applyReceivedEmail(opts: { name: string; startup: string; token: string; contactBy: string }): Content {
|
||
return layout({
|
||
subject: `Application received: ${opts.startup} · GRV Summit`,
|
||
kicker: "Pitch competition",
|
||
title: "Application received",
|
||
paragraphs: [
|
||
`Thank you, ${opts.name.split(" ")[0]}! Your application for ${opts.startup} has been received and is now locked.`,
|
||
`Our reviewers will read every answer. We'll contact you by ${opts.contactBy}.`,
|
||
],
|
||
cta: { label: "View your submission", href: resumeUrl(opts.token) },
|
||
});
|
||
}
|
||
|
||
export function applyStaffEmail(opts: { id: string; rows: Row[]; startup: string }): Content {
|
||
return layout({
|
||
subject: `[GRV] New application: ${opts.startup}`,
|
||
kicker: "Pitch competition",
|
||
title: `New application: ${opts.startup}`,
|
||
paragraphs: ["A startup just submitted its application."],
|
||
rows: opts.rows,
|
||
cta: { label: "Open in admin", href: `${ADMIN_URL}/applications/${opts.id}` },
|
||
});
|
||
}
|
||
|
||
const resultCopy = {
|
||
SHORTLISTED: {
|
||
title: "You've been shortlisted",
|
||
body: "Congratulations! Your startup has been shortlisted for the GRV Summit pitch competition. We'll be in touch shortly with next steps.",
|
||
},
|
||
FINALIST: {
|
||
title: "You're a finalist",
|
||
body: "Congratulations! Your startup has been selected as a finalist and will pitch on stage at GRV Summit. Our team will contact you with preparation details.",
|
||
},
|
||
ACCEPTED: {
|
||
title: "You've been accepted",
|
||
body: "Congratulations! Your startup has been accepted into the GRV Summit programme. Our team will contact you shortly with onboarding details and next steps.",
|
||
},
|
||
REJECTED: {
|
||
title: "An update on your application",
|
||
body: "Thank you for applying to the GRV Summit pitch competition. After careful review, we're unable to move your application forward this year. We received many strong applications and hope to see you at the summit and in future editions.",
|
||
},
|
||
} as const;
|
||
|
||
export type ResultStatus = keyof typeof resultCopy;
|
||
export const isResultStatus = (status: string): status is ResultStatus => status in resultCopy;
|
||
|
||
export function applyResultEmail(status: ResultStatus, name: string, startup: string): Content {
|
||
const copy = resultCopy[status];
|
||
return layout({
|
||
subject: `${copy.title} · ${startup} · GRV Summit`,
|
||
kicker: "Pitch competition",
|
||
title: copy.title,
|
||
paragraphs: [`Hi ${name.split(" ")[0]},`, copy.body],
|
||
});
|
||
}
|
||
|
||
export function otpEmail(code: string): Content {
|
||
return layout({
|
||
subject: `${code} is your GRV Summit sign-in code`,
|
||
kicker: "Sign in",
|
||
title: `Your code: ${code}`,
|
||
paragraphs: ["Enter this code to sign in. It expires in 10 minutes.", "If you didn't ask for it, you can ignore this email."],
|
||
});
|
||
}
|
||
|
||
type OrderLine = { name: string; qty: number; size?: string | null };
|
||
|
||
export function orderReceivedEmail(opts: {
|
||
name: string;
|
||
number: string;
|
||
kind: "TICKET" | "MERCH";
|
||
items: OrderLine[];
|
||
total: string;
|
||
instructions: string;
|
||
}): Content {
|
||
const merch = opts.kind === "MERCH";
|
||
return layout({
|
||
subject: `Order ${opts.number} received · GRV Summit`,
|
||
kicker: merch ? "Merch order" : "Tickets",
|
||
title: `Thanks, ${opts.name.split(" ")[0]}`,
|
||
paragraphs: [
|
||
merch
|
||
? "Your merch is reserved. Pay and collect it at the GRV booth by showing your pickup code in the app."
|
||
: opts.instructions,
|
||
],
|
||
rows: [
|
||
["Order", opts.number],
|
||
...opts.items.map((i): Row => [i.name, `${i.qty}${i.size ? ` × ${i.size}` : ""}`]),
|
||
["Total", opts.total],
|
||
],
|
||
});
|
||
}
|
||
|
||
export function ticketsIssuedEmail(opts: { name: string; number: string; tickets: { tierName: string; url: string }[] }): Content {
|
||
return layout({
|
||
subject: `Your GRV Summit tickets · ${opts.number}`,
|
||
kicker: "Tickets",
|
||
title: "You're going to GRV Summit",
|
||
paragraphs: [
|
||
`Hi ${opts.name.split(" ")[0]}, your payment is confirmed. Show a ticket QR at check-in.`,
|
||
"Sign in to the GRV Summit app with this email to see your tickets, scan booths and join the raffle.",
|
||
],
|
||
rows: opts.tickets.map((t, i): Row => [`${t.tierName} #${i + 1}`, t.url]),
|
||
});
|
||
}
|