forked from Code-4-Community/scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 0
[SSF-62] Assigned Pantries Frontend #75
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
bhuvanh66
wants to merge
2
commits into
main
Choose a base branch
from
BH/SSF-62-Assigned-Pantries-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
2 commits
Select commit
Hold shift + click to select a range
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
289 changes: 289 additions & 0 deletions
289
apps/frontend/src/containers/volunteerAssignedPantries.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,289 @@ | ||
| import React, { useState, useEffect } from 'react'; | ||
| import { Funnel } from 'lucide-react'; | ||
| import { | ||
| Box, | ||
| Button, | ||
| Table, | ||
| Heading, | ||
| VStack, | ||
| Checkbox, | ||
| Text, | ||
| } from '@chakra-ui/react'; | ||
| import ApiClient from '@api/apiClient'; | ||
| import { Pantry } from 'types/types'; | ||
| import { RefrigeratedDonation } from '../types/pantryEnums'; | ||
| import { Assignments } from 'types/volunteerAssignments'; | ||
|
|
||
| const AssignedPantries: React.FC = () => { | ||
| const [assignments, setAssignments] = useState<Assignments[]>([]); | ||
| const [filteredAssignments, setFilteredAssignments] = useState<Assignments[]>([]); | ||
| const [pantryDetails, setPantryDetails] = useState<Map<number, Pantry>>(new Map()); | ||
| const [isFilterOpen, setIsFilterOpen] = useState(false); | ||
| const [filterRefrigeratorFriendly, setFilterRefrigeratorFriendly] = useState<boolean | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| const fetchAssignments = async () => { | ||
| try { | ||
|
|
||
| const data = await ApiClient.getAllAssignments() as Assignments[]; | ||
| setAssignments(data); | ||
| setFilteredAssignments(data); | ||
|
|
||
| const detailsMap = new Map<number, Pantry>(); | ||
| await Promise.all( | ||
| data | ||
| .filter(assignment => assignment.pantry) | ||
| .map(async (assignment) => { | ||
| try { | ||
| const pantry = await ApiClient.getPantry(assignment.pantry!.pantryId); | ||
| detailsMap.set(assignment.pantry!.pantryId, pantry); | ||
| } catch (error) { | ||
| console.error(`Error fetching pantry ${assignment.pantry!.pantryId}:`, error); | ||
| } | ||
| }) | ||
| ); | ||
| setPantryDetails(detailsMap); | ||
| } catch (error) { | ||
| console.error('Error fetching assignments:', error); | ||
| alert('Error fetching assigned pantries: ' + error); | ||
| } | ||
| }; | ||
|
|
||
| fetchAssignments(); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
|
|
||
| let filtered = [...assignments]; | ||
|
|
||
| if (filterRefrigeratorFriendly !== null) { | ||
| filtered = filtered.filter(assignment => { | ||
| if (!assignment.pantry) return false; | ||
| const pantry = pantryDetails.get(assignment.pantry.pantryId); | ||
| if (!pantry) return true; | ||
| const isRefrigeratorFriendlyValue = | ||
| pantry.refrigeratedDonation === RefrigeratedDonation.YES || | ||
| pantry.refrigeratedDonation === RefrigeratedDonation.SOMETIMES; | ||
| return isRefrigeratorFriendlyValue === filterRefrigeratorFriendly; | ||
| }); | ||
| } | ||
|
|
||
| setFilteredAssignments(filtered); | ||
| }, [filterRefrigeratorFriendly, assignments, pantryDetails]); | ||
|
|
||
|
|
||
| const handleViewOrders = (pantryId: number) => { | ||
| // TODO: Redirect to Order Management page when it's created | ||
| console.log('View orders for pantry:', pantryId); | ||
| }; | ||
|
|
||
| const isRefrigeratorFriendly = (pantryId: number): boolean => { | ||
| const pantry = pantryDetails.get(pantryId); | ||
| if (!pantry) return false; | ||
| return pantry.refrigeratedDonation === RefrigeratedDonation.YES || | ||
| pantry.refrigeratedDonation === RefrigeratedDonation.SOMETIMES; | ||
| }; | ||
|
|
||
| const getRefrigeratorFriendlyText = (pantryId: number): string => { | ||
| const pantry = pantryDetails.get(pantryId); | ||
| if (!pantry) return 'Loading...'; | ||
| if (pantry.refrigeratedDonation === RefrigeratedDonation.YES || | ||
| pantry.refrigeratedDonation === RefrigeratedDonation.SOMETIMES) { | ||
| return 'Refrigerator-Friendly'; | ||
| } | ||
| return 'Not Refrigerator-Friendly'; | ||
| }; | ||
|
|
||
| const tableHeaderStyles = { | ||
| borderBottom: '1px solid', | ||
| borderColor: 'neutral.100', | ||
| color: 'neutral.800', | ||
| fontFamily: 'inter', | ||
| fontWeight: '600', | ||
| fontSize: 'sm', | ||
| }; | ||
|
|
||
| return ( | ||
| <Box p={12}> | ||
| <Heading textStyle="h1" color="gray.600" mb={6}> | ||
| Assigned Pantries | ||
| </Heading> | ||
|
|
||
| {/* Filter Button */} | ||
| <Box display="flex" gap={2} mb={6} fontFamily="'Inter', sans-serif"> | ||
| <Box position="relative"> | ||
| <Button | ||
| onClick={() => setIsFilterOpen(!isFilterOpen)} | ||
| variant="outline" | ||
| color="neutral.600" | ||
| border="1px solid" | ||
| borderColor="neutral.200" | ||
| size="sm" | ||
| p={3} | ||
| fontFamily="ibm" | ||
| fontWeight="semibold" | ||
| > | ||
| <Funnel /> | ||
| Filter | ||
| </Button> | ||
|
|
||
| {isFilterOpen && ( | ||
| <> | ||
| <Box | ||
| position="fixed" | ||
| top={0} | ||
| left={0} | ||
| right={0} | ||
| bottom={0} | ||
| onClick={() => setIsFilterOpen(false)} | ||
| zIndex={10} | ||
| /> | ||
| <Box | ||
| position="absolute" | ||
| top="100%" | ||
| left={0} | ||
| mt={2} | ||
| bg="white" | ||
| border="1px solid" | ||
| borderColor="gray.200" | ||
| borderRadius="md" | ||
| boxShadow="lg" | ||
| p={4} | ||
| minW="275px" | ||
| zIndex={20} | ||
| > | ||
| <VStack align="stretch" gap={2}> | ||
| <Box display="flex" alignItems="center" gap={2}> | ||
| <Checkbox.Root | ||
| checked={filterRefrigeratorFriendly === true} | ||
| onCheckedChange={(e: { checked: boolean }) => | ||
| setFilterRefrigeratorFriendly(e.checked ? true : null) | ||
| } | ||
| color="black" | ||
| size="sm" | ||
| > | ||
| <Checkbox.HiddenInput /> | ||
| <Checkbox.Control /> | ||
| </Checkbox.Root> | ||
| <Text fontSize="sm" cursor="pointer" onClick={() => setFilterRefrigeratorFriendly(filterRefrigeratorFriendly === true ? null : true)}> | ||
| Refrigerator-Friendly Only | ||
| </Text> | ||
| </Box> | ||
|
|
||
| <Box display="flex" alignItems="center" gap={2}> | ||
| <Checkbox.Root | ||
| checked={filterRefrigeratorFriendly === false} | ||
| onCheckedChange={(e: { checked: boolean }) => | ||
| setFilterRefrigeratorFriendly(e.checked ? false : null) | ||
| } | ||
| color="black" | ||
| size="sm" | ||
| > | ||
| <Checkbox.HiddenInput /> | ||
| <Checkbox.Control /> | ||
| </Checkbox.Root> | ||
| <Text fontSize="sm" cursor="pointer" onClick={() => setFilterRefrigeratorFriendly(filterRefrigeratorFriendly === false ? null : false)}> | ||
| Not Refrigerator-Friendly Only | ||
| </Text> | ||
| </Box> | ||
| </VStack> | ||
| </Box> | ||
| </> | ||
| )} | ||
| </Box> | ||
| </Box> | ||
|
|
||
| {/* Pantries Table */} | ||
| <Table.Root> | ||
| <Table.Header> | ||
| <Table.Row> | ||
| <Table.ColumnHeader | ||
| {...tableHeaderStyles} | ||
| borderRight="1px solid" | ||
| borderRightColor="neutral.100" | ||
| width="40%" | ||
| > | ||
| Pantry | ||
| </Table.ColumnHeader> | ||
| <Table.ColumnHeader | ||
| {...tableHeaderStyles} | ||
| borderRight="1px solid" | ||
| borderRightColor="neutral.100" | ||
| width="35%" | ||
| > | ||
| Refrigerator-Friendly | ||
| </Table.ColumnHeader> | ||
| <Table.ColumnHeader | ||
| {...tableHeaderStyles} | ||
| textAlign="center" | ||
| width="25%" | ||
| > | ||
| Action | ||
| </Table.ColumnHeader> | ||
| </Table.Row> | ||
| </Table.Header> | ||
| <Table.Body> | ||
| {filteredAssignments.map((assignment) => { | ||
|
|
||
| if (!assignment.pantry) return null; | ||
|
|
||
| return ( | ||
| <Table.Row | ||
| key={assignment.assignmentId} | ||
| _hover={{ bg: 'gray.50' }} | ||
| > | ||
| <Table.Cell | ||
| textStyle="p2" | ||
| borderRight="1px solid" | ||
| borderRightColor="neutral.100" | ||
| py={0} | ||
| > | ||
| <Button | ||
| variant="plain" | ||
| textDecoration="underline" | ||
| onClick={() => assignment.pantry} | ||
| fontFamily="inter" | ||
| > | ||
| {assignment.pantry.pantryName} | ||
| </Button> | ||
| </Table.Cell> | ||
| <Table.Cell | ||
| textStyle="p2" | ||
| borderRight="1px solid" | ||
| borderRightColor="neutral.100" | ||
| color="neutral.700" | ||
| > | ||
| <Box | ||
| bg={assignment.pantry && isRefrigeratorFriendly(assignment.pantry.pantryId) ? 'gray.100' : 'orange.50'} | ||
| px={3} | ||
| py={1} | ||
| borderRadius="md" | ||
| display="inline-block" | ||
| fontSize="sm" | ||
| fontFamily="inter" | ||
| > | ||
| {assignment.pantry ? getRefrigeratorFriendlyText(assignment.pantry.pantryId) : 'N/A'} | ||
| </Box> | ||
| </Table.Cell> | ||
| <Table.Cell textStyle="p2" textAlign="center"> | ||
| <Button | ||
| variant="plain" | ||
| textDecoration="underline" | ||
| color="blue.600" | ||
| onClick={() => assignment.pantry && handleViewOrders(assignment.pantry.pantryId)} | ||
| fontFamily="inter" | ||
| fontSize="sm" | ||
| > | ||
| View Orders | ||
| </Button> | ||
| </Table.Cell> | ||
| </Table.Row> | ||
| ); | ||
| })} | ||
| </Table.Body> | ||
| </Table.Root> | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| export default AssignedPantries; | ||
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,18 @@ | ||
| export interface LimitedPantryInfo { | ||
| pantryId: number; | ||
| pantryName: string; | ||
| } | ||
|
|
||
| export interface Assignments { | ||
| assignmentId: number; | ||
| volunteer: { | ||
| id: number; | ||
| firstName: string; | ||
| lastName: string; | ||
| email: string; | ||
| phone: string; | ||
| role: string; | ||
| }; | ||
| pantry: LimitedPantryInfo | null; | ||
| } | ||
|
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this endpoint was deleted, the new equivalent is getAllVolunteers in the users controller. can you add a method to the apiclient and update this accordingly?