Compare commits
No commits in common. "2fb08a004430c0777972fbff2637c9d24c264a02" and "1ffda41f16928765236fb253da277bfcfccebb7d" have entirely different histories.
2fb08a0044
...
1ffda41f16
@ -1,4 +1,4 @@
|
|||||||
import React, { useState,useEffect } from "react";
|
import React, { useState } from "react";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import Avatar from "../common/Avatar";
|
import Avatar from "../common/Avatar";
|
||||||
import { convertShortTime } from "../../utils/dateUtils";
|
import { convertShortTime } from "../../utils/dateUtils";
|
||||||
@ -7,37 +7,17 @@ import usePagination from "../../hooks/usePagination";
|
|||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
const Attendance = ({ attendance, getRole, handleModalData }) => {
|
const Attendance = ({ attendance, getRole, handleModalData }) => {
|
||||||
|
const { currentPage, totalPages, currentItems, paginate } = usePagination(
|
||||||
|
attendance,
|
||||||
|
5
|
||||||
|
);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const navigate = useNavigate();
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="table-responsive text-nowrap">
|
<div className="table-responsive text-nowrap">
|
||||||
{attendance && attendance.length > 0 && (
|
{attendance && attendance.length > 0 ? (
|
||||||
<>
|
<>
|
||||||
<table className="table ">
|
<table className="table ">
|
||||||
<thead>
|
<thead>
|
||||||
@ -116,9 +96,6 @@ const Attendance = ({ attendance, getRole, handleModalData }) => {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
{!attendance && (
|
|
||||||
<span>No employees assigned to the project</span>
|
|
||||||
)}
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@ -168,6 +145,8 @@ const Attendance = ({ attendance, getRole, handleModalData }) => {
|
|||||||
</nav>
|
</nav>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
) : (
|
||||||
|
<span>No employees assigned to the project</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -16,41 +16,9 @@ const AttendanceLog = ({ handleModalData, projectId }) => {
|
|||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { data, loading, error } = useSelector((store) => store.attendanceLogs);
|
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 currentDate = new Date().toLocaleDateString( "en-CA" );
|
||||||
const { currentPage, totalPages, currentItems, paginate } = usePagination(
|
const { currentPage, totalPages, currentItems, paginate } = usePagination(
|
||||||
sortedFinalList,
|
data,
|
||||||
5
|
5
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -67,6 +35,7 @@ const AttendanceLog = ({ handleModalData, projectId }) => {
|
|||||||
}
|
}
|
||||||
}, [dateRange, projectId, isRefreshing]);
|
}, [dateRange, projectId, isRefreshing]);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import RegularizationActions from "./RegularizationActions";
|
|||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { useRegularizationRequests } from "../../hooks/useAttendance";
|
import { useRegularizationRequests } from "../../hooks/useAttendance";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import usePagination from "../../hooks/usePagination";
|
|
||||||
|
|
||||||
const Regularization = ({ handleRequest }) => {
|
const Regularization = ({ handleRequest }) => {
|
||||||
var selectedProject = useSelector((store) => store.localVariables.projectId);
|
var selectedProject = useSelector((store) => store.localVariables.projectId);
|
||||||
@ -17,19 +16,6 @@ const Regularization = ({ handleRequest }) => {
|
|||||||
setregularizedList(regularizes);
|
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 (
|
return (
|
||||||
<div className="table-responsive text-nowrap">
|
<div className="table-responsive text-nowrap">
|
||||||
<table className="table mb-0">
|
<table className="table mb-0">
|
||||||
@ -93,51 +79,6 @@ const Regularization = ({ handleRequest }) => {
|
|||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{!loading && (
|
|
||||||
<nav aria-label="Page ">
|
|
||||||
<ul className="pagination pagination-sm justify-content-end py-1">
|
|
||||||
<li
|
|
||||||
className={`page-item ${
|
|
||||||
currentPage === 1 ? "disabled" : ""
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
className="page-link btn-xs"
|
|
||||||
onClick={() => paginate(currentPage - 1)}
|
|
||||||
>
|
|
||||||
«
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
{[...Array(totalPages)].map((_, index) => (
|
|
||||||
<li
|
|
||||||
key={index}
|
|
||||||
className={`page-item ${
|
|
||||||
currentPage === index + 1 ? "active" : ""
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
className="page-link "
|
|
||||||
onClick={() => paginate(index + 1)}
|
|
||||||
>
|
|
||||||
{index + 1}
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
<li
|
|
||||||
className={`page-item ${
|
|
||||||
currentPage === totalPages ? "disabled" : ""
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
className="page-link "
|
|
||||||
onClick={() => paginate(currentPage + 1)}
|
|
||||||
>
|
|
||||||
»
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -76,9 +76,8 @@ const TimePicker = ({ label, onChange, interval = 10, value,checkInTime,checkOut
|
|||||||
}
|
}
|
||||||
} else if (checkInDate && checkOutDate) {
|
} else if (checkInDate && checkOutDate) {
|
||||||
// Case 3: Both check-in and checkout present
|
// Case 3: Both check-in and checkout present
|
||||||
const isSameDay = new Date(checkOutDate).toDateString() === new Date().toDateString();
|
|
||||||
minSelectable = new Date(checkOutDate);
|
minSelectable = new Date(checkOutDate);
|
||||||
maxSelectable = isSameDay ? new Date(dayEnd) : new Date(currentSlot);
|
maxSelectable = new Date(currentSlot);
|
||||||
}
|
}
|
||||||
|
|
||||||
const slot = new Date(dayStart.getTime());
|
const slot = new Date(dayStart.getTime());
|
||||||
|
|||||||
@ -74,20 +74,7 @@ const useAttendanceStatus = (attendanceData) => {
|
|||||||
text: "Regularize",
|
text: "Regularize",
|
||||||
color: 'btn-warning',
|
color: 'btn-warning',
|
||||||
});
|
});
|
||||||
} else if ( activity === 4 && checkInTime !== null && checkOutTime !== null && !timeElapsed( checkInTime, THRESH_HOLD ) )
|
}else if(activity === 4 && checkInTime !== null && checkOutTime !== null && !timeElapsed(checkInTime,THRESH_HOLD) ){
|
||||||
{
|
|
||||||
|
|
||||||
if ( activity === 4 && checkInTime !== null && checkOutTime !== null && new Date(checkOutTime).toDateString() !== new Date().toDateString())
|
|
||||||
{
|
|
||||||
setStatus( {
|
|
||||||
status: "Approved",
|
|
||||||
action: ACTIONS.APPROVED,
|
|
||||||
disabled: true,
|
|
||||||
text: "Approved",
|
|
||||||
color: 'btn-success',
|
|
||||||
} );
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
setStatus({
|
setStatus({
|
||||||
status: "Check-In",
|
status: "Check-In",
|
||||||
action: ACTIONS.CHECK_IN,
|
action: ACTIONS.CHECK_IN,
|
||||||
@ -95,10 +82,7 @@ const useAttendanceStatus = (attendanceData) => {
|
|||||||
text: "Check In",
|
text: "Check In",
|
||||||
color: 'btn-primary',
|
color: 'btn-primary',
|
||||||
})
|
})
|
||||||
}
|
}else if(activity === 2 && checkInTime !== null ){
|
||||||
}
|
|
||||||
else if ( activity === 2 && checkInTime !== null )
|
|
||||||
{
|
|
||||||
setStatus({
|
setStatus({
|
||||||
status: "Requested",
|
status: "Requested",
|
||||||
action: ACTIONS.REQUESTED,
|
action: ACTIONS.REQUESTED,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user