import React, { useEffect, useState } from "react"; import { useEmployeeAttendacesLog } from "../../hooks/useAttendance"; import { convertShortTime, formatUTCToLocalTime } from "../../utils/dateUtils"; import { useNavigate } from "react-router-dom"; import { THRESH_HOLD } from "../../utils/constants"; const AttendLogs = ({ Id }) => { const { logs, loading } = useEmployeeAttendacesLog(Id); const navigate = useNavigate(); const isCheckoutRegularized = ( activityTimeStr, checkoutTimeStr, threshHours ) => { if (!activityTimeStr || !checkoutTimeStr) return false; const activityTime = new Date(activityTimeStr); const checkoutTime = new Date(checkoutTimeStr); const threshTimeMs = threshHours * 60 * 60 * 1000; return checkoutTime - activityTime > threshTimeMs; }; const whichActivityPerform = (actvity, checkOutTime) => { switch (actvity) { case 1: return ( ); break; case 2: return ( ); break; case 3: return ( ); break; case 4: if ( checkOutTime && isCheckoutRegularized( logs[0]?.activityTime, checkOutTime, THRESH_HOLD ) ) { return ( ); } else { return ( ); } break; case 5: return ( ); break; default: break; } }; const LocationLink = (lat, lng) => { const url = `https://www.google.com/maps?q=${lat},${lng}`; window.open(url, "_blank"); // Open in new tab }; useEffect(() => { const tooltipTriggerList = Array.from( document.querySelectorAll('[data-bs-toggle="tooltip"]') ); tooltipTriggerList.forEach((el) => new bootstrap.Tooltip(el)); }, []); return (
{logs && !loading && (

Attendance logs for{" "} {logs[0]?.employee?.firstName + " " + logs[0]?.employee?.lastName}{" "} on {formatUTCToLocalTime(logs[0]?.activityTime)}

)}
{loading &&

Loading..

} {logs && logs.length > 0 && ( <>
{logs .slice() .sort((a, b) => b.id - a.id) .map((log, index) => ( ))}
Date Time Activity Location Recored By Description
{formatUTCToLocalTime(log.activityTime)} {convertShortTime(log.activityTime)} {whichActivityPerform(log.activity, log.activityTime)} {log?.latitude != 0 ? ( LocationLink(log?.latitude, log?.longitude) } > ) : ( "--" )} {`${log?.updatedByEmployee?.firstName ?? ""} ${ log?.updatedByEmployee?.lastName ?? "" }`} {log?.comment?.length > 50 ? `${log.comment.slice(0, 50)}...` : log.comment || "--"}
)}
); }; export default AttendLogs;