From e8886577d888c29e75364fbbcb1d4aab453a55dd Mon Sep 17 00:00:00 2001 From: Kartik Sharma Date: Sat, 13 Dec 2025 16:36:47 +0530 Subject: [PATCH] Correction in weidget. --- src/components/Dashboard/ServiceJobs.jsx | 112 +++++++++++++------- src/components/reports/ReportsDonutCard.jsx | 7 +- src/components/reports/ReportsLegend.jsx | 11 +- src/components/reports/report-dpr.jsx | 6 ++ 4 files changed, 86 insertions(+), 50 deletions(-) diff --git a/src/components/Dashboard/ServiceJobs.jsx b/src/components/Dashboard/ServiceJobs.jsx index d69a2faa..35ee2365 100644 --- a/src/components/Dashboard/ServiceJobs.jsx +++ b/src/components/Dashboard/ServiceJobs.jsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useEffect, useRef, useState } from "react"; import { useParams } from "react-router-dom"; import { useJobsProgression } from "../../hooks/useDashboard_Data"; import { SpinnerLoader } from "../common/Loader"; @@ -7,55 +7,90 @@ import { useServiceProject } from "../../hooks/useServiceProject"; const ServiceJobs = () => { const { projectId } = useParams(); + const { data, isLoading, isError } = useJobsProgression(projectId); const jobs = data || {}; - const { data: projectData, isLoading: projectLoading } = useServiceProject(projectId); + + const { data: projectData, isLoading: projectLoading } = + useServiceProject(projectId); + + const [activeTab, setActiveTab] = useState("tab-new"); + + // 👇 prevents re-running auto logic after first load + const hasInitializedTab = useRef(false); + const tabMapping = [ { id: "tab-new", label: "My Jobs", key: "myJobs" }, - { id: "tab-preparing", label: "Assigned", key: "assignedJobs" }, { id: "tab-shipping", label: "In Progress", key: "inProgressJobs" }, + { id: "tab-preparing", label: "Assigned", key: "assignedJobs" }, ]; + /* ---------- INITIAL TAB SELECTION ONLY ---------- */ + useEffect(() => { + if (hasInitializedTab.current || !jobs) return; + + if (jobs.myJobs?.length > 0) { + setActiveTab("tab-new"); + } else if (jobs.inProgressJobs?.length > 0) { + setActiveTab("tab-shipping"); + } else { + setActiveTab("tab-preparing"); + } + + hasInitializedTab.current = true; +}, [jobs]); + + return ( -
+
+ {/* Header */}
Service Jobs

- {projectLoading ? "Loading..." : projectData?.name || "All Projects"} + {projectLoading + ? "Loading..." + : projectData?.name || "All Projects"}

- - {/* ---------------- Tabs ---------------- */} -
    - {tabMapping.map((t, index) => ( -
  • + {/* Tabs */} +
      + {tabMapping.map((tab) => ( +
    • ))}
    - {/* ---------------- Tab Content ---------------- */} + {/* Content */}
    - {isLoading && ( -
    +
    )} - {isError && (

    { > No data found

    - )} {!isLoading && !isError && - tabMapping.map((t, index) => { - const list = jobs[t.key] || []; + tabMapping.map((tab) => { + const list = jobs[tab.key] || []; return (
    {list.length === 0 ? (

    { > No jobs found

    - ) : (
    - {list.map((job, i) => ( - + {list.map((job, index) => ( +
      - - {/* Assigned By */}
    • -
      - - Assigned By - -
      + + Assigned By +
      {job.assignedBy}

      {formatUTCToLocalTime(job.assignedAt)} @@ -121,23 +151,23 @@ const ServiceJobs = () => {

    • - {/* Project */}
    • -
      - Project -
      + + Project +
      {job.project}
      -

      {job.title}

      +

      + {job.title} +

    - {/* Divider */} - {i < list.length - 1 && ( + {index < list.length - 1 && (
    )}
    diff --git a/src/components/reports/ReportsDonutCard.jsx b/src/components/reports/ReportsDonutCard.jsx index d922c4cc..3565934a 100644 --- a/src/components/reports/ReportsDonutCard.jsx +++ b/src/components/reports/ReportsDonutCard.jsx @@ -9,6 +9,8 @@ const ReportsDonutCard = ({ donutClass = "", footer = "Team members present on the site", chartColor, + legend1 = "Completed", + legend2 = "Pending" }) => { return (
    @@ -24,7 +26,10 @@ const ReportsDonutCard = ({ completed={value} total={total} /> - +
    diff --git a/src/components/reports/ReportsLegend.jsx b/src/components/reports/ReportsLegend.jsx index cd2a533c..daea7b0a 100644 --- a/src/components/reports/ReportsLegend.jsx +++ b/src/components/reports/ReportsLegend.jsx @@ -1,19 +1,14 @@ -const ReportsLegend = () => { +const ReportsLegend = ({legend1, legend2}) => { return (
    - Completed + {legend1}
    - In Progress -
    - -
    - - Pending + {legend2}
    ); diff --git a/src/components/reports/report-dpr.jsx b/src/components/reports/report-dpr.jsx index 4ecc0073..24ae3a81 100644 --- a/src/components/reports/report-dpr.jsx +++ b/src/components/reports/report-dpr.jsx @@ -24,6 +24,8 @@ const ReportDPR = ({ project, date }) => { title={"TODAY'S ATTENDANCE"} total={data?.totalEmployees} value={data?.todaysAttendances} + legend1="Today's Attendance" + legend2="Total Employees" /> { value={data?.totalPlannedWork} chartColor={"blue"} footer="" + legend1="Completed Work" + legend2="Planned Work" /> { value={data?.totalCompletedWork} chartColor={"green"} footer="" + legend1="Completed Work" + legend2="Planned Work" />