From c4b589460a088b5d01ba47ee125646f6b22c7e53 Mon Sep 17 00:00:00 2001 From: Kartik Sharma Date: Thu, 13 Nov 2025 12:33:50 +0530 Subject: [PATCH] Correction in EmpReportingManger. --- src/components/Employee/EmpDashboard.jsx | 9 +- .../Employee/EmpReportingManager.jsx | 82 +++++++++---------- src/components/Employee/ManageReporting.jsx | 2 +- 3 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/components/Employee/EmpDashboard.jsx b/src/components/Employee/EmpDashboard.jsx index e3866cab..91958f3f 100644 --- a/src/components/Employee/EmpDashboard.jsx +++ b/src/components/Employee/EmpDashboard.jsx @@ -17,7 +17,7 @@ const EmpDashboard = ({ profile }) => { {" "} - +
@@ -83,9 +83,12 @@ const EmpDashboard = ({ profile }) => {
- {" "} - +
+
); diff --git a/src/components/Employee/EmpReportingManager.jsx b/src/components/Employee/EmpReportingManager.jsx index 61d33c37..813b0256 100644 --- a/src/components/Employee/EmpReportingManager.jsx +++ b/src/components/Employee/EmpReportingManager.jsx @@ -2,61 +2,59 @@ import React, { useState } from "react"; import { useOrganizationHierarchy } from "../../hooks/useEmployees"; import GlobalModel from "../common/GlobalModel"; import ManageReporting from "./ManageReporting"; +import Avatar from "../common/Avatar"; +import { SpinnerLoader } from "../common/Loader"; const EmpReportingManager = ({ employeeId, employee }) => { const { data, isLoading } = useOrganizationHierarchy(employeeId); const [showManageReportingModal, setShowManageReportingModal] = useState(false); - if (isLoading) return Loading...; + if (isLoading) + return ( +
+ +
+ ); - const primary = data?.find((item) => item.isPrimary); - const secondary = data?.filter((item) => !item.isPrimary); - - // Create comma-separated string for secondary managers - const secondaryNames = secondary - ?.map((item) => `${item.reportTo?.firstName || ""} ${item.reportTo?.lastName || ""}`.trim()) - .join(", "); + // Safe access to primary and secondary managers + const primaryManager = data?.find((d) => d.isPrimary)?.reportTo; + const secondaryManagers = data?.filter((d) => !d.isPrimary).map((d) => d.reportTo) || []; return (
-
- Update Reporting Manager + + Reporting Manager + -
+
+ {/* Primary Manager */} +
+
Primary Manager:
+
+ {primaryManager + ? `${primaryManager.firstName || ""} ${primaryManager.lastName || ""}` + : "NA"} +
+
- - {/* Primary Reporting Manager */} -
- - - Primary Reporting Manager - - : - - {primary?.reportTo?.firstName || NA}{" "} - {primary?.reportTo?.lastName || ""} - + {/* Secondary Managers */} + {secondaryManagers?.length > 0 && ( +
+
Secondary Managers:
+
+ {secondaryManagers + .map((m) => `${m.firstName || ""} ${m.lastName || ""}`) + .join(", ")} +
+
+ )}
- {/* Secondary Reporting Manager (comma-separated) */} - {secondary?.length > 0 && ( -
- - - Secondary Reporting Manager - - : - - {secondaryNames || NA} - -
- )} - - {/* Open Modal Button */} -
+ {/* Manage Reporting Button */} +
- {/* ManageReporting Modal */} + {/* Manage Reporting Modal */} {showManageReportingModal && ( setShowManageReportingModal(false)} > setShowManageReportingModal(false)} /> - )}
@@ -87,3 +84,4 @@ const EmpReportingManager = ({ employeeId, employee }) => { }; export default EmpReportingManager; + diff --git a/src/components/Employee/ManageReporting.jsx b/src/components/Employee/ManageReporting.jsx index c0d2cba6..b9857fea 100644 --- a/src/components/Employee/ManageReporting.jsx +++ b/src/components/Employee/ManageReporting.jsx @@ -110,7 +110,7 @@ const ManageReporting = ({ onClosed, employee, employeeId }) => { {/* Employee Name + Role */}
- + {`${employee.firstName || ""} ${employee.middleName || ""} ${employee.lastName || ""}`.trim() || "Employee Name NA"}