From 9cd56a8472a2656c7c777f2e4c69dd0f8f7f47ea Mon Sep 17 00:00:00 2001 From: T'JAMPENS QUENTIN p2406187 Date: Mon, 15 Dec 2025 14:25:25 +0100 Subject: [PATCH 01/14] Create event modal --- src/components/ToolBar/ToolBar.jsx | 8 ++------ src/components/ToolBar/ToolBar.module.css | 5 ----- .../createEventBtn/CreateEventBtn.jsx | 20 +++++++++++++++++++ .../createEventBtn/createEventBtn.module.css | 20 +++++++++++++++++++ 4 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 src/components/createEventBtn/CreateEventBtn.jsx create mode 100644 src/components/createEventBtn/createEventBtn.module.css diff --git a/src/components/ToolBar/ToolBar.jsx b/src/components/ToolBar/ToolBar.jsx index d1f069f..67ff494 100644 --- a/src/components/ToolBar/ToolBar.jsx +++ b/src/components/ToolBar/ToolBar.jsx @@ -1,8 +1,8 @@ import styles from "./ToolBar.module.css" -import {Link} from "react-router"; import Filter from "../Filter/Filter.jsx"; import {useEffect, useState} from "react"; import SearchBar from "../SearchBar/SearchBar.jsx"; +import CreateEventBtn from "../createEventBtn/CreateEventBtn.jsx"; function ToolBar({setFilters, filters, showCreate = true}) { @@ -37,11 +37,7 @@ function ToolBar({setFilters, filters, showCreate = true}) { ) : null}
{showCreate ? ( - - + - + ) : null} + + setIsOpen(false)}> + + + + + +} \ No newline at end of file diff --git a/src/components/createEventBtn/createEventBtn.module.css b/src/components/createEventBtn/createEventBtn.module.css new file mode 100644 index 0000000..fae169d --- /dev/null +++ b/src/components/createEventBtn/createEventBtn.module.css @@ -0,0 +1,20 @@ +.createButton { + font-size: 1.5rem; + color: black; +} + +.createButton { + display: flex; + align-items: center; + justify-content: center; + border: none; + border-radius: 50% !important; + width: 55px !important; + height: 55px !important; + transition: all 0.5s ease; +} + +.createButton:hover { + transform: translateY(-5px); + cursor: pointer; +} \ No newline at end of file From 67b02c297f65916dc7ceb8587cb16cbdb52de5fa Mon Sep 17 00:00:00 2001 From: T'JAMPENS QUENTIN p2406187 Date: Mon, 15 Dec 2025 15:31:56 +0100 Subject: [PATCH 02/14] Create event function --- src/utils/event/createEvent.js | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/utils/event/createEvent.js diff --git a/src/utils/event/createEvent.js b/src/utils/event/createEvent.js new file mode 100644 index 0000000..4098dd7 --- /dev/null +++ b/src/utils/event/createEvent.js @@ -0,0 +1,36 @@ +import getXSRFToken from "../getXSRF.js"; + +export default async function createEvent(name, description) { + const csrfToken = await getXSRFToken(); + + try { + const response = await fetch(`http://${import.meta.env.VITE_API_URL}/api/events/create`, { + method: 'POST', + credentials: 'include', + headers: { + 'Content-Type': 'application/json', + 'X-XSRF-TOKEN': csrfToken, + 'Accept': 'application/json' + }, + body: JSON.stringify({ name, description }), + }); + + const data = await response.json(); + + if (!response.ok) { + if (response.status === 422) { + return { + status: 422, + errors: data.errors + }; + } + + throw new Error(`Erreur HTTP ${response.status}`); + } + + return { status: response.status, data }; + + } catch (error) { + return { status: "error", error }; + } +} From 9ad78b342e6735bec7bdd04e95b7f81fcc262a2e Mon Sep 17 00:00:00 2001 From: T'JAMPENS QUENTIN p2406187 Date: Mon, 15 Dec 2025 15:32:11 +0100 Subject: [PATCH 03/14] Call create function + update style --- .../createEventBtn/CreateEventBtn.jsx | 22 +++++++++++++++++++ .../createEventBtn/createEventBtn.module.css | 21 ++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/components/createEventBtn/CreateEventBtn.jsx b/src/components/createEventBtn/CreateEventBtn.jsx index 9a4a7c2..3e638db 100644 --- a/src/components/createEventBtn/CreateEventBtn.jsx +++ b/src/components/createEventBtn/CreateEventBtn.jsx @@ -2,19 +2,41 @@ import styles from "./createEventBtn.module.css" import { useState } from "react"; import Modal from "../ui/modal/modal.jsx"; import Button from "../ui/button/button.jsx"; +import TextInput from "../ui/input/input.jsx"; +import createEvent from "../../utils/event/createEvent.js" export default function CreateEventBtn() { const [isOpen, setIsOpen] = useState(false); + const [name, setName] = useState(""); + const [description, setDescription] = useState(""); + + const handleCreateEvent = async () => { + + if(name !== "" || description !== "") await createEvent(name, description); + setIsOpen(false); + } return <> setIsOpen(false)}> +
+
+

Titre

+ setName(e.target.value)} /> +
+
+

Description

+ setDescription(e.target.value)} /> +
+ + +
} \ No newline at end of file diff --git a/src/components/createEventBtn/createEventBtn.module.css b/src/components/createEventBtn/createEventBtn.module.css index fae169d..5676052 100644 --- a/src/components/createEventBtn/createEventBtn.module.css +++ b/src/components/createEventBtn/createEventBtn.module.css @@ -17,4 +17,25 @@ .createButton:hover { transform: translateY(-5px); cursor: pointer; +} + +.inputContainer { + + h2 { + margin-bottom: 0.5rem; + } + + margin: 1em; +} + +.create { + align-self: center; +} + +.section { + display: flex; + flex-direction: column; + gap: 10px; + margin-top: 15px; + margin-bottom: 15px; } \ No newline at end of file From 3051a0b2ca49bb09f7f191555ebebd5f210b447e Mon Sep 17 00:00:00 2001 From: T'JAMPENS QUENTIN p2406187 Date: Mon, 15 Dec 2025 16:49:07 +0100 Subject: [PATCH 04/14] Create ValidationErrorPage --- src/layout.jsx | 1 + .../ValidationErrorPage.jsx | 30 +++++++++++++++++++ .../validationErrorPage.module.css | 25 ++++++++++++++++ src/router.js | 5 ++++ 4 files changed, 61 insertions(+) create mode 100644 src/pages/waitValidationPage/ValidationErrorPage.jsx create mode 100644 src/pages/waitValidationPage/validationErrorPage.module.css diff --git a/src/layout.jsx b/src/layout.jsx index 4689a4e..4fa0991 100644 --- a/src/layout.jsx +++ b/src/layout.jsx @@ -13,6 +13,7 @@ function Layout(){ if (loading) return

Loading

; if (!user) return ; + if(user && user.validate === 0) return ; return (
diff --git a/src/pages/waitValidationPage/ValidationErrorPage.jsx b/src/pages/waitValidationPage/ValidationErrorPage.jsx new file mode 100644 index 0000000..15995e9 --- /dev/null +++ b/src/pages/waitValidationPage/ValidationErrorPage.jsx @@ -0,0 +1,30 @@ +import styles from "./validationErrorPage.module.css" +import Background from "../../components/background/background.jsx"; +import Button from "../../components/ui/button/button.jsx"; +import { useContext } from "react"; +import { AuthContext } from "../../contexts/auth/AuthContext.js"; +import { Navigate, useNavigate } from "react-router"; + +export default function ValidationErrorPage() { + + const { logout, user } = useContext(AuthContext); + const navigate = useNavigate(); + + const handleLogout = async () => { + await logout(); + navigate("/login"); + } + + if(user && user.validate === 1) return ; + + return +
+

Votre compte n'a pas été validé

+
+

Votre compte n'a pas encore été validé, veuillez attendre la vérification de votre compte par un membre autorisé.

+

Contact : contact@example.com

+ +
+
+
+} \ No newline at end of file diff --git a/src/pages/waitValidationPage/validationErrorPage.module.css b/src/pages/waitValidationPage/validationErrorPage.module.css new file mode 100644 index 0000000..e4a398d --- /dev/null +++ b/src/pages/waitValidationPage/validationErrorPage.module.css @@ -0,0 +1,25 @@ +.title { + color: white; + font-size: xx-large; + margin-bottom: 20px; +} + +.content { + display: flex; + flex-direction: column; + z-index: 2; + padding: 10px; +} + +.container { + padding: 20px; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + gap: 15px; + + p { + font-size: large; + } +} \ No newline at end of file diff --git a/src/router.js b/src/router.js index f3fdef6..bf44302 100644 --- a/src/router.js +++ b/src/router.js @@ -7,6 +7,7 @@ import RegisterPage from "./pages/Register/RegisterPage.jsx"; import VolunteersPage from "./pages/Volunteers/VolunteersPage"; import ProfilePage from "./pages/Profile/ProfilePage"; import EventsPage from "./pages/Events/EventsPage.jsx"; +import ValidationErrorPage from "./pages/waitValidationPage/ValidationErrorPage.jsx"; const router = createBrowserRouter([ { @@ -17,6 +18,10 @@ const router = createBrowserRouter([ path: "/register", Component: RegisterPage, }, + { + path: "/error/validation", + Component: ValidationErrorPage + }, { path: "/", Component: Layout, From 7fa9b74bd8ed329c5a18daa8f8954f60066463c9 Mon Sep 17 00:00:00 2001 From: T'JAMPENS QUENTIN p2406187 Date: Mon, 15 Dec 2025 17:04:06 +0100 Subject: [PATCH 05/14] Create ThemeSwitcher story --- src/stories/ThemeSwitcher.stories.jsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/stories/ThemeSwitcher.stories.jsx diff --git a/src/stories/ThemeSwitcher.stories.jsx b/src/stories/ThemeSwitcher.stories.jsx new file mode 100644 index 0000000..f285b15 --- /dev/null +++ b/src/stories/ThemeSwitcher.stories.jsx @@ -0,0 +1,20 @@ +import ThemeSwitcher from "../components/ui/themeSwitcher/ThemeSwitcher.jsx"; +import Background from "../components/background/background.jsx"; + +export default { + title: 'UI/ThemeSwitcher', + component: ThemeSwitcher, + parameters: { + layout: 'centered', + }, + tags: ['autodocs'], +}; + +const ThemeSwitcherRender = () => { + return + + +}; + +export const Default = () => ; + From 9f681d6345eabaf3a1df255e5bcb0f5d7a4c414a Mon Sep 17 00:00:00 2001 From: T'JAMPENS QUENTIN p2406187 Date: Wed, 17 Dec 2025 14:32:04 +0100 Subject: [PATCH 06/14] Create VolunteerProfilePage --- src/pages/VolunteerProfile/VolunteerProfilePage.jsx | 13 +++++++++++++ .../VolunteerProfilePage.module.css | 0 src/router.js | 5 +++++ 3 files changed, 18 insertions(+) create mode 100644 src/pages/VolunteerProfile/VolunteerProfilePage.jsx create mode 100644 src/pages/VolunteerProfile/VolunteerProfilePage.module.css diff --git a/src/pages/VolunteerProfile/VolunteerProfilePage.jsx b/src/pages/VolunteerProfile/VolunteerProfilePage.jsx new file mode 100644 index 0000000..f56ec75 --- /dev/null +++ b/src/pages/VolunteerProfile/VolunteerProfilePage.jsx @@ -0,0 +1,13 @@ +import styles from "./VolunteerProfilePage.module.css" +import { useParams } from "react-router"; + + +export default function VolunteerProfilePage() { + + const params = useParams(); + const id = params.id; + + return
+ +
+} \ No newline at end of file diff --git a/src/pages/VolunteerProfile/VolunteerProfilePage.module.css b/src/pages/VolunteerProfile/VolunteerProfilePage.module.css new file mode 100644 index 0000000..e69de29 diff --git a/src/router.js b/src/router.js index bf44302..25c91b9 100644 --- a/src/router.js +++ b/src/router.js @@ -8,6 +8,7 @@ import VolunteersPage from "./pages/Volunteers/VolunteersPage"; import ProfilePage from "./pages/Profile/ProfilePage"; import EventsPage from "./pages/Events/EventsPage.jsx"; import ValidationErrorPage from "./pages/waitValidationPage/ValidationErrorPage.jsx"; +import VolunteerProfilePage from "./pages/VolunteerProfile/VolunteerProfilePage.jsx"; const router = createBrowserRouter([ { @@ -45,6 +46,10 @@ const router = createBrowserRouter([ { path: "/volunteers", Component: VolunteersPage, + }, + { + path: "/profile/:id", + Component: VolunteerProfilePage, } ] } From 204caf3a8c3e19a6d78ad3e79fdb2c8be6851ad0 Mon Sep 17 00:00:00 2001 From: T'JAMPENS QUENTIN p2406187 Date: Wed, 17 Dec 2025 14:34:56 +0100 Subject: [PATCH 07/14] Fix logo --- src/components/Header/Header.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Header/Header.jsx b/src/components/Header/Header.jsx index 03a1161..ee04918 100644 --- a/src/components/Header/Header.jsx +++ b/src/components/Header/Header.jsx @@ -41,7 +41,7 @@ function Header() { @@ -114,7 +114,7 @@ function Header() { className={styles.closeBtn} onClick={() => setNotifications(prev => prev.filter((_, i) => i !== index))} > - supprimer la notification + supprimer la notification
)) From 20bbc62b3d01797ebd04c73b71f4895dbc8311d1 Mon Sep 17 00:00:00 2001 From: T'JAMPENS QUENTIN p2406187 Date: Wed, 17 Dec 2025 14:46:19 +0100 Subject: [PATCH 09/14] Link VolunteerProfilePage to backend server --- .../VolunteerProfile/VolunteerProfilePage.jsx | 52 +++++- .../VolunteerProfilePage.module.css | 164 ++++++++++++++++++ 2 files changed, 214 insertions(+), 2 deletions(-) diff --git a/src/pages/VolunteerProfile/VolunteerProfilePage.jsx b/src/pages/VolunteerProfile/VolunteerProfilePage.jsx index f56ec75..06b4ee3 100644 --- a/src/pages/VolunteerProfile/VolunteerProfilePage.jsx +++ b/src/pages/VolunteerProfile/VolunteerProfilePage.jsx @@ -1,13 +1,61 @@ import styles from "./VolunteerProfilePage.module.css" import { useParams } from "react-router"; - +import { useEffect, useState } from "react"; +import getUserById from "../../utils/users/getUserById.js"; +import formatDate from "../../utils/date/formatDate.js"; +import Task from "../../components/Task/Task.jsx"; export default function VolunteerProfilePage() { const params = useParams(); const id = params.id; - return
+ const [user, setUser] = useState({}); + useEffect(() => { + (async () => { + const data = await getUserById(id); + setUser(data); + }) () + }, []); + + + return
+
+
+
+ Photo de profil +
+
+
+

{user.name} {user.lastname}

+
+
+
+

Role : {user.role}

+

Membre depuis : {formatDate(user.created_at)}

+
+
+

Mail : {user.email}

+

Téléphone : {user.phone === null ? "Pas de numéro enregistré" : user.phone}

+
+
+ +

Tâches :

+ {user.tasks && user.tasks.length > 0 ? ( + user.tasks.map((task, index) => ( + + )) + ) : ( +

Aucune tâche pour le moment.

+ )} + +
+
+
} \ No newline at end of file diff --git a/src/pages/VolunteerProfile/VolunteerProfilePage.module.css b/src/pages/VolunteerProfile/VolunteerProfilePage.module.css index e69de29..e9861dc 100644 --- a/src/pages/VolunteerProfile/VolunteerProfilePage.module.css +++ b/src/pages/VolunteerProfile/VolunteerProfilePage.module.css @@ -0,0 +1,164 @@ +.container { + width: 100%; + padding: 10px; + box-sizing: border-box; +} + +.profileboard { + width: 100%; + padding: 15px; + border-radius: 20px; + box-sizing: border-box; +} + +.contentWrapper { + display: flex; + flex-direction: column; + align-items: center; + width: 100%; +} + +.profilePictureContainer { + width: 120px; + height: 120px; + margin-bottom: 15px; +} + +.profilePicture { + width: 100%; + height: 100%; + border-radius: 50%; + object-fit: cover; +} + +.description { + width: 100%; + text-align: left; + margin-left:4%; +} + +.topDescription { + display: flex; + flex-direction: column; + align-items: center; + gap: 10px; + margin-bottom: 15px; +} + +.infoBlock { + width: 100%; + background: rgba(255, 255, 255, 0.1); + padding: 10px; + border-radius: 5px; +} + +.eventTasks { + max-height: 0; + overflow: hidden; + transition: max-height 0.3s ease-out, opacity 0.2s ease; + opacity: 0; + padding-left: 20px; +} + +.eventTasks.expanded { + max-height: 500px; + opacity: 1; + margin-top: 10px; +} +.description h2{ + font-size:30px; + +} +.profilePicture{ + width:90%; +} + +.settingsBtns { + display: flex; + gap: 5px; + justify-content: right; +} + +@media screen and (min-width: 768px) { + .contentWrapper { + flex-direction: row; + justify-content: flex-start; + align-items: flex-start; + } + + .profilePictureContainer { + width: 150px; + height: 150px; + margin-right: 20px; + margin-bottom: 0; + } + + .description { + width: calc(100% - 170px); + margin-left:4%; + } + + .topDescription { + flex-direction: row; + justify-content: space-between; + } + + .infoBlock { + width: 48%; + } + + .event { + padding: 15px; + } + .description h2{ + font-size:30px; + } + .profilePicture{ + width:90%; + } +} +.description button{ + width:50px; + height:50px; + +} + +.headerProfile { + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; + margin-bottom: 20px; +} + +/* Desktop (1024px et plus) */ +@media screen and (min-width: 1024px) { + .container { + max-width: 100%; + margin: 0 auto; + padding: 20px; + } + + .profileboard { + padding: 25px; + } + + .profilePictureContainer { + width: 30%; + height:auto; + } + .profilePicture{ + width:90%; + } + .description { + width: calc(100% - 200px); + margin-left:4%; + } + + .event { + padding: 18px; + } + .description h2{ + font-size:30px; + } +} From 6147b98c523349c2cd84b46f73d68a2c614381c1 Mon Sep 17 00:00:00 2001 From: T'JAMPENS QUENTIN p2406187 Date: Wed, 17 Dec 2025 14:50:11 +0100 Subject: [PATCH 10/14] improve ux --- src/pages/Profile/ProfilePage.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/Profile/ProfilePage.jsx b/src/pages/Profile/ProfilePage.jsx index aaa1338..b2602d0 100644 --- a/src/pages/Profile/ProfilePage.jsx +++ b/src/pages/Profile/ProfilePage.jsx @@ -31,12 +31,12 @@ function ProfilePage() {

Mail : {user.email}

-

Téléphone : {user.phone}

+

Téléphone : {user.phone === null ? "Pas de numéro enregistré" : user.phone}

-

Vos Événements :

+

Tâches :

{user.tasks && user.tasks.length > 0 ? ( user.tasks.map((task, index) => ( From fa9298a3343aa356c7a1f490466f06aef24f36af Mon Sep 17 00:00:00 2001 From: T'JAMPENS QUENTIN p2406187 Date: Wed, 17 Dec 2025 15:05:29 +0100 Subject: [PATCH 11/14] Create PageNotFound.jsx --- src/pages/PageNotFound/PageNotFound.jsx | 10 ++++++++++ src/pages/PageNotFound/PageNotFound.module.css | 0 src/router.js | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 src/pages/PageNotFound/PageNotFound.jsx create mode 100644 src/pages/PageNotFound/PageNotFound.module.css diff --git a/src/pages/PageNotFound/PageNotFound.jsx b/src/pages/PageNotFound/PageNotFound.jsx new file mode 100644 index 0000000..35299a6 --- /dev/null +++ b/src/pages/PageNotFound/PageNotFound.jsx @@ -0,0 +1,10 @@ +import Background from "../../components/background/background.jsx"; + +export default function PageNotFound() { + + return + +

404

+ +
+} \ No newline at end of file diff --git a/src/pages/PageNotFound/PageNotFound.module.css b/src/pages/PageNotFound/PageNotFound.module.css new file mode 100644 index 0000000..e69de29 diff --git a/src/router.js b/src/router.js index 25c91b9..7b34c16 100644 --- a/src/router.js +++ b/src/router.js @@ -9,6 +9,7 @@ import ProfilePage from "./pages/Profile/ProfilePage"; import EventsPage from "./pages/Events/EventsPage.jsx"; import ValidationErrorPage from "./pages/waitValidationPage/ValidationErrorPage.jsx"; import VolunteerProfilePage from "./pages/VolunteerProfile/VolunteerProfilePage.jsx"; +import PageNotFound from "./pages/PageNotFound/PageNotFound.jsx"; const router = createBrowserRouter([ { @@ -23,6 +24,10 @@ const router = createBrowserRouter([ path: "/error/validation", Component: ValidationErrorPage }, + { + path: "/*", + Component: PageNotFound, + }, { path: "/", Component: Layout, From 883d19d7c4026d48a6c101f5a7d4640c20a4981f Mon Sep 17 00:00:00 2001 From: T'JAMPENS QUENTIN p2406187 Date: Wed, 17 Dec 2025 15:10:58 +0100 Subject: [PATCH 12/14] Update PageNotFound.jsx --- src/pages/PageNotFound/PageNotFound.jsx | 18 ++++++++-- .../PageNotFound/PageNotFound.module.css | 33 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/pages/PageNotFound/PageNotFound.jsx b/src/pages/PageNotFound/PageNotFound.jsx index 35299a6..27b8630 100644 --- a/src/pages/PageNotFound/PageNotFound.jsx +++ b/src/pages/PageNotFound/PageNotFound.jsx @@ -1,10 +1,24 @@ import Background from "../../components/background/background.jsx"; +import styles from "./PageNotFound.module.css" +import { useNavigate } from "react-router"; export default function PageNotFound() { + const navigate = useNavigate(); + return +
+

Page non trouvée

+
+

+ Désolé, la page que vous recherchez n’existe pas ou n’est plus disponible.
+ Vous pouvez :
+ - Vérifier l’URL pour une éventuelle erreur de saisie.
+ - Revenir à l’accueil navigate("/")} className={styles.redirectSpan}>ici.
-

404

- +

+

Contact : contact@example.com

+
+
} \ No newline at end of file diff --git a/src/pages/PageNotFound/PageNotFound.module.css b/src/pages/PageNotFound/PageNotFound.module.css index e69de29..70e36f9 100644 --- a/src/pages/PageNotFound/PageNotFound.module.css +++ b/src/pages/PageNotFound/PageNotFound.module.css @@ -0,0 +1,33 @@ +.title { + color: white; + font-size: xx-large; + margin-bottom: 20px; +} + +.content { + display: flex; + flex-direction: column; + z-index: 2; + padding: 10px; +} + +.container { + padding: 20px; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + gap: 15px; + + p { + font-size: large; + } +} +.redirectSpan { + color: blue; + text-decoration: underline; +} + +.redirectSpan:hover { + cursor: pointer; +} \ No newline at end of file From c2f4c9fa55afe3289df33f5b694e9f9a8aec31a1 Mon Sep 17 00:00:00 2001 From: T'JAMPENS QUENTIN p2406187 Date: Wed, 17 Dec 2025 15:20:51 +0100 Subject: [PATCH 13/14] Redirect to 404 page if user not found --- .../VolunteerProfile/VolunteerProfilePage.jsx | 16 ++++++++++++---- src/router.js | 4 ++++ src/utils/users/getUserById.js | 9 ++++++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/pages/VolunteerProfile/VolunteerProfilePage.jsx b/src/pages/VolunteerProfile/VolunteerProfilePage.jsx index 06b4ee3..1f18805 100644 --- a/src/pages/VolunteerProfile/VolunteerProfilePage.jsx +++ b/src/pages/VolunteerProfile/VolunteerProfilePage.jsx @@ -4,20 +4,28 @@ import { useEffect, useState } from "react"; import getUserById from "../../utils/users/getUserById.js"; import formatDate from "../../utils/date/formatDate.js"; import Task from "../../components/Task/Task.jsx"; +import { useNavigate } from "react-router"; export default function VolunteerProfilePage() { const params = useParams(); const id = params.id; + const navigate = useNavigate(); + const [user, setUser] = useState({}); useEffect(() => { (async () => { - const data = await getUserById(id); - setUser(data); - }) () - }, []); + const result = await getUserById(id); + if (result?.error === 'not_found') { + navigate("/404"); + } else { + setUser(result); + } + })(); + }, [id]); + return
diff --git a/src/router.js b/src/router.js index 7b34c16..e9b0c56 100644 --- a/src/router.js +++ b/src/router.js @@ -28,6 +28,10 @@ const router = createBrowserRouter([ path: "/*", Component: PageNotFound, }, + { + path: "/404", + Component: PageNotFound, + }, { path: "/", Component: Layout, diff --git a/src/utils/users/getUserById.js b/src/utils/users/getUserById.js index 59af94a..1fad659 100644 --- a/src/utils/users/getUserById.js +++ b/src/utils/users/getUserById.js @@ -1,4 +1,4 @@ -export default async function getUserById (id) { +export default async function getUserById(id) { try { const res = await fetch(`http://${import.meta.env.VITE_API_URL}/api/users/${id}`, { method: 'GET', @@ -9,12 +9,15 @@ export default async function getUserById (id) { }); if (!res.ok) { + if (res.status === 404) { + return { error: 'not_found' }; + } throw new Error(`Erreur serveur : ${res.status}`); } return await res.json(); } catch (err) { console.error('Erreur :', err); - return null; + return { error: 'server_error' }; } -} \ No newline at end of file +} From ef948432d1f4a257735f079e44bd33bd3f08446f Mon Sep 17 00:00:00 2001 From: T'JAMPENS QUENTIN p2406187 Date: Wed, 17 Dec 2025 15:33:37 +0100 Subject: [PATCH 14/14] Show admin link if user is admin --- src/components/Header/Header.jsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/Header/Header.jsx b/src/components/Header/Header.jsx index 74bfc31..d467539 100644 --- a/src/components/Header/Header.jsx +++ b/src/components/Header/Header.jsx @@ -1,7 +1,8 @@ import styles from "./Header.module.css" import { Link, NavLink } from "react-router"; -import { useEffect, useRef, useState } from "react"; +import {useContext, useEffect, useRef, useState} from "react"; import getUserNotifications from "../../utils/getUserNotifications.js"; +import {AuthContext} from "../../contexts/auth/AuthContext.js"; function Header() { const [notificationMenu, setnotificationMenu] = useState(false); @@ -10,6 +11,7 @@ function Header() { const [notifications, setNotifications] = useState([{"content" : "ok"}, {"content" : "pourquoi pas antoine"}]); const notificationRef = useRef(null); + const { user } = useContext(AuthContext); useEffect(() => { @@ -53,6 +55,9 @@ function Header() { isActive ? styles.activeLink : styles.link}> Bénévoles + {user.isAdmin && isActive ? styles.activeLink : styles.link}> + Administration + }
@@ -84,6 +89,9 @@ function Header() { isActive ? styles.activeLink : styles.link}> Bénévoles + {user.isAdmin && isActive ? styles.activeLink : styles.link}> + Administration + }