Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Sep 25, 2025. It is now read-only.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 351
Added functionality to send Email to selected Group of People#712
Merged
ojeytonwilliams
merged 6 commits into
freeCodeCamp:main
from
Ravichandra-C:email_participantsSep 27, 2021
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a1e22c2
Added functionality to send Email to selected Group of People
3af1f06
Changes made based on lint errors
41589dd
Updated the components for linter rules to Pass
Ravichandra-C a0b8c47
Updated the Interested button to Cancelled and Updated the Queries in…
48b7378
Updated the Code based on the PR review
e3a31ae
Updated the error message in the Modal
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
114 changes: 114 additions & 0 deletions
114 client/src/modules/dashboard/Events/components/SendEmailModal.tsx
This file contains hidden or 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,114 @@ | ||
| import { Button } from '@chakra-ui/button'; | ||
| import { Checkbox } from '@chakra-ui/checkbox'; | ||
| import { Stack } from '@chakra-ui/layout'; | ||
| import { | ||
| Modal, | ||
| ModalBody, | ||
| ModalContent, | ||
| ModalHeader, | ||
| ModalCloseButton, | ||
| ModalFooter, | ||
| ModalOverlay, | ||
| } from '@chakra-ui/modal'; | ||
| import { Alert, AlertIcon, AlertDescription } from '@chakra-ui/react'; | ||
| import React from 'react'; | ||
| import { useForm } from 'react-hook-form'; | ||
| import { useSendEventInviteMutation } from 'generated/graphql'; | ||
| interface SendEmailModalProps { | ||
| onClose: () => any; | ||
| isOpen: boolean; | ||
| eventId: number; | ||
| } | ||
| interface FormInputs { | ||
| confirmed: boolean; | ||
| on_waitlist: boolean; | ||
| canceled: boolean; | ||
| } | ||
| const SendEmailModal: React.FC<SendEmailModalProps> = ({ | ||
| onClose, | ||
| isOpen, | ||
| eventId, | ||
| }) => { | ||
| const { | ||
| register, | ||
| getValues, | ||
| handleSubmit, | ||
| formState: { errors }, | ||
| } = useForm<FormInputs>({ defaultValues: { confirmed: true } }); | ||
| const atLeastOneChecked = () => { | ||
| return ( | ||
| getValues('confirmed') || | ||
| getValues('on_waitlist') || | ||
| getValues('canceled') | ||
| ); | ||
| }; | ||
| const [publish] = useSendEventInviteMutation(); | ||
| const onSubmit = (data: FormInputs) => { | ||
| const emailGroups = []; | ||
| if (data.confirmed) { | ||
| emailGroups.push('confirmed'); | ||
| } | ||
| if (data.canceled) { | ||
| emailGroups.push('canceled'); | ||
| } | ||
| if (data.on_waitlist) { | ||
| emailGroups.push('on_waitlist'); | ||
| } | ||
| publish({ variables: { id: eventId, emailGroups: emailGroups } }); | ||
| onClose(); | ||
| }; | ||
| return ( | ||
| <Modal isOpen={isOpen} onClose={onClose}> | ||
| <ModalOverlay /> | ||
| <ModalContent> | ||
| <ModalHeader>Send Email to Attendees</ModalHeader> | ||
| <ModalCloseButton /> | ||
| <ModalBody> | ||
| <form id="sendemail" onSubmit={handleSubmit(onSubmit)}> | ||
| <label htmlFor="attendees"> | ||
| Who do you want to send the email to? | ||
| </label> | ||
| <Stack spacing={10} direction="row"> | ||
| <Checkbox | ||
| {...register('confirmed', { validate: atLeastOneChecked })} | ||
| > | ||
| Confirmed | ||
| </Checkbox> | ||
| <Checkbox | ||
| {...register('on_waitlist', { validate: atLeastOneChecked })} | ||
| > | ||
| Waitlist | ||
| </Checkbox> | ||
| <Checkbox | ||
| {...register('canceled', { validate: atLeastOneChecked })} | ||
| > | ||
| Cancelled | ||
| </Checkbox> | ||
| </Stack> | ||
| </form> | ||
| {Object.keys(errors).length == 3 && ( | ||
| <Alert status="error"> | ||
| <AlertIcon /> | ||
| <AlertDescription> | ||
| Please select at least one checkbox | ||
| </AlertDescription> | ||
| </Alert> | ||
| )} | ||
| </ModalBody> | ||
| <ModalFooter> | ||
| <Button colorScheme="teal" mr={3} onClick={onClose}> | ||
| Close | ||
| </Button> | ||
| <Button type="submit" variant="solid" form="sendemail"> | ||
| Send Email | ||
| </Button> | ||
| </ModalFooter> | ||
| </ModalContent> | ||
| </Modal> | ||
| ); | ||
| }; | ||
| export default SendEmailModal; |
This file contains hidden or 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 |
|---|---|---|
| @@ -273,17 +273,60 @@ ${venue.postal_code} <br> | ||
| } | ||
| @Mutation(() => Boolean) | ||
| async sendEventInvite(@Arg('id', () => Int) id: number) { | ||
| async sendEventInvite( | ||
| @Arg('id', () => Int) id: number, | ||
| @Arg('emailGroups', () => [String], { | ||
| nullable: true, | ||
| defaultValue: ['interested'], | ||
| }) | ||
| emailGroups: Array<'confirmed' | 'on_waitlist' | 'canceled' | 'interested'>, | ||
| ) { | ||
| const event = await Event.findOne(id, { | ||
| relations: ['venue', 'chapter', 'chapter.users', 'chapter.users.user'], | ||
| relations: [ | ||
| 'venue', | ||
| 'chapter', | ||
| 'chapter.users', | ||
| 'chapter.users.user', | ||
| 'rsvps', | ||
| 'rsvps.user', | ||
| ], | ||
| }); | ||
| if (!event) throw new Error("Can't find event"); | ||
| // TODO: the default should probably be to bcc everyone. | ||
| const addresses = event.chapter.users | ||
| .filter((role) => role.interested) | ||
| .map(({ user }) => user.email); | ||
| const addresses: string[] = []; | ||
| if (emailGroups.includes('interested')) { | ||
| const interestedUsers: string[] = event.chapter.users | ||
| .filter((role) => role.interested) | ||
| .map(({ user }) => user.email); | ||
| addresses.push(...interestedUsers); | ||
| } | ||
Ravichandra-C marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (emailGroups.includes('on_waitlist')) { | ||
| const waitlistUsers: string[] = event.rsvps | ||
| .filter((rsvp) => rsvp.on_waitlist && rsvp.interested) | ||
| .map(({ user }) => user.email); | ||
| addresses.push(...waitlistUsers); | ||
| } | ||
| if (emailGroups.includes('confirmed')) { | ||
| const confirmedUsers: string[] = event.rsvps | ||
| .filter( | ||
| (rsvp) => !rsvp.on_waitlist && !rsvp.canceled && rsvp.interested, | ||
| ) | ||
| .map(({ user }) => user.email); | ||
| addresses.push(...confirmedUsers); | ||
| } | ||
| if (emailGroups.includes('canceled')) { | ||
| const confirmedUsers: string[] = event.rsvps | ||
| .filter((rsvp) => rsvp.canceled && rsvp.interested) | ||
| .map(({ user }) => user.email); | ||
| addresses.push(...confirmedUsers); | ||
| } | ||
| if (!addresses.length) { | ||
| return true; | ||
| } | ||
| const subject = `Invitation to ${event.name}.`; | ||
| const chapterURL = `${process.env.CLIENT_LOCATION}/chapters/${event.chapter.id}`; | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.