From 51c01d94a996184c7dbc018e0819a03e55eaa1e4 Mon Sep 17 00:00:00 2001 From: Greg V Date: Fri, 22 Dec 2023 12:59:05 -0700 Subject: [PATCH] Adding upcoming events into email directly --- .../admin+/_email+/CustomEmail.server.tsx | 20 ++++++++++++++++++- app/routes/admin+/_email+/email.tsx | 12 ++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/routes/admin+/_email+/CustomEmail.server.tsx b/app/routes/admin+/_email+/CustomEmail.server.tsx index 7029ab0..d259549 100644 --- a/app/routes/admin+/_email+/CustomEmail.server.tsx +++ b/app/routes/admin+/_email+/CustomEmail.server.tsx @@ -2,7 +2,7 @@ import { Container, Html, Link, Tailwind, Text } from '@react-email/components' import tailwindConfig from '../../../../tailwind.config.ts' import { siteBaseUrl, siteName } from '~/data.ts' -export function CustomEmail({ message }: { message: string }) { +export function CustomEmail({ upcomingEvents, message }: { upcomingEvents: any[], message: string }) { return ( @@ -17,6 +17,24 @@ export function CustomEmail({ message }: { message: string }) { View upcoming events + { + // List out upcoming events with event.title + // Render event.start and event.end with a date format + upcomingEvents.map(event => { + return ( +
+ + 🐴 {event.title} {event.start.toLocaleString()} - {event.end.toLocaleTimeString()} + +
+ ) + } + ) + + + + + }

diff --git a/app/routes/admin+/_email+/email.tsx b/app/routes/admin+/_email+/email.tsx index 8565294..aa68f92 100644 --- a/app/routes/admin+/_email+/email.tsx +++ b/app/routes/admin+/_email+/email.tsx @@ -65,6 +65,7 @@ export async function action({ request, params }: DataFunctionArgs) { ] const selectedRoles = roles.filter(role => submission.payload[role] === 'on') const recipients = await getRecipientsFromRoles(selectedRoles) + const upcomingEvents = await getUpcomingEvents(5); if (recipients.length === 0) { return json( @@ -82,7 +83,7 @@ export async function action({ request, params }: DataFunctionArgs) { sendEmail({ to: recipient, subject: submission.payload.subject, - react: , + react: , }).then(result => { if (result.status === 'error') { console.error( @@ -241,6 +242,15 @@ export default function Email() { ) } +async function getUpcomingEvents(limit: number) { + const events = await prisma.event.findMany({ + where: { start: { gt: new Date() } }, + take: limit, + }) + return events +} + + async function getRecipientsFromRoles(roles: string[]) { const recipients = new Set() if (roles.includes('allVolunteers')) {