forked from Code-4-Community/scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 0
SSF-92 Volunteer Management Frontend and Add New Volunteer Modal #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Juwang110
wants to merge
18
commits into
main
Choose a base branch
from
jw/SSF-92-volunteer-management-frontend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5382942
Refactoring visual elements
Juwang110 f745231
pagination functionality
Juwang110 d22d126
Removing volunteer type filtering and display
Juwang110 1d24d7c
visual updates
Juwang110 a941c41
modal setup for add volunteer
Juwang110 5a39ddb
Modal frontend setup
Juwang110 b10d9eb
callbacks and email/phone invalid handling
Juwang110 c85a3fa
refactoring to closer align with figma
Juwang110 6c9f810
Merge pull request #77 from Code-4-Community/main
Juwang110 91ff9fd
Aligning add volunteer modal with figma
Juwang110 61f722e
Merge branch 'jw/SSF-92-volunteer-management-frontend' of https://git…
Juwang110 21d9104
Refining submit status alerts
Juwang110 a5b8bf3
minor visual updates
Juwang110 e6f8502
Adding volunteer initial icons
Juwang110 66888e4
minor visual refactoring
Juwang110 2d286af
Refactoring add volunteer modal to use USPhoneInput
Juwang110 96fb6d6
visual refactoring
Juwang110 23d500f
visual refactoring
Juwang110 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
146 changes: 146 additions & 0 deletions
146
apps/frontend/src/components/forms/addNewVolunteerModal.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,146 @@ | ||
| import { | ||
| Dialog, | ||
| Button, | ||
| Text, | ||
| Flex, | ||
| Field, | ||
| Input, | ||
| CloseButton, | ||
| Box | ||
| } from '@chakra-ui/react'; | ||
| import { useState } from 'react'; | ||
| import { Role, UserDto } from "../../types/types"; | ||
| import ApiClient from '@api/apiClient'; | ||
| import { USPhoneInput } from './usPhoneInput'; | ||
| import { PlusIcon } from 'lucide-react'; | ||
|
|
||
| interface NewVolunteerModalProps { | ||
| onSubmitSuccess?: () => void; | ||
| onSubmitFail?: () => void; | ||
| } | ||
|
|
||
| const NewVolunteerModal: React.FC<NewVolunteerModalProps> = ({ onSubmitSuccess, onSubmitFail }) => { | ||
| const [firstName, setFirstName] = useState(""); | ||
| const [lastName, setLastName] = useState(""); | ||
| const [email, setEmail] = useState(""); | ||
| const [phone, setPhone] = useState(""); | ||
|
|
||
| const [isOpen, setIsOpen] = useState(false); | ||
|
|
||
| const [error, setError] = useState(""); | ||
|
|
||
| const handleSubmit = async () => { | ||
| console.log("RAW phone value:", phone); | ||
| if (!firstName || !lastName || !email || !phone || phone === "+1") { | ||
| setError("Please fill in all fields. *"); | ||
| return; | ||
| } | ||
|
|
||
| setError(""); | ||
|
|
||
| const newVolunteer: UserDto = { | ||
| firstName, | ||
| lastName, | ||
| email, | ||
| phone, | ||
| role: Role.STANDARD_VOLUNTEER | ||
| }; | ||
|
|
||
| try { | ||
| await ApiClient.postUser(newVolunteer); | ||
| if (onSubmitSuccess) onSubmitSuccess(); | ||
| handleClear(); | ||
| } catch (error: any) { | ||
| const message = error.response?.data?.message; | ||
| const hasEmailError = Array.isArray(message) && message.some((msg: any) => typeof msg === "string" && (msg.toLowerCase().includes("email"))); | ||
| const hasPhoneError = Array.isArray(message) && message.some((msg: any) => typeof msg === "string" && (msg.toLowerCase().includes("phone"))); | ||
|
|
||
| if (hasEmailError) { | ||
| setError("Please specify a valid email. *") | ||
| } else if (hasPhoneError) { | ||
| setError("Please specify a valid phone number. *") | ||
| } else { | ||
| if (onSubmitFail) onSubmitFail(); | ||
| handleClear(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const handleClear = () => { | ||
| setFirstName(""); | ||
| setLastName(""); | ||
| setEmail(""); | ||
| setPhone(""); | ||
| setError(""); | ||
| setIsOpen(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog.Root open={isOpen} onOpenChange={setIsOpen}> | ||
| <Dialog.Trigger asChild> | ||
Juwang110 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <Button borderColor="neutral.200" variant="outline" color="neutral.600" fontFamily="ibm" fontWeight="semibold" fontSize="14px" gap={1.5}> | ||
| <Box as={PlusIcon} boxSize="17px" strokeWidth={2.5} /> | ||
| Add | ||
| </Button> | ||
| </Dialog.Trigger> | ||
| <Dialog.Backdrop /> | ||
| <Dialog.Positioner alignItems="center"> | ||
| <Dialog.Content maxW="40em" mt="-8"> | ||
amywng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <Dialog.Header pb={1}> | ||
| <Dialog.Title fontSize="18px" fontWeight={600} fontFamily="Inter" color="#000"> | ||
| Add New Volunteer | ||
| </Dialog.Title> | ||
| <CloseButton onClick={() => setIsOpen(false)} size="md" position="absolute" top={3} right={3}/> | ||
| </Dialog.Header> | ||
| <Dialog.Body color="neutral.800" fontWeight={600} textStyle="p2"> | ||
| <Text mb="1.5em" color="#52525B" fontWeight={400}> | ||
| Complete all information in the form to register a new volunteer. | ||
| </Text> | ||
| <Flex gap={8} justifyContent="flex-start" my={4}> | ||
| <Field.Root> | ||
| <Field.Label textStyle="p2" color="neutral.800" fontWeight={600}>First Name</Field.Label> | ||
| <Input color="neutral.700" textStyle="p2" fontWeight={400} value={firstName} onChange={(e) => setFirstName(e.target.value)}/> | ||
| </Field.Root> | ||
| <Field.Root> | ||
| <Field.Label textStyle="p2" color="neutral.800" fontWeight={600}>Last Name</Field.Label> | ||
| <Input color="neutral.700" textStyle="p2" fontWeight={400} value={lastName} onChange={(e) => setLastName(e.target.value)}/> | ||
| </Field.Root> | ||
| </Flex> | ||
| <Field.Root> | ||
| <Field.Label textStyle="p2" color="neutral.800" fontWeight={600}>Email</Field.Label> | ||
| <Input color="neutral.700" textStyle="p2" fontWeight={400} value={email} onChange={(e) => setEmail(e.target.value)}/> | ||
| </Field.Root> | ||
| <Field.Root my={4}> | ||
| <Field.Label textStyle="p2" color="neutral.800" fontWeight={600}>Phone Number</Field.Label> | ||
| <USPhoneInput | ||
| value={phone} | ||
| onChange={setPhone} | ||
| inputProps={{ | ||
| color: 'neutral.700', | ||
| textStyle: 'p2', | ||
| fontWeight: 400, | ||
| }} | ||
| /> | ||
| </Field.Root> | ||
| {error && ( | ||
| <Text color="red" mb={3} fontWeight={400} fontSize="12px" fontFamily="Inter"> | ||
| {error} | ||
| </Text> | ||
| )} | ||
| <Flex justifyContent="flex-end" mt={10} gap={2.5}> | ||
| <Button textStyle="p2" fontWeight={600} color="neutral.800" variant='outline' onClick={handleClear}>Cancel</Button> | ||
Juwang110 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <Button textStyle="p2" fontWeight={600} bg={'#213C4A'} color={'white'} onClick={handleSubmit}>Submit</Button> | ||
| </Flex> | ||
| </Dialog.Body> | ||
| </Dialog.Content> | ||
| </Dialog.Positioner> | ||
| </Dialog.Root> | ||
| ); | ||
| }; | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| export default NewVolunteerModal; | ||
Oops, something went wrong.
Oops, something went wrong.
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.