diff --git a/src/components/Dashboard/Dashboard.jsx b/src/components/Dashboard/Dashboard.jsx index ce915566..29e3e755 100644 --- a/src/components/Dashboard/Dashboard.jsx +++ b/src/components/Dashboard/Dashboard.jsx @@ -8,29 +8,80 @@ import { useDashboardTeamsCardData, useDashboardTasksCardData, } from "../../hooks/useDashboard_Data"; -import ProjectProgressChart from "./ProjectProgressChart"; +import ProjectCompletionChart from "./ProjectCompletionChart"; const Dashboard = () => { const { projects, loading } = useProjects(); const [selectedProjectId, setSelectedProjectId] = useState("all"); const [range, setRange] = useState("1W"); + const getDaysFromRange = (range) => { + switch (range) { + case "1D": + return 1; + case "1W": + return 7; + case "15D": + return 15; + case "1M": + return 30; + case "3M": + return 90; + case "1Y": + return 365; + case "5Y": + return 1825; + default: + return 7; + } + }; + + const days = getDaysFromRange(range); + const today = new Date(); + // const FromDate = today.toISOString().split("T")[0]; + const FromDate = today.toLocaleDateString('en-CA'); // Always today const { projectsCardData } = useDashboardProjectsCardData(); const { teamsCardData } = useDashboardTeamsCardData(); const { tasksCardData } = useDashboardTasksCardData(); - // Bar chart logic - const projectNames = projects?.map((p) => p.name) || []; - const projectProgress = - projects?.map((p) => { - const completed = p.completedWork || 0; - const planned = p.plannedWork || 1; - const percent = (completed / planned) * 100; - return Math.min(Math.round(percent), 100); - }) || []; + const { dashboard_data, loading: isLineChartLoading } = useDashboard_Data({ + days, + FromDate, + projectId: selectedProjectId === "all" ? null : selectedProjectId, + }); - + // Sort dashboard_data by date ascending + const sortedDashboardData = [...dashboard_data].sort( + (a, b) => new Date(a.date) - new Date(b.date) + ); + + + // Line chart data + const lineChartSeries = [ + { + name: "Planned Work", + data: sortedDashboardData.map((d) => d.plannedTask || 0), + }, + { + name: "Completed Work", + data: sortedDashboardData.map((d) => d.completedTask || 0), + }, + ]; + + const lineChartCategories = sortedDashboardData.map((d) => + new Date(d.date).toLocaleDateString("en-US", { + month: "short", + day: "numeric", + }) + ); + const lineChartCategoriesDates = sortedDashboardData.map((d) => + new Date(d.date).toLocaleDateString("en-US", { + month: "short", + day: "numeric", + year: "numeric", + }) + ); return (
@@ -111,27 +162,84 @@ const Dashboard = () => {
{/* Bar Chart */} -
-
-
-
-
Projects
-

Projects Completion Status

-
-
-
- -
-
+
+
{/* Line Chart */}
- +
+
+ {/* Row 1: Title + Project Selector */} +
+
+
Project Progress
+

Progress Overview by Project

+
+ +
+ + +
    +
  • + +
  • + {projects?.map((project) => ( +
  • + +
  • + ))} +
+
+
+ + {/* Row 2: Time Range Buttons */} +
+ {["1D", "1W", "15D", "1M", "3M", "1Y", "5Y"].map((key) => ( + + ))} +
+
+
+ +
+
diff --git a/src/components/Dashboard/ProjectCompletionChart.jsx b/src/components/Dashboard/ProjectCompletionChart.jsx new file mode 100644 index 00000000..f0c85179 --- /dev/null +++ b/src/components/Dashboard/ProjectCompletionChart.jsx @@ -0,0 +1,37 @@ +import React from "react"; +import HorizontalBarChart from "../Charts/HorizontalBarChart"; +import { useProjects } from "../../hooks/useProjects"; + +const ProjectCompletionChart = () => { + const { projects, loading } = useProjects(); + + // Bar chart logic + const projectNames = projects?.map((p) => p.name) || []; + const projectProgress = + projects?.map((p) => { + const completed = p.completedWork || 0; + const planned = p.plannedWork || 1; + const percent = (completed / planned) * 100; + return Math.min(Math.round(percent), 100); + }) || []; + + return ( +
+
+
+
Projects
+

Projects Completion Status

+
+
+
+ +
+
+ ); +}; + +export default ProjectCompletionChart;