diff --git a/api/application.js b/api/application.js index bd30d50..ab168ea 100644 --- a/api/application.js +++ b/api/application.js @@ -4,7 +4,7 @@ const { Pool } = require('pg'); const nodemailer = require('nodemailer'); const { syncApplication } = require('./google-sheets'); -const { createPayment } = require('./mollie'); +const { createPayment, TICKET_LABELS, calculateAmount } = require('./mollie'); // Initialize PostgreSQL connection pool const pool = new Pool({ @@ -24,10 +24,23 @@ const smtp = nodemailer.createTransport({ tls: { rejectUnauthorized: false }, }); +// Week labels for email display +const WEEK_LABELS = { + week1: 'Week 1: Return to the Commons (Aug 24-30)', + week2: 'Week 2: Post-Capitalist Production (Aug 31-Sep 6)', + week3: 'Week 3: Future Living (Sep 7-13)', + week4: 'Week 4: Governance & Funding Models (Sep 14-20)', +}; + // Email templates -const confirmationEmail = (application) => ({ - subject: 'Application Received - Valley of the Commons', - html: ` +const confirmationEmail = (application) => { + const ticketLabel = TICKET_LABELS[application.contribution_amount] || application.contribution_amount || 'Not selected'; + const amount = application.contribution_amount ? calculateAmount(application.contribution_amount, (application.weeks || []).length) : null; + const weeksHtml = (application.weeks || []).map(w => `
  • ${WEEK_LABELS[w] || w}
  • `).join(''); + + return { + subject: 'Application Received - Valley of the Commons', + html: `

    Thank You for Applying!

    @@ -35,9 +48,29 @@ const confirmationEmail = (application) => ({

    We've received your application to join Valley of the Commons (August 24 - September 20, 2026).

    +
    +

    Your Booking Summary

    + + + + + + ${amount ? ` + + + ` : ''} + + + + +
    Ticket:${ticketLabel}
    Amount:€${amount}
    Attendance:${application.attendance_type === 'full' ? 'Full 4 weeks' : 'Partial'}
    + ${weeksHtml ? `

    Weeks selected:

    ` : ''} +
    +

    What happens next?

      +
    1. Complete your payment (if you haven't already)
    2. Our team will review your application
    3. We may reach out with follow-up questions
    4. You'll receive a decision within 2-3 weeks
    5. @@ -64,7 +97,8 @@ const confirmationEmail = (application) => ({

    ` -}); + }; +}; const adminNotificationEmail = (application) => ({ subject: `New Application: ${application.first_name} ${application.last_name}`, @@ -235,6 +269,7 @@ module.exports = async function handler(req, res) { ] ); + const weeksSelected = Array.isArray(data.weeks) ? data.weeks : []; const application = { id: result.rows[0].id, submitted_at: result.rows[0].submitted_at, @@ -253,6 +288,8 @@ module.exports = async function handler(req, res) { referral_name: data.referral_name, arrival_date: data.arrival_date, departure_date: data.departure_date, + weeks: weeksSelected, + contribution_amount: data.contribution_amount, }; // Sync to Google Sheets (fire-and-forget backup)