diff --git a/client/src/pages/SupervisorDashboard.js b/client/src/pages/SupervisorDashboard.js index 1871dbd4..8a704d34 100644 --- a/client/src/pages/SupervisorDashboard.js +++ b/client/src/pages/SupervisorDashboard.js @@ -8,7 +8,7 @@ const SupervisorDashboard = () => { const [selectedForm, setSelectedForm] = useState(null); const [loading, setLoading] = useState(true); const [message, setMessage] = useState(""); - + useEffect(() => { // Token used for authentication for future @@ -82,22 +82,24 @@ const SupervisorDashboard = () => { ); setMessage(res.data.message || `${action} successful`); - setRequests(prev => prev.filter(req => req._id !== id)); - setSelectedForm(null); + setRequests(prev => prev.filter(req => req._id !== id)); // remove from table + return true; } catch (err) { console.error(`Failed to ${action} request:`, err); setMessage(`Failed to ${action} request.`); + return false; } }; + const openFormView = (form) => setSelectedForm(form); const closeFormView = () => setSelectedForm(null); const formatDate = (date) => new Date(date).toLocaleDateString(); const sortedRequests = [...requests] - .filter((req) => req.status.toLowerCase() === "submitted") - .sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt)); - + .filter((req) => req.supervisor_status?.toLowerCase() === "pending") + .sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt)); + let content; if (loading) { @@ -147,16 +149,58 @@ const SupervisorDashboard = () => {

Supervisor Dashboard

{message &&

{message}

} - {content} + {loading ? ( +

Loading...

+ ) : sortedRequests.length === 0 ? ( +
+
No pending approvals.
+
+ ) : ( + + + + + + + + + + + + + {sortedRequests.map((req) => ( + + + + + + + + + ))} + +
Student NameSooner IDEmailForm TypeSubmittedStatus
{req.interneeName || req.studentName} + + {req.interneeEmail || req.studentEmail}{req.form_type}{formatDate(req.createdAt)} + + {req.supervisor_status || req.status} + +
+ )} + {selectedForm && ( + handleAction(selectedForm.form_type, id, action, comment, signature) + } /> )}
); }; -export default SupervisorDashboard; \ No newline at end of file +export default SupervisorDashboard; diff --git a/client/src/pages/ViewFormModal.js b/client/src/pages/ViewFormModal.js index cc811e2c..85aeed9f 100644 --- a/client/src/pages/ViewFormModal.js +++ b/client/src/pages/ViewFormModal.js @@ -7,26 +7,17 @@ const ViewFormModal = ({ formData, onClose, onAction }) => { const [error, setError] = useState(""); const handleDecision = (action) => { - if (!comment.trim()) { - setError("Comment is required before taking action."); - return; - } - if (!signature.trim()) { - setError("Signature is required before approval/rejection."); - return; - } - - const payloadComment = `${comment.trim()} | Supervisor Signature: ${signature.trim()}`; + if (!comment.trim()) return setError("Comment is required."); + if (!signature.trim()) return setError("Signature is required."); setError(""); - onAction(formData._id, formData.form_type, action, payloadComment); + onAction(formData._id, action, comment.trim(), signature.trim()); }; - return ( -
-
-

A.1 Internship Request Form

- - + // ✅ Inserted rendering helpers + const renderA1 = () => ( + <> +

A1 – Internship Request Form

+
@@ -60,52 +51,69 @@ const ViewFormModal = ({ formData, onClose, onAction }) => {
Field
+ + ); -
- Task Descriptions & Outcomes: -
    - {formData.tasks?.map((task, index) => ( -
  • - Task {index + 1}: {task.description} -
    - Outcomes: {task.outcomes?.join(", ") || "N/A"} -
  • - ))} -
-
- -
- - setSignature(e.target.value)} - placeholder="Enter your full name" - style={{ width: "100%", padding: "6px", marginTop: "5px", borderRadius: "4px" }} - /> -
- -
- -