diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx index ac4edbdd3651dcd94cf070d21ee369533b50a979..099bf49bf715365217dcc498e29e569469adac0f 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 ce4841c449394c1c94556eedc157ef246b2c16bc..09bd61c230356abe2a910124467bfaec46fe7ebe 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 782e3ca27bf0837d7010867559100d476c80e1bf..4572bdb0ec7d70ba91d01eaa2919398609fffadc 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 c9931f33224923999e42f57eb5f8c7cebbb86eb9..1418c729486cdfb18c009c23e3481473043e6e71 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 (