diff --git a/.gitignore b/.gitignore index 7f5b38cc7..1851250da 100644 --- a/.gitignore +++ b/.gitignore @@ -141,3 +141,4 @@ dist /client/package-lock.json /server/package-lock.json +.DS_Store \ No newline at end of file diff --git a/client/src/pages/CoordinatorCumulativeReviewForm.js b/client/src/pages/CoordinatorCumulativeReviewForm.js new file mode 100644 index 000000000..0dd496df3 --- /dev/null +++ b/client/src/pages/CoordinatorCumulativeReviewForm.js @@ -0,0 +1,122 @@ +import React, { useEffect, useState } from "react"; +import { useParams, useNavigate } from "react-router-dom"; +import axios from "axios"; +import Swal from "sweetalert2"; +import "../styles/CoordinatorCumulativeReviewForm.css"; + +const CoordinatorCumulativeReviewForm = () => { + const { groupIndex } = useParams(); + const navigate = useNavigate(); + + const [reports, setReports] = useState([]); + const [coordinatorComment, setCoordinatorComment] = useState(""); + const [supervisorComment, setSupervisorComment] = useState(""); + const [loading, setLoading] = useState(true); + + // Fetch the report group when component mounts + useEffect(() => { + const fetchGroup = async () => { + try { + const res = await axios.get( + `${process.env.REACT_APP_API_URL}/api/reports/cumulative/group/${groupIndex}` + ); + if (res.data.success) { + const fetchedReports = res.data.group.reports || []; + setReports(fetchedReports); + setSupervisorComment(fetchedReports[0]?.supervisorComments || "Not available"); + } + } catch (err) { + console.error("Failed to fetch group:", err); + } finally { + setLoading(false); + } + }; + + fetchGroup(); + }, [groupIndex]); + + // Submit coordinator comments for all reports in the group + const handleSubmit = async () => { + if (!coordinatorComment.trim()) { + Swal.fire("Error", "Comment cannot be empty.", "error"); + return; + } + + try { + const weeks = reports.map((report) => report.week); // extract weeks + + await axios.post(`${process.env.REACT_APP_API_URL}/api/reports/coordinator-comments`, { + groupIndex: parseInt(groupIndex), + comments: coordinatorComment.trim(), + weeks, + }); + + Swal.fire("Success", "Coordinator comment submitted.", "success"); + + localStorage.setItem("reviewedGroupIndex", groupIndex); // ✅ For dashboard refresh + navigate("/coordinator-dashboard"); + } catch (err) { + console.error("Failed to submit coordinator comment", err); + Swal.fire("Error", "Failed to submit comment. Please try again.", "error"); + } + }; + + + if (loading) { + return

Loading...

; + } + + return ( +
+

Review Cumulative Weekly Reports

+ + + + + + + + + + + + {reports.map((report, idx) => ( + + + + + + + ))} + +
WeekHoursTasksLessons
{report.week}{report.hours}{report.tasks}{report.lessons}
+ +
+ +
{supervisorComment}
+
+ +
+ + + + + + {message &&

{message}

} +
+ ); +}; + +export default CoordinatorReviewForm; diff --git a/client/src/pages/CumulativeReviewForm.js b/client/src/pages/CumulativeReviewForm.js new file mode 100644 index 000000000..d621db4fc --- /dev/null +++ b/client/src/pages/CumulativeReviewForm.js @@ -0,0 +1,134 @@ +import React, { useEffect, useState } from "react"; +import { useParams, useNavigate } from "react-router-dom"; +import axios from "axios"; +import Swal from "sweetalert2"; +import "../styles/CumulativeReviewForm.css"; + +const CumulativeReviewForm = () => { + const { groupIndex } = useParams(); + const navigate = useNavigate(); + + const [groupData, setGroupData] = useState(null); + const [loading, setLoading] = useState(true); + const [comment, setComment] = useState(""); + + useEffect(() => { + const fetchGroup = async () => { + try { + const res = await axios.get( + `${process.env.REACT_APP_API_URL}/api/reports/cumulative/group/${groupIndex}` + ); + setGroupData(res.data.group); + } catch (err) { + console.error("Failed to fetch group:", err); + Swal.fire({ + icon: "error", + title: "Failed to load report group.", + }); + } finally { + setLoading(false); + } + }; + + fetchGroup(); + }, [groupIndex]); + + const handleSubmit = async () => { + if (!comment.trim()) { + return Swal.fire({ + icon: "warning", + title: "Comment cannot be empty!", + }); + } + + try { + await axios.post( + `${process.env.REACT_APP_API_URL}/api/reports/supervisor-comments`, + { + groupIndex: groupData.groupIndex, + comments: comment, + weeks: groupData.weeks, + } + ); + + Swal.fire({ + icon: "success", + title: "Comment Submitted Successfully!", + timer: 1500, + showConfirmButton: false, + }); + + navigate("/supervisor-dashboard"); + } catch (err) { + console.error("Error submitting comment:", err); + Swal.fire({ + icon: "error", + title: "Failed to submit comment.", + }); + } + }; + + if (loading) return

Loading...

; + if (!groupData) return

No data found.

; + + return ( +
+

Review Cumulative Weekly Reports

+ + + + + + + + + + + + {groupData.reports.map((report, index) => ( + + navigate( + `/weekly-report/${groupIndex}/week-${report.week}/${groupData.studentName}`, + { + state: { reportData: report }, + } + ) + } + > + + + + + + ))} + + +
WeekHoursTasksLessons
{report.week}{report.hours}{report.tasks}{report.lessons}
+ +