- Drivers' List
+ Drivers List
List of Drivers within the university.
diff --git a/frontend/src/pages/RegistrationList.tsx b/frontend/src/pages/RegistrationList.tsx
index 5c931ed..09e7e93 100644
--- a/frontend/src/pages/RegistrationList.tsx
+++ b/frontend/src/pages/RegistrationList.tsx
@@ -1,4 +1,4 @@
-import { useState } from "react";
+import { useEffect, useState } from "react";
import { toast } from "react-toastify";
import useGetRegistration from "../hooks/registration-hooks/useGetRegistration";
import useDeleteRegistration from "../hooks/registration-hooks/useDeleteRegistration";
@@ -7,14 +7,21 @@ import Loading from "../components/Loading";
import RegistrationListCard from "../components/RegistrationListCard";
import { Registration } from "../types/datatypes";
import { useApproveRegistration } from "../hooks/registration-hooks/useApproveRegistration";
+import SearchAndSort from "../components/SearchAndSort";
const RegistrationList = () => {
const { registration: registrations, loading } = useGetRegistration();
- const { deleteRegistration, deleteloading: deleteLoading } =
- useDeleteRegistration();
+ const { deleteRegistration } = useDeleteRegistration();
const [selectedRegistration, setSelectedRegistration] =
useState();
const { approveRegistration } = useApproveRegistration();
+ const [sortedRegistrations, setSortedRegistrations] = useState<
+ Registration[]
+ >([]);
+ const [originalRegistrations, setOriginalRegistrations] = useState<
+ Registration[]
+ >([]);
+ const [isSorted, setIsSorted] = useState(false); // Tracks toggle state
const handleRegisterClick = (registration: Registration) => {
setSelectedRegistration(registration);
@@ -34,24 +41,33 @@ const RegistrationList = () => {
// Perform the deletion of the registration
await deleteRegistration(selectedRegistration.license_number);
- // After deletion, remove the registration from the list
setSelectedRegistration(undefined);
+ }
+ };
- // Optionally, you can update the list by filtering out the deleted registration
- // const updatedRegistrations = registrations.filter(
- // (registration) => registration.license_number !== selectedRegistration.license_number
- // );
- // setRegistrations(updatedRegistrations); // If you manage registrations in state
-
- toast.success("Registration has been rejected rawr.");
+ const handleSortToggle = () => {
+ if (!registrations) return;
- // Optionally, refresh the list or perform any other necessary updates
- setTimeout(() => {
- window.location.reload();
- }, 1000);
+ if (isSorted) {
+ setSortedRegistrations(originalRegistrations); // Reset to original order
+ } else {
+ const sorted = [...registrations].sort((a, b) => {
+ const nameA = `${a.first_name} ${a.last_name}`.toLowerCase();
+ const nameB = `${b.first_name} ${b.last_name}`.toLowerCase();
+ return nameA.localeCompare(nameB);
+ });
+ setSortedRegistrations(sorted);
}
+ setIsSorted(!isSorted); // Toggle the sort state
};
+ useEffect(() => {
+ if (registrations) {
+ setOriginalRegistrations(registrations);
+ setSortedRegistrations(registrations);
+ }
+ }, [registrations]);
+
if (loading) return ;
return (
@@ -59,11 +75,11 @@ const RegistrationList = () => {
-
-
-
+
+
+
{selectedRegistration ? (
-
+
@@ -75,18 +91,18 @@ const RegistrationList = () => {