From 7b0e6923a9df765ce2e6d47039f116890f869c87 Mon Sep 17 00:00:00 2001 From: bereck-work Date: Sun, 21 Dec 2025 10:34:20 +0000 Subject: [PATCH] (Feat-Fix): Lots of fixes. --- src/pages/DashboardPage.tsx | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/pages/DashboardPage.tsx b/src/pages/DashboardPage.tsx index 91c23de..013848b 100644 --- a/src/pages/DashboardPage.tsx +++ b/src/pages/DashboardPage.tsx @@ -262,24 +262,23 @@ export const DashboardPage: React.FC = () => { e.department_id === supervisor.department_id, ); - // Get employees without a contractor but in this department (e.g., swapped employees) - // But exclude employees who have an active swap with an original contractor - const unassignedEmployees = employees.filter( - (e) => - e.role === "Employee" && - getEffectiveDepartmentId(e.id, e.department_id) === supervisor.department_id && - !e.contractor_id && - !activeSwaps.find((s) => s.employee_id === e.id && s.original_contractor_id), - ); + // Find employees swapped INTO this department (without a specific target contractor) + const swappedIntoThisDept = activeSwaps + .filter((s) => s.target_department_id === supervisor.department_id && !s.target_contractor_id) + .map((swap) => { + const emp = employees.find((e) => e.id === swap.employee_id); + const originalContractor = employees.find((e) => e.id === swap.original_contractor_id); + return emp ? { emp, originalContractor, swap } : null; + }) + .filter((x): x is NonNullable => x !== null); const contractorNodes = deptContractors.map((contractor) => { - // Include employees whose original contractor (from swap) is this one - // OR whose current contractor is this one AND they're not swapped away + // Include employees whose original contractor is this one (they belong here) const contractorEmployees = employees.filter( (e) => e.role === "Employee" && getEffectiveContractorId(e.id, e.contractor_id) === contractor.id, ); - // Find employees swapped INTO this contractor (target_contractor_id matches) + // Find employees swapped INTO this specific contractor const swappedInEmployees = activeSwaps .filter((s) => s.target_contractor_id === contractor.id) .map((swap) => employees.find((e) => e.id === swap.employee_id))