diff --git a/frontend/src/components/dashboard/DonutChart.jsx b/frontend/src/components/dashboard/DonutChart.jsx deleted file mode 100644 index 63fc591..0000000 --- a/frontend/src/components/dashboard/DonutChart.jsx +++ /dev/null @@ -1,39 +0,0 @@ -import { DonutChart } from "@tremor/react"; -import { axiosInstance } from "src/api/AxiosConfig"; -import { useState, useEffect } from "react"; - -export function DonutChartGraph() { - const [donutData, setDonutData] = useState([]); - - useEffect(() => { - const fetchDonutData = async () => { - try { - const response = await axiosInstance.get("/dashboard/stats/"); - const todoCount = response.data.todo_count || 0; - const recurrenceCount = response.data.recurrence_count || 0; - - const donutData = [ - { name: "Todo", count: todoCount }, - { name: "Recurrence", count: recurrenceCount }, - ]; - - setDonutData(donutData); - } catch (error) { - console.error("Error fetching donut data:", error); - } - }; - fetchDonutData(); - }, []); - - return ( - - ); -} diff --git a/frontend/src/components/dashboard/KpiCard.jsx b/frontend/src/components/dashboard/KpiCard.jsx index c5c3165..85c74c9 100644 --- a/frontend/src/components/dashboard/KpiCard.jsx +++ b/frontend/src/components/dashboard/KpiCard.jsx @@ -13,7 +13,7 @@ export function KpiCard() { useEffect(() => { const fetchKpiCardData = async () => { try { - const response = await axiosInstance.get("/dashboard/stats/"); + const response = await axiosInstance.get("/dashboard/todostats/"); const completedThisWeek = response.data.completed_this_week || 0; const completedLastWeek = response.data.completed_last_week || 0; const percentage = (completedThisWeek / completedLastWeek) * 100; diff --git a/frontend/src/components/dashboard/PieChart.jsx b/frontend/src/components/dashboard/PieChart.jsx index 73f132b..645137b 100644 --- a/frontend/src/components/dashboard/PieChart.jsx +++ b/frontend/src/components/dashboard/PieChart.jsx @@ -1,37 +1,34 @@ import { DonutChart } from "@tremor/react"; -import axiosInstance from "../../api/configs/AxiosConfig"; +import { axiosInstance } from "src/api/AxiosConfig"; +import { useState, useEffect } from "react"; -const fetchPieData = async () => { - try { - let res = await axiosInstance.get("/dashboard/stats/"); - // let todoCount = res.data.todo_count; - // let recurrenceCount = res.data.recurrence_count; - let todoCount = 10; - let recurrenceCount = 15; - if (todoCount === undefined) { - todoCount = 0; - } - if (recurrenceCount === undefined) { - recurrenceCount = 0; - } - const donutData = [ - { name: "Completed Tasks", count: todoCount }, - { name: "Uncompleted Tasks", count: recurrenceCount }, - ]; - return donutData; - } catch (error) { - console.error("Error fetching donut data:", error); - return []; - } -}; +export function DonutChartGraph() { + const [donutData, setDonutData] = useState([]); -const pieDataArray = await fetchPieData(); + useEffect(() => { + const fetchDonutData = async () => { + try { + const response = await axiosInstance.get("/dashboard/todostats/"); + const totalTask = response.data.total_tasks || 0; + const completedTask = response.data.total_completed_tasks || 0; + + const donutData = [ + { name: "Completed task", count: totalTask }, + { name: "Total task", count: completedTask }, + ]; + + setDonutData(donutData); + } catch (error) { + console.error("Error fetching donut data:", error); + } + }; + fetchDonutData(); + }, []); -export function PieChartGraph() { return ( { const fetchProgressData = async () => { try { - const response = await axiosInstance.get("/dashboard/stats/"); + const response = await axiosInstance.get("/dashboard/todostats/"); let completedLastWeek = response.data.completed_last_week || 0; let assignLastWeek = response.data.tasks_assigned_last_week || 0; diff --git a/frontend/src/components/dashboard/dashboard.jsx b/frontend/src/components/dashboard/dashboard.jsx index 7825141..47bcaba 100644 --- a/frontend/src/components/dashboard/dashboard.jsx +++ b/frontend/src/components/dashboard/dashboard.jsx @@ -10,10 +10,11 @@ import { Title, Legend, } from "@tremor/react"; -import {KpiCard} from "./KpiCard"; +import { KpiCard } from "./KpiCard"; import { BarChartGraph } from "./Barchart"; import { AreaChartGraph } from "./Areachart"; -import {ProgressCircleChart} from "./ProgressCircle"; +import { DonutChartGraph } from "./PieChart"; +import { ProgressCircleChart } from "./ProgressCircle"; const valueFormatter = (number) => `$ ${new Intl.NumberFormat("us").format(number).toString()}`; @@ -59,17 +60,20 @@ export function Dashboard() { -
+ +
Tasks +
+