(Feat-Fix): Fixed employee swapping not showing up in the Daily Attendance dashboard.
This commit is contained in:
@@ -245,16 +245,6 @@ export const DashboardPage: React.FC = () => {
|
||||
return currentContractorId;
|
||||
};
|
||||
|
||||
// Helper function to get the effective department ID for an employee
|
||||
// If employee has an active swap, return the original department ID
|
||||
const getEffectiveDepartmentId = (employeeId: number, currentDepartmentId?: number) => {
|
||||
const swap = activeSwaps.find((s) => s.employee_id === employeeId);
|
||||
if (swap) {
|
||||
return swap.original_department_id;
|
||||
}
|
||||
return currentDepartmentId;
|
||||
};
|
||||
|
||||
return supervisors.map((supervisor) => {
|
||||
const deptContractors = employees.filter(
|
||||
(e) =>
|
||||
@@ -373,14 +363,14 @@ export const DashboardPage: React.FC = () => {
|
||||
};
|
||||
});
|
||||
|
||||
// Add unassigned employees node if there are any
|
||||
if (unassignedEmployees.length > 0) {
|
||||
// Add "Swapped In" node for employees swapped into this department without a specific contractor
|
||||
if (swappedIntoThisDept.length > 0) {
|
||||
contractorNodes.push({
|
||||
id: -supervisor.department_id!, // Negative ID to avoid conflicts
|
||||
name: "Unassigned (Swapped)",
|
||||
name: "Swapped In",
|
||||
role: "Contractor",
|
||||
department: supervisor.department_name || "",
|
||||
children: unassignedEmployees.map((emp) => {
|
||||
children: swappedIntoThisDept.map(({ emp, originalContractor }) => {
|
||||
const empAttendance = attendance.find((a) =>
|
||||
a.employee_id === emp.id
|
||||
);
|
||||
@@ -390,12 +380,11 @@ export const DashboardPage: React.FC = () => {
|
||||
|
||||
return {
|
||||
id: emp.id,
|
||||
name: emp.name,
|
||||
name: `${emp.name} (from ${originalContractor?.name || "other"})`,
|
||||
role: "Employee",
|
||||
department: emp.department_name || "",
|
||||
subDepartment: empAllocation?.sub_department_name || "-",
|
||||
activity: empAllocation?.description || empAllocation?.activity ||
|
||||
"Swapped",
|
||||
activity: empAllocation?.description || empAllocation?.activity || "-",
|
||||
status: empAttendance
|
||||
? (empAttendance.status === "CheckedIn" ||
|
||||
empAttendance.status === "CheckedOut"
|
||||
|
||||
Reference in New Issue
Block a user