From 5ea9fde2b603fc3b00193012668dac720d5a12e9 Mon Sep 17 00:00:00 2001 From: alphamine123 <mohammedamine.zaime1@usmba.ac.ma> Date: Fri, 14 Mar 2025 08:48:59 +0100 Subject: [PATCH] implement user profile --- src/App.jsx | 5 ++--- src/components/Navbar.jsx | 21 +++++++++---------- src/components/dashboard/TaskStats.jsx | 7 ++++--- src/components/dashboard/TasksStatPercent.jsx | 6 ++++-- src/components/todolist/Todolist.jsx | 5 ++++- src/pages/SignIn.jsx | 2 +- src/pages/SignUp.jsx | 4 ++-- 7 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 444e24b..c5a22fb 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -18,10 +18,9 @@ function App() { <Navbar /> <main className="flex-grow pt-4"> <Routes> - <Route path="/signin" element={<SignIn />} /> + <Route path="/" element={<SignIn />} /> <Route path="/signup" element={<SignUp />} /> - <Route path="/" element={<Home />} /> - <Route path="/todolist" element={<Todolist />} /> + <Route path="/home" element={<Home />} /> </Routes> </main> <Footer /> diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx index 8809421..1f772b1 100644 --- a/src/components/Navbar.jsx +++ b/src/components/Navbar.jsx @@ -26,7 +26,7 @@ const Navbar = () => { const handleLogout = () => { localStorage.removeItem("user"); setIsAuthenticated(false); - navigate("/signin"); + navigate("/"); }; return ( @@ -34,25 +34,24 @@ const Navbar = () => { <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> <div className="flex justify-between h-16"> <div className="flex items-center"> - <Link to="/" className="flex items-center gap-2"> + <Link to="/home" className="flex items-center gap-2"> <CheckCircle className="h-8 w-8 text-violet-600 dark:text-violet-400" /> <span className="text-xl font-semibold text-gray-900 dark:text-white">TaskMaster</span> </Link> </div> <div className="flex items-center gap-6"> + {isAuthenticated ? ( <Link - to="/" + to="/home" className="text-gray-700 dark:text-white hover:text-violet-600 dark:hover:text-violet-400 px-3 py-2 rounded-md text-sm font-medium" > Dashboard - </Link> - <Link - to="/todolist" - className="text-gray-700 dark:text-white hover:text-violet-600 dark:hover:text-violet-400 px-3 py-2 rounded-md text-sm font-medium" - > - Tasks List - </Link> + </Link>) : (<p></p>)} + + + + {/* Bouton Light/Dark Mode */} <button onClick={toggleTheme} className="p-2 rounded-md bg-gray-200 dark:bg-gray-700"> @@ -72,7 +71,7 @@ const Navbar = () => { <> <Link - to="/signin" + to="/" className="text-gray-700 dark:text-white hover:text-violet-600 dark:hover:text-violet-400 px-3 py-2 rounded-md text-sm font-medium" > Login diff --git a/src/components/dashboard/TaskStats.jsx b/src/components/dashboard/TaskStats.jsx index f334de7..5e345d5 100644 --- a/src/components/dashboard/TaskStats.jsx +++ b/src/components/dashboard/TaskStats.jsx @@ -5,9 +5,10 @@ import { useTasks } from "@context/TasksContext"; const TaskStats = () => { const { tasks } = useTasks(); - const completed = tasks.filter(task => task.isCompleted).length; - const incompleted = tasks.filter(task => !task.isCompleted).length; - const total = tasks.length; + const currentUser = JSON.parse(localStorage.getItem("currentUser")); + const completed = tasks.filter(task => task.isCompleted && task.email == currentUser.email).length; + const incompleted = tasks.filter(task => !task.isCompleted && task.email == currentUser.email).length; + const total = tasks.filter(task => task.email == currentUser.email).length; return ( <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4"> diff --git a/src/components/dashboard/TasksStatPercent.jsx b/src/components/dashboard/TasksStatPercent.jsx index fbd1998..1c93391 100644 --- a/src/components/dashboard/TasksStatPercent.jsx +++ b/src/components/dashboard/TasksStatPercent.jsx @@ -4,8 +4,10 @@ import { useTasks } from "@context/TasksContext"; const TasksStatPercent = () => { const { tasks } = useTasks(); - const totalTasks = tasks.length; - const completedTasks = tasks.filter(task => task.isCompleted).length; + const currentUser = JSON.parse(localStorage.getItem("currentUser")); + + const totalTasks = tasks.filter(task => task.email == currentUser.email).length; + const completedTasks = tasks.filter(task => task.isCompleted && task.email == currentUser.email).length; const radius = 50; const circumference = 2 * Math.PI * radius; diff --git a/src/components/todolist/Todolist.jsx b/src/components/todolist/Todolist.jsx index 50bfd20..a0f591c 100644 --- a/src/components/todolist/Todolist.jsx +++ b/src/components/todolist/Todolist.jsx @@ -8,7 +8,9 @@ export default function Todolist({ selectedDate=null }) { const { tasks, setTasks } = useTasks() const newTask = () => { + const currentUser = JSON.parse(localStorage.getItem("currentUser")); return { + email : currentUser.email, name: "", isCompleted: false, dueDate: new Date().toISOString().split("T")[0], @@ -57,7 +59,8 @@ export default function Todolist({ selectedDate=null }) { } const filteredTasks = selectedDate ? tasks.filter(task => { - if (!task.dueDate) return false; + const currentUser = JSON.parse(localStorage.getItem("currentUser")); + if (!task.dueDate || task.email != currentUser.email) return false; const taskDate = new Date(task.dueDate); return taskDate.toDateString() === selectedDate.toDateString(); }) : tasks; diff --git a/src/pages/SignIn.jsx b/src/pages/SignIn.jsx index e32929e..740aed4 100644 --- a/src/pages/SignIn.jsx +++ b/src/pages/SignIn.jsx @@ -16,7 +16,7 @@ const SignIn = () => { if (result.success) { localStorage.setItem("user", JSON.stringify(result.user)); window.dispatchEvent(new Event("storage")); - navigate("/"); // Rediriger vers Home après connexion + navigate("/home"); // Rediriger vers Home après connexion } else { setError(result.message); } diff --git a/src/pages/SignUp.jsx b/src/pages/SignUp.jsx index 9f28cb2..f1b716e 100644 --- a/src/pages/SignUp.jsx +++ b/src/pages/SignUp.jsx @@ -15,7 +15,7 @@ const SignUp = () => { const result = signUp(name, email, password); if (result.success) { - navigate("/signin"); // Rediriger vers Sign In après l'inscription + navigate("/"); // Rediriger vers Sign In après l'inscription } else { setError(result.message); } @@ -72,7 +72,7 @@ const SignUp = () => { <p className="mt-4 text-center text-sm text-gray-600 dark:text-gray-300"> Already have an account? - <Link to="/signin" className="text-blue-600 dark:text-blue-400 ml-1">Sign in</Link> + <Link to="/" className="text-blue-600 dark:text-blue-400 ml-1">Sign in</Link> </p> </div> </div> -- GitLab