This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added functionality to send Email to selected Group of People (#712)
* Added functionality to send Email to selected Group of People i. Server 1. resolver.ts Modified the sendEventInvite Resolver to take an emailGroup as optional argument. ii. Client 1. Added New argument in method definitions in graphql.tsx 2. Created a new Modal component to shoqw the checkboxes for seleting the group 3. Added a button in Actions components to show the Modal componenet * Updated the Interested button to Cancelled and Updated the Queries in resolver 1. sendEmailModal.tsx 1. Created the Interface of FormInputs 2. Used the interface in useForm 3. renamed the metho to atleastOneChecked 4. Removed the Extra error message in atleastonechecked 5. Removed defaultChecked 2. resolver.ts 1. Added the strict type Checking in emailGroups Parameter 2. Removed the console.log * Updated the error message in the Modal Co-authored-by: Ravi <Ravichandra.cheekati@oracle.com>
- Loading branch information
1 parent
4fc5ad0
commit f72989d
Showing
4 changed files
with
175 additions
and
8 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
114 changes: 114 additions & 0 deletions
114
client/src/modules/dashboard/Events/components/SendEmailModal.tsx
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,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 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