diff --git a/src/components/Dashboard/ExpenseByProject.jsx b/src/components/Dashboard/ExpenseByProject.jsx index 11de982c..89e914b8 100644 --- a/src/components/Dashboard/ExpenseByProject.jsx +++ b/src/components/Dashboard/ExpenseByProject.jsx @@ -1,18 +1,18 @@ import React, { useState, useEffect } from "react"; import Chart from "react-apexcharts"; import { useExpenseType } from "../../hooks/masterHook/useMaster"; -import { useSelectedProject } from "../../slices/apiDataManager"; +import { useSelector } from "react-redux"; import { useExpenseDataByProject } from "../../hooks/useDashboard_Data"; const ExpenseByProject = () => { - const projectId = useSelectedProject(); + const projectId = useSelector((store) => store.localVariables.projectId); const [range, setRange] = useState("12M"); const [selectedType, setSelectedType] = useState(""); + const [viewMode, setViewMode] = useState("Category"); const [chartData, setChartData] = useState({ categories: [], data: [] }); const { ExpenseTypes, loading: typeLoading } = useExpenseType(); - // Fetch API data const { data: expenseApiData, isLoading } = useExpenseDataByProject( projectId, selectedType, @@ -25,46 +25,95 @@ const ExpenseByProject = () => { (item) => `${item.monthName} ${item.year}` ); const data = expenseApiData.map((item) => item.total); - setChartData({ categories, data }); } else { setChartData({ categories: [], data: [] }); } }, [expenseApiData]); + const getSelectedTypeName = () => { + if (!selectedType) return "All Types"; + const found = ExpenseTypes.find((t) => t.id === selectedType); + return found ? found.name : "All Types"; + }; + const options = { chart: { type: "bar", toolbar: { show: false } }, plotOptions: { bar: { horizontal: false, columnWidth: "55%", borderRadius: 4 } }, dataLabels: { enabled: true, formatter: (val) => val }, - xaxis: { categories: chartData.categories, labels: { style: { fontSize: "12px" }, rotate: -45 } }, + xaxis: { + categories: chartData.categories, + labels: { style: { fontSize: "12px" }, rotate: -45 }, + }, + tooltip: { + y: { + formatter: (val) => `${val.toLocaleString()} (${getSelectedTypeName()})`, + }, + }, + annotations: { xaxis: [{ x: 0, strokeDashArray: 0, }] }, fill: { opacity: 1 }, - colors: ["#2196f3"] + colors: ["#2196f3"], }; const series = [ { - name: selectedType || "Expense", - data: chartData.data - } + name: getSelectedTypeName(), + data: chartData.data, + }, ]; return (
Detailed project expenses
+Detailed project expenses
Loading chart...
) : ( @@ -103,5 +159,3 @@ const ExpenseByProject = () => { }; export default ExpenseByProject; - - diff --git a/src/components/Layout/Header.jsx b/src/components/Layout/Header.jsx index 870672e3..ec8aadb0 100644 --- a/src/components/Layout/Header.jsx +++ b/src/components/Layout/Header.jsx @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useState,useMemo } from "react"; +import { useCallback, useEffect, useState, useMemo } from "react"; import getGreetingMessage from "../../utils/greetingHandler"; import { cacheData, @@ -22,7 +22,7 @@ import { ALLOW_PROJECTSTATUS_ID, MANAGE_PROJECT, UUID_REGEX } from "../../utils/ import { useAuthModal, useLogout } from "../../hooks/useAuth"; const Header = () => { - const { profile } = useProfile(); + const { profile } = useProfile(); const { data: masterData } = useMaster(); const location = useLocation(); const dispatch = useDispatch(); @@ -58,8 +58,8 @@ const Header = () => { isDashboardPath ? projectNames : projectNames?.filter((project) => - ALLOW_PROJECTSTATUS_ID.includes(project.projectStatusId) - ), + ALLOW_PROJECTSTATUS_ID.includes(project.projectStatusId) + ), [projectNames, isDashboardPath] ); @@ -67,11 +67,11 @@ const Header = () => { if (projectLoading) return "Loading..."; if (!projectNames?.length) return "No Projects Assigned"; if (projectNames.length === 1) return projectNames[0].name; - if (selectedProject === null) return "All Projects"; + if (selectedProject === null) return "All Projects"; const selectedObj = projectNames.find((p) => p.id === selectedProject); return selectedObj - ? selectedObj.name - : projectNames[0]?.name || "No Projects Assigned"; + ? selectedObj.name + : projectNames[0]?.name || "No Projects Assigned"; }, [projectLoading, projectNames, selectedProject]); // ===== Role Helper ===== @@ -200,13 +200,13 @@ const Header = () => { style={{ overflow: "auto", maxHeight: "300px" }} > -