581 lines
19 KiB
JavaScript
581 lines
19 KiB
JavaScript
import { Resend } from "resend";
|
|
|
|
const resend = new Resend(process.env.RESEND_API_KEY);
|
|
|
|
/**
|
|
* Send event registration confirmation email
|
|
*/
|
|
export async function sendEventRegistrationEmail(registration, eventData) {
|
|
const formatDate = (dateString) => {
|
|
const date = new Date(dateString);
|
|
return new Intl.DateTimeFormat("en-US", {
|
|
weekday: "long",
|
|
year: "numeric",
|
|
month: "long",
|
|
day: "numeric",
|
|
}).format(date);
|
|
};
|
|
|
|
const formatTime = (startDate, endDate) => {
|
|
const start = new Date(startDate);
|
|
const end = new Date(endDate);
|
|
|
|
const timeFormat = new Intl.DateTimeFormat("en-US", {
|
|
hour: "numeric",
|
|
minute: "2-digit",
|
|
timeZoneName: "short",
|
|
});
|
|
|
|
return `${timeFormat.format(start)} - ${timeFormat.format(end)}`;
|
|
};
|
|
|
|
try {
|
|
const { data, error } = await resend.emails.send({
|
|
from: "Ghost Guild <events@babyghosts.org>",
|
|
to: [registration.email],
|
|
subject: `You're registered for ${eventData.title}`,
|
|
html: `
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<style>
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
line-height: 1.6;
|
|
color: #333;
|
|
max-width: 600px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
}
|
|
.header {
|
|
background-color: #1a1a2e;
|
|
color: #fff;
|
|
padding: 30px;
|
|
text-align: center;
|
|
border-radius: 8px 8px 0 0;
|
|
}
|
|
.content {
|
|
background-color: #f9f9f9;
|
|
padding: 30px;
|
|
border-radius: 0 0 8px 8px;
|
|
}
|
|
.event-details {
|
|
background-color: #fff;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
margin: 20px 0;
|
|
border-left: 4px solid #3b82f6;
|
|
}
|
|
.detail-row {
|
|
margin: 10px 0;
|
|
}
|
|
.label {
|
|
font-weight: 600;
|
|
color: #666;
|
|
font-size: 14px;
|
|
}
|
|
.value {
|
|
color: #1a1a2e;
|
|
font-size: 16px;
|
|
}
|
|
.button {
|
|
display: inline-block;
|
|
background-color: #3b82f6;
|
|
color: #fff;
|
|
padding: 12px 30px;
|
|
text-decoration: none;
|
|
border-radius: 6px;
|
|
margin: 20px 0;
|
|
}
|
|
.footer {
|
|
text-align: center;
|
|
margin-top: 30px;
|
|
padding-top: 20px;
|
|
border-top: 1px solid #ddd;
|
|
color: #666;
|
|
font-size: 14px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="header">
|
|
<h1 style="margin: 0;">You're Registered! 🎉</h1>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<p>Hi ${registration.name},</p>
|
|
|
|
<p>Thank you for registering for <strong>${eventData.title}</strong>!</p>
|
|
|
|
<div class="event-details">
|
|
<div class="detail-row">
|
|
<div class="label">Date</div>
|
|
<div class="value">${formatDate(eventData.startDate)}</div>
|
|
</div>
|
|
|
|
<div class="detail-row">
|
|
<div class="label">Time</div>
|
|
<div class="value">${formatTime(eventData.startDate, eventData.endDate)}</div>
|
|
</div>
|
|
|
|
<div class="detail-row">
|
|
<div class="label">Location</div>
|
|
<div class="value">${eventData.location}</div>
|
|
</div>
|
|
</div>
|
|
|
|
${eventData.description ? `<p>${eventData.description}</p>` : ""}
|
|
|
|
${
|
|
registration.ticketType &&
|
|
registration.ticketType !== "guest" &&
|
|
registration.amountPaid > 0
|
|
? `
|
|
<div class="event-details" style="margin-top: 20px;">
|
|
<h3 style="margin-top: 0; color: #1a1a2e;">Ticket Information</h3>
|
|
<div class="detail-row">
|
|
<div class="label">Ticket Type</div>
|
|
<div class="value">${registration.ticketType === "member" ? "Member Ticket" : "Public Ticket"}</div>
|
|
</div>
|
|
<div class="detail-row">
|
|
<div class="label">Amount Paid</div>
|
|
<div class="value">$${registration.amountPaid.toFixed(2)} CAD</div>
|
|
</div>
|
|
${
|
|
registration.paymentId
|
|
? `
|
|
<div class="detail-row">
|
|
<div class="label">Transaction ID</div>
|
|
<div class="value" style="font-size: 12px; font-family: monospace;">${registration.paymentId}</div>
|
|
</div>
|
|
`
|
|
: ""
|
|
}
|
|
</div>
|
|
`
|
|
: registration.ticketType === "member" &&
|
|
registration.amountPaid === 0
|
|
? `
|
|
<div style="background-color: #e0e7ff; border-left: 4px solid #6366f1; padding: 15px; border-radius: 4px; margin: 20px 0;">
|
|
<p style="margin: 0; color: #4338ca;">
|
|
<strong>✨ Member Benefit:</strong> This event is free for Ghost Guild members!
|
|
</p>
|
|
</div>
|
|
`
|
|
: ""
|
|
}
|
|
|
|
<center>
|
|
<a href="${process.env.BASE_URL || "https://ghostguild.org"}/events/${eventData.slug || eventData._id}" class="button">
|
|
View Event Details
|
|
</a>
|
|
</center>
|
|
|
|
<p style="margin-top: 30px; font-size: 14px; color: #666;">
|
|
<strong>Need to cancel?</strong><br>
|
|
Visit the event page and click "Cancel Registration" to remove yourself from the attendee list.
|
|
</p>
|
|
</div>
|
|
|
|
<div class="footer">
|
|
<p>Ghost Guild</p>
|
|
<p>
|
|
Questions? Email us at
|
|
<a href="mailto:events@babyghosts.org">events@babyghosts.org</a>
|
|
</p>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
`,
|
|
});
|
|
|
|
if (error) {
|
|
console.error("Failed to send registration email:", error);
|
|
return { success: false, error };
|
|
}
|
|
|
|
return { success: true, data };
|
|
} catch (error) {
|
|
console.error("Error sending registration email:", error);
|
|
return { success: false, error };
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Send event cancellation confirmation email
|
|
*/
|
|
export async function sendEventCancellationEmail(registration, eventData) {
|
|
try {
|
|
const { data, error } = await resend.emails.send({
|
|
from: "Ghost Guild <events@ghostguild.org>",
|
|
to: [registration.email],
|
|
subject: `Registration cancelled: ${eventData.title}`,
|
|
html: `
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<style>
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
line-height: 1.6;
|
|
color: #333;
|
|
max-width: 600px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
}
|
|
.header {
|
|
background-color: #1a1a2e;
|
|
color: #fff;
|
|
padding: 30px;
|
|
text-align: center;
|
|
border-radius: 8px 8px 0 0;
|
|
}
|
|
.content {
|
|
background-color: #f9f9f9;
|
|
padding: 30px;
|
|
border-radius: 0 0 8px 8px;
|
|
}
|
|
.button {
|
|
display: inline-block;
|
|
background-color: #3b82f6;
|
|
color: #fff;
|
|
padding: 12px 30px;
|
|
text-decoration: none;
|
|
border-radius: 6px;
|
|
margin: 20px 0;
|
|
}
|
|
.footer {
|
|
text-align: center;
|
|
margin-top: 30px;
|
|
padding-top: 20px;
|
|
border-top: 1px solid #ddd;
|
|
color: #666;
|
|
font-size: 14px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="header">
|
|
<h1 style="margin: 0;">Registration Cancelled</h1>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<p>Hi ${registration.name},</p>
|
|
|
|
<p>Your registration for <strong>${eventData.title}</strong> has been cancelled.</p>
|
|
|
|
<p>We're sorry you can't make it. You can always register again if your plans change.</p>
|
|
|
|
<center>
|
|
<a href="${process.env.BASE_URL || "https://ghostguild.org"}/events" class="button">
|
|
Browse Other Events
|
|
</a>
|
|
</center>
|
|
</div>
|
|
|
|
<div class="footer">
|
|
<p>Ghost Guild</p>
|
|
<p>
|
|
Questions? Email us at
|
|
<a href="mailto:events@babyghosts.org">events@babyghosts.org</a>
|
|
</p>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
`,
|
|
});
|
|
|
|
if (error) {
|
|
console.error("Failed to send cancellation email:", error);
|
|
return { success: false, error };
|
|
}
|
|
|
|
return { success: true, data };
|
|
} catch (error) {
|
|
console.error("Error sending cancellation email:", error);
|
|
return { success: false, error };
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Send series pass confirmation email
|
|
*/
|
|
export async function sendSeriesPassConfirmation(options) {
|
|
const { to, name, series, ticket, events, paymentId } = options;
|
|
|
|
const formatDate = (dateString) => {
|
|
const date = new Date(dateString);
|
|
return new Intl.DateTimeFormat("en-US", {
|
|
weekday: "long",
|
|
year: "numeric",
|
|
month: "long",
|
|
day: "numeric",
|
|
}).format(date);
|
|
};
|
|
|
|
const formatTime = (startDate, endDate) => {
|
|
const start = new Date(startDate);
|
|
const end = new Date(endDate);
|
|
|
|
const timeFormat = new Intl.DateTimeFormat("en-US", {
|
|
hour: "numeric",
|
|
minute: "2-digit",
|
|
timeZoneName: "short",
|
|
});
|
|
|
|
return `${timeFormat.format(start)} - ${timeFormat.format(end)}`;
|
|
};
|
|
|
|
const formatPrice = (price, currency = "CAD") => {
|
|
if (price === 0) return "Free";
|
|
return new Intl.NumberFormat("en-CA", {
|
|
style: "currency",
|
|
currency,
|
|
}).format(price);
|
|
};
|
|
|
|
const seriesTypeLabels = {
|
|
workshop_series: "Workshop Series",
|
|
recurring_meetup: "Recurring Meetup",
|
|
multi_day: "Multi-Day Event",
|
|
course: "Course",
|
|
tournament: "Tournament",
|
|
};
|
|
|
|
try {
|
|
const { data, error } = await resend.emails.send({
|
|
from: "Ghost Guild <events@babyghosts.org>",
|
|
to: [to],
|
|
subject: `Your Series Pass for ${series.title}`,
|
|
html: `
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<style>
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
line-height: 1.6;
|
|
color: #333;
|
|
max-width: 600px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
}
|
|
.header {
|
|
background: linear-gradient(135deg, #7c3aed 0%, #5b21b6 100%);
|
|
color: #fff;
|
|
padding: 30px;
|
|
text-align: center;
|
|
border-radius: 8px 8px 0 0;
|
|
}
|
|
.content {
|
|
background-color: #f9f9f9;
|
|
padding: 30px;
|
|
border-radius: 0 0 8px 8px;
|
|
}
|
|
.pass-details {
|
|
background-color: #fff;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
margin: 20px 0;
|
|
border-left: 4px solid #7c3aed;
|
|
}
|
|
.event-list {
|
|
background-color: #fff;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
margin: 20px 0;
|
|
}
|
|
.event-item {
|
|
padding: 15px;
|
|
margin: 10px 0;
|
|
background-color: #f9f9f9;
|
|
border-radius: 6px;
|
|
border-left: 3px solid #7c3aed;
|
|
}
|
|
.detail-row {
|
|
margin: 10px 0;
|
|
}
|
|
.label {
|
|
font-weight: 600;
|
|
color: #666;
|
|
font-size: 14px;
|
|
}
|
|
.value {
|
|
color: #1a1a2e;
|
|
font-size: 16px;
|
|
}
|
|
.member-benefit {
|
|
background-color: #dcfce7;
|
|
border: 2px solid #86efac;
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
margin: 20px 0;
|
|
}
|
|
.footer {
|
|
text-align: center;
|
|
padding: 20px;
|
|
color: #666;
|
|
font-size: 14px;
|
|
}
|
|
.button {
|
|
display: inline-block;
|
|
background-color: #7c3aed;
|
|
color: #fff;
|
|
padding: 12px 24px;
|
|
text-decoration: none;
|
|
border-radius: 6px;
|
|
margin: 10px 0;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="header">
|
|
<h1 style="margin: 0; font-size: 28px;">🎫 Your Series Pass is Ready!</h1>
|
|
<p style="margin: 10px 0 0 0; opacity: 0.9;">You're registered for all events</p>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<p style="font-size: 18px; margin-bottom: 10px;">Hi ${name},</p>
|
|
|
|
<p>
|
|
Great news! Your series pass for <strong>${series.title}</strong> is confirmed.
|
|
You're now registered for all ${events.length} events in this ${seriesTypeLabels[series.type] || "series"}.
|
|
</p>
|
|
|
|
${
|
|
ticket.isFree && ticket.type === "member"
|
|
? `
|
|
<div class="member-benefit">
|
|
<p style="margin: 0; font-weight: 600; color: #166534;">
|
|
✨ Member Benefit
|
|
</p>
|
|
<p style="margin: 5px 0 0 0; color: #166534;">
|
|
This series pass is free for Ghost Guild members. Thank you for being part of our community!
|
|
</p>
|
|
</div>
|
|
`
|
|
: ""
|
|
}
|
|
|
|
<div class="pass-details">
|
|
<h2 style="margin: 0 0 15px 0; color: #7c3aed; font-size: 20px;">Series Pass Details</h2>
|
|
|
|
<div class="detail-row">
|
|
<div class="label">Series</div>
|
|
<div class="value">${series.title}</div>
|
|
</div>
|
|
|
|
${
|
|
series.description
|
|
? `
|
|
<div class="detail-row">
|
|
<div class="label">About</div>
|
|
<div class="value">${series.description}</div>
|
|
</div>
|
|
`
|
|
: ""
|
|
}
|
|
|
|
<div class="detail-row">
|
|
<div class="label">Pass Type</div>
|
|
<div class="value">${ticket.type === "member" ? "Member Pass" : "Public Pass"}</div>
|
|
</div>
|
|
|
|
<div class="detail-row">
|
|
<div class="label">Amount Paid</div>
|
|
<div class="value">${formatPrice(ticket.price, ticket.currency)}</div>
|
|
</div>
|
|
|
|
${
|
|
paymentId
|
|
? `
|
|
<div class="detail-row">
|
|
<div class="label">Transaction ID</div>
|
|
<div class="value" style="font-family: monospace; font-size: 14px;">${paymentId}</div>
|
|
</div>
|
|
`
|
|
: ""
|
|
}
|
|
|
|
<div class="detail-row">
|
|
<div class="label">Total Events</div>
|
|
<div class="value">${events.length} events included</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="event-list">
|
|
<h3 style="margin: 0 0 15px 0; color: #1a1a2e; font-size: 18px;">Your Event Schedule</h3>
|
|
<p style="color: #666; font-size: 14px; margin-bottom: 15px;">
|
|
You're automatically registered for all of these events:
|
|
</p>
|
|
|
|
${events
|
|
.map(
|
|
(event, index) => `
|
|
<div class="event-item">
|
|
<div style="font-weight: 600; color: #7c3aed; margin-bottom: 5px;">
|
|
Event ${index + 1}: ${event.title}
|
|
</div>
|
|
<div style="font-size: 14px; color: #666; margin: 5px 0;">
|
|
📅 ${formatDate(event.startDate)}
|
|
</div>
|
|
<div style="font-size: 14px; color: #666; margin: 5px 0;">
|
|
🕐 ${formatTime(event.startDate, event.endDate)}
|
|
</div>
|
|
<div style="font-size: 14px; color: #666; margin: 5px 0;">
|
|
📍 ${event.location}
|
|
</div>
|
|
</div>
|
|
`,
|
|
)
|
|
.join("")}
|
|
</div>
|
|
|
|
<div style="text-align: center; margin: 30px 0;">
|
|
<a href="https://ghostguild.org/dashboard" class="button">
|
|
View in Dashboard
|
|
</a>
|
|
</div>
|
|
|
|
<div style="background-color: #fff; padding: 20px; border-radius: 8px; border: 1px solid #e5e7eb;">
|
|
<h3 style="margin: 0 0 10px 0; font-size: 16px;">What's Next?</h3>
|
|
<ul style="margin: 10px 0; padding-left: 20px;">
|
|
<li>Mark these dates in your calendar</li>
|
|
<li>You'll receive individual reminders before each event</li>
|
|
<li>Event links and materials will be shared closer to each date</li>
|
|
<li>Join the conversation in our Slack community</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="footer">
|
|
<p style="margin: 10px 0;">
|
|
Questions? Email us at
|
|
<a href="mailto:events@babyghosts.org">events@babyghosts.org</a>
|
|
</p>
|
|
<p style="margin: 10px 0; color: #999; font-size: 12px;">
|
|
Ghost Guild • Building solidarity economies in gaming
|
|
</p>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
`,
|
|
});
|
|
|
|
if (error) {
|
|
console.error("Failed to send series pass confirmation email:", error);
|
|
return { success: false, error };
|
|
}
|
|
|
|
return { success: true, data };
|
|
} catch (error) {
|
|
console.error("Error sending series pass confirmation email:", error);
|
|
return { success: false, error };
|
|
}
|
|
}
|