forked from Code-4-Community/scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 0
SSF-194 Admin Pantry Management Frontend #164
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
20
commits into
main
Choose a base branch
from
jw/ssf-194-admin-pantry-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
20 commits
Select commit
Hold shift + click to select a range
2ac780b
frontend for pantry management
Juwang110 73f1e0d
assign volunteers modal
Juwang110 51b7eeb
Merge branch 'main' into jw/ssf-194-admin-pantry-management-frontend
Juwang110 1da1fcc
format issues
Juwang110 f2a01bb
fetch pantries bug fix
Juwang110 f283a84
comments
Juwang110 036f7d6
Merge branch 'main' into jw/ssf-194-admin-pantry-management-frontend
Juwang110 7305e66
comments
Juwang110 6a63067
Merge branch 'jw/ssf-194-admin-pantry-management-frontend' of https:/…
Juwang110 36b11dd
Merge branch 'main' into jw/ssf-194-admin-pantry-management-frontend
Juwang110 a3cb81c
comments
Juwang110 568554c
comments
Juwang110 49d6efc
Merge branch 'main' into jw/ssf-194-admin-pantry-management-frontend
Juwang110 138bb93
Merge branch 'main' into jw/ssf-194-admin-pantry-management-frontend
Juwang110 a5ac4cf
Merge branch 'main' into jw/ssf-194-admin-pantry-management-frontend
Juwang110 fec3e1b
comments
Juwang110 d7707c1
Merge branch 'main' into jw/ssf-194-admin-pantry-management-frontend
Juwang110 ee79b4c
Merge branch 'main' into jw/ssf-194-admin-pantry-management-frontend
Juwang110 c5734f8
Merge branch 'main' into jw/ssf-194-admin-pantry-management-frontend
Juwang110 178377d
comment
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
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
282 changes: 282 additions & 0 deletions
282
apps/frontend/src/components/forms/assignVolunteersModal.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,282 @@ | ||
| import ApiClient from '@api/apiClient'; | ||
| import { | ||
| Box, | ||
| Button, | ||
| Checkbox, | ||
| CloseButton, | ||
| Dialog, | ||
| Flex, | ||
| Input, | ||
| InputGroup, | ||
| Text, | ||
| VStack, | ||
| } from '@chakra-ui/react'; | ||
| import { useAlert } from '../../hooks/alert'; | ||
| import { useEffect, useState } from 'react'; | ||
| import { ApprovedPantryResponse, Assignments } from 'types/types'; | ||
| import { SearchIcon } from 'lucide-react'; | ||
| import { getInitials, USER_ICON_COLORS } from '@utils/utils'; | ||
| import { FloatingAlert } from '@components/floatingAlert'; | ||
| import { useModalBodyCleanup } from '../../hooks/modalBodyCleanup'; | ||
|
|
||
| interface AssignVolunteersModalProps { | ||
| pantry: ApprovedPantryResponse; | ||
| onSuccess: () => void; | ||
| onClose: () => void; | ||
| isOpen: boolean; | ||
| } | ||
|
|
||
| type VolunteerDisplay = { | ||
|
Juwang110 marked this conversation as resolved.
|
||
| userId: number; | ||
| firstName: string; | ||
| lastName: string; | ||
| }; | ||
|
|
||
| const AssignVolunteersModal: React.FC<AssignVolunteersModalProps> = ({ | ||
| pantry, | ||
| onSuccess, | ||
| onClose, | ||
| isOpen, | ||
| }) => { | ||
| useModalBodyCleanup(); | ||
| const [alertState, setAlertMessage] = useAlert(); | ||
|
|
||
| const [volunteers, setVolunteers] = useState<VolunteerDisplay[]>([]); | ||
|
|
||
| const [selectedIds, setSelectedIds] = useState<Set<number>>(new Set()); | ||
|
|
||
| const [searchName, setSearchName] = useState<string>(''); | ||
|
|
||
| const handleSearchNameChange = ( | ||
| event: React.ChangeEvent<HTMLInputElement>, | ||
| ) => { | ||
| setSearchName(event.target.value); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| if (!isOpen) return; | ||
| const fetchVolunteers = async () => { | ||
|
Juwang110 marked this conversation as resolved.
|
||
| try { | ||
| const allVolunteers: Assignments[] = await ApiClient.getVolunteers(); | ||
|
|
||
| const assignedIds = new Set(pantry.volunteers.map((v) => v.userId)); | ||
|
|
||
| const normalized: VolunteerDisplay[] = allVolunteers.map((v) => ({ | ||
| userId: v.id, | ||
| firstName: v.firstName, | ||
| lastName: v.lastName, | ||
| })); | ||
|
|
||
| setVolunteers(normalized); | ||
| setSelectedIds(new Set(assignedIds)); | ||
| } catch { | ||
| setAlertMessage('Error fetching volunteers'); | ||
| } | ||
| }; | ||
|
|
||
| fetchVolunteers(); | ||
| }, [pantry, setAlertMessage, isOpen]); | ||
|
|
||
| const filteredVolunteers = volunteers.filter((v) => { | ||
| const fullName = `${v.firstName} ${v.lastName}`.toLowerCase(); | ||
| return fullName.includes(searchName.toLowerCase()); | ||
| }); | ||
|
|
||
| const handleToggle = (userId: number, checked: boolean) => { | ||
| setSelectedIds((prev) => { | ||
| const next = new Set(prev); | ||
| if (checked) next.add(userId); | ||
| else next.delete(userId); | ||
| return next; | ||
| }); | ||
| }; | ||
|
|
||
| const handleSave = async () => { | ||
| try { | ||
| const originalIds = new Set(pantry.volunteers.map((v) => v.userId)); | ||
|
|
||
| const addVolunteerIds = [...selectedIds].filter( | ||
| (id) => !originalIds.has(id), | ||
| ); | ||
| const removeVolunteerIds = [...originalIds].filter( | ||
| (id) => !selectedIds.has(id), | ||
| ); | ||
|
|
||
| if (addVolunteerIds.length > 0 || removeVolunteerIds.length > 0) { | ||
| await ApiClient.updatePantryVolunteers(pantry.pantryId, { | ||
| addVolunteerIds, | ||
| removeVolunteerIds, | ||
| }); | ||
| } | ||
|
|
||
| onSuccess(); | ||
| onClose(); | ||
| } catch { | ||
| setAlertMessage('Error saving volunteer assignments'); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog.Root | ||
| size="md" | ||
| open={isOpen} | ||
| onOpenChange={(e: { open: boolean }) => { | ||
| if (!e.open) onClose(); | ||
| }} | ||
| closeOnInteractOutside | ||
| > | ||
| {alertState && ( | ||
| <FloatingAlert | ||
| key={alertState.id} | ||
| message={alertState.message} | ||
| status="error" | ||
| timeout={6000} | ||
| /> | ||
| )} | ||
| <Dialog.Backdrop /> | ||
| <Dialog.Positioner> | ||
| <Dialog.Content> | ||
| <Dialog.CloseTrigger asChild> | ||
|
Juwang110 marked this conversation as resolved.
|
||
| <CloseButton | ||
| color="var(--chakra-colors-neutral-700)" | ||
| size="md" | ||
| mt={3} | ||
| /> | ||
| </Dialog.CloseTrigger> | ||
|
|
||
| <Dialog.Header pb={0}> | ||
| <Dialog.Title | ||
|
Juwang110 marked this conversation as resolved.
|
||
| fontSize="18px" | ||
| fontFamily="inter" | ||
| fontWeight={600} | ||
| color="black" | ||
| mt={3} | ||
| > | ||
| Assign Volunteers | ||
| </Dialog.Title> | ||
| </Dialog.Header> | ||
| <Dialog.Body pb={6}> | ||
| <VStack align="stretch" gap={4}> | ||
| <Text textStyle="p2" color="gray.dark"> | ||
| {pantry.pantryName} | ||
| </Text> | ||
| <VStack align="stretch" gap={8} mt={6}> | ||
| <InputGroup | ||
| startElement={ | ||
| <Box> | ||
| <SearchIcon | ||
| color="var(--chakra-colors-neutral-600)" | ||
| size={13} | ||
| strokeWidth={3} | ||
| /> | ||
| </Box> | ||
| } | ||
| px={3} | ||
| > | ||
| <Input | ||
| placeholder="Search" | ||
| value={searchName} | ||
| borderColor="neutral.100" | ||
| ps="8" | ||
| onChange={handleSearchNameChange} | ||
| color="neutral.600" | ||
| textStyle="p2" | ||
| _focusVisible={{ boxShadow: 'none', outline: 'none' }} | ||
| /> | ||
| </InputGroup> | ||
| <Box maxH="300px" overflowY="auto" px={3}> | ||
|
Juwang110 marked this conversation as resolved.
|
||
| <VStack align="stretch" gap={0}> | ||
| {filteredVolunteers.map((volunteer) => ( | ||
| <Flex | ||
| key={volunteer.userId} | ||
| align="center" | ||
| justify="space-between" | ||
| borderBottom="1px solid" | ||
| borderColor="neutral.100" | ||
| > | ||
| <Flex align="center" gap={3} py={2}> | ||
| <Box | ||
| borderRadius="full" | ||
| bg={ | ||
| USER_ICON_COLORS[ | ||
| volunteer.userId % USER_ICON_COLORS.length | ||
| ] | ||
| } | ||
| width="33px" | ||
| height="33px" | ||
| display="flex" | ||
| alignItems="center" | ||
| justifyContent="center" | ||
| color="white" | ||
| fontSize="12px" | ||
| flexShrink={0} | ||
| > | ||
| {getInitials( | ||
| volunteer.firstName, | ||
| volunteer.lastName, | ||
| )} | ||
| </Box> | ||
|
|
||
| <Text color="neutral.700" textStyle="p2"> | ||
| {volunteer.firstName} {volunteer.lastName} | ||
| </Text> | ||
| </Flex> | ||
|
|
||
| <Box | ||
| borderLeft="1px solid" | ||
| borderColor="neutral.100" | ||
| pl={4} | ||
| alignSelf="stretch" | ||
| display="flex" | ||
| alignItems="center" | ||
| > | ||
| <Checkbox.Root | ||
| checked={selectedIds.has(volunteer.userId)} | ||
| onCheckedChange={(e: { checked: boolean }) => | ||
| handleToggle(volunteer.userId, e.checked) | ||
| } | ||
| size="md" | ||
| > | ||
| <Checkbox.HiddenInput /> | ||
| <Checkbox.Control | ||
| borderRadius="2px" | ||
| borderColor="neutral.100" | ||
| /> | ||
| </Checkbox.Root> | ||
| </Box> | ||
| </Flex> | ||
| ))} | ||
|
|
||
| {filteredVolunteers.length === 0 && ( | ||
| <Text | ||
| color="neutral.500" | ||
| fontSize="14px" | ||
| textAlign="center" | ||
| py={4} | ||
| > | ||
| No volunteers found | ||
| </Text> | ||
| )} | ||
| </VStack> | ||
| </Box> | ||
| <Box w="100%" display="flex" justifyContent="flex-end"> | ||
| <Button | ||
| bg="blue.core" | ||
| color="white" | ||
|
Juwang110 marked this conversation as resolved.
|
||
| fontWeight={600} | ||
| onClick={handleSave} | ||
| px={10} | ||
| > | ||
| Save Changes | ||
| </Button> | ||
| </Box> | ||
| </VStack> | ||
| </VStack> | ||
| </Dialog.Body> | ||
| </Dialog.Content> | ||
| </Dialog.Positioner> | ||
| </Dialog.Root> | ||
| ); | ||
| }; | ||
|
|
||
| export default AssignVolunteersModal; | ||
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
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.