diff --git a/apps/frontend/src/api/apiClient.ts b/apps/frontend/src/api/apiClient.ts index 5e822dfb1..746bc2df2 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/dashboardStats.tsx b/apps/frontend/src/components/dashboardStats.tsx index 35fdfc9c2..6754fab0a 100644 --- a/apps/frontend/src/components/dashboardStats.tsx +++ b/apps/frontend/src/components/dashboardStats.tsx @@ -9,7 +9,7 @@ export function DashboardStats({ stats }: DashboardStatsProps) { const colors = ['blue.core', 'red', 'yellow.hover', 'teal.ssf']; return ( - + {Object.entries(stats).map(([key, value], index) => { const color = colors[index % colors.length]; diff --git a/apps/frontend/src/components/pageEmptyState.tsx b/apps/frontend/src/components/pageEmptyState.tsx new file mode 100644 index 000000000..a6476f4b5 --- /dev/null +++ b/apps/frontend/src/components/pageEmptyState.tsx @@ -0,0 +1,70 @@ +import React from 'react'; +import { Box, Button, Text } from '@chakra-ui/react'; +import { CircleCheck } from 'lucide-react'; +import { useNavigate } from 'react-router-dom'; + +interface PageEmptyStateProps { + entity?: string; + subtitle?: string; + primaryButtonText: string; + primaryButtonLink: string; + secondaryButtonText: string; + secondaryButtonLink: string; +} + +const PageEmptyState: React.FC = ({ + entity, + subtitle, + primaryButtonText, + primaryButtonLink, + secondaryButtonText, + secondaryButtonLink, +}) => { + const navigate = useNavigate(); + const message = subtitle ?? `You have no ${entity} at this time`; + + return ( + + + + + + Nothing to see here! + + + {message} + + + + + + + ); +}; + +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..96a91773c --- /dev/null +++ b/apps/frontend/src/components/sectionEmptyState.tsx @@ -0,0 +1,30 @@ +import { Box, Text } from '@chakra-ui/react'; + +interface EmptyStateProps { + entity?: string; + subtitle?: string; +} + +const SectionEmptyState: React.FC = ({ entity, subtitle }) => { + const message = subtitle ?? `You have no ${entity} at this time`; + return ( + + + Nothing to see here! + + + {message} + + + ); +}; + +export default SectionEmptyState; diff --git a/apps/frontend/src/containers/adminDashboard.tsx b/apps/frontend/src/containers/adminDashboard.tsx index 7ce01914e..c371aaa30 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/foodManufacturerDashboard.tsx b/apps/frontend/src/containers/foodManufacturerDashboard.tsx index 93dd02e0d..466acc8d3 100644 --- a/apps/frontend/src/containers/foodManufacturerDashboard.tsx +++ b/apps/frontend/src/containers/foodManufacturerDashboard.tsx @@ -6,12 +6,16 @@ import { DonationDetails, DonationReminderDto, FoodManufacturer, + User, } 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'; +import SectionEmptyState from '@components/sectionEmptyState'; +import PageEmptyState from '@components/pageEmptyState'; +import { DashboardStats } from '@components/dashboardStats'; const FoodManufacturerDashboard: React.FC = () => { const navigate = useNavigate(); @@ -19,15 +23,23 @@ const FoodManufacturerDashboard: React.FC = () => { const [errorAlertState, setErrorMessage] = useAlert(); const [foodManufacturer, setFoodManufacturer] = useState(null); + const [user, setUser] = useState(null); const [upcomingReminders, setUpcomingReminders] = useState< DonationReminderDto[] >([]); const [recentDonations, setRecentDonations] = useState([]); + const [stats, setStats] = useState | null>(null); useEffect(() => { const fetchFmData = async () => { let fmId: number; try { + const currentUser = await ApiClient.getMe(); + setUser(currentUser); + + const userStats = await ApiClient.getUserStats(currentUser.id); + setStats(userStats); + fmId = await ApiClient.getCurrentUserFoodManufacturerId(); const fm = await ApiClient.getFoodManufacturer(fmId); setFoodManufacturer(fm); @@ -41,14 +53,12 @@ const FoodManufacturerDashboard: React.FC = () => { 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') { const sorted = donations.value .map((d: DonationDetails) => d.donation) @@ -66,6 +76,11 @@ const FoodManufacturerDashboard: React.FC = () => { fetchFmData(); }, [setErrorMessage]); + if (!foodManufacturer) return null; + + const isPageEmpty = + upcomingReminders.length === 0 && recentDonations.length === 0; + return ( {errorAlertState && ( @@ -80,47 +95,85 @@ const FoodManufacturerDashboard: React.FC = () => { Welcome, {foodManufacturer?.foodManufacturerName} - - Upcoming Donations - - - {upcomingReminders.map((reminder) => ( - - navigate( - `${ROUTES.FM_DONATION_MANAGEMENT}?donationId=${reminder.donation.donationId}`, - ) - } - /> - ))} - + {stats && } - - Recent Donations - - - {recentDonations.map((donation) => ( - - navigate( - `${ROUTES.FM_DONATION_MANAGEMENT}?donationId=${donation.donationId}`, - ) - } - /> - ))} - + {isPageEmpty ? ( + + ) : ( + <> + + Upcoming Donations + + {upcomingReminders.length === 0 ? ( + + + + ) : ( + + {upcomingReminders.map((reminder) => ( + + navigate( + `${ROUTES.FM_DONATION_MANAGEMENT}?donationId=${reminder.donation.donationId}`, + ) + } + /> + ))} + + )} + + + Recent Donations + + {recentDonations.length === 0 ? ( + + + + ) : ( + + {recentDonations.map((donation) => ( + + navigate( + `${ROUTES.FM_DONATION_MANAGEMENT}?donationId=${donation.donationId}`, + ) + } + /> + ))} + + )} + + )} ); }; diff --git a/apps/frontend/src/containers/pantryDashboard.tsx b/apps/frontend/src/containers/pantryDashboard.tsx index 182c9a9ef..b3e39bbb5 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..8b28df94c 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}`, + ) + } + /> + ))} + + )} + + )} ); };