From 4445ef18abff6d2292732300c4e07d58c2c67804 Mon Sep 17 00:00:00 2001 From: "kartik.sharma" Date: Mon, 26 May 2025 11:19:59 +0530 Subject: [PATCH] Dashboard Component View. --- src/components/Dashboard/Dashboard.jsx | 230 ++----------------------- 1 file changed, 14 insertions(+), 216 deletions(-) diff --git a/src/components/Dashboard/Dashboard.jsx b/src/components/Dashboard/Dashboard.jsx index e4ac83ef..1e4cceaf 100644 --- a/src/components/Dashboard/Dashboard.jsx +++ b/src/components/Dashboard/Dashboard.jsx @@ -1,252 +1,50 @@ -import React, { useState } from "react"; -import HorizontalBarChart from "../Charts/HorizontalBarChart"; -import LineChart from "../Charts/LineChart"; -import { useProjects } from "../../hooks/useProjects"; +import React from "react"; import { - useDashboard_Data, useDashboardProjectsCardData, useDashboardTeamsCardData, useDashboardTasksCardData, } from "../../hooks/useDashboard_Data"; +import Projects from "./Projects"; import Teams from "./Teams"; +import TasksCard from "./Tasks"; +import ProjectCompletionChart from "./ProjectCompletionChart"; +import ProjectProgressChart from "./ProjectProgressChart"; 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(); - 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) - ); - - // 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); - }) || []; - - // 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 (
{/* Projects Card */}
-
-
-
- {" "} - Projects -
-
-
-
-

- {projectsCardData.totalProjects?.toLocaleString()} -

- Total -
-
-

- {projectsCardData.ongoingProjects?.toLocaleString()} -

- Ongoing -
-
-
+
{/* Teams Card */} -
- {/* Use the Teams component */} +
+
{/* Tasks Card */}
-
-
-
- Tasks -
-
-
-
-

- {tasksCardData.totalTasks?.toLocaleString()} -

- Total -
-
-

- {tasksCardData.completedTasks?.toLocaleString()} -

- Completed -
-
-
+
- {/* Bar Chart */} + {/* Bar Chart (Project Completion) */}
-
-
-
-
Projects
-

Projects Completion Status

-
-
-
- -
-
+
- {/* Line Chart */} + {/* Line Chart (Project Progress) */}
-
-
- {/* 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) => ( - - ))} -
-
-
- -
-
+
); }; -export default Dashboard; +export default Dashboard; \ No newline at end of file -- 2.43.0