Compare commits
19 Commits
eec208db89
...
254aaf1977
| Author | SHA1 | Date | |
|---|---|---|---|
| 254aaf1977 | |||
| bb224ea3e7 | |||
| 536f4d4e3a | |||
| d7986e4af4 | |||
| 527e052786 | |||
| 52ef65cce0 | |||
| 32434da93f | |||
| 276a2ca9f4 | |||
| aa43dd4540 | |||
| a001875a56 | |||
| f565e83413 | |||
| 55625246ce | |||
| 9f1b8f7090 | |||
| c35b7954fc | |||
| 3848130cde | |||
| 74c2906527 | |||
| 7535028b44 | |||
| 3925926084 | |||
| 3709346d42 |
@ -6,7 +6,11 @@ import RenderAttendanceStatus from "./RenderAttendanceStatus";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { fetchAttendanceData, setAttendanceData } from "../../slices/apiSlice/attedanceLogsSlice"; // Make sure setAttendanceData is correctly imported
|
||||
import DateRangePicker from "../common/DateRangePicker";
|
||||
import { clearCacheKey, getCachedData } from "../../slices/apiDataManager";
|
||||
import eventBus from "../../services/eventBus";
|
||||
import AttendanceRepository from "../../repositories/AttendanceRepository";
|
||||
import { useAttendancesLogs } from "../../hooks/useAttendance";
|
||||
import { queryClient } from "../../layouts/AuthLayout";
|
||||
|
||||
// Custom hook for pagination
|
||||
const usePagination = (data, itemsPerPage) => {
|
||||
@ -16,9 +20,6 @@ const usePagination = (data, itemsPerPage) => {
|
||||
const maxPage = Math.ceil(totalItems / itemsPerPage);
|
||||
|
||||
const currentItems = useMemo(() => {
|
||||
if (!Array.isArray(data) || data.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const startIndex = (currentPage - 1) * itemsPerPage;
|
||||
const endIndex = startIndex + itemsPerPage;
|
||||
return data.slice(startIndex, endIndex);
|
||||
@ -60,6 +61,8 @@ const AttendanceLog = ({
|
||||
endDate: defaultEndDate
|
||||
});
|
||||
const dispatch = useDispatch();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [showPending,setShowPending] = useState(false)
|
||||
|
||||
const { data: attendanceLogsData, loading: logsLoading, isFetching: logsFetching } = useSelector(
|
||||
(state) => state.attendanceLogs
|
||||
@ -67,7 +70,6 @@ const AttendanceLog = ({
|
||||
|
||||
const [isRefreshing, setIsRefreshing] = useState(false); // Local state for refresh spinner
|
||||
|
||||
// Memoize today and yesterday dates to prevent re-creation on every render
|
||||
const today = useMemo(() => {
|
||||
const d = new Date();
|
||||
d.setHours(0, 0, 0, 0);
|
||||
@ -80,20 +82,22 @@ const AttendanceLog = ({
|
||||
d.setHours(0, 0, 0, 0); // Set to start of day for accurate comparison
|
||||
return d;
|
||||
}, []);
|
||||
const yesterday = new Date();
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
|
||||
const isSameDay = useCallback((dateStr) => {
|
||||
const isSameDay = (dateStr) => {
|
||||
if (!dateStr) return false;
|
||||
const d = new Date(dateStr);
|
||||
d.setHours(0, 0, 0, 0);
|
||||
return d.getTime() === today.getTime();
|
||||
}, [today]);
|
||||
};
|
||||
|
||||
const isBeforeToday = useCallback((dateStr) => {
|
||||
const isBeforeToday = (dateStr) => {
|
||||
if (!dateStr) return false;
|
||||
const d = new Date(dateStr);
|
||||
d.setHours(0, 0, 0, 0);
|
||||
return d.getTime() < today.getTime();
|
||||
}, [today]);
|
||||
};
|
||||
|
||||
const sortByName = useCallback((a, b) => {
|
||||
const nameA = `${a.firstName || ""} ${a.lastName || ""}`.toLowerCase();
|
||||
@ -101,7 +105,7 @@ const AttendanceLog = ({
|
||||
return nameA.localeCompare(nameB);
|
||||
}, []);
|
||||
|
||||
// Effect to fetch attendance data when dateRange or projectId changes, or when refreshed
|
||||
// Effect to fetch attendance data when dateRange or projectId changes
|
||||
useEffect(() => {
|
||||
const { startDate, endDate } = dateRange;
|
||||
dispatch(
|
||||
@ -111,26 +115,21 @@ const AttendanceLog = ({
|
||||
toDate: endDate,
|
||||
})
|
||||
);
|
||||
// Reset refreshing state only after the dispatch, assuming fetchAttendanceData
|
||||
// will eventually update logsLoading/logsFetching
|
||||
const timer = setTimeout(() => { // Give Redux time to update
|
||||
setIsRefreshing(false);
|
||||
}, 500); // Small delay to show spinner for a bit longer
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, [dateRange, projectId, dispatch, isRefreshing]);
|
||||
setIsRefreshing(false); // Reset refreshing state after fetch attempt
|
||||
}, [dateRange, projectId, dispatch, isRefreshing]); // isRefreshing is a dependency because it triggers a re-fetch
|
||||
|
||||
const processedData = useMemo(() => {
|
||||
let filteredData = showOnlyCheckout
|
||||
? (attendanceLogsData || []).filter((item) => item.checkOutTime === null) // Ensure attendanceLogsData is an array
|
||||
: (attendanceLogsData || []); // Ensure attendanceLogsData is an array
|
||||
let filteredData = showOnlyCheckout // Use the prop directly
|
||||
? attendanceLogsData.filter((item) => item.checkOutTime === null) // Use attendanceLogsData
|
||||
: attendanceLogsData; // Use attendanceLogsData
|
||||
|
||||
// Apply search query filter
|
||||
if (searchQuery) {
|
||||
const lowerCaseSearchQuery = searchQuery.toLowerCase();
|
||||
filteredData = filteredData.filter((att) => {
|
||||
// Construct a full name from available parts, filtering out null/undefined
|
||||
const fullName = [att.firstName, att.middleName, att.lastName]
|
||||
.filter(Boolean)
|
||||
.filter(Boolean) // This removes null, undefined, or empty string parts
|
||||
.join(" ")
|
||||
.toLowerCase();
|
||||
|
||||
@ -243,15 +242,19 @@ const AttendanceLog = ({
|
||||
const employeeHandler = useCallback(
|
||||
(msg) => {
|
||||
const { startDate, endDate } = dateRange;
|
||||
dispatch(
|
||||
fetchAttendanceData({
|
||||
projectId,
|
||||
fromDate: startDate,
|
||||
toDate: endDate,
|
||||
})
|
||||
);
|
||||
if (data.some((item) => item.employeeId == msg.employeeId)) {
|
||||
// dispatch(
|
||||
// fetchAttendanceData({
|
||||
// ,
|
||||
// fromDate: startDate,
|
||||
// toDate: endDate,
|
||||
// })
|
||||
// );
|
||||
|
||||
refetch()
|
||||
}
|
||||
},
|
||||
[projectId, dateRange, dispatch]
|
||||
[selectedProject, dateRange, data]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@ -417,8 +420,9 @@ const AttendanceLog = ({
|
||||
(pageNumber) => (
|
||||
<li
|
||||
key={pageNumber}
|
||||
className={`page-item ${currentPage === pageNumber ? "active" : ""
|
||||
}`}
|
||||
className={`page-item ${
|
||||
currentPage === pageNumber ? "active" : ""
|
||||
}`}
|
||||
>
|
||||
<button
|
||||
className="page-link"
|
||||
@ -430,8 +434,9 @@ const AttendanceLog = ({
|
||||
)
|
||||
)}
|
||||
<li
|
||||
className={`page-item ${currentPage === totalPages ? "disabled" : ""
|
||||
}`}
|
||||
className={`page-item ${
|
||||
currentPage === totalPages ? "disabled" : ""
|
||||
}`}
|
||||
>
|
||||
<button
|
||||
className="page-link"
|
||||
@ -447,4 +452,4 @@ const AttendanceLog = ({
|
||||
);
|
||||
};
|
||||
|
||||
export default AttendanceLog;
|
||||
export default AttendanceLog;
|
||||
|
||||
@ -7,16 +7,19 @@ import { useRegularizationRequests } from "../../hooks/useAttendance";
|
||||
import moment from "moment";
|
||||
import usePagination from "../../hooks/usePagination";
|
||||
import eventBus from "../../services/eventBus";
|
||||
import { cacheData } from "../../slices/apiDataManager";
|
||||
import { cacheData, clearCacheKey } from "../../slices/apiDataManager";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
const Regularization = ({ handleRequest, searchQuery }) => {
|
||||
const selectedProject = useSelector((store) => store.localVariables.projectId);
|
||||
const [regularizesList, setRegularizedList] = useState([]);
|
||||
const { regularizes, loading, refetch } = useRegularizationRequests(selectedProject);
|
||||
const Regularization = ({ handleRequest }) => {
|
||||
const queryClient = useQueryClient();
|
||||
var selectedProject = useSelector((store) => store.localVariables.projectId);
|
||||
const [regularizesList, setregularizedList] = useState([]);
|
||||
const { regularizes, loading, error, refetch } =
|
||||
useRegularizationRequests(selectedProject);
|
||||
|
||||
// Update regularizesList when regularizes data changes
|
||||
useEffect(() => {
|
||||
setRegularizedList(regularizes);
|
||||
setregularizedList(regularizes);
|
||||
}, [regularizes]);
|
||||
|
||||
const sortByName = useCallback((a, b) => {
|
||||
@ -83,27 +86,34 @@ const Regularization = ({ handleRequest, searchQuery }) => {
|
||||
|
||||
return (
|
||||
<div className="table-responsive text-nowrap pb-4">
|
||||
<table className="table mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colSpan={2}>Name</th>
|
||||
<th>Date</th>
|
||||
<th>
|
||||
<i className="bx bxs-down-arrow-alt text-success"></i>Check-In
|
||||
</th>
|
||||
<th>
|
||||
<i className="bx bxs-up-arrow-alt text-danger"></i>Check-Out
|
||||
</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{!loading && currentItems?.length > 0 ? (
|
||||
currentItems.map((att, index) => (
|
||||
{loading ? (
|
||||
<div className="my-2">
|
||||
<p className="text-secondary">Loading...</p>
|
||||
</div>
|
||||
) : currentItems?.length > 0 ? (
|
||||
<table className="table mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colSpan={2}>Name</th>
|
||||
<th>Date</th>
|
||||
<th>
|
||||
<i className="bx bxs-down-arrow-alt text-success"></i>Check-In
|
||||
</th>
|
||||
<th>
|
||||
<i className="bx bxs-up-arrow-alt text-danger"></i>Check-Out
|
||||
</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{currentItems?.map((att, index) => (
|
||||
<tr key={index}>
|
||||
<td colSpan={2}>
|
||||
<div className="d-flex justify-content-start align-items-center">
|
||||
<Avatar firstName={att.firstName} lastName={att.lastName} />
|
||||
<Avatar
|
||||
firstName={att.firstName}
|
||||
lastName={att.lastName}
|
||||
></Avatar>
|
||||
<div className="d-flex flex-column">
|
||||
<a href="#" className="text-heading text-truncate">
|
||||
<span className="fw-normal">
|
||||
@ -118,33 +128,24 @@ const Regularization = ({ handleRequest, searchQuery }) => {
|
||||
<td>
|
||||
{att.checkOutTime ? convertShortTime(att.checkOutTime) : "--"}
|
||||
</td>
|
||||
<td className="text-center">
|
||||
<td className="text-center ">
|
||||
<RegularizationActions
|
||||
attendanceData={att}
|
||||
handleRequest={handleRequest}
|
||||
refresh={refetch}
|
||||
/>
|
||||
{/* </div> */}
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
) : (
|
||||
<tr>
|
||||
<td
|
||||
colSpan={6}
|
||||
className="text-center"
|
||||
style={{
|
||||
height: "200px",
|
||||
verticalAlign: "middle",
|
||||
borderBottom: "none",
|
||||
}}
|
||||
>
|
||||
{loading ? "Loading..." : "No Record Found"}
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
) : (
|
||||
<div className="my-4">
|
||||
{" "}
|
||||
<span className="text-secondary">No Requests Found !</span>
|
||||
</div>
|
||||
)}
|
||||
{!loading && totalPages > 1 && (
|
||||
<nav aria-label="Page ">
|
||||
<ul className="pagination pagination-sm justify-content-end py-1 mt-3">
|
||||
@ -159,18 +160,25 @@ const Regularization = ({ handleRequest, searchQuery }) => {
|
||||
{[...Array(totalPages)].map((_, index) => (
|
||||
<li
|
||||
key={index}
|
||||
className={`page-item ${currentPage === index + 1 ? "active" : ""}`}
|
||||
className={`page-item ${
|
||||
currentPage === index + 1 ? "active" : ""
|
||||
}`}
|
||||
>
|
||||
<button className="page-link" onClick={() => paginate(index + 1)}>
|
||||
<button
|
||||
className="page-link "
|
||||
onClick={() => paginate(index + 1)}
|
||||
>
|
||||
{index + 1}
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
<li
|
||||
className={`page-item ${currentPage === totalPages ? "disabled" : ""}`}
|
||||
className={`page-item ${
|
||||
currentPage === totalPages ? "disabled" : ""
|
||||
}`}
|
||||
>
|
||||
<button
|
||||
className="page-link"
|
||||
className="page-link "
|
||||
onClick={() => paginate(currentPage + 1)}
|
||||
>
|
||||
»
|
||||
@ -183,4 +191,4 @@ const Regularization = ({ handleRequest, searchQuery }) => {
|
||||
);
|
||||
};
|
||||
|
||||
export default Regularization;
|
||||
export default Regularization;
|
||||
|
||||
@ -129,8 +129,6 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
||||
dispatch(changeMaster("Job Role"));
|
||||
// Initial state should reflect "All Roles" selected
|
||||
setSelectedRoles(["all"]);
|
||||
// Initial state should reflect "All Roles" selected
|
||||
setSelectedRoles(["all"]);
|
||||
}, [dispatch]);
|
||||
|
||||
// Modified handleRoleChange to handle multiple selections
|
||||
@ -651,4 +649,5 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
||||
</div>
|
||||
</div> );
|
||||
};
|
||||
|
||||
export default AssignTask;
|
||||
@ -6,18 +6,25 @@ import {
|
||||
import Breadcrumb from "../../components/common/Breadcrumb";
|
||||
import AttendanceLog from "../../components/Activities/AttendcesLogs";
|
||||
import Attendance from "../../components/Activities/Attendance";
|
||||
import AttendanceModel from "../../components/Activities/AttendanceModel";
|
||||
// import AttendanceModel from "../../components/Activities/AttendanceModel";
|
||||
import showToast from "../../services/toastService";
|
||||
// import { useProjects } from "../../hooks/useProjects";
|
||||
import Regularization from "../../components/Activities/Regularization";
|
||||
import { useAttendance } from "../../hooks/useAttendance";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { setProjectId } from "../../slices/localVariablesSlice";
|
||||
import { markCurrentAttendance } from "../../slices/apiSlice/attendanceAllSlice";
|
||||
// import { markCurrentAttendance } from "../../slices/apiSlice/attendanceAllSlice";
|
||||
import { hasUserPermission } from "../../utils/authUtils";
|
||||
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||
import { REGULARIZE_ATTENDANCE } from "../../utils/constants";
|
||||
import eventBus from "../../services/eventBus";
|
||||
import AttendanceRepository from "../../repositories/AttendanceRepository";
|
||||
// import AttendanceRepository from "../../repositories/AttendanceRepository";
|
||||
import { useProjectName } from "../../hooks/useProjects";
|
||||
import GlobalModel from "../../components/common/GlobalModel";
|
||||
import CheckCheckOutmodel from "../../components/Activities/CheckCheckOutForm";
|
||||
import AttendLogs from "../../components/Activities/AttendLogs";
|
||||
// import Confirmation from "../../components/Activities/Confirmation";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
const AttendancePage = () => {
|
||||
const [activeTab, setActiveTab] = useState("all");
|
||||
@ -211,11 +218,11 @@ const AttendancePage = () => {
|
||||
|
||||
return (
|
||||
<>
|
||||
{isCreateModalOpen && modelConfig && (
|
||||
{/* {isCreateModalOpen && modelConfig && (
|
||||
<div
|
||||
className="modal fade show"
|
||||
style={{ display: "block" }}
|
||||
id="check-Out-modal"
|
||||
id="check-Out-modalg"
|
||||
tabIndex="-1"
|
||||
aria-hidden="true"
|
||||
>
|
||||
@ -225,6 +232,29 @@ const AttendancePage = () => {
|
||||
handleSubmitForm={handleSubmit}
|
||||
/>
|
||||
</div>
|
||||
)} */}
|
||||
{isCreateModalOpen && modelConfig && (
|
||||
<GlobalModel
|
||||
isOpen={isCreateModalOpen}
|
||||
size={modelConfig?.action === 6 && "lg"}
|
||||
closeModal={closeModal}
|
||||
>
|
||||
{(modelConfig?.action === 0 ||
|
||||
modelConfig?.action === 1 ||
|
||||
modelConfig?.action === 2) && (
|
||||
<CheckCheckOutmodel
|
||||
modeldata={modelConfig}
|
||||
closeModal={closeModal}
|
||||
/>
|
||||
)}
|
||||
{/* For view logs */}
|
||||
{modelConfig?.action === 6 && (
|
||||
<AttendLogs Id={modelConfig?.id} closeModal={closeModal} />
|
||||
)}
|
||||
{modelConfig?.action === 7 && (
|
||||
<Confirmation closeModal={closeModal} />
|
||||
)}
|
||||
</GlobalModel>
|
||||
)}
|
||||
|
||||
<div className="container-fluid">
|
||||
@ -286,11 +316,8 @@ const AttendancePage = () => {
|
||||
</ul>
|
||||
<div className="tab-content attedanceTabs py-0 px-1 px-sm-3" >
|
||||
{activeTab === "all" && (
|
||||
<>
|
||||
{!attLoading && (
|
||||
<div className="tab-pane fade show active py-0">
|
||||
<Attendance
|
||||
attendance={filteredAndSearchedTodayAttendance()}
|
||||
handleModalData={handleModalData}
|
||||
getRole={getRole}
|
||||
setshowOnlyCheckout={setShowPending}
|
||||
@ -301,12 +328,13 @@ const AttendancePage = () => {
|
||||
{!attLoading && filteredAndSearchedTodayAttendance()?.length === 0 && (
|
||||
<p>
|
||||
{" "}
|
||||
{showPending
|
||||
{showPending
|
||||
? "No Pending Available"
|
||||
: "No Employee assigned yet."}{" "}
|
||||
</p>
|
||||
)}
|
||||
</>
|
||||
</div>
|
||||
)}
|
||||
{activeTab === "logs" && (
|
||||
<div className="tab-pane fade show active py-0">
|
||||
@ -327,8 +355,6 @@ const AttendancePage = () => {
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!attLoading && !attendances && <span>Not Found</span>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -336,4 +362,4 @@ const AttendancePage = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default AttendancePage;
|
||||
export default AttendancePage;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user