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 ( -
+ {completedCount} +
+ + {(totalCount ? (completedCount / totalCount) * 100 : 0).toFixed(0)}% + ++ {inProgressCount} +
+ + {(totalCount ? (inProgressCount / totalCount) * 100 : 0).toFixed(0)}% + ++ {pendingCount} +
+ + {(totalCount ? (pendingCount / totalCount) * 100 : 0).toFixed(0)}% + +