(Feat-Fix): Lots of fixes.

This commit is contained in:
2025-12-21 10:34:20 +00:00
parent d36d925e38
commit 7b0e6923a9

View File

@@ -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<typeof x> => 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))