diff --git a/client/src/App.tsx b/client/src/App.tsx
index c0b78d6..4ad07a2 100644
--- a/client/src/App.tsx
+++ b/client/src/App.tsx
@@ -24,6 +24,7 @@ import UsersManagement from "./pages/UsersManagement";
import ResetPasswordPage from "./pages/ResetPasswordPage";
import ForgotPasswordPage from "./pages/ForgotPasswordPage";
import RestrictedLayout from "./layouts/restricted";
+import Ranking from "./pages/Ranking";
function App() {
return (
@@ -89,6 +90,10 @@ function App() {
} path="createEvent" />
} path="editEvent/:id" />
+
+
+ } />
+
diff --git a/client/src/components/AdministratorNavigationPanel.tsx b/client/src/components/AdministratorNavigationPanel.tsx
index cc78b6b..0d7123c 100644
--- a/client/src/components/AdministratorNavigationPanel.tsx
+++ b/client/src/components/AdministratorNavigationPanel.tsx
@@ -63,9 +63,8 @@ export default function AdministratorNavigationPanel() {
return (
@@ -167,7 +163,7 @@ export default function AdministratorNavigationPanel() {
}
- onClickRef="#"
+ onClickRef="ranking"
/>
([]);
+ const [sortDescriptor, setSortDescriptor] = useState({
+ column: 'avgBill',
+ direction: 'ascending',
+ });
+
+ useEffect(() => {
+ const getFormData = async () => {
+ try {
+ const response = await instance.get(`${config.serverAddress}/hbcform`);
+ const processedData = response.data.map((data: FormData) => ({
+ ...data,
+ electricalBill: Number(data.electricalBill),
+ waterBill: Number(data.waterBill),
+ totalBill: Number(data.totalBill),
+ avgBill: Number(data.avgBill),
+ }));
+ setFormData(processedData);
+ } catch (error) {
+ console.log("Failed to fetch form data");
+ }
+ };
+
+ getFormData();
+ }, []);
+
+ const sortFormData = (list: FormData[], descriptor: SortDescriptor) => {
+ const { column, direction } = descriptor;
+
+ if (column === 'avgBill') {
+ return [...list].sort((a, b) =>
+ direction === 'ascending' ? a.avgBill - b.avgBill : b.avgBill - a.avgBill
+ );
+ }
+
+ return list; // No sorting if the column is not 'avgBill'
+ };
+
+ const handleSort = () => {
+ const { direction } = sortDescriptor;
+ const newDirection = direction === 'ascending' ? 'descending' : 'ascending';
+
+ setSortDescriptor({ column: 'avgBill', direction: newDirection });
+ };
+
+ const renderSortIndicator = () => {
+ if (sortDescriptor.column === 'avgBill') {
+ return sortDescriptor.direction === 'ascending' ? ↑ : ↓ ;
+ }
+ return null;
+ };
+
+ const sortedFormData = sortFormData(formData, sortDescriptor);
+
+ return (
+
+ Form Data
+
+
+
+
+ Average Bill {renderSortIndicator()}
+
+ Form ID
+ User ID
+ Electrical Bill
+ Water Bill
+ Total Bill
+ Number of Dependents
+ Electrical Bill Picture
+ Water Bill Picture
+ Actions
+
+
+ {sortedFormData.map((data) => (
+
+ ${data.avgBill.toFixed(2)}
+ {data.id}
+ {data.userId}
+ ${data.electricalBill.toFixed(2)}
+ ${data.waterBill.toFixed(2)}
+ ${data.totalBill.toFixed(2)}
+ {data.noOfDependents}
+
+ {data.ebPicture && }
+
+
+ {data.wbPicture && }
+
+
+
+
+
+
+ ))}
+
+
+
+
+ );
+}