diff --git a/src/components/Activities/AttendcesLogs.jsx b/src/components/Activities/AttendcesLogs.jsx index 626c3c05..6d3dc32c 100644 --- a/src/components/Activities/AttendcesLogs.jsx +++ b/src/components/Activities/AttendcesLogs.jsx @@ -1,64 +1,69 @@ import React, { useEffect, useState } from "react"; +import moment from "moment"; import Avatar from "../common/Avatar"; import { convertShortTime } from "../../utils/dateUtils"; import RenderAttendanceStatus from "./RenderAttendanceStatus"; import { useSelector, useDispatch } from "react-redux"; import { fetchAttendanceData } from "../../slices/apiSlice/attedanceLogsSlice"; +import DateRangePicker from "../common/DateRangePicker"; +import { getCachedData } from "../../slices/apiDataManager"; +import usePagination from "../../hooks/usePagination"; -const AttendanceLog = ({ attendance, handleModalData, projectId }) => { +const AttendanceLog = ({ handleModalData, projectId }) => { const [attendances, setAttendnaces] = useState([]); const [selectedDate, setSelectedDate] = useState(""); + const [dateRange, setDateRange] = useState({ startDate: "", endDate: "" }); const dispatch = useDispatch(); const { data, loading, error } = useSelector((store) => store.attendanceLogs); - - // Set the default selected date to the current date - - // const currentDate = new Date().toISOString().split("T")[0]; // "YYYY-MM-DD" - const currentDate = new Date().toLocaleDateString('en-CA'); - const handleDateChange = (e) => { - const date = e.target.value; - setSelectedDate(date); - if (date) { - dispatch(fetchAttendanceData({ projectId, date: date })); - } - }; + const [isRefreshing, setIsRefreshing] = useState(true); + const currentDate = new Date().toLocaleDateString( "en-CA" ); + const { currentPage, totalPages, currentItems, paginate } = usePagination( + data, + 5 + ); useEffect(() => { - // If attendance has check-in time, filter it - setAttendnaces(attendance?.filter((record) => record.checkInTime !== null)); - setSelectedDate(currentDate); // Set default selected date to today - }, [attendance]); - - const renderAttendanceData = - selectedDate === currentDate ? attendances : data; + const { startDate, endDate } = dateRange; + if (startDate && endDate) { + dispatch( + fetchAttendanceData({ + projectId, + fromDate: startDate, + toDate: endDate, + }) + ); + } + }, [dateRange, projectId, isRefreshing]); + return ( <>
-
- + +
+
+ setIsRefreshing(!isRefreshing)} />
-
- {attendance && attendance.length > 0 ? ( + {data && data.length > 0 ? ( - + {loading && } {error && } - {selectedDate && renderAttendanceData.length === 0 && ( + {data && data.length === 0 && ( )} - {renderAttendanceData?.map((attendance, index) => ( + {currentItems?.map((attendance, index) => ( - +
Name RoleDate {" "} Check-In @@ -72,13 +77,13 @@ const AttendanceLog = ({ attendance, handleModalData, projectId }) => {
Loading...{error}
No Data Found
@@ -95,7 +100,10 @@ const AttendanceLog = ({ attendance, handleModalData, projectId }) => {
{attendance.jobRoleName} + {" "} + {moment(attendance.checkInTime).format("DD-MMM-YYYY")} + {convertShortTime(attendance.checkInTime)} {attendance.checkOutTime @@ -118,6 +126,51 @@ const AttendanceLog = ({ attendance, handleModalData, projectId }) => { No employee logs )} + {!loading && ( + + )} ); }; diff --git a/src/pages/Activities/AttendancePage.jsx b/src/pages/Activities/AttendancePage.jsx index 91ca62f0..2445f5fd 100644 --- a/src/pages/Activities/AttendancePage.jsx +++ b/src/pages/Activities/AttendancePage.jsx @@ -20,6 +20,8 @@ import { useHasUserPermission } from "../../hooks/useHasUserPermission"; import { REGULARIZE_ATTENDANCE } from "../../utils/constants"; const AttendancePage = () => { + const [activeTab, setActiveTab] = useState("all"); + const loginUser = getCachedProfileData(); var selectedProject = useSelector((store) => store.localVariables.projectId); const { projects, loading: projectLoading } = useProjects(); @@ -121,7 +123,7 @@ const AttendancePage = () => {
    {loginUser && loginUser?.projects?.length > 1 && ( @@ -152,18 +154,17 @@ const AttendancePage = () => { )} +
  • @@ -171,12 +172,10 @@ const AttendancePage = () => {
  • @@ -184,12 +183,12 @@ const AttendancePage = () => {
  • @@ -198,39 +197,30 @@ const AttendancePage = () => {
    {projectLoading && Loading..} {!projectLoading && !attendances && Not Found} - {projects && projects.length > 0 && ( - <> - - - - + + {activeTab === "all" && ( +
    + +
    + )} + + {activeTab === "logs" && ( +
    + +
    + )} + + {activeTab === "regularization" && DoRegularized && ( +
    + +
    )}