forked from Code-4-Community/scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 0
SSF-198 Admin Dashboard Frontend #169
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
10 commits
Select commit
Hold shift + click to select a range
d69b264
implemented cards for admin dashboard
Juwang110 07b10b2
Merge branch 'main' into jw/ssf-198-admin-dashboard-frontend
Juwang110 329169e
comments
Juwang110 81270b3
Merge branch 'main' into jw/ssf-198-admin-dashboard-frontend
Juwang110 2804ef0
Merge branch 'main' into jw/ssf-198-admin-dashboard-frontend
Juwang110 b0e8c61
comments
Juwang110 ec2c73e
Merge branch 'main' into jw/ssf-198-admin-dashboard-frontend
Juwang110 50f492b
comments
Juwang110 4de6261
comment
Juwang110 335e26b
Merge branch 'main' into jw/ssf-198-admin-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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| import React, { useEffect, useState } from 'react'; | ||
| import { Box, Heading, Text } from '@chakra-ui/react'; | ||
| import DashboardCard, { | ||
| ORDER_STATUS_BADGE, | ||
| DONATION_STATUS_BADGE, | ||
| } from '@components/dashboardCard'; | ||
| import { | ||
| PendingApplication, | ||
| OrderSummary, | ||
| Donation, | ||
| User, | ||
| } from '../types/types'; | ||
| import { DashboardCardType } from '@components/dashboardCard'; | ||
| import ApiClient from '@api/apiClient'; | ||
| import { useAlert } from '../hooks/alert'; | ||
| import { FloatingAlert } from '@components/floatingAlert'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
|
|
||
| const AdminDashboard: React.FC = () => { | ||
| const navigate = useNavigate(); | ||
|
|
||
| const [alertState, setAlertMessage] = useAlert(); | ||
| const [pendingApplications, setPendingApplications] = useState< | ||
| PendingApplication[] | ||
| >([]); | ||
| const [recentOrders, setRecentOrders] = useState<OrderSummary[]>([]); | ||
| const [recentDonations, setRecentDonations] = useState<Donation[]>([]); | ||
| const [currentUser, setCurrentUser] = useState<User | null>(null); | ||
|
|
||
| const fetchPendingApplications = async () => { | ||
| try { | ||
| const pendingApplications = | ||
| await ApiClient.getRecentPendingApplications(); | ||
| setPendingApplications(pendingApplications); | ||
| } catch { | ||
| setAlertMessage('Error fetching pending applications'); | ||
| } | ||
| }; | ||
|
|
||
| const fetchRecentOrders = async () => { | ||
| try { | ||
| const allOrders = await ApiClient.getAllOrders(); | ||
| const sortedOrders = allOrders.sort( | ||
| (a: OrderSummary, b: OrderSummary) => | ||
| new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(), | ||
| ); | ||
| const recentOrders = sortedOrders.slice(0, 2); | ||
| setRecentOrders(recentOrders); | ||
| } catch { | ||
| setAlertMessage('Error fetching orders'); | ||
| } | ||
| }; | ||
|
|
||
| const fetchRecentDonations = async () => { | ||
| try { | ||
| const allDonations = await ApiClient.getAllDonations(); | ||
| const sortedDonations = allDonations.sort( | ||
| (a: Donation, b: Donation) => | ||
| new Date(b.dateDonated).getTime() - new Date(a.dateDonated).getTime(), | ||
| ); | ||
| const recentDonations = sortedDonations.slice(0, 2); | ||
| setRecentDonations(recentDonations); | ||
| } catch { | ||
| setAlertMessage('Error fetching donations'); | ||
| } | ||
| }; | ||
|
|
||
| const fetchMe = async () => { | ||
| let user: User; | ||
| try { | ||
| user = await ApiClient.getMe(); | ||
| setCurrentUser(user); | ||
| } catch { | ||
| setAlertMessage('Authentication error. Please log in and try again.'); | ||
| return; | ||
| } | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| fetchMe(); | ||
| fetchRecentDonations(); | ||
| fetchRecentOrders(); | ||
| fetchPendingApplications(); | ||
| }, [setAlertMessage]); | ||
|
|
||
| return ( | ||
| <Box p={12}> | ||
| {alertState && ( | ||
| <FloatingAlert | ||
| key={alertState.id} | ||
| message={alertState.message} | ||
| status={'error'} | ||
| timeout={6000} | ||
| /> | ||
| )} | ||
| <Heading textStyle="h1" color="gray.600" mb={6}> | ||
| Welcome, {currentUser?.firstName} {currentUser?.lastName} | ||
| </Heading> | ||
|
|
||
| <Text textStyle="p" color="gray.light" fontWeight={600} mb={4}> | ||
| Pending Actions | ||
| </Text> | ||
| <Box display="grid" gridTemplateColumns="repeat(2, 1fr)" gap={4} mb={16}> | ||
| {pendingApplications.map((application) => ( | ||
| <DashboardCard | ||
| type={DashboardCardType.ACTION} | ||
| title={application.name} | ||
| date={application.dateApplied} | ||
| key={application.id} | ||
| linkText="View Application Details" | ||
| badge={{ | ||
| label: | ||
| application.type === 'pantry' ? 'Pantry' : 'Food Manufacturer', | ||
| bg: 'neutral.100', | ||
| color: 'neutral.600', | ||
| }} | ||
| onLinkClick={() => { | ||
| navigate( | ||
| application.type === 'pantry' | ||
| ? `/pantry-application-details/${application.id}` | ||
| : `/food-manufacturer-application-details/${application.id}`, | ||
| ); | ||
| }} | ||
| /> | ||
| ))} | ||
| </Box> | ||
|
|
||
| <Text textStyle="p" color="gray.light" fontWeight={600} mb={4}> | ||
| Recent Orders | ||
| </Text> | ||
| <Box display="grid" gridTemplateColumns="repeat(2, 1fr)" gap={4} mb={16}> | ||
| {recentOrders.map((order) => ( | ||
| <DashboardCard | ||
| key={order.orderId} | ||
| type={DashboardCardType.ORDER} | ||
| title={`Order #${order.orderId}`} | ||
| date={order.createdAt} | ||
| subtitle={order.request.pantry.pantryName} | ||
| linkText="View Order Details" | ||
| badge={ORDER_STATUS_BADGE[order.status]} | ||
| assignee={{ | ||
| id: order.assignee.id, | ||
| firstName: order.assignee.firstName, | ||
| lastName: order.assignee.lastName, | ||
| }} | ||
| onLinkClick={() => | ||
| navigate(`/admin-order-management?orderId=${order.orderId}`) | ||
| } | ||
| /> | ||
| ))} | ||
| </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" | ||
| badge={DONATION_STATUS_BADGE[donation.status]} | ||
| onLinkClick={() => | ||
| navigate(`/admin-donation?donationId=${donation.donationId}`) | ||
| } | ||
| /> | ||
| ))} | ||
| </Box> | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| export default AdminDashboard; | ||
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
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.