Skip to content

Commit

Permalink
#67 send email to peeps when unregister
Browse files Browse the repository at this point in the history
  • Loading branch information
gregv committed Dec 29, 2023
1 parent 0d56cdf commit 813a0ee
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/routes/resources+/event-register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { json, type DataFunctionArgs } from '~/remix.ts'
import { prisma } from '~/utils/db.server.ts'
import { sendEmail } from '~/utils/email.server.ts'
import { RegistrationEmail, RegistrationNoticeForAdmins } from './registration-emails.server.tsx'
import { UnregistrationEmail } from './unregistration-emails.server.tsx'
import { createEvent, type DateArray } from 'ics'
import type { User, Event } from '@prisma/client'
import { differenceInMinutes } from 'date-fns'
Expand Down Expand Up @@ -64,6 +65,22 @@ export async function action({ request }: DataFunctionArgs) {
},
},
})

sendEmail({
to: user.email,
subject: `Event Unregistration Notification`,
attachments: [],
react: <UnregistrationEmail event={event} role={submission.value.role} />,
}).then(result => {
if (result.status == 'error') {
// TODO: think through this case and how to handle it properly
console.error(
'There was an error sending an event registration email: ',
JSON.stringify(result.error),
)
}
})

notifyAdmins({
user: user,
event: event,
Expand Down
44 changes: 44 additions & 0 deletions app/routes/resources+/unregistration-emails.server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { Event } from '@prisma/client'
import { Container, Html, Tailwind, Text } from '@react-email/components'
import tailwindConfig from '~/../tailwind.config.ts'
import { format } from 'date-fns'
import { volunteerTypes } from '~/data.ts'

export function UnregistrationEmail({
event,
role,
}: {
event: Event
role: 'cleaningCrew' | 'lessonAssistants' | 'sideWalkers' | 'horseLeaders'
}) {
let roleName
for (let v of volunteerTypes) {
if (v.field == role) {
roleName = v.displayName
}
}

return (
<Tailwind config={tailwindConfig}>
<Html lang="en" dir="ltr">
<Container>
<h1>
<Text>Thanks for considering volunteering! We hope to see you again!</Text>
</h1>
<p>
<Text>
You've unregistered to volunteer{' '}
{roleName ? `as one of the ${roleName}` : ''} to help with the
following event:
</Text>
<Text>{event.title}</Text>
<Text>On: {format(event.start, 'MMMM do, y')}</Text>
<Text>
From: {format(event.start, 'p')} - {format(event.end, 'p')}
</Text>
</p>
</Container>
</Html>
</Tailwind>
)
}

0 comments on commit 813a0ee

Please sign in to comment.