-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/event invite participants (#203)
* feat: create email for sending manual invitation * fix: use proper data * fix: react-email as external packages * feat: invite email component * feat: create endpoint to request sending invitation email * Refactor EventInviteModal component to handle email sending and error handling
- Loading branch information
1 parent
739f6b3
commit ffa18fa
Showing
7 changed files
with
363 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,22 +269,26 @@ export async function SendEventRescheduledEmail( | |
} | ||
|
||
export async function SendEventManualInvitationEmail( | ||
email: string, | ||
event?: selectEvent, | ||
host?: selectUser | ||
event: selectEvent, | ||
email: string | ||
) { | ||
const mg = new Mailgun(formData); | ||
const mailer = mg.client({ | ||
key: MAILER_API_KEY, | ||
username: 'api', | ||
}); | ||
|
||
const html = render(EventManualInvitation({}), { pretty: true }); | ||
const html = render( | ||
EventManualInvitation({ | ||
event, | ||
}), | ||
{ pretty: true } | ||
); | ||
|
||
mailer.messages.create(MAILER_DOMAIN, { | ||
html: html, | ||
from: 'inLive Room Events <[email protected]>', | ||
to: email, | ||
subject: `You've been invited to a Webinar`, | ||
subject: `Webinar Invitation: ${event.name}`, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { getCurrentAuthenticated } from '@/(server)/_shared/utils/get-current-authenticated'; | ||
import { eventService } from '@/(server)/api/_index'; | ||
import { cookies } from 'next/headers'; | ||
import { NextResponse } from 'next/server'; | ||
import { z } from 'zod'; | ||
|
||
const sendInviteEmailSchema = z.object({ | ||
emails: z.array(z.string().email()), | ||
}); | ||
|
||
export async function POST( | ||
request: Request, | ||
{ params }: { params: { slugOrId: string } } | ||
) { | ||
const slugOrId = params.slugOrId; | ||
const cookieStore = cookies(); | ||
const requestToken = cookieStore.get('token'); | ||
|
||
if (!requestToken) { | ||
return NextResponse.json( | ||
{ | ||
code: 401, | ||
message: 'Please check if token is provided in the cookie', | ||
}, | ||
{ status: 401 } | ||
); | ||
} | ||
|
||
const response = await getCurrentAuthenticated(requestToken?.value || ''); | ||
const user = response.data ? response.data : null; | ||
|
||
if (!user) { | ||
return NextResponse.json( | ||
{ | ||
code: 401, | ||
ok: false, | ||
message: | ||
'User not found, please check if token is provided in the cookie is valid', | ||
}, | ||
{ status: 401 } | ||
); | ||
} | ||
|
||
try { | ||
const event = await eventService.getEventBySlugOrID(slugOrId, user.id); | ||
if (!event) { | ||
return NextResponse.json( | ||
{ | ||
code: 404, | ||
ok: false, | ||
message: 'Event not found', | ||
}, | ||
{ status: 404 } | ||
); | ||
} | ||
|
||
if (event.status !== 'published') { | ||
return NextResponse.json( | ||
{ | ||
code: 400, | ||
ok: false, | ||
message: 'Event is not published', | ||
}, | ||
{ status: 400 } | ||
); | ||
} | ||
|
||
try { | ||
const reqJSON = await request.json(); | ||
|
||
const emails = sendInviteEmailSchema.parse(reqJSON); | ||
emails.emails.forEach((email) => { | ||
eventService.sendManualEmailInvitation(event, email); | ||
}); | ||
} catch (e) { | ||
return NextResponse.json( | ||
{ | ||
code: 400, | ||
ok: false, | ||
message: e, | ||
}, | ||
{ status: 400 } | ||
); | ||
} | ||
|
||
return NextResponse.json( | ||
{ | ||
code: 200, | ||
ok: true, | ||
message: 'Emails sent successfully', | ||
}, | ||
{ status: 200 } | ||
); | ||
} catch (e) { | ||
console.log(e); | ||
return NextResponse.json( | ||
{ | ||
code: 500, | ||
ok: false, | ||
message: 'Internal server error', | ||
}, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.