Merge VolunteerProfilePage into ProfilePage
This commit is contained in:
1 parent
ff50056bee
commit
bd415209a5
2 files changed
+50
-83
No files matched your search
@@ -1,20 +1,24 @@
|
|||||||
import { useContext, useEffect } from "react";
|
import {useContext, useEffect, useState} from "react";
|
||||||
import styles from "./ProfilePage.module.css";
|
import styles from "./ProfilePage.module.css";
|
||||||
|
|
||||||
import {AuthContext} from "../../contexts/auth/AuthContext";
|
import {AuthContext} from "../../contexts/auth/AuthContext";
|
||||||
import formatDate from "../../utils/date/formatDate";
|
import formatDate from "../../utils/date/formatDate";
|
||||||
|
import Task from "../../components/Task/Task";
|
||||||
|
import SettingsModal from "./components/SettingsModal/SettingsModal";
|
||||||
|
import { useParams } from "react-router";
|
||||||
|
import { useNavigate } from "react-router";
|
||||||
|
import getUserById from "../../utils/users/getUserById.js";
|
||||||
|
|
||||||
//import Task from "../../components/Task/Task";
|
|
||||||
//import SettingsModal from "./components/SettingsModal/SettingsModal";
|
|
||||||
|
|
||||||
interface TaskType {
|
interface TaskType {
|
||||||
id: number;
|
id: number;
|
||||||
title?: string;
|
title?: string;
|
||||||
completed?: boolean;
|
completed?: boolean;
|
||||||
|
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface User {
|
interface User {
|
||||||
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
lastname: string;
|
lastname: string;
|
||||||
role: string;
|
role: string;
|
||||||
@@ -25,17 +29,41 @@ interface User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface AuthContextType {
|
interface AuthContextType {
|
||||||
user: User | null;
|
user: User;
|
||||||
update: () => void;
|
update: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function ProfilePage() {
|
function ProfilePage() {
|
||||||
|
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { id } = useParams();
|
||||||
const { user, update } = useContext(AuthContext) as AuthContextType;
|
const { user, update } = useContext(AuthContext) as AuthContextType;
|
||||||
|
const [profileUser, setProfileUser] = useState<User | null>(null);
|
||||||
|
|
||||||
|
const isOwnProfile = !id || user.id.toString() === id;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
update();
|
update();
|
||||||
|
(async () => {
|
||||||
|
|
||||||
|
if(!isOwnProfile) {
|
||||||
|
console.log(id);
|
||||||
|
const res = await getUserById(id);
|
||||||
|
|
||||||
|
if (res.status === 404) {
|
||||||
|
navigate("/404");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res.status !== 200) {
|
||||||
|
console.error("Erreur lors du chargement du profil", res);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setProfileUser(res.data);
|
||||||
|
} else setProfileUser(user)
|
||||||
|
}) ()
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -53,45 +81,47 @@ function ProfilePage(){
|
|||||||
<div className={styles.description}>
|
<div className={styles.description}>
|
||||||
<div className={styles.headerProfile}>
|
<div className={styles.headerProfile}>
|
||||||
<h2>
|
<h2>
|
||||||
{user?.name} {user?.lastname}
|
{profileUser?.name} {profileUser?.lastname}
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.topDescription}>
|
<div className={styles.topDescription}>
|
||||||
<div className={`${styles.infoBlock} glassBorder`}>
|
<div className={`${styles.infoBlock} glassBorder`}>
|
||||||
<p>
|
<p>
|
||||||
<strong>Role :</strong> {user?.role}
|
<strong>Role :</strong> {profileUser?.role}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<strong>Membre depuis :</strong>{" "}
|
<strong>Membre depuis :</strong>{" "}
|
||||||
{user && formatDate(user.created_at)}
|
{profileUser && formatDate(profileUser.created_at)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={`${styles.infoBlock} glassBorder`}>
|
<div className={`${styles.infoBlock} glassBorder`}>
|
||||||
<p>
|
<p>
|
||||||
<strong>Mail :</strong> {user?.email}
|
<strong>Mail :</strong> {profileUser?.email}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<strong>Téléphone :</strong>{" "}
|
<strong>Téléphone :</strong>{" "}
|
||||||
{user?.phone ?? "Pas de numéro enregistré"}
|
{profileUser?.phone ?? "Pas de numéro enregistré"}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{isOwnProfile && (
|
||||||
<div className={styles.settingImage}>
|
<div className={styles.settingImage}>
|
||||||
{/* <SettingsModal />*/}
|
<SettingsModal />
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>Tâches :</h2>
|
<h2>Tâches :</h2>
|
||||||
|
|
||||||
{/* {user && user.tasks.length > 0 ? (
|
{profileUser && profileUser.tasks.length > 0 ? (
|
||||||
user.tasks.map((task) => (
|
profileUser.tasks.map((task) => (
|
||||||
<Task key={task.id} task={task}/>
|
<Task key={task.id} task={task}/>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<p>Aucune tâche pour le moment.</p>
|
<p>Aucune tâche pour le moment.</p>
|
||||||
)}*/}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -100,66 +130,3 @@ function ProfilePage(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default ProfilePage;
|
export default ProfilePage;
|
||||||
|
|
||||||
|
|
||||||
/*import React, { useContext, useEffect } from "react";
|
|
||||||
import styles from "./ProfilePage.module.css";
|
|
||||||
import { AuthContext } from "../../contexts/auth/AuthContext.js";
|
|
||||||
import formatDate from "../../utils/date/formatDate.js";
|
|
||||||
import Task from "../../components/Task/Task";
|
|
||||||
import SettingsModal from "./components/SettingsModal/SettingsModal.jsx";
|
|
||||||
|
|
||||||
function ProfilePage() {
|
|
||||||
|
|
||||||
const { user, update } = useContext(AuthContext);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
update();
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={styles.container}>
|
|
||||||
<div className={`${styles.profileboard} glassCard`}>
|
|
||||||
<div className={styles.contentWrapper}>
|
|
||||||
<div className={styles.profilePictureContainer}>
|
|
||||||
<img
|
|
||||||
src="/react.svg"
|
|
||||||
alt="Photo de profil"
|
|
||||||
className={styles.profilePicture}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className={styles.description}>
|
|
||||||
<div className={styles.headerProfile}>
|
|
||||||
<h2> {user?.name} {user?.lastname} </h2>
|
|
||||||
</div>
|
|
||||||
<div className={styles.topDescription}>
|
|
||||||
<div className={`${styles.infoBlock} glassBorder`}>
|
|
||||||
<p><strong>Role :</strong> {user?.role}</p>
|
|
||||||
<p><strong>Membre depuis :</strong> {user && formatDate(user.created_at)}</p>
|
|
||||||
</div>
|
|
||||||
<div className={`${styles.infoBlock} glassBorder`}>
|
|
||||||
<p><strong>Mail :</strong> {user?.email} </p>
|
|
||||||
<p><strong>Téléphone :</strong> {user?.phone === null ? "Pas de numéro enregistré" : user?.phone}</p>
|
|
||||||
</div>
|
|
||||||
<div className={styles.settingImage}>
|
|
||||||
<SettingsModal />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h2>Tâches :</h2>
|
|
||||||
{user && user.tasks.length > 0 ? (
|
|
||||||
user.tasks.map((task, index) => (
|
|
||||||
<Task key={index} task={task} />
|
|
||||||
))
|
|
||||||
) : (
|
|
||||||
<p>Aucune tâche pour le moment.</p>
|
|
||||||
)}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ProfilePage;*/
|
|
||||||
+5
-5
@@ -47,10 +47,6 @@ const router = createBrowserRouter([
|
|||||||
path: "/admin",
|
path: "/admin",
|
||||||
Component:AdminPage,
|
Component:AdminPage,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path:"/profile",
|
|
||||||
Component:ProfilePage,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "/events",
|
path: "/events",
|
||||||
Component: EventsPage,
|
Component: EventsPage,
|
||||||
@@ -59,9 +55,13 @@ const router = createBrowserRouter([
|
|||||||
path: "/volunteers",
|
path: "/volunteers",
|
||||||
Component: VolunteersPage,
|
Component: VolunteersPage,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path:"/profile",
|
||||||
|
Component:ProfilePage,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "/profile/:id",
|
path: "/profile/:id",
|
||||||
Component: VolunteerProfilePage,
|
Component: ProfilePage,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/events/:id",
|
path: "/events/:id",
|
||||||
|
|||||||
Reference in new issue
Block a user