From b5084ad99d1498951406b2c8fd33b17384654ff2 Mon Sep 17 00:00:00 2001 From: Kartik Sharma Date: Fri, 3 Oct 2025 12:30:52 +0530 Subject: [PATCH] Creating a new weidget in Dashboard for expense. --- src/components/Dashboard/Dashboard.jsx | 4 + src/components/Dashboard/ExpenseByProject.jsx | 123 ++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 src/components/Dashboard/ExpenseByProject.jsx diff --git a/src/components/Dashboard/Dashboard.jsx b/src/components/Dashboard/Dashboard.jsx index 9435d3bc..7e32df7a 100644 --- a/src/components/Dashboard/Dashboard.jsx +++ b/src/components/Dashboard/Dashboard.jsx @@ -17,6 +17,7 @@ import AttendanceOverview from "./AttendanceOverview"; import { useSelectedProject } from "../../slices/apiDataManager"; import { useProjectName } from "../../hooks/useProjects"; import ExpenseAnalysis from "./ExpenseAnalysis"; +import ExpenseByProject from "./ExpenseByProject"; const Dashboard = () => { // const { projectsCardData } = useDashboardProjectsCardData(); @@ -34,6 +35,9 @@ const Dashboard = () => {
+
+ +
{!isAllProjectsSelected && (
diff --git a/src/components/Dashboard/ExpenseByProject.jsx b/src/components/Dashboard/ExpenseByProject.jsx new file mode 100644 index 00000000..178d837e --- /dev/null +++ b/src/components/Dashboard/ExpenseByProject.jsx @@ -0,0 +1,123 @@ +import React, { useState } from "react"; +import Chart from "react-apexcharts"; + +const ExpenseByProject = () => { + const [range, setRange] = useState("12M"); + + // Dummy data grouped by year + const expenseData = { + "6M": { + categories: [ + { quarter: "Q1" }, + { quarter: "Q2" }, + { quarter: "Q3" }, + { quarter: "Q4" }, + ], + data: [400, 430, 448, 470] + }, + "12M": { + categories: [ + { quarter: "Q1" }, + { quarter: "Q2" }, + { quarter: "Q3" }, + { quarter: "Q4" }, + { quarter: "Q1" }, + { quarter: "Q2" }, + { quarter: "Q3" }, + { quarter: "Q4" }, + ], + data: [400, 430, 448, 470, 540, 580, 690, 690] + }, + All: { + categories: [ + { quarter: "Q1" }, + { quarter: "Q2" }, + { quarter: "Q3" }, + { quarter: "Q4" }, + { quarter: "Q1" }, + { quarter: "Q2" }, + { quarter: "Q3" }, + { quarter: "Q4" }, + ], + data: [300, 350, 370, 390, 420, 460, 500, 530] + } + }; + + const options = { + chart: { type: "bar", toolbar: { show: false } }, + plotOptions: { + bar: { + horizontal: false, + columnWidth: "55%", + borderRadius: 4 + } + }, + dataLabels: { + enabled: true, + formatter: (val) => val + }, + xaxis: { + categories: expenseData[range].categories.map(c => `${c.quarter}`), + labels: { + style: { fontSize: "12px" }, + rotate: -45 + }, + group: { + groups: [ + { + title: "2022", + cols: 4 + }, + { + title: "2023", + cols: 4 + }, + { + title: "2024", + cols: 4 + } + ] + } + }, + yaxis: { + title: { text: "Expense" } + }, + fill: { opacity: 1 }, + colors: ["#2196f3"] + }; + + const series = [ + { + name: "Expense", + data: expenseData[range].data + } + ]; + + return ( +
+
+
+
Expense Breakdown
+

Detailed project expenses

+
+
+ {["6M", "12M", "All"].map((item) => ( + + ))} +
+
+
+ +
+
+ ); +}; + +export default ExpenseByProject; \ No newline at end of file