@@ -50,20 +50,58 @@ export async function POST(
5050 reason
5151 )
5252
53- // Send notification email to company
54- if ( rejectedEvent . company && rejectedEvent . company . email ) {
55- const emailContent = getEventRejectedEmail ( {
56- eventTitle : rejectedEvent . title ,
57- companyName : rejectedEvent . company . name ,
58- rejectionReason : reason ,
59- editUrl : `${ process . env . NEXT_PUBLIC_SITE_URL || 'https://codeunia.com' } /dashboard/company/events/${ rejectedEvent . slug } /edit` ,
60- guidelines : `${ process . env . NEXT_PUBLIC_SITE_URL || 'https://codeunia.com' } /guidelines` ,
53+ // Get creator's email from profiles table
54+ let creatorEmail : string | null = null
55+ let creatorName : string | null = null
56+
57+ if ( rejectedEvent . created_by ) {
58+ const { createClient } = await import ( '@/lib/supabase/server' )
59+ const supabase = await createClient ( )
60+ const { data : creatorProfile } = await supabase
61+ . from ( 'profiles' )
62+ . select ( 'email, first_name, last_name' )
63+ . eq ( 'id' , rejectedEvent . created_by )
64+ . single ( )
65+
66+ if ( creatorProfile ) {
67+ creatorEmail = creatorProfile . email
68+ creatorName = creatorProfile . first_name
69+ ? `${ creatorProfile . first_name } ${ creatorProfile . last_name || '' } ` . trim ( )
70+ : null
71+ }
72+ }
73+
74+ // Prepare email content
75+ const emailContent = getEventRejectedEmail ( {
76+ eventTitle : rejectedEvent . title ,
77+ companyName : rejectedEvent . company ?. name || 'Your Company' ,
78+ rejectionReason : reason ,
79+ editUrl : `${ process . env . NEXT_PUBLIC_SITE_URL || 'https://codeunia.com' } /dashboard/company/${ rejectedEvent . company ?. slug } /events` ,
80+ guidelines : `${ process . env . NEXT_PUBLIC_SITE_URL || 'https://codeunia.com' } /guidelines` ,
81+ creatorName : creatorName || undefined ,
82+ } )
83+
84+ // Send notification email to event creator (primary)
85+ if ( creatorEmail ) {
86+ console . log ( `📧 Sending event rejection email to creator: ${ creatorEmail } ` )
87+ await sendEmail ( {
88+ to : creatorEmail ,
89+ subject : emailContent . subject ,
90+ html : emailContent . html ,
91+ } ) . catch ( error => {
92+ console . error ( '❌ Failed to send rejection email to creator:' , error )
6193 } )
94+ }
6295
96+ // Also send to company email if different from creator
97+ if ( rejectedEvent . company ?. email && rejectedEvent . company . email !== creatorEmail ) {
98+ console . log ( `📧 Sending event rejection email to company: ${ rejectedEvent . company . email } ` )
6399 await sendEmail ( {
64100 to : rejectedEvent . company . email ,
65101 subject : emailContent . subject ,
66102 html : emailContent . html ,
103+ } ) . catch ( error => {
104+ console . error ( '❌ Failed to send rejection email to company:' , error )
67105 } )
68106 }
69107
@@ -100,14 +138,21 @@ function getEventRejectedEmail(params: {
100138 rejectionReason : string
101139 editUrl : string
102140 guidelines : string
141+ creatorName ?: string
103142} ) {
143+ const greeting = params . creatorName ? `Hi ${ params . creatorName } ,` : 'Hello,'
144+
104145 const content = `
105146 <h2 style="margin: 0 0 20px 0; color: #111827; font-size: 20px;">
106147 Event Review Update
107148 </h2>
108149
109150 <p style="margin: 0 0 15px 0; color: #374151; font-size: 16px; line-height: 1.5;">
110- Thank you for submitting your event to CodeUnia. After review, we're unable to approve your event at this time.
151+ ${ greeting }
152+ </p>
153+
154+ <p style="margin: 0 0 15px 0; color: #374151; font-size: 16px; line-height: 1.5;">
155+ Thank you for submitting your event to Codeunia. After review, we're unable to approve your event at this time.
111156 </p>
112157
113158 <div style="background-color: #fef2f2; border-left: 4px solid #ef4444; padding: 15px; margin: 20px 0; border-radius: 4px;">
@@ -158,7 +203,7 @@ function getEventRejectedEmail(params: {
158203<head>
159204 <meta charset="utf-8">
160205 <meta name="viewport" content="width=device-width, initial-scale=1.0">
161- <title>Event Review Update - CodeUnia </title>
206+ <title>Event Review Update - Codeunia </title>
162207</head>
163208<body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; background-color: #f5f5f5;">
164209 <table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f5f5f5; padding: 20px;">
@@ -167,7 +212,7 @@ function getEventRejectedEmail(params: {
167212 <table width="600" cellpadding="0" cellspacing="0" style="background-color: #ffffff; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
168213 <tr>
169214 <td style="background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%); padding: 30px; text-align: center;">
170- <h1 style="margin: 0; color: #ffffff; font-size: 24px; font-weight: bold;">CodeUnia </h1>
215+ <h1 style="margin: 0; color: #ffffff; font-size: 24px; font-weight: bold;">Codeunia </h1>
171216 </td>
172217 </tr>
173218 <tr>
@@ -181,7 +226,7 @@ function getEventRejectedEmail(params: {
181226 Need help? Visit our <a href="${ process . env . NEXT_PUBLIC_SITE_URL || 'https://codeunia.com' } /protected/help" style="color: #3b82f6; text-decoration: none;">Help Center</a>
182227 </p>
183228 <p style="margin: 0; color: #9ca3af; font-size: 12px;">
184- © ${ new Date ( ) . getFullYear ( ) } CodeUnia . All rights reserved.
229+ © ${ new Date ( ) . getFullYear ( ) } Codeunia . All rights reserved.
185230 </p>
186231 </td>
187232 </tr>
0 commit comments