diff --git a/client/src/Pages/AdminFacultyPage.jsx b/client/src/Pages/AdminFacultyPage.jsx index a87fd65..c64b348 100644 --- a/client/src/Pages/AdminFacultyPage.jsx +++ b/client/src/Pages/AdminFacultyPage.jsx @@ -18,10 +18,12 @@ export const AdminFacultyPage = () => { program: '', courses: [''], }); + const [courses, setcourses] = useState({}); // Fetch all faculties useEffect(() => { fetchFaculties(); + fetchCourses(); }, []); const fetchFaculties = async () => { @@ -29,6 +31,19 @@ export const AdminFacultyPage = () => { setFaculties(res.data); }; + const fetchCourses = async () => { + try { + const res = await axios.get("http://localhost:8080/api/courses"); + const courseMap = res.data.reduce((acc, course) => { + acc[course.courseId] = course.name; + return acc; + }, {}); + setcourses(courseMap); + } catch (error) { + console.error("Error fetching courses: ", error); + } + }; + // Add or Update Faculty const handleAddOrUpdateFaculty = async (e) => { e.preventDefault(); @@ -180,7 +195,6 @@ export const AdminFacultyPage = () => { style={inputStyle} /> setCurrentFaculty({ ...currentFaculty, department: e.target.value })} @@ -197,16 +211,23 @@ export const AdminFacultyPage = () => { /> -

Courses:

+ {currentFaculty.courses.map((course, index) => (
- handleCourseChange(index, e.target.value)} style={{ ...inputStyle, flex: 1 }} - /> + > + + {Object.entries(courses).map(([courseId, courseName]) => ( + + ))} + +
))} @@ -239,13 +260,23 @@ export const AdminFacultyPage = () => { {filteredFaculties.length > 0 ? ( filteredFaculties.map((f) => ( - {f.facultyId} - {f.name} - {f.email} - {f.department} - {f.program} - {f.courses.join(', ')} - + {f.facultyId} + {f.name} + {f.email} + {f.department} + {f.program} + +