Compare commits
4 Commits
41f3628d45
...
7c9607cb78
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c9607cb78 | ||
|
|
cbf376d5b6 | ||
|
|
00902fff9f | ||
|
|
c254b98405 |
@ -5,9 +5,15 @@ import { convertShortTime } from "../../utils/dateUtils";
|
|||||||
import RenderAttendanceStatus from "./RenderAttendanceStatus";
|
import RenderAttendanceStatus from "./RenderAttendanceStatus";
|
||||||
import usePagination from "../../hooks/usePagination";
|
import usePagination from "../../hooks/usePagination";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import {ITEMS_PER_PAGE} from "../../utils/constants";
|
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
||||||
|
|
||||||
const Attendance = ({ attendance, getRole, handleModalData }) => {
|
const Attendance = ({
|
||||||
|
attendance,
|
||||||
|
getRole,
|
||||||
|
handleModalData,
|
||||||
|
setshowOnlyCheckout,
|
||||||
|
showOnlyCheckout,
|
||||||
|
}) => {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [todayDate, setTodayDate] = useState(new Date());
|
const [todayDate, setTodayDate] = useState(new Date());
|
||||||
@ -19,7 +25,7 @@ const Attendance = ({ attendance, getRole, handleModalData }) => {
|
|||||||
const sortByName = (a, b) => {
|
const sortByName = (a, b) => {
|
||||||
const nameA = (a.firstName + a.lastName).toLowerCase();
|
const nameA = (a.firstName + a.lastName).toLowerCase();
|
||||||
const nameB = (b.firstName + b.lastName).toLowerCase();
|
const nameB = (b.firstName + b.lastName).toLowerCase();
|
||||||
return nameA.localeCompare(nameB);
|
return nameA?.localeCompare(nameB);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Filter employees based on activity
|
// Filter employees based on activity
|
||||||
@ -39,41 +45,47 @@ const Attendance = ({ attendance, getRole, handleModalData }) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="table-responsive text-nowrap">
|
<div className="table-responsive text-nowrap">
|
||||||
|
<div className="d-flex text-start align-items-center py-2">
|
||||||
|
<strong>Date : {todayDate.toLocaleDateString("en-GB")}</strong>
|
||||||
|
|
||||||
|
<div className="form-check form-switch text-start m-0 ms-5">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
className="form-check-input"
|
||||||
|
role="switch"
|
||||||
|
id="inactiveEmployeesCheckbox"
|
||||||
|
checked={showOnlyCheckout}
|
||||||
|
onChange={(e) => setshowOnlyCheckout(e.target.checked)}
|
||||||
|
/>
|
||||||
|
<label className="form-check-label ms-0">Show Pending</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{attendance && attendance.length > 0 && (
|
{attendance && attendance.length > 0 && (
|
||||||
<>
|
<>
|
||||||
<table className="table ">
|
<table className="table ">
|
||||||
<thead>
|
<thead>
|
||||||
<tr className="border-none" style={{ textAlign: 'left' }}>
|
<tr className="border-top-1">
|
||||||
<td style={{ borderBottom: 'none' }}>
|
<th colSpan={2}>Name</th>
|
||||||
<strong>Date : {todayDate.toLocaleDateString('en-GB')}</strong>
|
<th>Role</th>
|
||||||
</td>
|
<th>
|
||||||
<td style={{ paddingLeft: '20px', borderBottom: 'none' }}></td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<th className="border-top-0" colSpan={2}>
|
|
||||||
Name
|
|
||||||
</th>
|
|
||||||
<th className="border-top-0">Role</th>
|
|
||||||
<th className="border-top-0">
|
|
||||||
<i className="bx bxs-down-arrow-alt text-success"></i>
|
<i className="bx bxs-down-arrow-alt text-success"></i>
|
||||||
Check-In
|
Check-In
|
||||||
</th>
|
</th>
|
||||||
<th className="border-top-0">
|
<th>
|
||||||
<i className="bx bxs-up-arrow-alt text-danger"></i>Check-Out
|
<i className="bx bxs-up-arrow-alt text-danger"></i>Check-Out
|
||||||
</th>
|
</th>
|
||||||
<th className="border-top-0">Actions</th>
|
<th>Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="table-border-bottom-0">
|
<tbody className="table-border-bottom-0 ">
|
||||||
{currentItems &&
|
{currentItems &&
|
||||||
currentItems
|
currentItems
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
// If checkInTime exists, compare it, otherwise, treat null as earlier than a date
|
// If checkInTime exists, compare it, otherwise, treat null as earlier than a date
|
||||||
const checkInA = a.checkInTime
|
const checkInA = a?.checkInTime
|
||||||
? new Date(a.checkInTime)
|
? new Date(a.checkInTime)
|
||||||
: new Date(0);
|
: new Date(0);
|
||||||
const checkInB = b.checkInTime
|
const checkInB = b?.checkInTime
|
||||||
? new Date(b.checkInTime)
|
? new Date(b.checkInTime)
|
||||||
: new Date(0);
|
: new Date(0);
|
||||||
return checkInB - checkInA; // Sort in descending order of checkInTime
|
return checkInB - checkInA; // Sort in descending order of checkInTime
|
||||||
@ -131,12 +143,13 @@ const Attendance = ({ attendance, getRole, handleModalData }) => {
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{!loading>20 && (
|
{!loading > 20 && (
|
||||||
<nav aria-label="Page ">
|
<nav aria-label="Page ">
|
||||||
<ul className="pagination pagination-sm justify-content-end py-1">
|
<ul className="pagination pagination-sm justify-content-end py-1">
|
||||||
<li
|
<li
|
||||||
className={`page-item ${currentPage === 1 ? "disabled" : ""
|
className={`page-item ${
|
||||||
}`}
|
currentPage === 1 ? "disabled" : ""
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="page-link btn-xs"
|
className="page-link btn-xs"
|
||||||
@ -148,8 +161,9 @@ const Attendance = ({ attendance, getRole, handleModalData }) => {
|
|||||||
{[...Array(totalPages)].map((_, index) => (
|
{[...Array(totalPages)].map((_, index) => (
|
||||||
<li
|
<li
|
||||||
key={index}
|
key={index}
|
||||||
className={`page-item ${currentPage === index + 1 ? "active" : ""
|
className={`page-item ${
|
||||||
}`}
|
currentPage === index + 1 ? "active" : ""
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="page-link "
|
className="page-link "
|
||||||
@ -160,8 +174,9 @@ const Attendance = ({ attendance, getRole, handleModalData }) => {
|
|||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
<li
|
<li
|
||||||
className={`page-item ${currentPage === totalPages ? "disabled" : ""
|
className={`page-item ${
|
||||||
}`}
|
currentPage === totalPages ? "disabled" : ""
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="page-link "
|
className="page-link "
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import { getCachedData } from "../../slices/apiDataManager";
|
|||||||
const usePagination = (data, itemsPerPage) => {
|
const usePagination = (data, itemsPerPage) => {
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const maxPage = Math.ceil(data.length / itemsPerPage);
|
const maxPage = Math.ceil(data.length / itemsPerPage);
|
||||||
|
|
||||||
const currentItems = useMemo(() => {
|
const currentItems = useMemo(() => {
|
||||||
const startIndex = (currentPage - 1) * itemsPerPage;
|
const startIndex = (currentPage - 1) * itemsPerPage;
|
||||||
const endIndex = startIndex + itemsPerPage;
|
const endIndex = startIndex + itemsPerPage;
|
||||||
@ -21,10 +20,21 @@ const usePagination = (data, itemsPerPage) => {
|
|||||||
const paginate = useCallback((pageNumber) => setCurrentPage(pageNumber), []);
|
const paginate = useCallback((pageNumber) => setCurrentPage(pageNumber), []);
|
||||||
const resetPage = useCallback(() => setCurrentPage(1), []);
|
const resetPage = useCallback(() => setCurrentPage(1), []);
|
||||||
|
|
||||||
return { currentPage, totalPages: maxPage, currentItems, paginate, resetPage };
|
return {
|
||||||
|
currentPage,
|
||||||
|
totalPages: maxPage,
|
||||||
|
currentItems,
|
||||||
|
paginate,
|
||||||
|
resetPage,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const AttendanceLog = ({ handleModalData, projectId, showOnlyCheckout }) => {
|
const AttendanceLog = ({
|
||||||
|
handleModalData,
|
||||||
|
projectId,
|
||||||
|
setshowOnlyCheckout,
|
||||||
|
showOnlyCheckout,
|
||||||
|
}) => {
|
||||||
const [dateRange, setDateRange] = useState({ startDate: "", endDate: "" });
|
const [dateRange, setDateRange] = useState({ startDate: "", endDate: "" });
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { data, loading, error } = useSelector((store) => store.attendanceLogs);
|
const { data, loading, error } = useSelector((store) => store.attendanceLogs);
|
||||||
@ -54,7 +64,7 @@ const AttendanceLog = ({ handleModalData, projectId, showOnlyCheckout }) => {
|
|||||||
const sortByName = (a, b) => {
|
const sortByName = (a, b) => {
|
||||||
const nameA = a.firstName.toLowerCase() + a.lastName.toLowerCase();
|
const nameA = a.firstName.toLowerCase() + a.lastName.toLowerCase();
|
||||||
const nameB = b.firstName.toLowerCase() + b.lastName.toLowerCase();
|
const nameB = b.firstName.toLowerCase() + b.lastName.toLowerCase();
|
||||||
return nameA.localeCompare(nameB);
|
return nameA?.localeCompare(nameB);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -83,14 +93,24 @@ const AttendanceLog = ({ handleModalData, projectId, showOnlyCheckout }) => {
|
|||||||
const group3 = filteredData
|
const group3 = filteredData
|
||||||
.filter((d) => d.activity === 1 && isBeforeToday(d.checkInTime))
|
.filter((d) => d.activity === 1 && isBeforeToday(d.checkInTime))
|
||||||
.sort(sortByName);
|
.sort(sortByName);
|
||||||
const group4 = filteredData
|
const group4 = filteredData.filter(
|
||||||
.filter((d) => d.activity === 4 && isBeforeToday(d.checkOutTime));
|
(d) => d.activity === 4 && isBeforeToday(d.checkOutTime)
|
||||||
|
);
|
||||||
const group5 = filteredData
|
const group5 = filteredData
|
||||||
.filter((d) => d.activity === 2 && isBeforeToday(d.checkOutTime))
|
.filter((d) => d.activity === 2 && isBeforeToday(d.checkOutTime))
|
||||||
.sort(sortByName);
|
.sort(sortByName);
|
||||||
const group6 = filteredData.filter((d) => d.activity === 5).sort(sortByName);
|
const group6 = filteredData
|
||||||
|
.filter((d) => d.activity === 5)
|
||||||
|
.sort(sortByName);
|
||||||
|
|
||||||
const sortedList = [...group1, ...group2, ...group3, ...group4, ...group5, ...group6];
|
const sortedList = [
|
||||||
|
...group1,
|
||||||
|
...group2,
|
||||||
|
...group3,
|
||||||
|
...group4,
|
||||||
|
...group5,
|
||||||
|
...group6,
|
||||||
|
];
|
||||||
|
|
||||||
// Group by date
|
// Group by date
|
||||||
const groupedByDate = sortedList.reduce((acc, item) => {
|
const groupedByDate = sortedList.reduce((acc, item) => {
|
||||||
@ -103,17 +123,22 @@ const AttendanceLog = ({ handleModalData, projectId, showOnlyCheckout }) => {
|
|||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
// Sort dates in descending order
|
// Sort dates in descending order
|
||||||
const sortedDates = Object.keys(groupedByDate).sort((a, b) => new Date(b) - new Date(a));
|
const sortedDates = Object.keys(groupedByDate).sort(
|
||||||
|
(a, b) => new Date(b) - new Date(a)
|
||||||
|
);
|
||||||
|
|
||||||
// Create the final sorted array
|
// Create the final sorted array
|
||||||
const finalData = sortedDates.flatMap((date) => groupedByDate[date]);
|
const finalData = sortedDates.flatMap((date) => groupedByDate[date]);
|
||||||
setProcessedData(finalData);
|
setProcessedData(finalData);
|
||||||
}, [data, showOnlyCheckout]);
|
}, [data, showOnlyCheckout]);
|
||||||
|
|
||||||
const { currentPage, totalPages, currentItems: paginatedAttendances, paginate, resetPage } = usePagination(
|
const {
|
||||||
processedData,
|
currentPage,
|
||||||
20
|
totalPages,
|
||||||
);
|
currentItems: paginatedAttendances,
|
||||||
|
paginate,
|
||||||
|
resetPage,
|
||||||
|
} = usePagination(processedData, 20);
|
||||||
|
|
||||||
// Reset to the first page whenever processedData changes (due to switch on/off)
|
// Reset to the first page whenever processedData changes (due to switch on/off)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -122,57 +147,89 @@ const AttendanceLog = ({ handleModalData, projectId, showOnlyCheckout }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<div
|
||||||
<div
|
className="dataTables_length text-start py-2 d-flex justify-content-between"
|
||||||
className="dataTables_length text-start py-2 d-flex justify-content-between"
|
id="DataTables_Table_0_length"
|
||||||
id="DataTables_Table_0_length"
|
>
|
||||||
>
|
<div className="d-flex align-items-center my-0 ">
|
||||||
<div className="col-md-3 my-0 ">
|
<DateRangePicker
|
||||||
<DateRangePicker onRangeChange={setDateRange} defaultStartDate={yesterday} />
|
onRangeChange={setDateRange}
|
||||||
</div>
|
defaultStartDate={yesterday}
|
||||||
<div className="col-md-2 m-0 text-end">
|
/>
|
||||||
<i
|
<div className="form-check form-switch text-start m-0 ms-5">
|
||||||
className={`bx bx-refresh cursor-pointer fs-4 ${loading || isRefreshing ? "spin" : ""
|
<input
|
||||||
}`}
|
type="checkbox"
|
||||||
title="Refresh"
|
className="form-check-input"
|
||||||
onClick={() => setIsRefreshing(true)}
|
role="switch"
|
||||||
|
id="inactiveEmployeesCheckbox"
|
||||||
|
checked={showOnlyCheckout}
|
||||||
|
onChange={(e) => setshowOnlyCheckout(e.target.checked)}
|
||||||
/>
|
/>
|
||||||
|
<label className="form-check-label ms-0">Show Pending</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="table-responsive text-nowrap" style={{ minHeight: "250px" }}>
|
<div className="col-md-2 m-0 text-end">
|
||||||
{data && data.length > 0 && (
|
<i
|
||||||
<table className="table mb-0">
|
className={`bx bx-refresh cursor-pointer fs-4 ${
|
||||||
<thead>
|
loading || isRefreshing ? "spin" : ""
|
||||||
|
}`}
|
||||||
|
title="Refresh"
|
||||||
|
onClick={() => setIsRefreshing(true)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="table-responsive text-nowrap"
|
||||||
|
style={{ minHeight: "250px" }}
|
||||||
|
>
|
||||||
|
{data && data.length > 0 && (
|
||||||
|
<table className="table mb-0">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th className="border-top-1" colSpan={2}>
|
||||||
|
Name
|
||||||
|
</th>
|
||||||
|
<th className="border-top-1">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 || isRefreshing) && (
|
||||||
<tr>
|
<tr>
|
||||||
<th className="border-top-1" colSpan={2}>
|
<td colSpan={6}>Loading...</td>
|
||||||
Name
|
|
||||||
</th>
|
|
||||||
<th className="border-top-1">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>
|
</tr>
|
||||||
</thead>
|
)}
|
||||||
<tbody>
|
{!loading &&
|
||||||
{(loading || isRefreshing) && (
|
!isRefreshing &&
|
||||||
<tr>
|
paginatedAttendances.reduce((acc, attendance, index, arr) => {
|
||||||
<td colSpan={6}>Loading...</td>
|
const currentDate = moment(
|
||||||
</tr>
|
attendance.checkInTime || attendance.checkOutTime
|
||||||
)}
|
).format("YYYY-MM-DD");
|
||||||
{!loading && !isRefreshing && paginatedAttendances.reduce((acc, attendance, index, arr) => {
|
|
||||||
const currentDate = moment(attendance.checkInTime || attendance.checkOutTime).format("YYYY-MM-DD");
|
|
||||||
const previousAttendance = arr[index - 1];
|
const previousAttendance = arr[index - 1];
|
||||||
const previousDate = previousAttendance ? moment(previousAttendance.checkInTime || previousAttendance.checkOutTime).format("YYYY-MM-DD") : null;
|
const previousDate = previousAttendance
|
||||||
|
? moment(
|
||||||
|
previousAttendance.checkInTime ||
|
||||||
|
previousAttendance.checkOutTime
|
||||||
|
).format("YYYY-MM-DD")
|
||||||
|
: null;
|
||||||
|
|
||||||
if (!previousDate || currentDate !== previousDate) {
|
if (!previousDate || currentDate !== previousDate) {
|
||||||
acc.push(
|
acc.push(
|
||||||
<tr key={`header-${currentDate}`} className="table-row-header">
|
<tr
|
||||||
|
key={`header-${currentDate}`}
|
||||||
|
className="table-row-header"
|
||||||
|
>
|
||||||
<td colSpan={6} className="text-start">
|
<td colSpan={6} className="text-start">
|
||||||
<strong>{moment(currentDate).format("DD-MM-YYYY")}</strong>
|
<strong>
|
||||||
|
{moment(currentDate).format("DD-MM-YYYY")}
|
||||||
|
</strong>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
@ -186,10 +243,7 @@ const AttendanceLog = ({ handleModalData, projectId, showOnlyCheckout }) => {
|
|||||||
lastName={attendance.lastName}
|
lastName={attendance.lastName}
|
||||||
/>
|
/>
|
||||||
<div className="d-flex flex-column">
|
<div className="d-flex flex-column">
|
||||||
<a
|
<a href="#" className="text-heading text-truncate">
|
||||||
href="#"
|
|
||||||
className="text-heading text-truncate"
|
|
||||||
>
|
|
||||||
<span className="fw-normal">
|
<span className="fw-normal">
|
||||||
{attendance.firstName} {attendance.lastName}
|
{attendance.firstName} {attendance.lastName}
|
||||||
</span>
|
</span>
|
||||||
@ -198,11 +252,15 @@ const AttendanceLog = ({ handleModalData, projectId, showOnlyCheckout }) => {
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{moment(attendance.checkInTime || attendance.checkOutTime).format("DD-MMM-YYYY")}
|
{moment(
|
||||||
|
attendance.checkInTime || attendance.checkOutTime
|
||||||
|
).format("DD-MMM-YYYY")}
|
||||||
</td>
|
</td>
|
||||||
<td>{convertShortTime(attendance.checkInTime)}</td>
|
<td>{convertShortTime(attendance.checkInTime)}</td>
|
||||||
<td>
|
<td>
|
||||||
{attendance.checkOutTime ? convertShortTime(attendance.checkOutTime) : "--"}
|
{attendance.checkOutTime
|
||||||
|
? convertShortTime(attendance.checkOutTime)
|
||||||
|
: "--"}
|
||||||
</td>
|
</td>
|
||||||
<td className="text-center">
|
<td className="text-center">
|
||||||
<RenderAttendanceStatus
|
<RenderAttendanceStatus
|
||||||
@ -216,40 +274,55 @@ const AttendanceLog = ({ handleModalData, projectId, showOnlyCheckout }) => {
|
|||||||
);
|
);
|
||||||
return acc;
|
return acc;
|
||||||
}, [])}
|
}, [])}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
)}
|
||||||
|
{!loading && !isRefreshing && data.length === 0 && (
|
||||||
)}
|
<span>No employee logs</span>
|
||||||
{!loading && !isRefreshing && data.length === 0 && <span>No employee logs</span>}
|
)}
|
||||||
{error && !loading && !isRefreshing && (
|
{error && !loading && !isRefreshing && (
|
||||||
<tr>
|
<tr>
|
||||||
<td colSpan={6}>{error}</td>
|
<td colSpan={6}>{error}</td>
|
||||||
</tr>
|
</tr>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{!loading && !isRefreshing && processedData.length > 10 && (
|
{!loading && !isRefreshing && processedData.length > 10 && (
|
||||||
<nav aria-label="Page ">
|
<nav aria-label="Page ">
|
||||||
<ul className="pagination pagination-sm justify-content-end py-1">
|
<ul className="pagination pagination-sm justify-content-end py-1">
|
||||||
<li className={`page-item ${currentPage === 1 ? "disabled" : ""}`}>
|
<li className={`page-item ${currentPage === 1 ? "disabled" : ""}`}>
|
||||||
<button className="page-link btn-xs" onClick={() => paginate(currentPage - 1)}>
|
<button
|
||||||
|
className="page-link btn-xs"
|
||||||
|
onClick={() => paginate(currentPage - 1)}
|
||||||
|
>
|
||||||
«
|
«
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
{Array.from({ length: totalPages }, (_, i) => i + 1).map((pageNumber) => (
|
{Array.from({ length: totalPages }, (_, i) => i + 1).map(
|
||||||
<li
|
(pageNumber) => (
|
||||||
key={pageNumber}
|
<li
|
||||||
className={`page-item ${currentPage === pageNumber ? "active" : ""}`}
|
key={pageNumber}
|
||||||
>
|
className={`page-item ${
|
||||||
<button className="page-link" onClick={() => paginate(pageNumber)}>
|
currentPage === pageNumber ? "active" : ""
|
||||||
{pageNumber}
|
}`}
|
||||||
</button>
|
>
|
||||||
</li>
|
<button
|
||||||
))}
|
className="page-link"
|
||||||
|
onClick={() => paginate(pageNumber)}
|
||||||
|
>
|
||||||
|
{pageNumber}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
)
|
||||||
|
)}
|
||||||
<li
|
<li
|
||||||
className={`page-item ${currentPage === totalPages ? "disabled" : ""}`}
|
className={`page-item ${
|
||||||
|
currentPage === totalPages ? "disabled" : ""
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<button className="page-link" onClick={() => paginate(currentPage + 1)}>
|
<button
|
||||||
|
className="page-link"
|
||||||
|
onClick={() => paginate(currentPage + 1)}
|
||||||
|
>
|
||||||
»
|
»
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@ -20,7 +20,7 @@ const Regularization = ({ handleRequest }) => {
|
|||||||
const sortByName = (a, b) => {
|
const sortByName = (a, b) => {
|
||||||
const nameA = a.firstName.toLowerCase() + a.lastName.toLowerCase();
|
const nameA = a.firstName.toLowerCase() + a.lastName.toLowerCase();
|
||||||
const nameB = b.firstName.toLowerCase() + b.lastName.toLowerCase();
|
const nameB = b.firstName.toLowerCase() + b.lastName.toLowerCase();
|
||||||
return nameA.localeCompare(nameB);
|
return nameA?.localeCompare(nameB);
|
||||||
};
|
};
|
||||||
const filteredData = [...regularizesList]?.sort(sortByName);
|
const filteredData = [...regularizesList]?.sort(sortByName);
|
||||||
|
|
||||||
|
|||||||
@ -510,7 +510,7 @@ const ManageEmployee = ({ employeeId, onClosed }) => {
|
|||||||
Select Role
|
Select Role
|
||||||
</option>
|
</option>
|
||||||
{[...job_role]
|
{[...job_role]
|
||||||
.sort((a, b) => a.name.localeCompare(b.name))
|
.sort((a, b) => a?.name?.localeCompare(b.name))
|
||||||
.map((item) => (
|
.map((item) => (
|
||||||
<option value={item?.id} key={item.id}>
|
<option value={item?.id} key={item.id}>
|
||||||
{item?.name}{" "}
|
{item?.name}{" "}
|
||||||
|
|||||||
@ -273,7 +273,7 @@ const EditActivityModal = ({
|
|||||||
activities
|
activities
|
||||||
.slice()
|
.slice()
|
||||||
.sort((a, b) =>
|
.sort((a, b) =>
|
||||||
(a.activityName || "").localeCompare(
|
(a.activityName || "")?.localeCompare(
|
||||||
b.activityName || ""
|
b.activityName || ""
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -312,7 +312,7 @@ const EditActivityModal = ({
|
|||||||
categories
|
categories
|
||||||
.slice()
|
.slice()
|
||||||
.sort((a, b) =>
|
.sort((a, b) =>
|
||||||
(a.name || "").localeCompare(
|
(a.name || "")?.localeCompare(
|
||||||
b.name || ""
|
b.name || ""
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@ -140,7 +140,7 @@ const FloorModel = ({
|
|||||||
buildings
|
buildings
|
||||||
.filter((building) => building?.name)
|
.filter((building) => building?.name)
|
||||||
.sort((a, b) =>
|
.sort((a, b) =>
|
||||||
(a.name || "").localeCompare(b.name || "")
|
(a.name || "")?.localeCompare(b.name || "")
|
||||||
)
|
)
|
||||||
.map((building) => (
|
.map((building) => (
|
||||||
<option key={building.id} value={building.id}>
|
<option key={building.id} value={building.id}>
|
||||||
@ -172,7 +172,7 @@ const FloorModel = ({
|
|||||||
[...selectedBuilding.floors]
|
[...selectedBuilding.floors]
|
||||||
.filter((floor) => floor?.floorName)
|
.filter((floor) => floor?.floorName)
|
||||||
.sort((a, b) =>
|
.sort((a, b) =>
|
||||||
(a.floorName || "").localeCompare(
|
(a.floorName || "")?.localeCompare(
|
||||||
b.floorName || ""
|
b.floorName || ""
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@ -159,7 +159,7 @@ const TaskModel = ({
|
|||||||
const newCategories = categories?.slice()?.sort((a, b) => {
|
const newCategories = categories?.slice()?.sort((a, b) => {
|
||||||
const nameA = a?.name || "";
|
const nameA = a?.name || "";
|
||||||
const nameB = b?.name || "";
|
const nameB = b?.name || "";
|
||||||
return nameA.localeCompare(nameB);
|
return nameA?.localeCompare(nameB);
|
||||||
});
|
});
|
||||||
setCategoryData(newCategories);
|
setCategoryData(newCategories);
|
||||||
setSelectedCategory(newCategories[0])
|
setSelectedCategory(newCategories[0])
|
||||||
@ -230,7 +230,7 @@ const TaskModel = ({
|
|||||||
(floor) =>
|
(floor) =>
|
||||||
floor?.floorName && Array.isArray(floor.workAreas)
|
floor?.floorName && Array.isArray(floor.workAreas)
|
||||||
)
|
)
|
||||||
?.sort((a, b) => a.floorName.localeCompare(b.floorName))
|
?.sort((a, b) => a.floorName?.localeCompare(b.floorName))
|
||||||
?.map((floor) => (
|
?.map((floor) => (
|
||||||
<option key={floor.id} value={floor.id}>
|
<option key={floor.id} value={floor.id}>
|
||||||
{floor.floorName} - ({floor.workAreas.length} Work
|
{floor.floorName} - ({floor.workAreas.length} Work
|
||||||
@ -263,7 +263,7 @@ const TaskModel = ({
|
|||||||
<option value="0">Select Work Area</option>
|
<option value="0">Select Work Area</option>
|
||||||
{selectedFloor.workAreas
|
{selectedFloor.workAreas
|
||||||
?.filter((workArea) => workArea?.areaName)
|
?.filter((workArea) => workArea?.areaName)
|
||||||
?.sort((a, b) => a.areaName.localeCompare(b.areaName))
|
?.sort((a, b) => a.areaName?.localeCompare(b.areaName))
|
||||||
?.map((workArea) => (
|
?.map((workArea) => (
|
||||||
<option key={workArea.id} value={workArea.id}>
|
<option key={workArea.id} value={workArea.id}>
|
||||||
{workArea.areaName}
|
{workArea.areaName}
|
||||||
@ -299,7 +299,7 @@ const TaskModel = ({
|
|||||||
?.sort((a, b) => {
|
?.sort((a, b) => {
|
||||||
const nameA = a?.activityName || "";
|
const nameA = a?.activityName || "";
|
||||||
const nameB = b?.activityName || "";
|
const nameB = b?.activityName || "";
|
||||||
return nameA.localeCompare(nameB);
|
return nameA?.localeCompare(nameB);
|
||||||
})
|
})
|
||||||
?.map((activity) => (
|
?.map((activity) => (
|
||||||
<option key={activity.id} value={activity.id}>
|
<option key={activity.id} value={activity.id}>
|
||||||
|
|||||||
@ -197,7 +197,7 @@ const WorkAreaModel = ({
|
|||||||
?.sort((a, b) => {
|
?.sort((a, b) => {
|
||||||
const nameA = a.floorName || "";
|
const nameA = a.floorName || "";
|
||||||
const nameB = b.floorName || "";
|
const nameB = b.floorName || "";
|
||||||
return nameA.localeCompare(nameB);
|
return nameA?.localeCompare(nameB);
|
||||||
})
|
})
|
||||||
?.map((floor) => (
|
?.map((floor) => (
|
||||||
<option key={floor.id} value={floor.id}>
|
<option key={floor.id} value={floor.id}>
|
||||||
@ -231,7 +231,7 @@ const WorkAreaModel = ({
|
|||||||
?.sort((a, b) => {
|
?.sort((a, b) => {
|
||||||
const nameA = a.areaName || "";
|
const nameA = a.areaName || "";
|
||||||
const nameB = b.areaName || "";
|
const nameB = b.areaName || "";
|
||||||
return nameA.localeCompare(nameB);
|
return nameA?.localeCompare(nameB);
|
||||||
})
|
})
|
||||||
?.map((workArea) => (
|
?.map((workArea) => (
|
||||||
<option key={workArea.id} value={workArea.id}>
|
<option key={workArea.id} value={workArea.id}>
|
||||||
|
|||||||
@ -43,8 +43,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.img-preview {
|
.img-preview {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 500px;
|
height: 500px;
|
||||||
background-color: #E9E9E9;
|
object-fit: cover;
|
||||||
text-align: center;
|
object-position: center;
|
||||||
|
}
|
||||||
|
.img-preview img{
|
||||||
|
width: 100%;
|
||||||
|
height: 100%
|
||||||
}
|
}
|
||||||
@ -143,7 +143,8 @@ export const useEmployeesAllOrByProjectId = (projectId, showInactive) => {
|
|||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
const fetchData = async (showInactive) => {
|
const fetchData = async (showInactive) => {
|
||||||
if (projectId) {
|
if ( projectId )
|
||||||
|
{
|
||||||
const Employees_cache = getCachedData("employeeListByProject");
|
const Employees_cache = getCachedData("employeeListByProject");
|
||||||
if (!Employees_cache || Employees_cache.projectId !== projectId) {
|
if (!Employees_cache || Employees_cache.projectId !== projectId) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@ -166,18 +167,11 @@ export const useEmployeesAllOrByProjectId = (projectId, showInactive) => {
|
|||||||
setEmployees(Employees_cache.data);
|
setEmployees(Employees_cache.data);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
|
{
|
||||||
const cacheKey = showInactive
|
const cacheKey = showInactive
|
||||||
? "allInactiveEmployeeList"
|
? "allInactiveEmployeeList"
|
||||||
: "allEmployeeList";
|
: "allEmployeeList";
|
||||||
const employeesCache = getCachedData(cacheKey);
|
|
||||||
|
|
||||||
if (employeesCache) {
|
|
||||||
setEmployees(employeesCache.data);
|
|
||||||
setLoading(false);
|
|
||||||
} else {
|
|
||||||
setLoading(true);
|
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await EmployeeRepository.getAllEmployeeList(
|
const response = await EmployeeRepository.getAllEmployeeList(
|
||||||
@ -190,7 +184,7 @@ export const useEmployeesAllOrByProjectId = (projectId, showInactive) => {
|
|||||||
setError("Failed to fetch data.");
|
setError("Failed to fetch data.");
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ export const useProjects = () => {
|
|||||||
const filterProjects = (projectsList) => {
|
const filterProjects = (projectsList) => {
|
||||||
return projectsList
|
return projectsList
|
||||||
.filter((proj) => projectIds.includes(String(proj.id)))
|
.filter((proj) => projectIds.includes(String(proj.id)))
|
||||||
.sort((a, b) => a.name.localeCompare(b.name));
|
.sort((a, b) => a?.name?.localeCompare(b.name));
|
||||||
};
|
};
|
||||||
|
|
||||||
const projects_cache = getCachedData("projectslist");
|
const projects_cache = getCachedData("projectslist");
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import { REGULARIZE_ATTENDANCE } from "../../utils/constants";
|
|||||||
|
|
||||||
const AttendancePage = () => {
|
const AttendancePage = () => {
|
||||||
const [activeTab, setActiveTab] = useState("all");
|
const [activeTab, setActiveTab] = useState("all");
|
||||||
const [showOnlyCheckout, setShowOnlyCheckout] = useState(false);
|
const [showOnlyCheckout, setShowOnlyCheckout] = useState();
|
||||||
const loginUser = getCachedProfileData();
|
const loginUser = getCachedProfileData();
|
||||||
var selectedProject = useSelector((store) => store.localVariables.projectId);
|
var selectedProject = useSelector((store) => store.localVariables.projectId);
|
||||||
const { projects, loading: projectLoading } = useProjects();
|
const { projects, loading: projectLoading } = useProjects();
|
||||||
@ -112,7 +112,7 @@ const AttendancePage = () => {
|
|||||||
// )
|
// )
|
||||||
// : attendances;
|
// : attendances;
|
||||||
const filteredAttendance = showOnlyCheckout
|
const filteredAttendance = showOnlyCheckout
|
||||||
? attendances?.filter((att) => att?.checkOutTime === null)
|
? attendances?.filter((att) => att?.checkInTime !== null && att?.checkOutTime === null)
|
||||||
: attendances;
|
: attendances;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -230,6 +230,8 @@ const AttendancePage = () => {
|
|||||||
attendance={filteredAttendance}
|
attendance={filteredAttendance}
|
||||||
handleModalData={handleModalData}
|
handleModalData={handleModalData}
|
||||||
getRole={getRole}
|
getRole={getRole}
|
||||||
|
setshowOnlyCheckout={setShowOnlyCheckout}
|
||||||
|
showOnlyCheckout={showOnlyCheckout}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
@ -240,6 +242,7 @@ const AttendancePage = () => {
|
|||||||
<AttendanceLog
|
<AttendanceLog
|
||||||
handleModalData={handleModalData}
|
handleModalData={handleModalData}
|
||||||
projectId={selectedProject}
|
projectId={selectedProject}
|
||||||
|
setshowOnlyCheckout={setShowOnlyCheckout}
|
||||||
showOnlyCheckout={showOnlyCheckout}
|
showOnlyCheckout={showOnlyCheckout}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -181,7 +181,7 @@ const Directory = ({ IsPage = true, prefernceContacts }) => {
|
|||||||
(c.bucketIds || []).some((id) => selectedBucketIds.includes(id));
|
(c.bucketIds || []).some((id) => selectedBucketIds.includes(id));
|
||||||
|
|
||||||
return matchesSearch && matchesCategory && matchesBucket;
|
return matchesSearch && matchesCategory && matchesBucket;
|
||||||
}).sort((a, b) => a.name.localeCompare(b.name));
|
}).sort((a, b) => a?.name?.localeCompare(b.name));
|
||||||
}, [
|
}, [
|
||||||
ContactList,
|
ContactList,
|
||||||
searchText,
|
searchText,
|
||||||
|
|||||||
@ -42,7 +42,7 @@ const AttendancesEmployeeRecords = ({ employee }) => {
|
|||||||
const sortByName = (a, b) => {
|
const sortByName = (a, b) => {
|
||||||
const nameA = a.firstName.toLowerCase() + a.lastName.toLowerCase();
|
const nameA = a.firstName.toLowerCase() + a.lastName.toLowerCase();
|
||||||
const nameB = b.firstName.toLowerCase() + b.lastName.toLowerCase();
|
const nameB = b.firstName.toLowerCase() + b.lastName.toLowerCase();
|
||||||
return nameA.localeCompare(nameB);
|
return nameA?.localeCompare(nameB);
|
||||||
};
|
};
|
||||||
|
|
||||||
const group1 = data
|
const group1 = data
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import { useEmployeesAllOrByProjectId } from "../../hooks/useEmployees";
|
|||||||
import { useProjects } from "../../hooks/useProjects";
|
import { useProjects } from "../../hooks/useProjects";
|
||||||
import { useProfile } from "../../hooks/useProfile";
|
import { useProfile } from "../../hooks/useProfile";
|
||||||
import { hasUserPermission } from "../../utils/authUtils";
|
import { hasUserPermission } from "../../utils/authUtils";
|
||||||
import { MANAGE_EMPLOYEES } from "../../utils/constants";
|
import { ITEMS_PER_PAGE, MANAGE_EMPLOYEES } from "../../utils/constants";
|
||||||
import { clearCacheKey } from "../../slices/apiDataManager";
|
import { clearCacheKey } from "../../slices/apiDataManager";
|
||||||
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
import SuspendEmp from "../../components/Employee/SuspendEmp";
|
import SuspendEmp from "../../components/Employee/SuspendEmp";
|
||||||
@ -29,10 +29,9 @@ const EmployeeList = () => {
|
|||||||
const [selectedProject, setSelectedProject] = useState(() => selectedProjectId || "");
|
const [selectedProject, setSelectedProject] = useState(() => selectedProjectId || "");
|
||||||
const { projects, loading: projectLoading } = useProjects();
|
const { projects, loading: projectLoading } = useProjects();
|
||||||
const [showInactive, setShowInactive] = useState(false);
|
const [showInactive, setShowInactive] = useState(false);
|
||||||
const [showAllEmployees, setShowAllEmployees] = useState(false); // New state for "All Employee"
|
const [showAllEmployees, setShowAllEmployees] = useState(false);
|
||||||
const Manage_Employee = useHasUserPermission(MANAGE_EMPLOYEES);
|
const Manage_Employee = useHasUserPermission(MANAGE_EMPLOYEES);
|
||||||
|
|
||||||
// Modify the hook to conditionally pass selectedProject or null based on showAllEmployees
|
|
||||||
const { employees, loading, setLoading, error, recallEmployeeData } =
|
const { employees, loading, setLoading, error, recallEmployeeData } =
|
||||||
useEmployeesAllOrByProjectId(showAllEmployees ? null : selectedProject, showInactive);
|
useEmployeesAllOrByProjectId(showAllEmployees ? null : selectedProject, showInactive);
|
||||||
const [projectsList, setProjectsList] = useState(projects || []);
|
const [projectsList, setProjectsList] = useState(projects || []);
|
||||||
@ -40,7 +39,7 @@ const EmployeeList = () => {
|
|||||||
const [employeeList, setEmployeeList] = useState([]);
|
const [employeeList, setEmployeeList] = useState([]);
|
||||||
const [modelConfig, setModelConfig] = useState();
|
const [modelConfig, setModelConfig] = useState();
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const [itemsPerPage] = useState(20);
|
const [itemsPerPage] = useState(ITEMS_PER_PAGE);
|
||||||
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
||||||
const [isEmployeeModalOpen, setIsEmployeeModalOpen] = useState(false);
|
const [isEmployeeModalOpen, setIsEmployeeModalOpen] = useState(false);
|
||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
@ -86,7 +85,7 @@ const EmployeeList = () => {
|
|||||||
}`.toLowerCase();
|
}`.toLowerCase();
|
||||||
const nameB = `${b.firstName || ""}${b.middleName || ""}${b.lastName || ""
|
const nameB = `${b.firstName || ""}${b.middleName || ""}${b.lastName || ""
|
||||||
}`.toLowerCase();
|
}`.toLowerCase();
|
||||||
return nameA.localeCompare(nameB);
|
return nameA?.localeCompare(nameB);
|
||||||
});
|
});
|
||||||
|
|
||||||
setEmployeeList(sorted);
|
setEmployeeList(sorted);
|
||||||
@ -189,10 +188,11 @@ const EmployeeList = () => {
|
|||||||
recallEmployeeData(e.target.checked);
|
recallEmployeeData(e.target.checked);
|
||||||
};
|
};
|
||||||
|
|
||||||
// New handler for "All Employee" toggle
|
|
||||||
const handleAllEmployeesToggle = (e) => {
|
const handleAllEmployeesToggle = (e) => {
|
||||||
const isChecked = e.target.checked;
|
const isChecked = e.target.checked;
|
||||||
setShowAllEmployees(isChecked);
|
setShowInactive(false)
|
||||||
|
setShowAllEmployees( isChecked );
|
||||||
|
|
||||||
recallEmployeeData(showInactive, isChecked ? null : selectedProject);
|
recallEmployeeData(showInactive, isChecked ? null : selectedProject);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -304,7 +304,7 @@ const EmployeeList = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Show Inactive Employees Switch */}
|
{/* Show Inactive Employees Switch */}
|
||||||
{!showAllEmployees && (
|
{showAllEmployees && (
|
||||||
<div className="form-check form-switch text-start">
|
<div className="form-check form-switch text-start">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
@ -559,7 +559,7 @@ const EmployeeList = () => {
|
|||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td className=" d-none d-md-table-cell">
|
<td className=" d-none d-md-table-cell">
|
||||||
{moment(item.joiningDate).format("DD-MMM-YYYY")}
|
{moment(item.joiningDate)?.format("DD-MMM-YYYY")}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{showInactive ? (
|
{showInactive ? (
|
||||||
|
|||||||
@ -34,7 +34,7 @@ const MasterTable = ({ data, columns, loading, handleModalData }) => {
|
|||||||
if (!sortKey) return 0;
|
if (!sortKey) return 0;
|
||||||
const aValue = a[sortKey] || "";
|
const aValue = a[sortKey] || "";
|
||||||
const bValue = b[sortKey] || "";
|
const bValue = b[sortKey] || "";
|
||||||
return aValue.localeCompare(bValue);
|
return aValue?.localeCompare(bValue);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Pagination logic
|
// Pagination logic
|
||||||
|
|||||||
@ -50,7 +50,7 @@ const ProjectList = () => {
|
|||||||
.filter((statusId) => grouped[statusId])
|
.filter((statusId) => grouped[statusId])
|
||||||
.flatMap((statusId) =>
|
.flatMap((statusId) =>
|
||||||
grouped[statusId].sort((a, b) =>
|
grouped[statusId].sort((a, b) =>
|
||||||
a.name.toLowerCase().localeCompare(b.name.toLowerCase())
|
a.name.toLowerCase()?.localeCompare(b.name.toLowerCase())
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user