From c66f4a3227873ce8a89f21b8ce5054f4876756dc Mon Sep 17 00:00:00 2001 From: Mahima Date: Sun, 20 Apr 2025 03:45:56 -0500 Subject: [PATCH 1/6] Update A3 modal and dashboard: ViewFormModal & SupervisorDashboard enhancements --- client/src/pages/SupervisorDashboard.js | 107 ++++++++++++------------ client/src/pages/ViewFormModal.js | 65 +++++++++----- 2 files changed, 95 insertions(+), 77 deletions(-) diff --git a/client/src/pages/SupervisorDashboard.js b/client/src/pages/SupervisorDashboard.js index 18cc054d..f4f4404c 100644 --- a/client/src/pages/SupervisorDashboard.js +++ b/client/src/pages/SupervisorDashboard.js @@ -12,16 +12,16 @@ const SupervisorDashboard = () => { useEffect(() => { const fetchRequests = async () => { try { - const res = await axios.get(`${process.env.REACT_APP_API_URL}/api/submissions/pending`); - + const res = await axios.get(`${process.env.REACT_APP_API_URL}/api/evaluation`); setRequests(res.data); setLoading(false); } catch (err) { - console.error("Error fetching requests:", err); + console.error("AXIOS ERROR:", err.response?.data || err.message); setMessage("Error fetching requests."); setLoading(false); } }; + fetchRequests(); }, []); @@ -30,7 +30,10 @@ const SupervisorDashboard = () => { if (!confirmed) return; try { - const res = await axios.post(`${process.env.REACT_APP_API_URL}/api/submissions/${id}/${action}`, { comment }); + const res = await axios.post( + `${process.env.REACT_APP_API_URL}/api/evaluation/${id}/${action}`, + { comment } + ); setMessage(res.data.message || `${action} successful`); setRequests(prev => prev.filter(req => req._id !== id)); @@ -43,63 +46,57 @@ const SupervisorDashboard = () => { const openFormView = (form) => setSelectedForm(form); const closeFormView = () => setSelectedForm(null); + const formatDate = (date) => new Date(date).toLocaleDateString(); - const formatDate = (dateStr) => new Date(dateStr).toLocaleDateString(); - - const sortedRequests = [...requests].sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt)); - - let content; - - if (loading) { - content =

Loading...

; - } - else if (sortedRequests.length === 0) { - content = ( -
-
No pending approvals.
-
- ); - } - else { - content = ( - - - - - - - - - - - - {sortedRequests.map((req) => ( - - - - - - - - ))} - -
Student NameStudent IDForm TypeDate SubmittedStatus
{req.name} - - {req.form_type}{formatDate(req.createdAt)} - - {req.supervisor_status} - -
- ); - } + const sortedRequests = [...requests].sort( + (a, b) => new Date(b.createdAt) - new Date(a.createdAt) + ); return (

Supervisor Dashboard

{message &&

{message}

} - {content} + {loading ? ( +

Loading...

+ ) : sortedRequests.length === 0 ? ( +
+
No A3 forms available.
+
+ ) : ( + + + + + + + + + + + + + {sortedRequests.map((req) => ( + + + + + + + + + ))} + +
Student NameSooner IDEmailForm TypeSubmittedStatus
{req.interneeName} + + {req.interneeEmail}{req.form_type}{formatDate(req.createdAt)} + + {req.supervisor_status} + +
+ )} + {selectedForm && ( { - const form = typeof formData.details === "string" ? JSON.parse(formData.details) : formData.details; const [comment, setComment] = useState(""); const [error, setError] = useState(""); @@ -11,34 +10,56 @@ const ViewFormModal = ({ formData, onClose, onAction }) => { setError("Comment is required before taking action."); return; } - setError(""); // clear error - onAction(formData._id, action, comment); + + const confirmed = window.confirm(`Are you sure you want to ${action} this request?`); + if (!confirmed) return; + + setError(""); + onAction(formData._id, action, comment.trim()); }; + const formatSignature = (sig) => + sig?.type === "text" ? `${sig.value} (Font: ${sig.font})` : "Signature unavailable"; + return (
-
-

Form: {formData.form_type}

-

Student: {formData.name}

+
+

A3 – Job Performance Evaluation

- {form.tasks && ( -
- Tasks: -
    {form.tasks.map((task, i) =>
  • {task}
  • )}
-
- )} +

Internee Details

+

Name: {formData.interneeName}

+

Sooner ID: {formData.interneeID}

+

Email: {formData.interneeEmail}

- {form.outcomes && ( -
- Outcomes: -
    {form.outcomes.map((o, i) =>
  • {o}
  • )}
-
+

Evaluation

+ {formData.evaluations?.length > 0 ? ( + + + + + + + + + + {formData.evaluations.map((item, index) => ( + + + + + + ))} + +
CategoryRatingComment
{item.category}{item.rating}{item.comment || "-"}
+ ) : ( +

No evaluation data found.

)} - {form.week &&

Week: {form.week}

} - {form.lessonsLearned &&

Lessons Learned: {form.lessonsLearned}

} +

Signatures

+

Advisor Signature: {formatSignature(formData.advisorSignature)}

+

Coordinator Signature: {formatSignature(formData.coordinatorSignature)}

-
+