academicYear logic

This commit is contained in:
amNobodyyy
2025-01-27 23:34:51 +05:30
parent 805d866190
commit 4466b33dff
9 changed files with 138 additions and 88 deletions

View File

@@ -1,6 +1,6 @@
import React, { useState, useEffect } from "react";
import { useLocation, useParams, useNavigate } from "react-router-dom";
import { fetchFaculties, saveAppointment, updateCourseStatus } from "../api";
import { fetchFaculties, saveAppointment } from "../api";
import "./CourseForm.css";
import "./Navbar.jsx";
import Navbar from "./Navbar.jsx";
@@ -9,7 +9,7 @@ const CourseForm = () => {
const { id } = useParams();
const location = useLocation();
const navigate = useNavigate();
const { course } = location.state || {};
const { course, academicYear } = location.state || {};
const [options, setOptions] = useState({ faculties: [] });
const [suggestions, setSuggestions] = useState({});
@@ -32,7 +32,7 @@ const CourseForm = () => {
});
const [examPeriod, setExamPeriod] = useState({
year: "",
year: academicYear || "",
startMonth: "",
endMonth: "",
});
@@ -110,6 +110,7 @@ const CourseForm = () => {
if (validateForm()) {
try {
const groupedTasks = {};
const academicYear = course?.academicYear || examPeriod.year;
Object.entries(tempAssignments).forEach(([field, facultyList]) => {
facultyList.forEach((faculty) => {
const assignedFaculty = options.faculties.find(
@@ -121,7 +122,8 @@ const CourseForm = () => {
facultyId: assignedFaculty.facultyId,
courseId: course?.courseId || id,
tasks: [],
examPeriod: `${examPeriod.year} (${examPeriod.startMonth} - ${examPeriod.endMonth})`,
examPeriod: `${examPeriod.startMonth} - ${examPeriod.endMonth}`,
academicYear,
};
}
groupedTasks[assignedFaculty.facultyId].tasks.push(field);
@@ -131,14 +133,14 @@ const CourseForm = () => {
const payload = Object.values(groupedTasks);
await saveAppointment(payload);
await updateCourseStatus(course?.courseId || id);
// await updateCourseStatus(course?.courseId || id);
const filteredCourses =
JSON.parse(localStorage.getItem("filteredCourses")) || [];
navigate("/courses", {
state: {
courses: filteredCourses,
updatedCourse: { ...course, status: "Submitted" },
academicYear: academicYear,
},
});
} catch (error) {
@@ -169,16 +171,12 @@ const CourseForm = () => {
</div>
<div className={errors.examPeriod ? "courseFormErrorSelect" : ""}>
<label className="courseFormLabel">Exam Period:</label>
<select
className="courseFormSelect"
<input
type="text"
className="courseFormInput courseFormReadOnly"
value={examPeriod.year}
onChange={(e) => setExamPeriod({ ...examPeriod, year: e.target.value })}
>
<option value="">Year</option>
{[2025, 2026, 2027].map(year => (
<option key={year} value={year}>{year}</option>
))}
</select>
readOnly
/>
<select
className="courseFormSelect"
value={examPeriod.startMonth}