fix: add @types/nodemailer and include event links in RSVP email content
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
"@types/node": "^20.4.5",
|
||||
"@types/cors": "^2.8.13",
|
||||
"@types/sqlite3": "^3.1.8",
|
||||
"@types/nodemailer": "^6.4.12",
|
||||
"typescript": "^5.1.6",
|
||||
"nodemon": "^3.0.1",
|
||||
"ts-node": "^10.9.1"
|
||||
|
||||
@@ -12,6 +12,7 @@ const transporter = nodemailer.createTransport({
|
||||
|
||||
export interface RSVPEmailData {
|
||||
eventTitle: string;
|
||||
eventSlug: string;
|
||||
name: string;
|
||||
attending: string;
|
||||
bringingGuests: string;
|
||||
@@ -25,6 +26,7 @@ export interface RSVPEmailData {
|
||||
export async function sendRSVPEmail(data: RSVPEmailData) {
|
||||
const {
|
||||
eventTitle,
|
||||
eventSlug,
|
||||
name,
|
||||
attending,
|
||||
bringingGuests,
|
||||
@@ -40,6 +42,11 @@ export async function sendRSVPEmail(data: RSVPEmailData) {
|
||||
const itemsList = itemsBringing.length ? itemsBringing.join(', ') : 'None';
|
||||
const otherItemsList = otherItems ? otherItems : 'None';
|
||||
|
||||
// Assume the frontend is served at the same host
|
||||
const baseUrl = process.env.FRONTEND_BASE_URL || '';
|
||||
const manageRsvpsUrl = `${baseUrl}/events/${eventSlug}/manage-rsvps`;
|
||||
const viewRsvpsUrl = `${baseUrl}/events/${eventSlug}/rsvps`;
|
||||
|
||||
const html = `
|
||||
<h2>RSVP Confirmation</h2>
|
||||
<p><strong>Event:</strong> ${eventTitle}</p>
|
||||
@@ -49,6 +56,8 @@ export async function sendRSVPEmail(data: RSVPEmailData) {
|
||||
<p><strong>Guest Names:</strong> ${guestList}</p>
|
||||
<p><strong>Items Bringing (from needed list):</strong> ${itemsList}</p>
|
||||
<p><strong>Other Items:</strong> ${otherItemsList}</p>
|
||||
<p><a href="${manageRsvpsUrl}">Manage RSVPs for this event</a></p>
|
||||
<p><a href="${viewRsvpsUrl}">View all RSVPs for this event</a></p>
|
||||
`;
|
||||
|
||||
await transporter.sendMail({
|
||||
|
||||
@@ -295,15 +295,17 @@ app.post('/api/events/:slug/rsvp', async (req: Request, res: Response) => {
|
||||
[eventId, name, attending, bringing_guests, guest_count, JSON.stringify(parsedGuestNames), JSON.stringify(parsedItemsBringing), other_items || '']
|
||||
);
|
||||
|
||||
// Fetch event title for the email
|
||||
const eventInfo = await db.get('SELECT title FROM events WHERE id = ?', [eventId]);
|
||||
// Fetch event title and slug for the email
|
||||
const eventInfo = await db.get('SELECT title, slug FROM events WHERE id = ?', [eventId]);
|
||||
const eventTitle = eventInfo ? eventInfo.title : slug;
|
||||
const eventSlug = eventInfo ? eventInfo.slug : slug;
|
||||
|
||||
// Send RSVP confirmation email (if email provided)
|
||||
if (req.body.email) {
|
||||
try {
|
||||
await sendRSVPEmail({
|
||||
eventTitle,
|
||||
eventSlug,
|
||||
name,
|
||||
attending,
|
||||
bringingGuests: bringing_guests,
|
||||
|
||||
Reference in New Issue
Block a user