Fixed backend issue, update course status working
This commit is contained in:
@@ -1,52 +1,3 @@
|
||||
// import React, { useState, useEffect } from 'react';
|
||||
// import { useLocation, useNavigate } from "react-router-dom";
|
||||
// import "./CourseTable.css";
|
||||
// import { fetchCourses } from '../api';
|
||||
|
||||
// const CourseTable = () => {
|
||||
// const { state } = useLocation();
|
||||
// const courses = state?.courses;
|
||||
// const navigate= useNavigate();
|
||||
// console.log(courses);
|
||||
|
||||
// useEffect(() => {
|
||||
// if (!courses || courses.length === 0) {
|
||||
// alert("No courses available");
|
||||
// }
|
||||
// }, [courses]);
|
||||
|
||||
// if (!courses) {
|
||||
// return <div>Loading...</div>;
|
||||
// }
|
||||
|
||||
// const handleRowClick = (course) => {
|
||||
// navigate(`/course-form/${course.courseId}`, { state: { course } });
|
||||
// };
|
||||
|
||||
// return (
|
||||
// <table className="course-table">
|
||||
// <thead>
|
||||
// <tr>
|
||||
// <th>CourseID</th>
|
||||
// <th>Course Name</th>
|
||||
// <th>Status</th>
|
||||
// </tr>
|
||||
// </thead>
|
||||
// <tbody>
|
||||
// {courses.map(course => (
|
||||
// <tr key={course.courseId} onClick={() => handleRowClick(course)}>
|
||||
// <td>{course.courseId}</td>
|
||||
// <td>{course.name}</td>
|
||||
// <td>{course.status}</td>
|
||||
// </tr>
|
||||
// ))}
|
||||
// </tbody>
|
||||
// </table>
|
||||
// );
|
||||
// }
|
||||
|
||||
// export default CourseTable;
|
||||
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
import "./CourseTable.css";
|
||||
@@ -75,22 +26,36 @@ const CourseTable = () => {
|
||||
fetchAllCourses();
|
||||
}, [state?.courses]);
|
||||
|
||||
// useEffect(() => {
|
||||
// if (state?.updatedCourse) {
|
||||
// setCourses((prevCourses) => {
|
||||
// // Filter only the updated course
|
||||
// const filteredCourses = prevCourses.filter((course) =>
|
||||
// course.courseId === state.updatedCourse.courseId
|
||||
// );
|
||||
|
||||
// return filteredCourses.map((course) =>
|
||||
// course.courseId === state.updatedCourse.courseId
|
||||
// ? { ...course, status: "Submitted" } // Update status
|
||||
// : course
|
||||
// );
|
||||
// });
|
||||
// }
|
||||
// }, [state?.updatedCourse]);
|
||||
|
||||
useEffect(() => {
|
||||
if (state?.updatedCourse) {
|
||||
setCourses((prevCourses) => {
|
||||
// Filter only the updated course
|
||||
const filteredCourses = prevCourses.filter((course) =>
|
||||
setCourses((prevCourses) =>
|
||||
prevCourses.map((course) =>
|
||||
course.courseId === state.updatedCourse.courseId
|
||||
);
|
||||
|
||||
return filteredCourses.map((course) =>
|
||||
course.courseId === state.updatedCourse.courseId
|
||||
? { ...course, status: "Submitted" } // Update status
|
||||
? { ...course, status: "Submitted" } // Update the status for the specific course
|
||||
: course
|
||||
);
|
||||
});
|
||||
)
|
||||
);
|
||||
}
|
||||
}, [state?.updatedCourse]);
|
||||
|
||||
|
||||
|
||||
if (loading) {
|
||||
return <div>Loading...</div>;
|
||||
|
||||
Reference in New Issue
Block a user