Admin Dashboard Page
Admin Dashboard Component Documentation
Overview
The AdminDashboard component is designed to display key metrics and reports to the admin user. It uses a container layout from MDBReact to organize the data presentation. The component fetches report data from the backend and displays it using several sub-components: TotalUsersCard, ActivePaymentsCard, TotalRevenueCard, and OverduePayments.
Structure
- Loading State: Utilizes
useStateto manage the loading state, displayingLargeLoadingSpinnerwhile fetching data. - Error Handling: Implements
ErrorComponentfor displaying any errors that occur during the fetch operation. - Sub-Components: Breaks down the UI into smaller components for each type of data.
useEffectHook: Manages side effects, fetching report data on component mount and when the user token changes.- Context: Uses
UserContextto access the current user’s token.
Sub-Components
TotalUsersCard: Displays the total number of users.ActivePaymentsCard: Shows the count of active recurring payments.TotalRevenueCard: Presents the total revenue collected for the current monthOverduePayments: Lists all overdue payments for the month in a tabular format.
Data Fetching
- API Call: Uses
getReportsfunction fromhelpers/reportsApito fetch the reports data. - Error Handling: Catches any errors during the API call and sets the error state.
- Dependency Array: Reacts to changes in the user’s token.
Usage
- Import and render
AdminDashboardin the admin route. - Ensure that
UserContextis properly set up to provide the current user’s token.
Future Enhancements
-
Data Visualization: Integrate chart libraries for visual representation of some metrics.
-
Dynamic Updates: Implement real-time data fetching to keep the dashboard updated.
-
Check Currency: Currently it calculates the current total payments for the month just based on all completed payments but it should also check for whether the payment is in xcd/us and differentiate.
Dependencies
mdb-react-ui-kitfor UI components.UserContextfor accessing user data.getReportsfromhelpers/reportsApifor API requests.- Custom components like
TotalUsersCard,ActivePaymentsCard, etc. for data display.
This component is crucial for the admin panel, providing a quick overview of key metrics and the financial health of the platform.