diff --git a/client/src/components/Student/StudentTable.jsx b/client/src/components/Student/StudentTable.jsx
index d32450f..f478ff9 100644
--- a/client/src/components/Student/StudentTable.jsx
+++ b/client/src/components/Student/StudentTable.jsx
@@ -1,4 +1,4 @@
-import { useCallback, useEffect, useState } from 'react';
+import { useCallback, useState } from 'react';
import { GrValidate } from 'react-icons/gr';
import { MdDelete } from 'react-icons/md';
import { toast } from 'react-toastify';
@@ -18,21 +18,36 @@ const StudentTable = () => {
const [companies, setCompanies] = useState([]);
const user = getUser();
- useEffect(() => {
- const fetchCompanies = async () => {
- try {
- const res = await getCompanies();
- res.data.forEach((company) => {
- company.id = company._id;
- });
- setCompanies(res.data);
- } catch (error) {
- console.error('Error fetching companies:', error);
- }
- };
- fetchCompanies();
+ const fetchStudentData = useCallback(async () => {
+ try {
+ const response = await getStudents();
+ response.data.users.forEach((student) => {
+ student.id = student._id;
+ });
+ response.data.users.sort((a, b) => a.rollNo.localeCompare(b.rollNo));
+ setStudents(response.data.users);
+ } catch (error) {
+ console.error('Error fetching students:', error);
+ }
+ }, []);
+
+ const fetchCompaniesData = useCallback(async () => {
+ try {
+ const res = await getCompanies();
+ res.data.forEach((company) => {
+ company.id = company._id;
+ });
+ setCompanies(res.data);
+ } catch (error) {
+ console.error('Error fetching companies:', error);
+ }
}, []);
+ const fetchData = useCallback(async () => {
+ await fetchStudentData();
+ await fetchCompaniesData();
+ }, [fetchStudentData, fetchCompaniesData]);
+
const closeModal = () => {
setIsModalOpen(false);
setSelectedStudent(null);
@@ -55,7 +70,7 @@ const StudentTable = () => {
toast.success();
setIsModalOpen(false);
setSelectedStudent(null);
- fetchData();
+ fetchStudentData();
} catch (error) {
toast.error();
}
@@ -67,7 +82,7 @@ const StudentTable = () => {
toast.success();
setSelectedStudentDelete(null);
setIsModalOpen(false);
- fetchData();
+ fetchStudentData();
} catch (error) {
toast.error();
}
@@ -77,7 +92,7 @@ const StudentTable = () => {
try {
const res = await updateUserRole(params.id, event.target.value);
toast.success();
- fetchData();
+ fetchStudentData();
} catch (error) {
toast.error();
}
@@ -87,7 +102,7 @@ const StudentTable = () => {
try {
const res = await updateStudentCompany(params.id, event.target.value);
toast.success();
- fetchData();
+ fetchStudentData();
} catch (error) {
toast.error();
}
@@ -126,14 +141,12 @@ const StudentTable = () => {
const companyDropdownRenderer = (params) => {
return (
-