diff --git a/src/hooks/useAttendanceStatus.js b/src/hooks/useAttendanceStatus.js index 4085fba2..3843b290 100644 --- a/src/hooks/useAttendanceStatus.js +++ b/src/hooks/useAttendanceStatus.js @@ -61,25 +61,37 @@ const useAttendanceStatus = (attendanceData) => { } // 3. Already checked in and out → Handle activity === 4 (Approved) - if (checkInTime && checkOutTime && activity === 4) { - if (!isSameDay(checkOutTime, now) && !timeElapsed(checkOutTime, THRESH_HOLD)) { - return setStatus({ - status: "Approved", - action: ACTIONS.APPROVED, - disabled: true, - text: "Approved", - color: 'btn-success', - }); - } else if (isSameDay(checkOutTime, now)) { - return setStatus({ - status: "Check-In", - action: ACTIONS.CHECK_IN, - disabled: false, - text: "Check In", - color: 'btn-primary', - }); - } - } +if (checkInTime && checkOutTime && activity === 4) { + if (!isSameDay(checkInTime, now) && !timeElapsed(checkInTime, THRESH_HOLD)) { + // Case: Past day, but still within threshold → Approved + return setStatus({ + status: "Approved", + action: ACTIONS.APPROVED, + disabled: true, + text: "Approved", + color: 'btn-success', + }); + } else if (isSameDay(checkOutTime, now)) { + // Case: same day → allow check-in again + return setStatus({ + status: "Check In", + action: ACTIONS.CHECK_IN, + disabled: false, + text: "Check In", + color: 'btn-primary', + }); + } else { + // Case: not same day AND over 48 hours → freeze status as Approved + return setStatus({ + status: "Approved", + action: ACTIONS.APPROVED, + disabled: true, + text: "Approved", + color: 'btn-success', + }); + } +} + // 4. Regularization Requested if (activity === 2) {