Attendance Tab Should Display All Records for Each Employee

This commit is contained in:
Kartik Sharma 2025-10-08 18:25:01 +05:30 committed by pramod.mahajan
parent 108ca1cc96
commit 7f33d5e6bd
5 changed files with 44 additions and 40 deletions

View File

@ -243,6 +243,7 @@ const AttendanceLog = ({ handleModalData, searchTerm, organizationId }) => {
return () => eventBus.off("employee", employeeHandler); return () => eventBus.off("employee", employeeHandler);
}, [employeeHandler]); }, [employeeHandler]);
return ( return (
<> <>
<div <div
@ -281,8 +282,10 @@ const AttendanceLog = ({ handleModalData, searchTerm, organizationId }) => {
<th className="border-top-1" colSpan={2}> <th className="border-top-1" colSpan={2}>
Name Name
</th> </th>
<th className="border-top-1">Project Name</th>
<th className="border-top-1">Date</th> <th className="border-top-1">Date</th>
{/* <th>Organization</th> */} {/* <th>Organization</th> */}
<th> <th>
<i className="bx bxs-down-arrow-alt text-success"></i> Check-In <i className="bx bxs-down-arrow-alt text-success"></i> Check-In
</th> </th>
@ -341,6 +344,7 @@ const AttendanceLog = ({ handleModalData, searchTerm, organizationId }) => {
</div> </div>
</div> </div>
</td> </td>
<td>{attendance.projectName || "--"}</td>
<td> <td>
{moment( {moment(
attendance.checkInTime || attendance.checkOutTime attendance.checkInTime || attendance.checkOutTime

View File

@ -11,6 +11,7 @@ import { cacheData, clearCacheKey, useSelectedProject } from "../../slices/apiDa
import { useQueryClient } from "@tanstack/react-query"; import { useQueryClient } from "@tanstack/react-query";
import Pagination from "../common/Pagination"; import Pagination from "../common/Pagination";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { employee } from "../../data/masters";
const Regularization = ({ handleRequest, searchTerm, projectId, organizationId, IncludeInActive }) => { const Regularization = ({ handleRequest, searchTerm, projectId, organizationId, IncludeInActive }) => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
@ -119,6 +120,8 @@ const Regularization = ({ handleRequest, searchTerm, projectId, organizationId,
return () => eventBus.off("employee", employeeHandler); return () => eventBus.off("employee", employeeHandler);
}, [employeeHandler]); }, [employeeHandler]);
console.log("Kartik",currentItems)
return ( return (
<div className="table-responsive text-nowrap pb-4" style={{ minHeight: "200px" }}> <div className="table-responsive text-nowrap pb-4" style={{ minHeight: "200px" }}>
{loading ? ( {loading ? (
@ -130,6 +133,7 @@ const Regularization = ({ handleRequest, searchTerm, projectId, organizationId,
<thead> <thead>
<tr> <tr>
<th colSpan={2}>Name</th> <th colSpan={2}>Name</th>
<th>Project Name</th>
<th>Date</th> <th>Date</th>
{/* <th>Organization</th> */} {/* <th>Organization</th> */}
<th> <th>
@ -169,6 +173,7 @@ const Regularization = ({ handleRequest, searchTerm, projectId, organizationId,
</div> </div>
</div> </div>
</td> </td>
<td>{att.projectName || "--"}</td>
<td>{moment(att.checkOutTime).format("DD-MMM-YYYY")}</td> <td>{moment(att.checkOutTime).format("DD-MMM-YYYY")}</td>
{/* <td>{att.organizationName || "--"}</td> */} {/* <td>{att.organizationName || "--"}</td> */}

View File

@ -99,7 +99,7 @@ const EmpAttendance = ({ employee }) => {
if ( if (
!existing || !existing ||
new Date(rec.checkInTime || rec.checkOutTime) > new Date(rec.checkInTime || rec.checkOutTime) >
new Date(existing.checkInTime || existing.checkOutTime) new Date(existing.checkInTime || existing.checkOutTime)
) { ) {
uniqueMap.set(key, rec); uniqueMap.set(key, rec);
} }
@ -123,7 +123,7 @@ const EmpAttendance = ({ employee }) => {
}; };
const closeModal = () => setIsModalOpen(false); const closeModal = () => setIsModalOpen(false);
const onSubmit = (formData) => {}; const onSubmit = (formData) => { };
return ( return (
<> <>
{isModalOpen && ( {isModalOpen && (
@ -152,20 +152,14 @@ const EmpAttendance = ({ employee }) => {
</form> </form>
</FormProvider> </FormProvider>
</> </>
</div> </div>
<div className="col-md-2 m-0 text-end">
<i
className={`bx bx-refresh cursor-pointer fs-4 ${
isFetching ? "spin" : ""
}`}
data-toggle="tooltip"
title="Refresh"
onClick={() => refetch()}
/>
</div>
</div> </div>
<div className="table-responsive text-nowrap"> <div className="table-responsive text-nowrap">
{!loading && data.length === 0 && <span>No employee logs</span>} {!loading && data.length === 0 && (
<span style={{ fontSize: "0.9rem" }}>
No attendance record found in selected date range
</span>
)}
{isError && <div className="text-center">{error.message}</div>} {isError && <div className="text-center">{error.message}</div>}
{loading && !data && <div className="text-center">Loading...</div>} {loading && !data && <div className="text-center">Loading...</div>}
{data && data.length > 0 && ( {data && data.length > 0 && (
@ -250,9 +244,8 @@ const EmpAttendance = ({ employee }) => {
{[...Array(totalPages)].map((_, index) => ( {[...Array(totalPages)].map((_, index) => (
<li <li
key={index} key={index}
className={`page-item ${ className={`page-item ${currentPage === index + 1 ? "active" : ""
currentPage === index + 1 ? "active" : "" }`}
}`}
> >
<button <button
className="page-link " className="page-link "
@ -263,9 +256,8 @@ const EmpAttendance = ({ employee }) => {
</li> </li>
))} ))}
<li <li
className={`page-item ${ className={`page-item ${currentPage === totalPages ? "disabled" : ""
currentPage === totalPages ? "disabled" : "" }`}
}`}
> >
<button <button
className="page-link " className="page-link "

View File

@ -42,7 +42,6 @@ export const useAttendance = (projectId, organizationId, includeInactive = false
export const useAttendancesLogs = (projectId, fromDate, toDate,organizationId) => { export const useAttendancesLogs = (projectId, fromDate, toDate,organizationId) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const enabled = !!projectId && !!fromDate && !!toDate;
const query = useQuery({ const query = useQuery({
queryKey: ['attendanceLogs', projectId, fromDate, toDate,organizationId], queryKey: ['attendanceLogs', projectId, fromDate, toDate,organizationId],
@ -55,7 +54,6 @@ export const useAttendancesLogs = (projectId, fromDate, toDate,organizationId) =
); );
return res.data; return res.data;
}, },
enabled,
}); });
useEffect(() => { useEffect(() => {
@ -123,7 +121,7 @@ export const useRegularizationRequests = (projectId, organizationId, IncludeInAc
refetch: recall, refetch: recall,
isFetching, isFetching,
} = useQuery({ } = useQuery({
queryKey: ["regularizedList", projectId, organizationId, IncludeInActive], // include filters in cache key queryKey: ["regularizedList", projectId, organizationId, IncludeInActive],
queryFn: async () => { queryFn: async () => {
const response = await AttendanceRepository.getRegularizeList( const response = await AttendanceRepository.getRegularizeList(
projectId, projectId,
@ -132,7 +130,6 @@ export const useRegularizationRequests = (projectId, organizationId, IncludeInAc
); );
return response.data; return response.data;
}, },
enabled: !!projectId, // only run if projectId exists
onError: (error) => { onError: (error) => {
showToast(error.message || "Error while fetching regularizes", "error"); showToast(error.message || "Error while fetching regularizes", "error");
}, },

View File

@ -2,8 +2,8 @@ import { api } from "../utils/axiosClient";
const AttendanceRepository = { const AttendanceRepository = {
markAttendance: (data) => api.post("/api/attendance/record", data), markAttendance: (data) => api.post("/api/attendance/record", data),
getAttendance: (projectId, organizationId, includeInactive,date) => { getAttendance: (projectId, organizationId, includeInactive, date) => {
let url = `/api/attendance/project/team`; let url = `/api/attendance/project/team`;
const params = []; const params = [];
@ -13,41 +13,47 @@ const AttendanceRepository = {
if (date) params.push(`date=${date}`); if (date) params.push(`date=${date}`);
if (params.length > 0) { if (params.length > 0) {
url += `&${params.join("&")}`; } url += `?${params.join("&")}`;
}
return api.get(url); return api.get(url);
}, },
getAttendanceFilteredByDate: (projectId, fromDate, toDate,organizationId) => { getAttendanceFilteredByDate: (projectId, fromDate, toDate, organizationId) => {
let url = `api/Attendance/project/log?projectId=${projectId}`; let url = `api/attendance/project/log`;
if (fromDate) {
url += `&dateFrom=${fromDate}`; const params = [];
if (projectId) params.push(`projectId=${projectId}`);
if (fromDate) params.push(`dateFrom=${fromDate}`);
if (toDate) params.push(`dateTo=${toDate}`);
if (organizationId) params.push(`organizationId=${organizationId}`);
if (params.length > 0) {
url += `?${params.join("&")}`;
} }
if (toDate) {
url += `&dateTo=${toDate}`;
}
if (organizationId) {
url += `&organizationId=${organizationId}`;
}
return api.get(url); return api.get(url);
}, },
getAttendanceLogs: (id) => api.get(`api/attendance/log/attendance/${id}`), getAttendanceLogs: (id) => api.get(`api/attendance/log/attendance/${id}`),
getRegularizeList: (projectId, organizationId, IncludeInActive) => { getRegularizeList: (projectId, organizationId, IncludeInActive) => {
let url = `/api/attendance/regularize?projectId=${projectId}`; let url = `/api/attendance/regularize`;
const params = []; const params = [];
if (projectId) params.push(`projectId=${projectId}`);
if (organizationId) params.push(`organizationId=${organizationId}`); if (organizationId) params.push(`organizationId=${organizationId}`);
if (IncludeInActive) params.push(`IncludeInActive=${IncludeInActive}`); if (IncludeInActive) params.push(`IncludeInActive=${IncludeInActive}`);
if (params.length > 0) { if (params.length > 0) {
url += `&${params.join("&")}`; } url += `?${params.join("&")}`;
}
return api.get(url); return api.get(url);
}, },
getAttendanceByEmployee: (employeeId, fromDate, toDate) => { getAttendanceByEmployee: (employeeId, fromDate, toDate) => {
let url = `api/Attendance/log/employee/${employeeId}?`; let url = `api/Attendance/log/employee/${employeeId}?`;
if (fromDate) { if (fromDate) {