CourseForm backend done
This commit is contained in:
@@ -1,11 +1,200 @@
|
|||||||
|
// import React, { useState, useEffect } from "react";
|
||||||
|
// import { useLocation, useParams, useNavigate } from "react-router-dom";
|
||||||
|
// import "./CourseForm.css";
|
||||||
|
|
||||||
|
// const CourseForm = () => {
|
||||||
|
// const { id } = useParams(); // Get the course ID from the URL params
|
||||||
|
// const location = useLocation();
|
||||||
|
// const navigate = useNavigate(); // Updated for navigation
|
||||||
|
// const { course } = location.state || {};
|
||||||
|
|
||||||
|
// const [options, setOptions] = useState({
|
||||||
|
// assessment: [],
|
||||||
|
// reassessment: [],
|
||||||
|
// paperSetting: [],
|
||||||
|
// moderation: [],
|
||||||
|
// pwdPaperSetter: [],
|
||||||
|
// oralsPracticals: [], // New field for Orals/Practicals
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const [formData, setFormData] = useState({
|
||||||
|
// assessment: "",
|
||||||
|
// reassessment: "",
|
||||||
|
// paperSetting: "",
|
||||||
|
// moderation: "",
|
||||||
|
// pwdPaperSetter: "",
|
||||||
|
// oralsPracticals: "", // New field for Orals/Practicals
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const [errors, setErrors] = useState({}); // To track validation errors
|
||||||
|
|
||||||
|
// // Fetch data for search bars
|
||||||
|
// useEffect(() => {
|
||||||
|
// const fetchOptions = async () => {
|
||||||
|
// try {
|
||||||
|
// const response = await fetch("/api/options"); // Replace with your API endpoint
|
||||||
|
// const data = await response.json();
|
||||||
|
// setOptions(data);
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error("Failed to fetch options:", error);
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// fetchOptions();
|
||||||
|
// }, []);
|
||||||
|
|
||||||
|
// const handleInputChange = (e) => {
|
||||||
|
// const { name, value } = e.target;
|
||||||
|
// setFormData({ ...formData, [name]: value });
|
||||||
|
// };
|
||||||
|
|
||||||
|
// const validateForm = () => {
|
||||||
|
// const newErrors = {};
|
||||||
|
// Object.keys(formData).forEach((field) => {
|
||||||
|
// if (!formData[field]) {
|
||||||
|
// newErrors[field] = "This field is required";
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// setErrors(newErrors);
|
||||||
|
// return Object.keys(newErrors).length === 0;
|
||||||
|
// };
|
||||||
|
|
||||||
|
// const handleSubmit = (e) => {
|
||||||
|
// e.preventDefault();
|
||||||
|
// if (validateForm()) {
|
||||||
|
// console.log("Form submitted:", formData);
|
||||||
|
|
||||||
|
// navigate("/courses", { state: { updatedCourse: { ...course, status: "Submitted" } } });
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// return (
|
||||||
|
// <div className="form-container">
|
||||||
|
// <h2>Course Info</h2>
|
||||||
|
// <form onSubmit={handleSubmit}>
|
||||||
|
// <label>
|
||||||
|
// Course ID:
|
||||||
|
// <input type="text" value={course?.id || id} readOnly />
|
||||||
|
// </label>
|
||||||
|
// <label>
|
||||||
|
// Course Name:
|
||||||
|
// <input type="text" value={course?.name || ""} readOnly />
|
||||||
|
// </label>
|
||||||
|
// <label className={errors.oralsPracticals ? "error" : ""}>
|
||||||
|
// Orals/Practicals:
|
||||||
|
// <input
|
||||||
|
// type="text"
|
||||||
|
// name="oralsPracticals"
|
||||||
|
// list="oralsPracticals-options"
|
||||||
|
// value={formData.oralsPracticals}
|
||||||
|
// onChange={handleInputChange}
|
||||||
|
// />
|
||||||
|
// <datalist id="oralsPracticals-options">
|
||||||
|
// {options.oralsPracticals.map((option, index) => (
|
||||||
|
// <option key={index} value={option} />
|
||||||
|
// ))}
|
||||||
|
// </datalist>
|
||||||
|
// {errors.oralsPracticals && <span className="error-message">{errors.oralsPracticals}</span>}
|
||||||
|
// </label>
|
||||||
|
// <label className={errors.assessment ? "error" : ""}>
|
||||||
|
// Assessment:
|
||||||
|
// <input
|
||||||
|
// type="text"
|
||||||
|
// name="assessment"
|
||||||
|
// list="assessment-options"
|
||||||
|
// value={formData.assessment}
|
||||||
|
// onChange={handleInputChange}
|
||||||
|
// />
|
||||||
|
// <datalist id="assessment-options">
|
||||||
|
// {options.assessment.map((option, index) => (
|
||||||
|
// <option key={index} value={option} />
|
||||||
|
// ))}
|
||||||
|
// </datalist>
|
||||||
|
// {errors.assessment && <span className="error-message">{errors.assessment}</span>}
|
||||||
|
// </label>
|
||||||
|
// <label className={errors.reassessment ? "error" : ""}>
|
||||||
|
// Reassessment:
|
||||||
|
// <input
|
||||||
|
// type="text"
|
||||||
|
// name="reassessment"
|
||||||
|
// list="reassessment-options"
|
||||||
|
// value={formData.reassessment}
|
||||||
|
// onChange={handleInputChange}
|
||||||
|
// />
|
||||||
|
// <datalist id="reassessment-options">
|
||||||
|
// {options.reassessment.map((option, index) => (
|
||||||
|
// <option key={index} value={option} />
|
||||||
|
// ))}
|
||||||
|
// </datalist>
|
||||||
|
// {errors.reassessment && <span className="error-message">{errors.reassessment}</span>}
|
||||||
|
// </label>
|
||||||
|
// <label className={errors.paperSetting ? "error" : ""}>
|
||||||
|
// Paper Setting:
|
||||||
|
// <input
|
||||||
|
// type="text"
|
||||||
|
// name="paperSetting"
|
||||||
|
// list="paperSetting-options"
|
||||||
|
// value={formData.paperSetting}
|
||||||
|
// onChange={handleInputChange}
|
||||||
|
// />
|
||||||
|
// <datalist id="paperSetting-options">
|
||||||
|
// {options.paperSetting.map((option, index) => (
|
||||||
|
// <option key={index} value={option} />
|
||||||
|
// ))}
|
||||||
|
// </datalist>
|
||||||
|
// {errors.paperSetting && <span className="error-message">{errors.paperSetting}</span>}
|
||||||
|
// </label>
|
||||||
|
// <label className={errors.moderation ? "error" : ""}>
|
||||||
|
// Moderation:
|
||||||
|
// <input
|
||||||
|
// type="text"
|
||||||
|
// name="moderation"
|
||||||
|
// list="moderation-options"
|
||||||
|
// value={formData.moderation}
|
||||||
|
// onChange={handleInputChange}
|
||||||
|
// />
|
||||||
|
// <datalist id="moderation-options">
|
||||||
|
// {options.moderation.map((option, index) => (
|
||||||
|
// <option key={index} value={option} />
|
||||||
|
// ))}
|
||||||
|
// </datalist>
|
||||||
|
// {errors.moderation && <span className="error-message">{errors.moderation}</span>}
|
||||||
|
// </label>
|
||||||
|
// <label className={errors.pwdPaperSetter ? "error" : ""}>
|
||||||
|
// PwD Paper Setter:
|
||||||
|
// <input
|
||||||
|
// type="text"
|
||||||
|
// name="pwdPaperSetter"
|
||||||
|
// list="pwdPaperSetter-options"
|
||||||
|
// value={formData.pwdPaperSetter}
|
||||||
|
// onChange={handleInputChange}
|
||||||
|
// />
|
||||||
|
// <datalist id="pwdPaperSetter-options">
|
||||||
|
// {options.pwdPaperSetter.map((option, index) => (
|
||||||
|
// <option key={index} value={option} />
|
||||||
|
// ))}
|
||||||
|
// </datalist>
|
||||||
|
// {errors.pwdPaperSetter && <span className="error-message">{errors.pwdPaperSetter}</span>}
|
||||||
|
// </label>
|
||||||
|
// <button type="submit" disabled={Object.keys(errors).length > 0}>Submit</button>
|
||||||
|
// </form>
|
||||||
|
// </div>
|
||||||
|
// );
|
||||||
|
// };
|
||||||
|
|
||||||
|
// export default CourseForm;
|
||||||
|
|
||||||
|
// CourseForm.jsx
|
||||||
|
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { useLocation, useParams, useNavigate } from "react-router-dom";
|
import { useLocation, useParams, useNavigate } from "react-router-dom";
|
||||||
|
import { fetchFaculties } from "../api";
|
||||||
import "./CourseForm.css";
|
import "./CourseForm.css";
|
||||||
|
|
||||||
const CourseForm = () => {
|
const CourseForm = () => {
|
||||||
const { id } = useParams(); // Get the course ID from the URL params
|
const { id } = useParams();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate(); // Updated for navigation
|
const navigate = useNavigate();
|
||||||
const { course } = location.state || {};
|
const { course } = location.state || {};
|
||||||
|
|
||||||
const [options, setOptions] = useState({
|
const [options, setOptions] = useState({
|
||||||
@@ -14,7 +203,8 @@ const CourseForm = () => {
|
|||||||
paperSetting: [],
|
paperSetting: [],
|
||||||
moderation: [],
|
moderation: [],
|
||||||
pwdPaperSetter: [],
|
pwdPaperSetter: [],
|
||||||
oralsPracticals: [], // New field for Orals/Practicals
|
oralsPracticals: [],
|
||||||
|
faculties: [], // New field for faculties
|
||||||
});
|
});
|
||||||
|
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
@@ -26,21 +216,23 @@ const CourseForm = () => {
|
|||||||
oralsPracticals: "", // New field for Orals/Practicals
|
oralsPracticals: "", // New field for Orals/Practicals
|
||||||
});
|
});
|
||||||
|
|
||||||
const [errors, setErrors] = useState({}); // To track validation errors
|
const [errors, setErrors] = useState({});
|
||||||
|
|
||||||
// Fetch data for search bars
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchOptions = async () => {
|
const fetchOptionsAndFaculties = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/options"); // Replace with your API endpoint
|
const facultiesData = await fetchFaculties(); // Fetch faculty names from the backend
|
||||||
const data = await response.json();
|
console.log(facultiesData);
|
||||||
setOptions(data);
|
setOptions(prevOptions => ({
|
||||||
|
...prevOptions,
|
||||||
|
faculties: facultiesData,
|
||||||
|
}));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to fetch options:", error);
|
console.error("Failed to fetch faculties:", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchOptions();
|
fetchOptionsAndFaculties();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleInputChange = (e) => {
|
const handleInputChange = (e) => {
|
||||||
@@ -59,15 +251,30 @@ const CourseForm = () => {
|
|||||||
return Object.keys(newErrors).length === 0;
|
return Object.keys(newErrors).length === 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// const handleSubmit = (e) => {
|
||||||
|
// e.preventDefault();
|
||||||
|
// if (validateForm()) {
|
||||||
|
// console.log("Form submitted:", formData);
|
||||||
|
// navigate("/courses", { state: { updatedCourse: { ...course, status: "Submitted" } } });
|
||||||
|
// }
|
||||||
|
// };
|
||||||
const handleSubmit = (e) => {
|
const handleSubmit = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (validateForm()) {
|
if (validateForm()) {
|
||||||
console.log("Form submitted:", formData);
|
console.log("Form submitted:", formData);
|
||||||
|
navigate("/courses", {
|
||||||
navigate("/courses", { state: { updatedCourse: { ...course, status: "Submitted" } } });
|
state: {
|
||||||
|
updatedCourse: {
|
||||||
|
...course,
|
||||||
|
status: "Submitted", // Update status
|
||||||
|
...formData, // Include form data if required
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="form-container">
|
<div className="form-container">
|
||||||
<h2>Course Info</h2>
|
<h2>Course Info</h2>
|
||||||
@@ -91,7 +298,7 @@ const CourseForm = () => {
|
|||||||
/>
|
/>
|
||||||
<datalist id="oralsPracticals-options">
|
<datalist id="oralsPracticals-options">
|
||||||
{options.oralsPracticals.map((option, index) => (
|
{options.oralsPracticals.map((option, index) => (
|
||||||
<option key={index} value={option} />
|
<option key={index} value={option.name} />
|
||||||
))}
|
))}
|
||||||
</datalist>
|
</datalist>
|
||||||
{errors.oralsPracticals && <span className="error-message">{errors.oralsPracticals}</span>}
|
{errors.oralsPracticals && <span className="error-message">{errors.oralsPracticals}</span>}
|
||||||
@@ -107,7 +314,7 @@ const CourseForm = () => {
|
|||||||
/>
|
/>
|
||||||
<datalist id="assessment-options">
|
<datalist id="assessment-options">
|
||||||
{options.assessment.map((option, index) => (
|
{options.assessment.map((option, index) => (
|
||||||
<option key={index} value={option} />
|
<option key={index} value={option.name} />
|
||||||
))}
|
))}
|
||||||
</datalist>
|
</datalist>
|
||||||
{errors.assessment && <span className="error-message">{errors.assessment}</span>}
|
{errors.assessment && <span className="error-message">{errors.assessment}</span>}
|
||||||
@@ -123,7 +330,7 @@ const CourseForm = () => {
|
|||||||
/>
|
/>
|
||||||
<datalist id="reassessment-options">
|
<datalist id="reassessment-options">
|
||||||
{options.reassessment.map((option, index) => (
|
{options.reassessment.map((option, index) => (
|
||||||
<option key={index} value={option} />
|
<option key={index} value={option.name} />
|
||||||
))}
|
))}
|
||||||
</datalist>
|
</datalist>
|
||||||
{errors.reassessment && <span className="error-message">{errors.reassessment}</span>}
|
{errors.reassessment && <span className="error-message">{errors.reassessment}</span>}
|
||||||
@@ -139,7 +346,7 @@ const CourseForm = () => {
|
|||||||
/>
|
/>
|
||||||
<datalist id="paperSetting-options">
|
<datalist id="paperSetting-options">
|
||||||
{options.paperSetting.map((option, index) => (
|
{options.paperSetting.map((option, index) => (
|
||||||
<option key={index} value={option} />
|
<option key={index} value={option.name} />
|
||||||
))}
|
))}
|
||||||
</datalist>
|
</datalist>
|
||||||
{errors.paperSetting && <span className="error-message">{errors.paperSetting}</span>}
|
{errors.paperSetting && <span className="error-message">{errors.paperSetting}</span>}
|
||||||
@@ -155,7 +362,7 @@ const CourseForm = () => {
|
|||||||
/>
|
/>
|
||||||
<datalist id="moderation-options">
|
<datalist id="moderation-options">
|
||||||
{options.moderation.map((option, index) => (
|
{options.moderation.map((option, index) => (
|
||||||
<option key={index} value={option} />
|
<option key={index} value={option.name} />
|
||||||
))}
|
))}
|
||||||
</datalist>
|
</datalist>
|
||||||
{errors.moderation && <span className="error-message">{errors.moderation}</span>}
|
{errors.moderation && <span className="error-message">{errors.moderation}</span>}
|
||||||
@@ -171,7 +378,7 @@ const CourseForm = () => {
|
|||||||
/>
|
/>
|
||||||
<datalist id="pwdPaperSetter-options">
|
<datalist id="pwdPaperSetter-options">
|
||||||
{options.pwdPaperSetter.map((option, index) => (
|
{options.pwdPaperSetter.map((option, index) => (
|
||||||
<option key={index} value={option} />
|
<option key={index} value={option.name} />
|
||||||
))}
|
))}
|
||||||
</datalist>
|
</datalist>
|
||||||
{errors.pwdPaperSetter && <span className="error-message">{errors.pwdPaperSetter}</span>}
|
{errors.pwdPaperSetter && <span className="error-message">{errors.pwdPaperSetter}</span>}
|
||||||
|
|||||||
@@ -1,69 +1,105 @@
|
|||||||
// import React from "react";
|
// import React, { useState, useEffect } from 'react';
|
||||||
// import { useNavigate } from "react-router-dom";
|
// import { useLocation, useNavigate } from "react-router-dom";
|
||||||
// import "./CourseTable.css";
|
// import "./CourseTable.css";
|
||||||
|
// import { fetchCourses } from '../api';
|
||||||
|
|
||||||
// const CourseTable = ({courses}) => {
|
// const CourseTable = () => {
|
||||||
// const navigate = useNavigate();
|
// 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) => {
|
// const handleRowClick = (course) => {
|
||||||
// navigate(`/course-form/${course.id}`, { state: { course } });
|
// navigate(`/course-form/${course.courseId}`, { state: { course } });
|
||||||
// };
|
// };
|
||||||
|
|
||||||
// return (
|
// return (
|
||||||
// <div className="course-table">
|
// <table className="course-table">
|
||||||
// <h1>Courses</h1>
|
// <thead>
|
||||||
// <table border="1">
|
// <tr>
|
||||||
// <thead>
|
// <th>CourseID</th>
|
||||||
// <tr>
|
// <th>Course Name</th>
|
||||||
// <th>Course ID</th>
|
// <th>Status</th>
|
||||||
// <th>Course Name</th>
|
// </tr>
|
||||||
// <th>Status</th>
|
// </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>
|
// </tr>
|
||||||
// </thead>
|
// ))}
|
||||||
// <tbody>
|
// </tbody>
|
||||||
// {courses.map((course) => (
|
// </table>
|
||||||
// <tr
|
|
||||||
// key={course.id}
|
|
||||||
// onClick={() => handleRowClick(course)}
|
|
||||||
// style={{ cursor: "pointer" }}
|
|
||||||
// >
|
|
||||||
// <td>{course.id}</td>
|
|
||||||
// <td>{course.name}</td>
|
|
||||||
// <td>
|
|
||||||
// <span className={`status ${course.status.replace(" ", "-")}`}>
|
|
||||||
// {course.status}
|
|
||||||
// </span>
|
|
||||||
// </td>
|
|
||||||
// </tr>
|
|
||||||
// ))}
|
|
||||||
// </tbody>
|
|
||||||
// </table>
|
|
||||||
// </div>
|
|
||||||
// );
|
// );
|
||||||
// };
|
// }
|
||||||
|
|
||||||
// export default CourseTable;
|
// export default CourseTable;
|
||||||
|
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from "react";
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
import "./CourseTable.css";
|
import "./CourseTable.css";
|
||||||
import { fetchCourses } from '../api';
|
import { fetchCourses } from "../api";
|
||||||
|
|
||||||
const CourseTable = () => {
|
const CourseTable = () => {
|
||||||
const { state } = useLocation();
|
const { state } = useLocation();
|
||||||
const courses = state?.courses;
|
const [courses, setCourses] = useState(state?.courses || []);
|
||||||
console.log(courses);
|
const [loading, setLoading] = useState(!state?.courses);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!courses || courses.length === 0) {
|
const fetchAllCourses = async () => {
|
||||||
alert("No courses available");
|
if (!state?.courses) {
|
||||||
}
|
try {
|
||||||
}, [courses]);
|
const fetchedCourses = await fetchCourses(); // Fetch courses from API
|
||||||
|
setCourses(fetchedCourses);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch courses:", error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (!courses) {
|
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]);
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
return <div>Loading...</div>;
|
return <div>Loading...</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleRowClick = (course) => {
|
||||||
|
navigate(`/course-form/${course.courseId}`, { state: { course } });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<table className="course-table">
|
<table className="course-table">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -74,16 +110,22 @@ const CourseTable = () => {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{courses.map(course => (
|
{courses.length > 0 ? (
|
||||||
<tr key={course.id}>
|
courses.map((course) => (
|
||||||
<td>{course.courseId}</td>
|
<tr key={course.courseId} onClick={() => handleRowClick(course)}>
|
||||||
<td>{course.name}</td>
|
<td>{course.courseId}</td>
|
||||||
<td>{course.status}</td>
|
<td>{course.name}</td>
|
||||||
|
<td>{course.status}</td>
|
||||||
|
</tr>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<tr>
|
||||||
|
<td colSpan="3">No courses available</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default CourseTable;
|
export default CourseTable;
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ const Welcom = () => {
|
|||||||
return (
|
return (
|
||||||
<div className="welcom-container">
|
<div className="welcom-container">
|
||||||
<div className="welcom-message">
|
<div className="welcom-message">
|
||||||
<h1>Welcome, John Doe</h1>
|
<h1>Welcome</h1>
|
||||||
<p>You're signed in as DEC/EIC</p>
|
<p>You're signed in</p>
|
||||||
</div>
|
</div>
|
||||||
<button className="next-button" onClick={goToFilterPage}>
|
<button className="next-button" onClick={goToFilterPage}>
|
||||||
Proceed
|
Proceed
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ const WelcomeWithFilter = () => {
|
|||||||
// Default welcome content
|
// Default welcome content
|
||||||
<div className="welcome-content">
|
<div className="welcome-content">
|
||||||
<div className="welcome-message">
|
<div className="welcome-message">
|
||||||
<h1>Welcome, John Doe</h1>
|
<h1>Welcome</h1>
|
||||||
<p>You’re signed in as DEC/EIC</p>
|
<p>You’re signed in</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="image-container">
|
<div className="image-container">
|
||||||
<img
|
<img
|
||||||
|
|||||||
@@ -26,3 +26,30 @@ export const fetchCourses = async (filterData) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const fetchFaculties = async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${BASE_URL}/faculty`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Failed to fetch faculties: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching faculties:", error.message);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fetchOptions = async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${BASE_URL}/options`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Failed to fetch options: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching options:", error.message);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
13
server/controller/facultyController.js
Normal file
13
server/controller/facultyController.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
const db = require('../ConnectionDb'); // Import your database module
|
||||||
|
|
||||||
|
const Faculty = require('../models/Faculty'); // Your Mongoose model for faculty
|
||||||
|
|
||||||
|
exports.getFaculties = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const faculties = await Faculty.find(); // Fetch all faculty documents from the 'faculties' collection
|
||||||
|
res.status(200).json(faculties);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching faculties:", error.message);
|
||||||
|
res.status(500).json({ error: "Failed to fetch faculties" });
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -6,9 +6,10 @@ const router = express.Router();
|
|||||||
// Get all faculty members
|
// Get all faculty members
|
||||||
router.get("/", async (req, res) => {
|
router.get("/", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const faculty = await Faculty.find();
|
const faculties = await Faculty.find();
|
||||||
res.json(faculty);
|
res.status(200).json(faculties);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error("Error fetching faculty members:", error.message);
|
||||||
res.status(500).json({ error: "Failed to fetch faculty members" });
|
res.status(500).json({ error: "Failed to fetch faculty members" });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -20,8 +21,9 @@ router.get("/:id", async (req, res) => {
|
|||||||
if (!faculty) {
|
if (!faculty) {
|
||||||
return res.status(404).json({ error: "Faculty member not found" });
|
return res.status(404).json({ error: "Faculty member not found" });
|
||||||
}
|
}
|
||||||
res.json(faculty);
|
res.status(200).json(faculty);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error("Error fetching faculty member:", error.message);
|
||||||
res.status(500).json({ error: "Failed to fetch faculty member" });
|
res.status(500).json({ error: "Failed to fetch faculty member" });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
37
server/routes/optionsRoutes.js
Normal file
37
server/routes/optionsRoutes.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
// const express = require('express');
|
||||||
|
// const router = express.Router();
|
||||||
|
|
||||||
|
// // Sample data (replace this with actual data fetching logic)
|
||||||
|
// const optionsData = {
|
||||||
|
// assessment: ["Option 1", "Option 2", "Option 3"],
|
||||||
|
// reassessment: ["Option A", "Option B"],
|
||||||
|
// paperSetting: ["Option X", "Option Y"],
|
||||||
|
// moderation: ["Option M", "Option N"],
|
||||||
|
// pwdPaperSetter: ["Option P", "Option Q"],
|
||||||
|
// oralsPracticals: ["Option O", "Option P"]
|
||||||
|
// };
|
||||||
|
|
||||||
|
// // GET route for fetching options
|
||||||
|
// router.get('/', (req, res) => {
|
||||||
|
// res.status(200).json(optionsData);
|
||||||
|
// });
|
||||||
|
|
||||||
|
// module.exports = router;
|
||||||
|
|
||||||
|
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const { getFaculties } = require('../controller/facultyController'); // Import your controller that interacts with the database
|
||||||
|
|
||||||
|
// GET route for fetching faculty names
|
||||||
|
router.get('/', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const faculties = await getFaculties(); // Fetch faculty names from database
|
||||||
|
res.status(200).json(faculties);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching faculties:", error.message);
|
||||||
|
res.status(500).json({ error: "Failed to fetch faculties" });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -16,6 +16,7 @@ const PasswordRouter = require("./routes/authRoutes");
|
|||||||
const courseRoutes = require("./routes/courseRoutes");
|
const courseRoutes = require("./routes/courseRoutes");
|
||||||
const facultyRoutes = require("./routes/facultyRoutes");
|
const facultyRoutes = require("./routes/facultyRoutes");
|
||||||
const appointmentRoutes = require("./routes/appointmentRoutes");
|
const appointmentRoutes = require("./routes/appointmentRoutes");
|
||||||
|
const optionsRoutes = require("./routes/optionsRoutes");
|
||||||
|
|
||||||
// Existing Database Connection
|
// Existing Database Connection
|
||||||
const { connectdb } = require("./ConnectionDb");
|
const { connectdb } = require("./ConnectionDb");
|
||||||
@@ -92,6 +93,7 @@ app.use("/password", PasswordRouter);
|
|||||||
app.use("/api/courses", courseRoutes);
|
app.use("/api/courses", courseRoutes);
|
||||||
app.use("/api/faculty", facultyRoutes);
|
app.use("/api/faculty", facultyRoutes);
|
||||||
app.use("/api/appointments", appointmentRoutes);
|
app.use("/api/appointments", appointmentRoutes);
|
||||||
|
app.use("/api/options", optionsRoutes);
|
||||||
|
|
||||||
// OAuth Routes
|
// OAuth Routes
|
||||||
app.get(
|
app.get(
|
||||||
@@ -200,6 +202,8 @@ app.get("*", (req, res) =>
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Start Server
|
// Start Server
|
||||||
const Port = process.env.PORT || 8080;
|
const Port = process.env.PORT || 8080;
|
||||||
app.listen(Port, () => {
|
app.listen(Port, () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user