From e0b5c6abd9905d3d01d6a0adc113e13246e0e08d Mon Sep 17 00:00:00 2001
From: fatima ezzahra majidi <fatima-ezzahra.majidi.etu@univ-lille.fr>
Date: Fri, 7 Mar 2025 07:07:12 +0000
Subject: [PATCH] =?UTF-8?q?am=C3=A9lioration?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/components/Navbar.jsx                 |  4 ++--
 src/components/Stages/StageForm.jsx       |  5 +++--
 src/components/Stages/StageList.jsx       | 11 +++++++----
 src/components/Stages/UpdateStageForm.jsx | 19 ++++++++++---------
 4 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx
index ac4edbd..099bf49 100644
--- a/src/components/Navbar.jsx
+++ b/src/components/Navbar.jsx
@@ -84,9 +84,9 @@ function Navbar() {
                 </a>
                 <ul className="dropdown-menu" aria-labelledby="entreprisesDropdown">
                   <li><Link className="dropdown-item" to="/entreprises">📜 Liste des Entreprises</Link></li>
-                  {(hasRole("ROLE_ENTREPRISE") || hasRole("ROLE_ADMIN")) && (
+                  
                     <li><Link className="dropdown-item" to="/ajouter-entreprise">âž• Ajouter/Modifier une Entreprise</Link></li>
-                  )}
+                  
                 </ul>
               </li>
             )}
diff --git a/src/components/Stages/StageForm.jsx b/src/components/Stages/StageForm.jsx
index ce4841c..09bd61c 100644
--- a/src/components/Stages/StageForm.jsx
+++ b/src/components/Stages/StageForm.jsx
@@ -34,10 +34,11 @@ function StageForm() {
     }
   
     const newStage = {
-      title,
+      name: title,  // ✅ Change from "" to title
       description,
-      enterprise: { id: parseInt(enterpriseId, 10) }, // Send enterprise as an object
+      enterprise: { id: parseInt(enterpriseId, 10) }, // Keep this as it is
     };
+    
   
     console.log("📌 Sending stage data:", newStage);
   
diff --git a/src/components/Stages/StageList.jsx b/src/components/Stages/StageList.jsx
index 782e3ca..4572bdb 100644
--- a/src/components/Stages/StageList.jsx
+++ b/src/components/Stages/StageList.jsx
@@ -12,15 +12,18 @@ function StageList() {
 
   const fetchStages = () => {
     fetch("http://localhost:8080/api/stages")
-      .then((response) => response.json())
-      .then((data) => setStages(data))
-      .catch((error) => console.error("Error fetching stages:", error));
+    .then((response) => response.json())
+    .then((data) => {
+      console.log("📌 Stages loaded:", data);  // ✅ Debugging Log
+      setStages(data);
+    })
+    .catch((error) => console.error("Error fetching stages:", error));
   };
 
   // Handle Delete
   const handleDelete = (id) => {
     if (window.confirm("Voulez-vous vraiment supprimer ce stage ?")) {
-      fetch(`http://localhost:8080/api/stages/${id}`, {
+      fetch(`http://localhost:8080/api/stages/delete/${id}`, {
         method: "DELETE",
       })
         .then(() => {
diff --git a/src/components/Stages/UpdateStageForm.jsx b/src/components/Stages/UpdateStageForm.jsx
index c9931f3..1418c72 100644
--- a/src/components/Stages/UpdateStageForm.jsx
+++ b/src/components/Stages/UpdateStageForm.jsx
@@ -38,16 +38,17 @@ function UpdateStageForm() {
 
   const handleSubmit = (e) => {
     e.preventDefault();
-    fetch(`http://localhost:8080/api/stages/${id}`, {
-      method: "PUT",
-      headers: { "Content-Type": "application/json" },
-      body: JSON.stringify(stage),
+    fetch(`http://localhost:8080/api/stages/${id}`)
+    .then((res) => res.json())
+    .then((data) => {
+      console.log("📌 Loaded stage:", data);  // ✅ Debugging Log
+      setStage({
+        name: data.name || "",  // ✅ Ensure name is stored
+        description: data.description || "",
+        enterprise: data.enterprise || null
+      });
     })
-      .then(() => {
-        alert("Stage mis à jour !");
-        navigate("/stages");
-      })
-      .catch((err) => console.error("Erreur:", err));
+    .catch((err) => console.error("Erreur:", err));
   };
 
   return (
-- 
GitLab