From 4466b33dff48b87849e1008b54e3126f1dea8847 Mon Sep 17 00:00:00 2001 From: amNobodyyy Date: Mon, 27 Jan 2025 23:34:51 +0530 Subject: [PATCH] academicYear logic --- client/src/App.js | 2 +- client/src/Pages/CourseForm.jsx | 28 +++---- client/src/Pages/CourseTable.jsx | 103 ++++++++++++------------ client/src/Pages/FilterPage.jsx | 50 ++++++++++-- client/src/Pages/Navbar.jsx | 17 ++-- client/src/Pages/courseConsolidated.jsx | 5 +- client/src/api.js | 12 +++ server/models/Appointment.js | 3 +- server/routes/appointmentRoutes.js | 6 +- 9 files changed, 138 insertions(+), 88 deletions(-) diff --git a/client/src/App.js b/client/src/App.js index 4b4b0d3..8659bb8 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -14,7 +14,7 @@ import "react-toastify/dist/ReactToastify.css"; import CourseTable from "./Pages/CourseTable"; import GenerateCSV from "./Pages/GenerateCSV"; import ConsolidatedTable from "./Pages/ConsolidatedTable"; -import CourseConsolidated from "./Pages/courseConsolidated"; +import CourseConsolidated from "./Pages/CourseConsolidated"; function App() { return ( diff --git a/client/src/Pages/CourseForm.jsx b/client/src/Pages/CourseForm.jsx index b1f5a60..1b8aa2b 100644 --- a/client/src/Pages/CourseForm.jsx +++ b/client/src/Pages/CourseForm.jsx @@ -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 = () => {
- + readOnly + /> { onChange={handleInputChange} > - - + + + +
diff --git a/client/src/Pages/Navbar.jsx b/client/src/Pages/Navbar.jsx index 7830bb6..7271eab 100644 --- a/client/src/Pages/Navbar.jsx +++ b/client/src/Pages/Navbar.jsx @@ -5,20 +5,21 @@ import "./Navbar.css"; // Navbar-specific styles const Navbar = () => { return ( -
+
- + + + Appointment To Examiner +
- Faculty Form + Faculty Consolidated - - Course Form + + Course Consolidated
-
- -
+
); diff --git a/client/src/Pages/courseConsolidated.jsx b/client/src/Pages/courseConsolidated.jsx index b6bb275..c03c544 100644 --- a/client/src/Pages/courseConsolidated.jsx +++ b/client/src/Pages/courseConsolidated.jsx @@ -1,8 +1,8 @@ import React, { useState, useEffect } from "react"; import axios from "axios"; -import * as XLSX from "xlsx-js-style"; import { jsPDF } from "jspdf"; import autoTable from "jspdf-autotable"; +import Navbar from "./Navbar"; const CourseConsolidated = () => { @@ -186,6 +186,8 @@ const CourseConsolidated = () => { return ( + <> +

Course Tables with Download Options @@ -392,6 +394,7 @@ const CourseConsolidated = () => {

+ ); }; diff --git a/client/src/api.js b/client/src/api.js index 5349583..16cf96c 100644 --- a/client/src/api.js +++ b/client/src/api.js @@ -78,6 +78,18 @@ export const fetchOptions = async () => { } }; +export const fetchAppointments = async (academicYear) => { + try { + const response = await fetch(`${BASE_URL}/appointments?academicYear=${academicYear}`); + if (!response.ok) { + throw new Error("Failed to fetch appointments"); + } + return await response.json(); + } catch (error) { + console.error(error); + return []; + } +}; // Save multiple appointments to MongoDB export const saveAppointment = async (appointmentsData) => { diff --git a/server/models/Appointment.js b/server/models/Appointment.js index e3b9efc..c4bae4f 100644 --- a/server/models/Appointment.js +++ b/server/models/Appointment.js @@ -8,7 +8,8 @@ const AppointmentSchema = new mongoose.Schema({ courseId: { type: String, required: true }, courseName: { type: String, required: true }, task: { type: String, required: true }, - examPeriod: { type: String, required: true }, // New field for exam period + examPeriod: { type: String, required: true }, + academicYear: {type: String, required: true}, }); module.exports = mongoose.model("Appointment", AppointmentSchema); diff --git a/server/routes/appointmentRoutes.js b/server/routes/appointmentRoutes.js index 683a656..fa0f559 100644 --- a/server/routes/appointmentRoutes.js +++ b/server/routes/appointmentRoutes.js @@ -14,7 +14,7 @@ router.post("/", async (req, res) => { const savedAppointments = []; for (const appointment of appointments) { - const { facultyId, courseId, tasks, examPeriod } = appointment; + const { facultyId, courseId, tasks, examPeriod, academicYear } = appointment; if ( !facultyId || @@ -43,6 +43,7 @@ router.post("/", async (req, res) => { courseName: course.name, task, examPeriod, + academicYear, }); const savedAppointment = await newAppointment.save(); savedAppointments.push(savedAppointment); @@ -58,8 +59,9 @@ router.post("/", async (req, res) => { // Get all appointments router.get("/", async (req, res) => { + const { academicYear } = req.query; try { - const appointments = await Appointment.find(); + const appointments = await Appointment.find({ academicYear }); res.json(appointments); } catch (error) { console.error("Error fetching appointments:", error);