diff --git a/src/Pages/Dashboard.tsx b/src/Pages/Dashboard.tsx index c0c82bf..7ee0092 100644 --- a/src/Pages/Dashboard.tsx +++ b/src/Pages/Dashboard.tsx @@ -1,48 +1,109 @@ // Pages/Dashboard.tsx -import { PieChart, Pie, Cell, Tooltip, Legend, ResponsiveContainer } from "recharts"; +import { + PieChart, + Pie, + Cell, + Tooltip, + Legend, + ResponsiveContainer, +} from "recharts"; import { useAuth } from "../Auth/AuthContext"; import useTodos from "../Hooks/useTodos"; +import { Statuses } from "../Data"; -const data = [ - { name: "Completed Tasks", value: 65 }, - { name: "In Progress", value: 20 }, - { name: "Pending", value: 15 }, -]; -// +const Dashboard = () => { + const { user } = useAuth(); + const { todos } = useTodos(user?.jwt); -const COLORS = ["#4CAF50", "#FFC107", "#F44336"]; -const {user} = useAuth(); + // Counts + const completedCount = + todos?.data.filter((todo) => todo.todo_status === Statuses[2].name).length || + 0; + const pendingCount = + todos?.data.filter((todo) => todo.todo_status === Statuses[0].name).length || + 0; + const inProgressCount = + todos?.data.filter((todo) => todo.todo_status === Statuses[1].name).length || + 0; -const {todos} = useTodos(user?.jwt); + const totalCount = completedCount + pendingCount + inProgressCount; + + // Pie chart data + const data = [ + { name: "Completed", value: completedCount }, + { name: "Pending", value: pendingCount }, + { name: "In Progress", value: inProgressCount }, + ]; + + const COLORS = ["#00C49F", "#FF8042", "#0088FE"]; -const Dashboard = () => { return ( -
-

📊 Dashboard Overview

+ <> +

+ Todo Status Overview +

-
-

Project Status

- + {/* Chart */} +
+ + `${name}: ${(percent * 100).toFixed(0)}%` + } outerRadius={100} - paddingAngle={5} dataKey="value" > - {data.map((entry, index) => ( - + {data.map((_, index) => ( + ))} - +
-
+ + {/* Stats cards */} +
+
+

Completed

+

+ {completedCount} +

+ + {(totalCount ? (completedCount / totalCount) * 100 : 0).toFixed(0)}% + +
+ +
+

In Progress

+

+ {inProgressCount} +

+ + {(totalCount ? (inProgressCount / totalCount) * 100 : 0).toFixed(0)}% + +
+ +
+

Pending

+

+ {pendingCount} +

+ + {(totalCount ? (pendingCount / totalCount) * 100 : 0).toFixed(0)}% + +
+
+ ); }; diff --git a/src/Pages/TodoLists.tsx b/src/Pages/TodoLists.tsx index 09d8e7a..4dc6385 100644 --- a/src/Pages/TodoLists.tsx +++ b/src/Pages/TodoLists.tsx @@ -25,7 +25,7 @@ const TodoLists = ({ return ( -
+
{todos.data.map((todo) => { const matchedStatus = Statuses.find(s => s.name === todo.todo_status);