diff --git a/src/components/Dashboard/ExpenseAnalysis.jsx b/src/components/Dashboard/ExpenseAnalysis.jsx
index 283e64c8..50528055 100644
--- a/src/components/Dashboard/ExpenseAnalysis.jsx
+++ b/src/components/Dashboard/ExpenseAnalysis.jsx
@@ -1,4 +1,4 @@
-import React, { useEffect, useMemo, useState } from "react";
+import React, { useEffect, useMemo } from "react";
import Chart from "react-apexcharts";
import { useExpenseAnalysis } from "../../hooks/useDashboard_Data";
import { useSelectedProject } from "../../slices/apiDataManager";
@@ -10,36 +10,27 @@ const ExpenseAnalysis = () => {
const projectId = useSelectedProject();
const methods = useForm({
- defaultValues: {
- startDate: "",
- endDate: "",
- },
+ defaultValues: { startDate: "", endDate: "" },
});
const { watch } = methods;
-
-
const [startDate, endDate] = watch(["startDate", "endDate"]);
+
const { data, isLoading, isError, error, isFetching } = useExpenseAnalysis(
- projectId,
- startDate ? localToUtc(startDate) : null,
- endDate ? localToUtc(endDate) : null
+ projectId,
+ startDate ? localToUtc(startDate) : null,
+ endDate ? localToUtc(endDate) : null
);
if (isError) return
{error.message}
;
-
-
-
const report = data?.report ?? [];
-
-const { labels, series, total } = useMemo(() => {
- const labels = report.map((item) => item.projectName);
- const series = report.map((item) => item.totalApprovedAmount || 0);
- const total = formatCurrency(data?.totalAmount || 0);
-
- return { labels, series, total };
-}, [report, data?.totalAmount]);
+ const { labels, series, total } = useMemo(() => {
+ const labels = report.map((item) => item.projectName);
+ const series = report.map((item) => item.totalApprovedAmount || 0);
+ const total = formatCurrency(data?.totalAmount || 0);
+ return { labels, series, total };
+ }, [report, data?.totalAmount]);
const donutOptions = {
chart: { type: "donut" },
@@ -63,26 +54,34 @@ const { labels, series, total } = useMemo(() => {
},
},
},
+ responsive: [
+ {
+ breakpoint: 576, // mobile breakpoint
+ options: {
+ chart: { width: "100%" },
+ },
+ },
+ ],
};
-
return (
<>
-
-
-
Expense Breakdown
-
Category Wise Expense Breakdown
+ {/* Header */}
+
+
+
Expense Breakdown
+
Category Wise Expense Breakdown
-
+ {/* Card body */}
- {/* Initial loading: show full loader */}
{isLoading && (
{
)}
- {/* Data display */}
{!isLoading && report.length === 0 && (
-
No data found
+
No data found
)}
{!isLoading && report.length > 0 && (
<>
- {/* Overlay spinner for refetch */}
{isFetching && (
Loading...
@@ -109,17 +106,18 @@ const { labels, series, total } = useMemo(() => {
item.totalApprovedAmount || 0)}
+ series={series}
type="donut"
- width="320"
+ width="100%"
+ height={320}
/>
-
+
{report.map((item, idx) => (
@@ -127,16 +125,14 @@ const { labels, series, total } = useMemo(() => {
className="avatar-initial rounded-2"
style={{
backgroundColor:
- donutOptions.colors[
- idx % donutOptions.colors.length
- ],
+ donutOptions.colors[idx % donutOptions.colors.length],
}}
>
- {item.projectName}
+ {item.projectName}
{formatCurrency(item.totalApprovedAmount)}