diff --git a/src/components/Activities/Attendance.jsx b/src/components/Activities/Attendance.jsx
index 0ee7fc97..e2f7b308 100644
--- a/src/components/Activities/Attendance.jsx
+++ b/src/components/Activities/Attendance.jsx
@@ -1,4 +1,4 @@
-import React, { useState } from "react";
+import React, { useState, useEffect } from "react";
import moment from "moment";
import Avatar from "../common/Avatar";
import { convertShortTime } from "../../utils/dateUtils";
@@ -7,17 +7,38 @@ import usePagination from "../../hooks/usePagination";
import { useNavigate } from "react-router-dom";
const Attendance = ({ attendance, getRole, handleModalData }) => {
- const { currentPage, totalPages, currentItems, paginate } = usePagination(
- attendance,
- 5
- );
const [loading, setLoading] = useState(false);
const navigate = useNavigate();
+ // Ensure attendance is an array
+ const attendanceList = Array.isArray(attendance) ? attendance : [];
+
+ // Function to sort by first and last name
+ const sortByName = (a, b) => {
+ const nameA = (a.firstName + a.lastName).toLowerCase();
+ const nameB = (b.firstName + b.lastName).toLowerCase();
+ return nameA.localeCompare(nameB);
+ };
+
+ // Filter employees based on activity
+ const group1 = attendanceList
+ .filter((d) => d.activity === 1 || d.activity === 4)
+ .sort(sortByName);
+ const group2 = attendanceList
+ .filter((d) => d.activity === 0)
+ .sort(sortByName);
+
+ const filteredData = [...group1, ...group2];
+
+ const { currentPage, totalPages, currentItems, paginate } = usePagination(
+ filteredData,
+ 5
+ );
+
return (
<>
- {attendance && attendance.length > 0 ? (
+ {attendance && attendance.length > 0 && (
<>
@@ -96,6 +117,9 @@ const Attendance = ({ attendance, getRole, handleModalData }) => {
))}
+ {!attendance && (
+ No employees assigned to the project
+ )}
@@ -145,8 +169,6 @@ const Attendance = ({ attendance, getRole, handleModalData }) => {
)}
>
- ) : (
-
No employees assigned to the project
)}
>
diff --git a/src/components/Activities/AttendcesLogs.jsx b/src/components/Activities/AttendcesLogs.jsx
index 6d3dc32c..219793f0 100644
--- a/src/components/Activities/AttendcesLogs.jsx
+++ b/src/components/Activities/AttendcesLogs.jsx
@@ -15,10 +15,44 @@ const AttendanceLog = ({ handleModalData, projectId }) => {
const [dateRange, setDateRange] = useState({ startDate: "", endDate: "" });
const dispatch = useDispatch();
const { data, loading, error } = useSelector((store) => store.attendanceLogs);
- const [isRefreshing, setIsRefreshing] = useState(true);
+ const [ isRefreshing, setIsRefreshing ] = useState( true );
+
+
+
+ const today = new Date();
+ today.setHours(0, 0, 0, 0); // Strip time to compare dates only
+
+ const isSameDay = (dateStr) => {
+ if (!dateStr) return false;
+ const d = new Date(dateStr);
+ d.setHours(0, 0, 0, 0);
+ return d.getTime() === today.getTime();
+ };
+
+ const isBeforeToday = (dateStr) => {
+ if (!dateStr) return false;
+ const d = new Date(dateStr);
+ d.setHours(0, 0, 0, 0);
+ return d.getTime() < today.getTime();
+ };
+
+ const sortByName = (a, b) => {
+ const nameA = a.firstName.toLowerCase() + a.lastName.toLowerCase();
+ const nameB = b.firstName.toLowerCase() + b.lastName.toLowerCase();
+ return nameA.localeCompare(nameB);
+ };
+
+ const group1 = data.filter(d => d.activity === 1 && isSameDay(d.checkInTime)).sort(sortByName);
+ const group2 = data.filter(d => d.activity === 4 && isSameDay(d.checkOutTime)).sort(sortByName);
+ const group3 = data.filter(d => d.activity === 1 && isBeforeToday(d.checkInTime)).sort(sortByName);
+ const group4 = data.filter(d => d.activity === 4 && isBeforeToday(d.checkOutTime)).sort(sortByName);
+ const group5 = data.filter(d => d.activity === 5).sort(sortByName);
+
+ const sortedFinalList = [...group1, ...group2, ...group3, ...group4, ...group5];
+
const currentDate = new Date().toLocaleDateString( "en-CA" );
const { currentPage, totalPages, currentItems, paginate } = usePagination(
- data,
+ sortedFinalList,
5
);
@@ -34,7 +68,8 @@ const AttendanceLog = ({ handleModalData, projectId }) => {
);
}
}, [dateRange, projectId, isRefreshing]);
-
+
+
return (
<>
diff --git a/src/components/Activities/Regularization.jsx b/src/components/Activities/Regularization.jsx
index dd61c8a3..fe4bcec1 100644
--- a/src/components/Activities/Regularization.jsx
+++ b/src/components/Activities/Regularization.jsx
@@ -5,16 +5,31 @@ import RegularizationActions from "./RegularizationActions";
import { useSelector } from "react-redux";
import { useRegularizationRequests } from "../../hooks/useAttendance";
import moment from "moment";
+import usePagination from "../../hooks/usePagination";
const Regularization = ({ handleRequest }) => {
- var selectedProject = useSelector((store) => store.localVariables.projectId);
+ var selectedProject = useSelector( ( store ) => store.localVariables.projectId );
+
const [regularizesList, setregularizedList] = useState([]);
const { regularizes, loading, error, refetch } =
useRegularizationRequests(selectedProject);
useEffect(() => {
setregularizedList(regularizes);
- }, [regularizes]);
+ }, [ regularizes ] );
+
+ const sortByName = (a, b) => {
+ const nameA = a.firstName.toLowerCase() + a.lastName.toLowerCase();
+ const nameB = b.firstName.toLowerCase() + b.lastName.toLowerCase();
+ return nameA.localeCompare(nameB);
+ };
+
+ const filteredData = regularizesList.sort(sortByName)
+
+ const { currentPage, totalPages, currentItems, paginate } = usePagination(
+ filteredData,
+ 5
+ );
return (
@@ -79,6 +94,52 @@ const Regularization = ({ handleRequest }) => {
))}
+
+ {!loading && (
+
+ )}
);
};