diff --git a/src/components/Dashboard/AttendanceChart.jsx b/src/components/Dashboard/AttendanceChart.jsx
index a4112a49..3b58b897 100644
--- a/src/components/Dashboard/AttendanceChart.jsx
+++ b/src/components/Dashboard/AttendanceChart.jsx
@@ -4,6 +4,7 @@ import ReactApexChart from "react-apexcharts";
import { useAttendanceOverviewData } from "../../hooks/useDashboard_Data";
import flatColors from "../Charts/flatColor";
import ChartSkeleton from "../Charts/Skelton";
+import { useSelectedProject } from "../../slices/apiDataManager";
const formatDate = (dateStr) => {
const date = new Date(dateStr);
@@ -13,16 +14,20 @@ const formatDate = (dateStr) => {
});
};
-const AttendanceOverview = ({projectId}) => {
+const AttendanceOverview = () => {
const [dayRange, setDayRange] = useState(7);
const [view, setView] = useState("chart");
-
- const { attendanceOverviewData, loading, error } = useAttendanceOverviewData(
- projectId,
+ const selectedProject = useSelectedProject()
+ const { data: attendanceOverviewData, isLoading, isError, error } = useAttendanceOverviewData(
+ selectedProject,
dayRange
);
const { tableData, roles, dates } = useMemo(() => {
+ if (!attendanceOverviewData || attendanceOverviewData.length === 0) {
+ return { tableData: [], roles: [], dates: [] };
+ }
+
const map = new Map();
attendanceOverviewData.forEach((entry) => {
@@ -35,7 +40,8 @@ const AttendanceOverview = ({projectId}) => {
...new Set(attendanceOverviewData.map((e) => e.role.trim())),
];
const sortedDates = [...map.keys()];
- const data = sortedDates.map((date) => {
+
+ const tableData = sortedDates.map((date) => {
const row = { date };
uniqueRoles.forEach((role) => {
row[role] = map.get(date)?.[role] ?? 0;
@@ -43,12 +49,8 @@ const AttendanceOverview = ({projectId}) => {
return row;
});
- return {
- tableData: data,
- roles: uniqueRoles,
- dates: sortedDates,
- };
- }, [attendanceOverviewData]);
+ return { tableData, roles: uniqueRoles, dates: sortedDates };
+ }, [attendanceOverviewData,isLoading,selectedProject,dayRange]);
const chartSeries = roles.map((role) => ({
name: role,
@@ -62,41 +64,21 @@ const AttendanceOverview = ({projectId}) => {
height: 400,
toolbar: { show: false },
},
- plotOptions: {
- bar: {
- borderRadius: 2,
- columnWidth: "60%",
- },
- },
- xaxis: {
- categories: tableData.map((row) => row.date),
- },
+ plotOptions: { bar: { borderRadius: 2, columnWidth: "60%" } },
+ xaxis: { categories: tableData.map((row) => row.date) },
yaxis: {
show: true,
- axisBorder: {
- show: true,
- color: "#78909C",
- offsetX: 0,
- offsetY: 0,
- },
- axisTicks: {
- show: true,
- borderType: "solid",
- color: "#78909C",
- width: 6,
- offsetX: 0,
- offsetY: 0,
- },
- },
- legend: {
- position: "bottom",
- },
- fill: {
- opacity: 1,
+ axisBorder: { show: true, color: "#78909C" },
+ axisTicks: { show: true, color: "#78909C", width: 6 },
},
+ legend: { position: "bottom" },
+ fill: { opacity: 1 },
colors: roles.map((_, i) => flatColors[i % flatColors.length]),
};
+ if (isLoading) return
Loading...
;
+ if (isError) return {error.message}
;
+
return (
{/* Header */}
@@ -116,18 +98,14 @@ const AttendanceOverview = ({projectId}) => {