forked from Code-4-Community/scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 0
Jx/ssf 202 dashboard stats #183
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
jxuistrying
wants to merge
2
commits into
main
Choose a base branch
from
jx/SSF-202-dashboard-stats
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import React from 'react'; | ||
| import { Box, Button } from '@chakra-ui/react'; | ||
| import { CircleCheck } from 'lucide-react'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
|
|
||
| interface PageEmptyStateProps { | ||
| subtitle: string; | ||
| primaryButtonText: string; | ||
| primaryButtonLink: string; | ||
| secondaryButtonText: string; | ||
| secondaryButtonLink: string; | ||
| } | ||
|
|
||
| const PageEmptyState: React.FC<PageEmptyStateProps> = ({ | ||
| subtitle, | ||
| primaryButtonText, | ||
| primaryButtonLink, | ||
| secondaryButtonText, | ||
| secondaryButtonLink, | ||
| }) => { | ||
| const navigate = useNavigate(); | ||
|
|
||
| return ( | ||
| <Box | ||
| display="flex" | ||
| flexDirection="column" | ||
| alignItems="center" | ||
| justifyContent="center" | ||
| textAlign="center" | ||
| fontFamily="'Inter', sans-serif" | ||
| fontSize="sm" | ||
| color="neutral.600" | ||
| py={10} | ||
| gap={2} | ||
| > | ||
| <Box mb={2}> | ||
| <CircleCheck size={24} color="#262626" /> | ||
| </Box> | ||
| <Box fontWeight="600" fontSize="lg" color="neutral.800"> | ||
| Nothing to see here. | ||
| </Box> | ||
| <Box color="neutral.700" fontWeight="400"> | ||
| {subtitle} | ||
| </Box> | ||
| <Box display="flex" gap={3} mt={4}> | ||
| <Button | ||
| bg="neutral.700" | ||
| color="white" | ||
| _hover={{ bg: 'neutral.800' }} | ||
| onClick={() => navigate(primaryButtonLink)} | ||
| > | ||
| {primaryButtonText} | ||
| </Button> | ||
| <Button | ||
| bg="neutral.300" | ||
| color="neutral.700" | ||
| _hover={{ bg: 'neutral.50' }} | ||
| onClick={() => navigate(secondaryButtonLink)} | ||
| > | ||
| {secondaryButtonText} | ||
| </Button> | ||
| </Box> | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| export default PageEmptyState; |
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,35 @@ | ||
| import { Box } from '@chakra-ui/react'; | ||
| import { CircleCheck } from 'lucide-react'; | ||
|
|
||
| interface EmptyStateProps { | ||
| subtitle: string; | ||
| } | ||
|
|
||
| const SectionEmptyState: React.FC<EmptyStateProps> = ({ subtitle }) => { | ||
| return ( | ||
| <Box | ||
| display="flex" | ||
| flexDirection="column" | ||
| alignItems="center" | ||
| justifyContent="center" | ||
| textAlign="center" | ||
| fontFamily="'Inter', sans-serif" | ||
| fontSize="sm" | ||
| color="neutral.600" | ||
| py={10} | ||
| gap={2} | ||
| > | ||
| <Box mb={2}> | ||
| <CircleCheck size={24} color="#262626" /> | ||
| </Box> | ||
| <Box fontWeight="600" fontSize="lg" color="neutral.800"> | ||
| Nothing to see here. | ||
| </Box> | ||
| <Box color="neutral.700" fontWeight="400"> | ||
| {subtitle} | ||
| </Box> | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| export default SectionEmptyState; |
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 |
|---|---|---|
|
|
@@ -16,6 +16,9 @@ import { useAlert } from '../hooks/alert'; | |
| import { FloatingAlert } from '@components/floatingAlert'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
| import { ROUTES } from '../routes'; | ||
| import SectionEmptyState from '@components/SectionEmptyState'; | ||
| import PageEmptyState from '@components/PageEmptyState'; | ||
| import { DashboardStats } from '@components/dashboardStats'; | ||
|
|
||
| const AdminDashboard: React.FC = () => { | ||
| const navigate = useNavigate(); | ||
|
|
@@ -27,6 +30,7 @@ const AdminDashboard: React.FC = () => { | |
| const [recentOrders, setRecentOrders] = useState<OrderSummary[]>([]); | ||
| const [recentDonations, setRecentDonations] = useState<Donation[]>([]); | ||
| const [currentUser, setCurrentUser] = useState<User | null>(null); | ||
| const [stats, setStats] = useState<Record<string, string> | null>(null); | ||
|
|
||
| const fetchPendingApplications = async () => { | ||
| try { | ||
|
|
@@ -71,6 +75,9 @@ const AdminDashboard: React.FC = () => { | |
| try { | ||
| user = await ApiClient.getMe(); | ||
| setCurrentUser(user); | ||
|
|
||
| const userStats = await ApiClient.getUserStats(user.id); | ||
| setStats(userStats); | ||
| } catch { | ||
| setAlertMessage('Authentication error. Please log in and try again.'); | ||
| return; | ||
|
|
@@ -84,6 +91,11 @@ const AdminDashboard: React.FC = () => { | |
| fetchPendingApplications(); | ||
| }, [setAlertMessage]); | ||
|
|
||
| const isPageEmpty = | ||
| pendingApplications.length === 0 && | ||
| recentOrders.length === 0 && | ||
| recentDonations.length === 0; | ||
|
|
||
| return ( | ||
| <Box p={12}> | ||
| {alertState && ( | ||
|
|
@@ -98,84 +110,135 @@ const AdminDashboard: React.FC = () => { | |
| 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' | ||
| ? ROUTES.PANTRY_MANAGEMENT_DETAILS.replace( | ||
| ':pantryId', | ||
| application.id.toString(), | ||
| ) | ||
| : ROUTES.FOOD_MANUFACTURER_APPLICATION_DETAILS.replace( | ||
| ':applicationId', | ||
| application.id.toString(), | ||
| ), | ||
| ); | ||
| }} | ||
| /> | ||
| ))} | ||
| </Box> | ||
| {stats && <DashboardStats stats={stats} />} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you investigate the frontend component and align the leftmost & rightmost (edges) of the top stat cards with the leftmost & rightmost of the bottom action cards? |
||
|
|
||
| <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> | ||
| {isPageEmpty ? ( | ||
| <PageEmptyState | ||
| subtitle="You have no orders or applications to review at this time." | ||
| primaryButtonText="View Pantries" | ||
| primaryButtonLink={ROUTES.PANTRY_MANAGEMENT} | ||
| secondaryButtonText="View Donations" | ||
| secondaryButtonLink={ROUTES.ADMIN_DONATION} | ||
| /> | ||
| ) : ( | ||
| <> | ||
| <Text textStyle="p" color="gray.light" fontWeight={600} mb={4}> | ||
| Pending Actions | ||
| </Text> | ||
| {pendingApplications.length === 0 ? ( | ||
| <Box mb={16}> | ||
| <SectionEmptyState subtitle="You have no pending applications at this time" /> | ||
| </Box> | ||
| ) : ( | ||
| <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' | ||
| ? ROUTES.PANTRY_MANAGEMENT_DETAILS.replace( | ||
| ':pantryId', | ||
| application.id.toString(), | ||
| ) | ||
| : ROUTES.FOOD_MANUFACTURER_APPLICATION_DETAILS.replace( | ||
| ':applicationId', | ||
| application.id.toString(), | ||
| ), | ||
| ); | ||
| }} | ||
| /> | ||
| ))} | ||
| </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> | ||
| <Text textStyle="p" color="gray.light" fontWeight={600} mb={4}> | ||
| Recent Orders | ||
| </Text> | ||
| {recentOrders.length === 0 ? ( | ||
| <Box mb={16}> | ||
| <SectionEmptyState subtitle="You have no recent orders at this time" /> | ||
| </Box> | ||
| ) : ( | ||
| <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> | ||
| {recentDonations.length === 0 ? ( | ||
| <Box mb={16}> | ||
| <SectionEmptyState subtitle="You have no recent donations at this time" /> | ||
| </Box> | ||
| ) : ( | ||
| <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> | ||
| ); | ||
| }; | ||
|
|
||
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.

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.
pls remove these duplicate files / changes of your other pr!