diff --git a/apps/frontend/src/api/apiClient.ts b/apps/frontend/src/api/apiClient.ts index d3ca7f72f..bdff0bec6 100644 --- a/apps/frontend/src/api/apiClient.ts +++ b/apps/frontend/src/api/apiClient.ts @@ -90,6 +90,12 @@ export class ApiClient { ); } + public async getUserStats(userId: number) { + return this.axiosInstance + .get(`/api/users/${userId}/stats`) + .then((response) => response.data); + } + public async postDonation(body: CreateDonationDto): Promise { return this.axiosInstance .post('/api/donations/', body) diff --git a/apps/frontend/src/components/PageEmptyState.tsx b/apps/frontend/src/components/PageEmptyState.tsx new file mode 100644 index 000000000..ade46fca6 --- /dev/null +++ b/apps/frontend/src/components/PageEmptyState.tsx @@ -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 = ({ + subtitle, + primaryButtonText, + primaryButtonLink, + secondaryButtonText, + secondaryButtonLink, +}) => { + const navigate = useNavigate(); + + return ( + + + + + + Nothing to see here. + + + {subtitle} + + + + + + + ); +}; + +export default PageEmptyState; diff --git a/apps/frontend/src/components/SectionEmptyState.tsx b/apps/frontend/src/components/SectionEmptyState.tsx new file mode 100644 index 000000000..0244f4582 --- /dev/null +++ b/apps/frontend/src/components/SectionEmptyState.tsx @@ -0,0 +1,35 @@ +import { Box } from '@chakra-ui/react'; +import { CircleCheck } from 'lucide-react'; + +interface EmptyStateProps { + subtitle: string; +} + +const SectionEmptyState: React.FC = ({ subtitle }) => { + return ( + + + + + + Nothing to see here. + + + {subtitle} + + + ); +}; + +export default SectionEmptyState; diff --git a/apps/frontend/src/containers/adminDashboard.tsx b/apps/frontend/src/containers/adminDashboard.tsx index 7ce01914e..6257a4beb 100644 --- a/apps/frontend/src/containers/adminDashboard.tsx +++ b/apps/frontend/src/containers/adminDashboard.tsx @@ -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([]); const [recentDonations, setRecentDonations] = useState([]); const [currentUser, setCurrentUser] = useState(null); + const [stats, setStats] = useState | 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 ( {alertState && ( @@ -98,84 +110,135 @@ const AdminDashboard: React.FC = () => { Welcome, {currentUser?.firstName} {currentUser?.lastName} - - Pending Actions - - - {pendingApplications.map((application) => ( - { - navigate( - application.type === 'pantry' - ? ROUTES.PANTRY_MANAGEMENT_DETAILS.replace( - ':pantryId', - application.id.toString(), - ) - : ROUTES.FOOD_MANUFACTURER_APPLICATION_DETAILS.replace( - ':applicationId', - application.id.toString(), - ), - ); - }} - /> - ))} - + {stats && } - - Recent Orders - - - {recentOrders.map((order) => ( - - navigate(`/admin-order-management?orderId=${order.orderId}`) - } - /> - ))} - + {isPageEmpty ? ( + + ) : ( + <> + + Pending Actions + + {pendingApplications.length === 0 ? ( + + + + ) : ( + + {pendingApplications.map((application) => ( + { + navigate( + application.type === 'pantry' + ? ROUTES.PANTRY_MANAGEMENT_DETAILS.replace( + ':pantryId', + application.id.toString(), + ) + : ROUTES.FOOD_MANUFACTURER_APPLICATION_DETAILS.replace( + ':applicationId', + application.id.toString(), + ), + ); + }} + /> + ))} + + )} - - Recent Donations - - - {recentDonations.map((donation) => ( - - navigate(`/admin-donation?donationId=${donation.donationId}`) - } - /> - ))} - + + Recent Orders + + {recentOrders.length === 0 ? ( + + + + ) : ( + + {recentOrders.map((order) => ( + + navigate(`/admin-order-management?orderId=${order.orderId}`) + } + /> + ))} + + )} + + + Recent Donations + + {recentDonations.length === 0 ? ( + + + + ) : ( + + {recentDonations.map((donation) => ( + + navigate( + `/admin-donation?donationId=${donation.donationId}`, + ) + } + /> + ))} + + )} + + )} ); }; diff --git a/apps/frontend/src/containers/pantryDashboard.tsx b/apps/frontend/src/containers/pantryDashboard.tsx index 182c9a9ef..ad47e704f 100644 --- a/apps/frontend/src/containers/pantryDashboard.tsx +++ b/apps/frontend/src/containers/pantryDashboard.tsx @@ -12,6 +12,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 PantryDashboard: React.FC = () => { const navigate = useNavigate(); @@ -22,6 +25,7 @@ const PantryDashboard: React.FC = () => { FoodRequestSummaryDto[] >([]); const [recentOrders, setRecentOrders] = useState([]); + const [stats, setStats] = useState | null>(null); useEffect(() => { const fetchDashboardData = async () => { @@ -30,6 +34,10 @@ const PantryDashboard: React.FC = () => { pantryId = await ApiClient.getCurrentUserPantryId(); const pantryData = await ApiClient.getPantry(pantryId); setPantry(pantryData); + + const user = await ApiClient.getMe(); + const userStats = await ApiClient.getUserStats(user.id); + setStats(userStats); } catch { setAlertMessage('Error fetching pantry information'); return; @@ -61,7 +69,25 @@ const PantryDashboard: React.FC = () => { fetchDashboardData(); }, [setAlertMessage]); - if (!pantry) return null; + if (!pantry) { + return ( + + + Pantry Dashboard + + + + ); + } + + const isPageEmpty = + recentFoodRequests.length === 0 && recentOrders.length === 0; return ( @@ -77,51 +103,87 @@ const PantryDashboard: React.FC = () => { Welcome, {pantry.pantryName} - - Recent Food Requests - - - {recentFoodRequests.map((fr) => ( - - navigate(`${ROUTES.REQUEST_FORM}?requestId=${fr.requestId}`) - } - /> - ))} - + {stats && } - - Recent Orders - - - {recentOrders.map((order) => ( - - navigate( - `${ROUTES.PANTRY_ORDER_MANAGEMENT}?orderId=${order.orderId}`, - ) - } - /> - ))} - + {isPageEmpty ? ( + + ) : ( + <> + + Recent Food Requests + + {recentFoodRequests.length === 0 ? ( + + + + ) : ( + + {recentFoodRequests.map((fr) => ( + + navigate(`${ROUTES.REQUEST_FORM}?requestId=${fr.requestId}`) + } + /> + ))} + + )} + + + Recent Orders + + {recentOrders.length === 0 ? ( + + + + ) : ( + + {recentOrders.map((order) => ( + + navigate( + `${ROUTES.PANTRY_ORDER_MANAGEMENT}?orderId=${order.orderId}`, + ) + } + /> + ))} + + )} + + )} ); }; diff --git a/apps/frontend/src/containers/volunteerDashboard.tsx b/apps/frontend/src/containers/volunteerDashboard.tsx index c33843670..e0ae23dbc 100644 --- a/apps/frontend/src/containers/volunteerDashboard.tsx +++ b/apps/frontend/src/containers/volunteerDashboard.tsx @@ -8,6 +8,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 VolunteerDashboard: React.FC = () => { const navigate = useNavigate(); @@ -18,12 +21,16 @@ const VolunteerDashboard: React.FC = () => { FoodRequestSummaryDto[] >([]); const [recentOrders, setRecentOrders] = useState([]); + const [stats, setStats] = useState | null>(null); useEffect(() => { const fetchDashboardData = async () => { try { const currentUser = await ApiClient.getMe(); setUser(currentUser); + + const userStats = await ApiClient.getUserStats(currentUser.id); + setStats(userStats); } catch { setAlertMessage('Error fetching user information'); return; @@ -53,6 +60,9 @@ const VolunteerDashboard: React.FC = () => { if (!user) return null; + const isPageEmpty = + recentFoodRequests.length === 0 && recentOrders.length === 0; + return ( {alertState && ( @@ -67,53 +77,89 @@ const VolunteerDashboard: React.FC = () => { Welcome, {user.firstName} {user.lastName} - - Recent Food Requests - - - {recentFoodRequests.map((fr) => ( - - navigate( - `${ROUTES.VOLUNTEER_REQUEST_MANAGEMENT}?requestId=${fr.requestId}`, - ) - } - /> - ))} - + {stats && } - - My Orders - - - {recentOrders.map((order) => ( - - navigate( - `${ROUTES.VOLUNTEER_ORDER_MANAGEMENT}?orderId=${order.orderId}`, - ) - } - /> - ))} - + {isPageEmpty ? ( + + ) : ( + <> + + Recent Food Requests + + {recentFoodRequests.length === 0 ? ( + + + + ) : ( + + {recentFoodRequests.map((fr) => ( + + navigate( + `${ROUTES.VOLUNTEER_REQUEST_MANAGEMENT}?requestId=${fr.requestId}`, + ) + } + /> + ))} + + )} + + + My Orders + + {recentOrders.length === 0 ? ( + + + + ) : ( + + {recentOrders.map((order) => ( + + navigate( + `${ROUTES.VOLUNTEER_ORDER_MANAGEMENT}?orderId=${order.orderId}`, + ) + } + /> + ))} + + )} + + )} ); }; diff --git a/apps/frontend/src/types/types.ts b/apps/frontend/src/types/types.ts index 2a1592b91..0f3cd6470 100644 --- a/apps/frontend/src/types/types.ts +++ b/apps/frontend/src/types/types.ts @@ -605,3 +605,24 @@ export interface UpdateDonationItemDetailsDto { estimatedValue?: number; foodRescue?: boolean; } + +export interface AdminVolunteerStats { + 'Food Requests': string; + Orders: string; + Donations: string; + Volunteers: string; +} + +export interface PantryDashboardStats { + 'Food Requests': string; + Orders: string; + 'Items Received': string; + 'Value Received': string; +} + +export interface ManufacturerDashboardStats { + Donations: string; + 'Value Donated': string; + 'Items Donated': string; + 'lbs Donated': string; +}