This commit is contained in:
Harikrishnan Gopal
2025-01-22 11:22:42 +05:30
parent 1fc49ca69a
commit 9e1734e395
7 changed files with 133 additions and 9 deletions

View File

@@ -13,6 +13,8 @@ import WelcomeWithFilter from "./Pages/WelcomeWithFilter";
import "react-toastify/dist/ReactToastify.css";
import CourseTable from "./Pages/CourseTable";
import GenerateCSV from "./Pages/GenerateCSV";
import ConsolidatedTable from "./Pages/ConsolidatedTable";
function App() {
return (
@@ -30,6 +32,7 @@ function App() {
<Route path="/ResetPw/:token" element={<ResetPwPage />}></Route>
<Route path="/Filter" element={<FilterPage />} />
<Route path="/courses" element={<CourseTable />} />
<Route path="/consolidated" element={<ConsolidatedTable />} />
</Routes>
</Router>
);

View File

@@ -0,0 +1,58 @@
import React, { useState, useEffect } from "react";
import axios from "axios";
const ConsolidatedTable = () => {
const [data, setData] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
const fetchData = async () => {
try {
const response = await axios.get("http://localhost:8080/api/data/consolidated");
setData(response.data);
setLoading(false);
} catch (error) {
console.error("Error fetching consolidated data:", error);
setLoading(false);
}
};
fetchData();
}, []);
if (loading) {
return <div>Loading...</div>;
}
return (
<div>
<h1>Consolidated Data</h1>
<table border="1" style={{ width: "100%", textAlign: "left" }}>
<thead>
<tr>
<th>Faculty ID</th>
<th>Faculty Name</th>
<th>Course ID</th>
<th>Course Name</th>
<th>Task</th>
</tr>
</thead>
<tbody>
{data.map((faculty) =>
faculty.tasks.map((task, index) => (
<tr key={`${faculty.facultyId}-${index}`}>
<td>{faculty.facultyId}</td>
<td>{faculty.facultyName}</td>
<td>{task.courseId}</td>
<td>{task.courseName}</td>
<td>{task.task}</td>
</tr>
))
)}
</tbody>
</table>
</div>
);
};
export default ConsolidatedTable;

View File

@@ -99,15 +99,20 @@ const CourseForm = () => {
await updateCourseStatus(course?.courseId || id);
console.log("Form submitted successfully:", payload);
const filteredCourses = JSON.parse(localStorage.getItem("filteredCourses")) || [];
// Redirect to courses page after successful submission
navigate("/courses", {
state: {
courses: filteredCourses,
updatedCourse: {
...course,
status: "Submitted",
},
},
});
} catch (error) {
console.error("Failed to save appointment:", error);
}

View File

@@ -23,16 +23,39 @@ const FilterPage = () => {
}
};
// const handleApplyFilter = async () => {
// if (!formData.scheme || !formData.semester || !formData.department || !formData.program) {
// alert("Please fill all the fields before applying the filter.");
// return;
// }
// try {
// const filteredCourses = await fetchCourses(formData);
// console.log(formData);
// if (filteredCourses.length > 0) {
// navigate("/courses", { state: { courses: filteredCourses } });
// } else {
// alert("No courses found for the selected filters.");
// }
// } catch (error) {
// console.error("Error fetching courses:", error);
// alert("Failed to fetch courses. Please try again later.");
// }
// };
const handleApplyFilter = async () => {
if (!formData.scheme || !formData.semester || !formData.department || !formData.program) {
alert("Please fill all the fields before applying the filter.");
return;
}
try {
const filteredCourses = await fetchCourses(formData);
console.log(formData);
if (filteredCourses.length > 0) {
// Save filteredCourses in localStorage
localStorage.setItem("filteredCourses", JSON.stringify(filteredCourses));
navigate("/courses", { state: { courses: filteredCourses } });
} else {
alert("No courses found for the selected filters.");
@@ -42,6 +65,7 @@ const FilterPage = () => {
alert("Failed to fetch courses. Please try again later.");
}
};
const getSemesters = () => {
if (!formData.program) return [];