MAJ accordeon auto page home
This commit is contained in:
@@ -39,9 +39,15 @@ const ConstructSection = ({
|
|||||||
// 2️⃣ Si localStorage est vide, récupérer les missions depuis WordPress
|
// 2️⃣ Si localStorage est vide, récupérer les missions depuis WordPress
|
||||||
const response = await api.get("wp/v2/pages/13?_fields=acf");
|
const response = await api.get("wp/v2/pages/13?_fields=acf");
|
||||||
|
|
||||||
if (response.data.acf?.mission && Array.isArray(response.data.acf.mission)) {
|
if (
|
||||||
|
response.data.acf?.mission &&
|
||||||
|
Array.isArray(response.data.acf.mission)
|
||||||
|
) {
|
||||||
setMissions(response.data.acf.mission);
|
setMissions(response.data.acf.mission);
|
||||||
localStorage.setItem("missions", JSON.stringify(response.data.acf.mission)); // Sauvegarde en local
|
localStorage.setItem(
|
||||||
|
"missions",
|
||||||
|
JSON.stringify(response.data.acf.mission)
|
||||||
|
); // Sauvegarde en local
|
||||||
console.log("✅ Missions chargées depuis WordPress !");
|
console.log("✅ Missions chargées depuis WordPress !");
|
||||||
} else {
|
} else {
|
||||||
// 3️⃣ Si aucune mission dans WordPress, utiliser des valeurs par défaut
|
// 3️⃣ Si aucune mission dans WordPress, utiliser des valeurs par défaut
|
||||||
@@ -52,7 +58,9 @@ const ConstructSection = ({
|
|||||||
];
|
];
|
||||||
setMissions(defaultMissions);
|
setMissions(defaultMissions);
|
||||||
localStorage.setItem("missions", JSON.stringify(defaultMissions));
|
localStorage.setItem("missions", JSON.stringify(defaultMissions));
|
||||||
console.log("⚠️ Aucune mission trouvée, valeurs par défaut utilisées !");
|
console.log(
|
||||||
|
"⚠️ Aucune mission trouvée, valeurs par défaut utilisées !"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -73,7 +81,8 @@ const ConstructSection = ({
|
|||||||
// ✅ Gestion des changements depuis d'autres onglets/navigateurs
|
// ✅ Gestion des changements depuis d'autres onglets/navigateurs
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleStorageChange = () => {
|
const handleStorageChange = () => {
|
||||||
const updatedMissions = JSON.parse(localStorage.getItem("missions")) || [];
|
const updatedMissions =
|
||||||
|
JSON.parse(localStorage.getItem("missions")) || [];
|
||||||
setMissions(updatedMissions);
|
setMissions(updatedMissions);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -95,22 +104,63 @@ const ConstructSection = ({
|
|||||||
{/* Left Column */}
|
{/* Left Column */}
|
||||||
<Grid item xs={12} md={6}>
|
<Grid item xs={12} md={6}>
|
||||||
<Box>
|
<Box>
|
||||||
<Typography variant="h2" sx={{ fontWeight: "bold", fontSize: { xs: "2rem", md: "2.4rem", lg: "3rem" } }}>
|
<Typography
|
||||||
|
variant="h2"
|
||||||
|
sx={{
|
||||||
|
fontWeight: "bold",
|
||||||
|
fontSize: { xs: "2rem", md: "2.4rem", lg: "3rem" },
|
||||||
|
}}
|
||||||
|
>
|
||||||
{constructTitle}{" "}
|
{constructTitle}{" "}
|
||||||
<Typography component="span" sx={{ fontSize: { xs: "2rem", md: "2rem", lg: "2rem" }, color: "#0e467f", fontWeight: "bold" }}>
|
<Typography
|
||||||
|
component="span"
|
||||||
|
sx={{
|
||||||
|
fontSize: { xs: "2rem", md: "2rem", lg: "2rem" },
|
||||||
|
color: "#0e467f",
|
||||||
|
fontWeight: "bold",
|
||||||
|
}}
|
||||||
|
>
|
||||||
{constructSubtitle}
|
{constructSubtitle}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Typography variant="body1" sx={{ mt: 2, fontWeight: "bold", color: "#0e467f" }}>
|
<Typography
|
||||||
|
variant="body1"
|
||||||
|
sx={{ mt: 2, fontWeight: "bold", color: "#0e467f" }}
|
||||||
|
>
|
||||||
Secteurs : {constructSector}
|
Secteurs : {constructSector}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Typography variant="body1" sx={{ mt: 2, fontSize: { xs: "1rem", md: "1.2rem" }, lineHeight: 1.6, color: "#666" }} dangerouslySetInnerHTML={{ __html: constructText }} />
|
<Typography
|
||||||
|
variant="body1"
|
||||||
|
sx={{
|
||||||
|
mt: 2,
|
||||||
|
fontSize: { xs: "1rem", md: "1.2rem" },
|
||||||
|
lineHeight: 1.6,
|
||||||
|
color: "#666",
|
||||||
|
}}
|
||||||
|
dangerouslySetInnerHTML={{ __html: constructText }}
|
||||||
|
/>
|
||||||
|
|
||||||
<Card sx={{ mt: 4, backgroundColor: "#0e467f", color: "#fff", borderRadius: "12px", boxShadow: "0 8px 20px rgba(0, 0, 0, 0.1)" }}>
|
<Card
|
||||||
|
sx={{
|
||||||
|
mt: 4,
|
||||||
|
backgroundColor: "#0e467f",
|
||||||
|
color: "#fff",
|
||||||
|
borderRadius: "12px",
|
||||||
|
boxShadow: "0 8px 20px rgba(0, 0, 0, 0.1)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Typography variant="body1" sx={{ fontSize: "1.1rem", lineHeight: 1.6, textAlign: "center" }} dangerouslySetInnerHTML={{ __html: constructNoteText }} />
|
<Typography
|
||||||
|
variant="body1"
|
||||||
|
sx={{
|
||||||
|
fontSize: "1.1rem",
|
||||||
|
lineHeight: 1.6,
|
||||||
|
textAlign: "center",
|
||||||
|
}}
|
||||||
|
dangerouslySetInnerHTML={{ __html: constructNoteText }}
|
||||||
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</Box>
|
</Box>
|
||||||
@@ -118,10 +168,29 @@ const ConstructSection = ({
|
|||||||
|
|
||||||
{/* Right Column */}
|
{/* Right Column */}
|
||||||
<Grid item xs={12} md={6}>
|
<Grid item xs={12} md={6}>
|
||||||
<Box sx={{ backgroundColor: "#fff", padding: 3 }}>
|
<Box
|
||||||
|
sx={{
|
||||||
|
position: "relative",
|
||||||
|
height: "400px",
|
||||||
|
backgroundImage: `url('https://picsum.photos/id/52/600/400.webp')`, // Replace with the image URL or dynamic data
|
||||||
|
backgroundSize: "cover",
|
||||||
|
backgroundPosition: "center",
|
||||||
|
padding: 3,
|
||||||
|
borderRadius: "15px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
{/* ✅ Correction de la duplication du titre */}
|
{/* ✅ Correction de la duplication du titre */}
|
||||||
{missionTitle && (
|
{missionTitle && (
|
||||||
<Typography variant="h3" sx={{ fontWeight: "bold", textAlign: "center", mt: 3, mb: 2, color: "#0e467f" }}>
|
<Typography
|
||||||
|
variant="h3"
|
||||||
|
sx={{
|
||||||
|
fontWeight: "bold",
|
||||||
|
textAlign: "center",
|
||||||
|
mt: 3,
|
||||||
|
mb: 2,
|
||||||
|
color: "#0e467f",
|
||||||
|
}}
|
||||||
|
>
|
||||||
{missionTitle}
|
{missionTitle}
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
@@ -129,9 +198,21 @@ const ConstructSection = ({
|
|||||||
{/* ✅ Accordéon dynamique */}
|
{/* ✅ Accordéon dynamique */}
|
||||||
{missions.length > 0 ? (
|
{missions.length > 0 ? (
|
||||||
missions.map((mission, index) => (
|
missions.map((mission, index) => (
|
||||||
<Accordion key={index} expanded={expanded === `panel${index}`} onChange={handleAccordionChange(`panel${index}`)}>
|
<Accordion
|
||||||
|
key={index}
|
||||||
|
expanded={expanded === `panel${index}`}
|
||||||
|
onChange={handleAccordionChange(`panel${index}`)}
|
||||||
|
>
|
||||||
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
||||||
<Typography variant="h6">{mission.title}</Typography>
|
<Typography
|
||||||
|
variant="h3"
|
||||||
|
sx={{
|
||||||
|
fontWeight: "bold",
|
||||||
|
fontSize: { xs: "1rem", md: "1.2rem", lg: "1.5rem" },
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{mission.title}
|
||||||
|
</Typography>
|
||||||
</AccordionSummary>
|
</AccordionSummary>
|
||||||
<AccordionDetails>
|
<AccordionDetails>
|
||||||
<Typography>{mission.details}</Typography>
|
<Typography>{mission.details}</Typography>
|
||||||
@@ -147,7 +228,22 @@ const ConstructSection = ({
|
|||||||
{/* Background Image et Items */}
|
{/* Background Image et Items */}
|
||||||
<Box sx={{ position: "relative", height: "auto", mt: 3 }}>
|
<Box sx={{ position: "relative", height: "auto", mt: 3 }}>
|
||||||
{missionItems?.map((item, index) => (
|
{missionItems?.map((item, index) => (
|
||||||
<Box key={index} sx={{ position: "absolute", top: item.top, left: item.left, transform: "translate(-50%, -50%)", backgroundColor: "#0e467f", color: "#fff", padding: "6px 12px", borderRadius: "20px", fontSize: "0.9rem", fontWeight: "bold", textAlign: "center" }}>
|
<Box
|
||||||
|
key={index}
|
||||||
|
sx={{
|
||||||
|
position: "absolute",
|
||||||
|
top: item.top,
|
||||||
|
left: item.left,
|
||||||
|
transform: "translate(-50%, -50%)",
|
||||||
|
backgroundColor: "#0e467f",
|
||||||
|
color: "#fff",
|
||||||
|
padding: "6px 12px",
|
||||||
|
borderRadius: "20px",
|
||||||
|
fontSize: "0.9rem",
|
||||||
|
fontWeight: "bold",
|
||||||
|
textAlign: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
{item.label}
|
{item.label}
|
||||||
</Box>
|
</Box>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -85,24 +85,24 @@ const GestionPageAccueil = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// ✅ Mise à jour des champs ACF
|
// ✅ Mise à jour des champs ACF
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
try {
|
try {
|
||||||
const newData = {
|
const newData = {
|
||||||
hero_title: heroTitle, // ✅ Enregistre le H1
|
hero_title: heroTitle, // ✅ Enregistre le H1
|
||||||
hero_text: heroText, // ✅ Enregistre le texte du Hero
|
hero_text: heroText, // ✅ Enregistre le texte du Hero
|
||||||
mission: missions, // ✅ Enregistre les missions
|
mission: missions, // ✅ Enregistre les missions
|
||||||
};
|
};
|
||||||
|
|
||||||
await updateHomePageACF(13, newData);
|
await updateHomePageACF(13, newData);
|
||||||
localStorage.setItem("missions", JSON.stringify(missions)); // ✅ Sauvegarde locale
|
localStorage.setItem("missions", JSON.stringify(missions)); // ✅ Sauvegarde locale
|
||||||
|
|
||||||
setSuccessMessage("✅ Modifications enregistrées avec succès !");
|
setSuccessMessage("✅ Modifications enregistrées avec succès !");
|
||||||
setTimeout(() => setSuccessMessage(""), 3000);
|
setTimeout(() => setSuccessMessage(""), 3000);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("❌ Erreur mise à jour :", error);
|
console.error("❌ Erreur mise à jour :", error);
|
||||||
setError("⚠ Impossible de mettre à jour les champs ACF.");
|
setError("⚠ Impossible de mettre à jour les champs ACF.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ✅ Gérer le téléversement d’une nouvelle image Hero
|
// ✅ Gérer le téléversement d’une nouvelle image Hero
|
||||||
const handleImageUpload = async (event) => {
|
const handleImageUpload = async (event) => {
|
||||||
@@ -134,17 +134,17 @@ const handleSave = async () => {
|
|||||||
}, [missions]);
|
}, [missions]);
|
||||||
|
|
||||||
// ✅ Fonction pour sauvegarder les missions dans WordPress
|
// ✅ Fonction pour sauvegarder les missions dans WordPress
|
||||||
const saveMissionsToWordPress = async (missions) => {
|
const saveMissionsToWordPress = async (missions) => {
|
||||||
try {
|
try {
|
||||||
const newData = { missions }; // Sauvegarde dans ACF
|
const newData = { missions }; // Sauvegarde dans ACF
|
||||||
await updateHomePageACF(13, newData);
|
await updateHomePageACF(13, newData);
|
||||||
|
|
||||||
localStorage.setItem("missions", JSON.stringify(missions)); // Sauvegarde locale
|
localStorage.setItem("missions", JSON.stringify(missions)); // Sauvegarde locale
|
||||||
console.log("✅ Missions enregistrées dans WordPress et localStorage !");
|
console.log("✅ Missions enregistrées dans WordPress et localStorage !");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("❌ Erreur lors de l'enregistrement des missions :", error);
|
console.error("❌ Erreur lors de l'enregistrement des missions :", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ✅ Ajouter une mission
|
// ✅ Ajouter une mission
|
||||||
const addMission = () => {
|
const addMission = () => {
|
||||||
@@ -263,41 +263,6 @@ const saveMissionsToWordPress = async (missions) => {
|
|||||||
multiline
|
multiline
|
||||||
rows={3}
|
rows={3}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* ✅ Bouton d'enregistrement */}
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="primary"
|
|
||||||
fullWidth
|
|
||||||
sx={{
|
|
||||||
mt: 3,
|
|
||||||
fontSize: "1.1rem",
|
|
||||||
fontWeight: "bold",
|
|
||||||
color: "#ffffff",
|
|
||||||
backgroundColor: "#0e467f",
|
|
||||||
"&:hover": { backgroundColor: "#093a6b" },
|
|
||||||
}}
|
|
||||||
onClick={handleSave}
|
|
||||||
>
|
|
||||||
💾 Enregistrer les modifications
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
{/* ✅ Bouton retour au Dashboard */}
|
|
||||||
<Button
|
|
||||||
variant="outlined"
|
|
||||||
color="secondary"
|
|
||||||
fullWidth
|
|
||||||
sx={{
|
|
||||||
mt: 2,
|
|
||||||
fontSize: "1rem",
|
|
||||||
fontWeight: "bold",
|
|
||||||
borderColor: "#0e467f",
|
|
||||||
color: "#0e467f",
|
|
||||||
}}
|
|
||||||
onClick={() => navigate("/admin/dashboard")}
|
|
||||||
>
|
|
||||||
⬅ Retour au Dashboard
|
|
||||||
</Button>
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -352,6 +317,42 @@ const saveMissionsToWordPress = async (missions) => {
|
|||||||
➕ Ajouter une mission
|
➕ Ajouter une mission
|
||||||
</Button>
|
</Button>
|
||||||
</Paper>
|
</Paper>
|
||||||
|
<Paper elevation={3} sx={{ marginTop: "30px", padding: "20px" }}>
|
||||||
|
{/* ✅ Bouton d'enregistrement */}
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
fullWidth
|
||||||
|
sx={{
|
||||||
|
mt: 3,
|
||||||
|
fontSize: "1.1rem",
|
||||||
|
fontWeight: "bold",
|
||||||
|
color: "#ffffff",
|
||||||
|
backgroundColor: "#0e467f",
|
||||||
|
"&:hover": { backgroundColor: "#093a6b" },
|
||||||
|
}}
|
||||||
|
onClick={handleSave}
|
||||||
|
>
|
||||||
|
💾 Enregistrer les modifications
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{/* ✅ Bouton retour au Dashboard */}
|
||||||
|
<Button
|
||||||
|
variant="outlined"
|
||||||
|
color="secondary"
|
||||||
|
fullWidth
|
||||||
|
sx={{
|
||||||
|
mt: 2,
|
||||||
|
fontSize: "1rem",
|
||||||
|
fontWeight: "bold",
|
||||||
|
borderColor: "#0e467f",
|
||||||
|
color: "#0e467f",
|
||||||
|
}}
|
||||||
|
onClick={() => navigate("/admin/dashboard")}
|
||||||
|
>
|
||||||
|
⬅ Retour au Dashboard
|
||||||
|
</Button>
|
||||||
|
</Paper>
|
||||||
</Paper>
|
</Paper>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user