From ea6353a4555a1f4a90966aeffcc11eb90c221c06 Mon Sep 17 00:00:00 2001 From: THIS ONE IS A LITTLE BIT TRICKY KRUB Date: Sat, 25 Nov 2023 14:34:23 +0700 Subject: [PATCH] Refactor dashboard component imports and remove unused code --- .../src/components/dashboard/PieChart.jsx | 43 +++++++++++++++ .../src/components/dashboard/dashboard.jsx | 53 +++++++++++-------- 2 files changed, 73 insertions(+), 23 deletions(-) create mode 100644 frontend/src/components/dashboard/PieChart.jsx diff --git a/frontend/src/components/dashboard/PieChart.jsx b/frontend/src/components/dashboard/PieChart.jsx new file mode 100644 index 0000000..73f132b --- /dev/null +++ b/frontend/src/components/dashboard/PieChart.jsx @@ -0,0 +1,43 @@ +import { DonutChart } from "@tremor/react"; +import axiosInstance from "../../api/configs/AxiosConfig"; + +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 []; + } +}; + +const pieDataArray = await fetchPieData(); + +export function PieChartGraph() { + return ( + + ); +} diff --git a/frontend/src/components/dashboard/dashboard.jsx b/frontend/src/components/dashboard/dashboard.jsx index 31cc71f..7825141 100644 --- a/frontend/src/components/dashboard/dashboard.jsx +++ b/frontend/src/components/dashboard/dashboard.jsx @@ -1,22 +1,29 @@ -import { Card, Grid, Tab, TabGroup, TabList, TabPanel, TabPanels, Text, Title, Legend } from "@tremor/react"; -import { KpiCard } from "./KpiCard"; +import { + Card, + Grid, + Tab, + TabGroup, + TabList, + TabPanel, + TabPanels, + Text, + Title, + Legend, +} from "@tremor/react"; +import {KpiCard} from "./KpiCard"; import { BarChartGraph } from "./Barchart"; -import { DonutChartGraph } from "./DonutChart"; import { AreaChartGraph } from "./Areachart"; -import { ProgressCircleChart } from "./ProgressCircle"; -import { useState } from "react"; +import {ProgressCircleChart} from "./ProgressCircle"; + +const valueFormatter = (number) => + `$ ${new Intl.NumberFormat("us").format(number).toString()}`; export function Dashboard() { - const [value, setValue] = useState({ - from: new Date(2021, 0, 1), - to: new Date(2023, 0, 7), - }); return (
Dashboard All of your progress will be shown right here. -
@@ -40,7 +47,8 @@ export function Dashboard() { + colors={["indigo"]} + > @@ -51,18 +59,17 @@ export function Dashboard() { -
- - Tasks - -
- -
-
+
+ + Tasks +
+ +
+