forked from Code-4-Community/scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 0
SSF-205 FM Dashboard Frontend #173
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4bdd3dc
frontend
Juwang110 cbfe5a8
Merge branch 'main' into jw/ssf-205-fm-dashboard-frontend
Juwang110 940a901
comments and conflicts
Juwang110 569e5c4
Merge branch 'main' into jw/ssf-205-fm-dashboard-frontend
Juwang110 fc57bea
comments
Juwang110 409e3a7
pagination functionality for deeplinking
Juwang110 1acc3d8
Merge branch 'main' into jw/ssf-205-fm-dashboard-frontend
Juwang110 474de8c
Merge branch 'main' into jw/ssf-205-fm-dashboard-frontend
Juwang110 4d255fc
comments
Juwang110 aff2045
Merge branch 'main' into jw/ssf-205-fm-dashboard-frontend
Juwang110 9eef5e5
comments
Juwang110 fe19495
fix unintended change
Juwang110 57acf93
Merge branch 'main' into jw/ssf-205-fm-dashboard-frontend
Juwang110 f207f68
remove deprecated deeplink code
Juwang110 81455fe
Merge branch 'main' into jw/ssf-205-fm-dashboard-frontend
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
Some comments aren't visible on the classic Files Changed page.
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
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
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
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
128 changes: 128 additions & 0 deletions
128
apps/frontend/src/containers/foodManufacturerDashboard.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,128 @@ | ||
| import React, { useEffect, useState } from 'react'; | ||
| import { Box, Heading, Text } from '@chakra-ui/react'; | ||
| import DashboardCard, { DashboardCardType } from '@components/dashboardCard'; | ||
| import { | ||
| Donation, | ||
| DonationDetails, | ||
| DonationReminderDto, | ||
| FoodManufacturer, | ||
| } from '../types/types'; | ||
| import ApiClient from '@api/apiClient'; | ||
| import { useAlert } from '../hooks/alert'; | ||
| import { FloatingAlert } from '@components/floatingAlert'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
| import { ROUTES } from '../routes'; | ||
|
|
||
| const FoodManufacturerDashboard: React.FC = () => { | ||
| const navigate = useNavigate(); | ||
|
|
||
| const [errorAlertState, setErrorMessage] = useAlert(); | ||
| const [foodManufacturer, setFoodManufacturer] = | ||
| useState<FoodManufacturer | null>(null); | ||
| const [upcomingReminders, setUpcomingReminders] = useState< | ||
| DonationReminderDto[] | ||
| >([]); | ||
| const [recentDonations, setRecentDonations] = useState<Donation[]>([]); | ||
|
|
||
| useEffect(() => { | ||
| const fetchFmData = async () => { | ||
| let fmId: number; | ||
| try { | ||
| fmId = await ApiClient.getCurrentUserFoodManufacturerId(); | ||
| const fm = await ApiClient.getFoodManufacturer(fmId); | ||
| setFoodManufacturer(fm); | ||
| } catch { | ||
| setErrorMessage('Error fetching your manufacturer profile.'); | ||
| return; | ||
| } | ||
|
|
||
| const [reminders, donations] = await Promise.allSettled([ | ||
| ApiClient.getNextTwoDonationReminders(fmId), | ||
| ApiClient.getAllDonationsByFoodManufacturer(fmId), | ||
| ]); | ||
|
|
||
| // If reminders is successfully retrieved from API with the Promise.allSettled | ||
| if (reminders.status === 'fulfilled') { | ||
| setUpcomingReminders(reminders.value); | ||
| } else { | ||
| setErrorMessage('Error fetching upcoming donations.'); | ||
| } | ||
|
|
||
| // If donations is successfully retrieved from API with the Promise.allSettled | ||
| if (donations.status === 'fulfilled') { | ||
|
Juwang110 marked this conversation as resolved.
|
||
| const sorted = donations.value | ||
| .map((d: DonationDetails) => d.donation) | ||
| .sort( | ||
| (a: Donation, b: Donation) => | ||
| new Date(b.dateDonated).getTime() - | ||
| new Date(a.dateDonated).getTime(), | ||
| ) | ||
| .slice(0, 2); | ||
| setRecentDonations(sorted); | ||
| } else { | ||
| setErrorMessage('Error fetching recent donations.'); | ||
| } | ||
| }; | ||
| fetchFmData(); | ||
| }, [setErrorMessage]); | ||
|
|
||
| return ( | ||
| <Box p={12}> | ||
| {errorAlertState && ( | ||
| <FloatingAlert | ||
| key={errorAlertState.id} | ||
| message={errorAlertState.message} | ||
| status="error" | ||
| timeout={6000} | ||
| /> | ||
| )} | ||
| <Heading textStyle="h1" color="gray.600" mb={6}> | ||
| Welcome, {foodManufacturer?.foodManufacturerName} | ||
| </Heading> | ||
|
|
||
| <Text textStyle="p" color="gray.light" fontWeight={600} mb={4}> | ||
| Upcoming Donations | ||
| </Text> | ||
| <Box display="grid" gridTemplateColumns="repeat(2, 1fr)" gap={4} mb={16}> | ||
| {upcomingReminders.map((reminder) => ( | ||
| <DashboardCard | ||
| key={`${reminder.donation.donationId}-${reminder.reminderDate}`} | ||
| type={DashboardCardType.UPCOMING_DONATION} | ||
| title={`Donation #${reminder.donation.donationId}`} | ||
|
Juwang110 marked this conversation as resolved.
|
||
| date={reminder.reminderDate} | ||
| subtitle={reminder.donation.foodManufacturer?.foodManufacturerName} | ||
| linkText="View Donation Requirements" | ||
| onLinkClick={() => | ||
| navigate( | ||
| `${ROUTES.FM_DONATION_MANAGEMENT}?donationId=${reminder.donation.donationId}`, | ||
| ) | ||
| } | ||
| /> | ||
| ))} | ||
| </Box> | ||
|
|
||
| <Text textStyle="p" color="gray.light" fontWeight={600} mb={4}> | ||
| Recent Donations | ||
| </Text> | ||
| <Box display="grid" gridTemplateColumns="repeat(2, 1fr)" gap={4} mb={16}> | ||
| {recentDonations.map((donation) => ( | ||
| <DashboardCard | ||
| key={donation.donationId} | ||
| type={DashboardCardType.RECENT_DONATION} | ||
| title={`Donation #${donation.donationId}`} | ||
| date={donation.dateDonated} | ||
| subtitle={donation.foodManufacturer?.foodManufacturerName} | ||
| linkText="View Donation Details" | ||
| onLinkClick={() => | ||
| navigate( | ||
| `${ROUTES.FM_DONATION_MANAGEMENT}?donationId=${donation.donationId}`, | ||
| ) | ||
| } | ||
| /> | ||
| ))} | ||
| </Box> | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| export default FoodManufacturerDashboard; | ||
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.