diff --git a/src/components/Candidatures/CandidacyForm.jsx b/src/components/Candidatures/CandidacyForm.jsx index 79953db0a5d5dc12dad1e33909e51b5cdedfdc0b..69b1dd6271eec34c7929b4f496f80d64d9b7dd30 100644 --- a/src/components/Candidatures/CandidacyForm.jsx +++ b/src/components/Candidatures/CandidacyForm.jsx @@ -9,8 +9,10 @@ const CandidacyForm = () => { const [formData, setFormData] = useState({ studentId: "", stageId: "", - univSupervisorId: "", // Add supervisor field + univSupervisorId: "", + comment: "", // ✅ Ajout du champ comment }); + useEffect(() => { fetch("http://localhost:8080/api/students") @@ -32,23 +34,33 @@ const CandidacyForm = () => { const handleSubmit = (e) => { e.preventDefault(); - + + const candidacyData = { + student: { id: formData.studentId }, + stage: { id: formData.stageId }, + univSupervisor: { id: formData.univSupervisorId }, + comment: formData.comment || "Aucun commentaire fourni", // ✅ Ajout du champ commentaire + }; + + console.log("📌 Sending Candidacy Data:", JSON.stringify(candidacyData, null, 2)); // Debug + fetch("http://localhost:8080/api/candidacies/add", { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - student: { id: formData.studentId }, - stage: { id: formData.stageId }, - univSupervisor: { id: formData.univSupervisorId }, // Include supervisor - }), + credentials: "include", + body: JSON.stringify(candidacyData), }) - .then((res) => res.json()) + .then((res) => { + console.log("📌 Response status:", res.status); + return res.json(); + }) .then((data) => { - console.log("Candidacy added:", data); - alert("Candidacy added successfully!"); + console.log("✅ Candidacy added successfully:", data); + alert("Candidature ajoutée avec succès !"); }) - .catch((err) => console.error("Error:", err)); + .catch((err) => console.error("⌠Error:", err.message)); }; + // Handle cancel button const handleCancel = () => { Navigate("/candidatures"); // Redirect back to candidacy list @@ -95,6 +107,15 @@ const CandidacyForm = () => { ))} </select> </div> + <div className="mb-3"> + <label className="form-label">Commentaire:</label> + <textarea + className="form-control" + name="comment" + value={formData.comment} + onChange={handleChange} + /> + </div> {/* Select UnivSupervisor */} <div className="mb-3"> diff --git a/src/components/Candidatures/CandidacyFormPrerempli.jsx b/src/components/Candidatures/CandidacyFormPrerempli.jsx index a306359e559a731bba740499a8575d7e5d259e1f..10b2a3f84e73e0fe1a05a9fce29fd2a709dd7c6b 100644 --- a/src/components/Candidatures/CandidacyFormPrerempli.jsx +++ b/src/components/Candidatures/CandidacyFormPrerempli.jsx @@ -10,6 +10,7 @@ const CandidacyFormPrerempli = () => { studentId: "", stageId: stageId || "", // ✅ Pre-fill with stageId from URL univSupervisorId: "", + comment: "", }); /** 🔹 Load the logged-in student from localStorage */ @@ -42,6 +43,7 @@ const CandidacyFormPrerempli = () => { student: { id: formData.studentId }, stage: { id: formData.stageId }, univSupervisor: { id: formData.univSupervisorId }, + comment: formData.comment || "Aucun commentaire fourni", }; console.log("📌 Sending Candidacy Data:", JSON.stringify(candidacyData, null, 2)); @@ -89,6 +91,15 @@ const CandidacyFormPrerempli = () => { disabled /> </div> + <div className="mb-3"> + <label className="form-label">Commentaire:</label> + <textarea + className="form-control" + name="comment" + value={formData.comment} + onChange={handleChange} + /> + </div> {/* Select UnivSupervisor */} <div className="mb-3"> diff --git a/src/components/Candidatures/CandidacyList.jsx b/src/components/Candidatures/CandidacyList.jsx index 069bbfb415d74b8ff531dd3d75930398213e072f..bdf2642d8663ccfdd9529c85b3df897b21117dd8 100644 --- a/src/components/Candidatures/CandidacyList.jsx +++ b/src/components/Candidatures/CandidacyList.jsx @@ -42,6 +42,7 @@ function CandidacyList() { <th>Superviseur Universitaire</th> <th>État de la Demande</th> <th>Statut Accepté</th> + <th>Commentaire</th> <th>Actions</th> {/* Added column for buttons */} </tr> </thead> @@ -54,6 +55,7 @@ function CandidacyList() { <td>{candidacy.univSupervisor?.name || "Non attribué"}</td> <td>{candidacy.requestState}</td> <td>{candidacy.acceptedState}</td> + <td>{candidacy.comment || "Pas de commentaire"}</td> <td> <button diff --git a/src/components/Candidatures/UpdateCandidacyForm.jsx b/src/components/Candidatures/UpdateCandidacyForm.jsx index 480df9e4284239ef33dc1c360c6a372fae4aba07..85b5e2bf7eab5a0951fe647057b462c4e8cd57e3 100644 --- a/src/components/Candidatures/UpdateCandidacyForm.jsx +++ b/src/components/Candidatures/UpdateCandidacyForm.jsx @@ -58,7 +58,7 @@ function UpdateCandidacyForm() { const handleSubmit = (e) => { e.preventDefault(); - fetch(`http://localhost:8080/api/candidacies/${id}`, { + fetch(`http://localhost:8080/api/candidacies/update/${id}`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(candidacy),