diff --git a/src/pages/api/email/send-reimbursement-email.ts b/src/pages/api/email/send-reimbursement-email.ts index de73154..13b0d01 100644 --- a/src/pages/api/email/send-reimbursement-email.ts +++ b/src/pages/api/email/send-reimbursement-email.ts @@ -436,15 +436,16 @@ async function sendSubmissionEmail(pb: any, resend: any, fromEmail: string, repl return false; } - const subject = `Reimbursement Submitted: ${reimbursement.title}`; + // Send confirmation email to submitter + const submitterSubject = `Reimbursement Submitted: ${reimbursement.title}`; - const html = ` + const submitterHtml = ` - ${subject} + ${submitterSubject}
@@ -509,18 +510,120 @@ async function sendSubmissionEmail(pb: any, resend: any, fromEmail: string, repl `; - const result = await resend.emails.send({ + // Send notification email to treasurer + const treasurerSubject = `New Reimbursement Request: ${reimbursement.title} - $${reimbursement.total_amount.toFixed(2)}`; + + const treasurerHtml = ` + + + + + + ${treasurerSubject} + + +
+

📋 New Reimbursement Request

+
+ +
+

Action Required

+

Hello Treasurer,

+

A new reimbursement request has been submitted and is awaiting review.

+ +
+

Reimbursement Details

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Submitted by:${user.name} (${user.email})
Title:${reimbursement.title}
Amount:$${reimbursement.total_amount.toFixed(2)}
Date of Purchase:${new Date(reimbursement.date_of_purchase).toLocaleDateString()}
Department:${reimbursement.department.charAt(0).toUpperCase() + reimbursement.department.slice(1)}
Payment Method:${reimbursement.payment_method}
Submitted:${new Date(reimbursement.created).toLocaleString()}
Status: + + Submitted - Awaiting Review + +
+ + ${reimbursement.additional_info ? ` +
+

Additional Information:

+
+ ${reimbursement.additional_info} +
+
+ ` : ''} +
+ +
+

📋 Next Steps:

+
    +
  • Review the submitted receipts and documentation
  • +
  • Log into the reimbursement portal to approve or request changes
  • +
  • The submitter will be notified of any status updates
  • +
+
+
+ +
+

This is an automated notification from IEEE UCSD Reimbursement System.

+

If you have any questions, please contact the submitter directly at ${user.email}

+
+ + + `; + + // Send both emails + const submitterResult = await resend.emails.send({ from: fromEmail, to: [user.email], replyTo: replyToEmail, - subject, - html, + subject: submitterSubject, + html: submitterHtml, }); - console.log('Submission confirmation email sent successfully:', result); - return true; + const treasurerResult = await resend.emails.send({ + from: fromEmail, + to: ['treasurer@ieeeatucsd.org'], + replyTo: user.email, // Set reply-to as the submitter for treasurer's convenience + subject: treasurerSubject, + html: treasurerHtml, + }); + + console.log('Submission confirmation email sent successfully:', submitterResult); + console.log('Treasurer notification email sent successfully:', treasurerResult); + + // Return true if at least one email was sent successfully + return !!(submitterResult && treasurerResult); } catch (error) { - console.error('Failed to send submission confirmation email:', error); + console.error('Failed to send submission emails:', error); return false; } }