diff --git a/frontend/src/components/Pages/CreatePost.jsx b/frontend/src/components/Pages/CreatePost.jsx index 4ef68d0..b8fd90a 100644 --- a/frontend/src/components/Pages/CreatePost.jsx +++ b/frontend/src/components/Pages/CreatePost.jsx @@ -1,54 +1,133 @@ -import { useState } from "react"; +import { useState, useEffect } from "react"; +import { useNavigate } from "react-router-dom"; import { uploadImage, createPost } from "../../wordpress"; +import { getToken } from "../../auth"; +import { + Box, + Container, + Typography, + TextField, + Button, + Paper, + Input, + IconButton, +} from "@mui/material"; +import { ArrowBack, Publish } from "@mui/icons-material"; function CreatePost() { - const [title, setTitle] = useState(""); - const [content, setContent] = useState(""); - const [file, setFile] = useState(null); + const [title, setTitle] = useState(""); + const [content, setContent] = useState(""); + const [file, setFile] = useState(null); + const navigate = useNavigate(); - const handleSubmit = async (e) => { - e.preventDefault(); + // ✅ Vérification de l'authentification : Redirection vers /login si l'utilisateur n'est pas connecté + useEffect(() => { + if (!getToken()) { + navigate("/admin/login"); + } + }, [navigate]); - try { - console.log("📢 Tentative d'upload de l'image..."); - const imageId = await uploadImage(file); + const handleSubmit = async (e) => { + e.preventDefault(); - console.log("📢 Création du post avec l'image mise en avant..."); - await createPost(title, content, imageId); + try { + console.log("📢 Tentative d'upload de l'image..."); + const imageId = await uploadImage(file); - alert("✅ Post créé avec succès !"); - } catch (error) { - alert("❌ Erreur lors de la création du post."); - } - }; + console.log("📢 Création du post avec l'image mise en avant..."); + await createPost(title, content, imageId); - return ( -
-

Créer un post

-
- setTitle(e.target.value)} - required - /> -