HofixedIssues_July_4W #322
@ -6,27 +6,34 @@ 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";
|
||||||
import { useAttendance } from "../../hooks/useAttendance"; // This hook is already providing data
|
import { useAttendance } from "../../hooks/useAttendance";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import eventBus from "../../services/eventBus";
|
import eventBus from "../../services/eventBus";
|
||||||
|
|
||||||
const Attendance = ({ getRole, handleModalData, attendance: filteredAndSearchedAttendanceFromParent, showOnlyCheckout, setshowOnlyCheckout }) => {
|
const Attendance = ({ getRole, handleModalData }) => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [todayDate, setTodayDate] = useState(new Date());
|
const [todayDate, setTodayDate] = useState(new Date());
|
||||||
|
const [ShowPending, setShowPending] = useState(false);
|
||||||
const selectedProject = useSelector(
|
const selectedProject = useSelector(
|
||||||
(store) => store.localVariables.projectId
|
(store) => store.localVariables.projectId
|
||||||
);
|
);
|
||||||
const {
|
const {
|
||||||
|
attendance,
|
||||||
loading: attLoading,
|
loading: attLoading,
|
||||||
recall: attrecall,
|
recall: attrecall,
|
||||||
isFetching
|
isFetching
|
||||||
} = useAttendance(selectedProject); // Keep this hook to manage recall and fetching status
|
} = useAttendance(selectedProject);
|
||||||
|
const filteredAttendance = ShowPending
|
||||||
|
? attendance?.filter(
|
||||||
|
(att) => att?.checkInTime !== null && att?.checkOutTime === null
|
||||||
|
)
|
||||||
|
: attendance;
|
||||||
|
|
||||||
const attendanceList = Array.isArray(filteredAndSearchedAttendanceFromParent)
|
const attendanceList = Array.isArray(filteredAttendance)
|
||||||
? filteredAndSearchedAttendanceFromParent
|
? filteredAttendance
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const sortByName = (a, b) => {
|
const sortByName = (a, b) => {
|
||||||
@ -34,7 +41,6 @@ const Attendance = ({ getRole, handleModalData, attendance: filteredAndSearchedA
|
|||||||
const nameB = (b.firstName + b.lastName).toLowerCase();
|
const nameB = (b.firstName + b.lastName).toLowerCase();
|
||||||
return nameA?.localeCompare(nameB);
|
return nameA?.localeCompare(nameB);
|
||||||
};
|
};
|
||||||
|
|
||||||
const group1 = attendanceList
|
const group1 = attendanceList
|
||||||
.filter((d) => d.activity === 1 || d.activity === 4)
|
.filter((d) => d.activity === 1 || d.activity === 4)
|
||||||
.sort(sortByName);
|
.sort(sortByName);
|
||||||
@ -42,39 +48,36 @@ const Attendance = ({ getRole, handleModalData, attendance: filteredAndSearchedA
|
|||||||
.filter((d) => d.activity === 0)
|
.filter((d) => d.activity === 0)
|
||||||
.sort(sortByName);
|
.sort(sortByName);
|
||||||
|
|
||||||
const finalFilteredDataForPagination = [...group1, ...group2];
|
const filteredData = [...group1, ...group2];
|
||||||
|
|
||||||
const { currentPage, totalPages, currentItems, paginate } = usePagination(
|
const { currentPage, totalPages, currentItems, paginate } = usePagination(
|
||||||
finalFilteredDataForPagination, // Use the data that's already been searched and grouped
|
filteredData,
|
||||||
ITEMS_PER_PAGE
|
ITEMS_PER_PAGE
|
||||||
);
|
);
|
||||||
|
|
||||||
const handler = useCallback(
|
const handler = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
if (selectedProject === msg.projectId) {
|
if (selectedProject == msg.projectId) {
|
||||||
queryClient.setQueryData(["attendance", selectedProject], (oldData) => {
|
queryClient.setQueryData(["attendance", selectedProject], (oldData) => {
|
||||||
if (!oldData) {
|
if (!oldData) {
|
||||||
queryClient.invalidateQueries({ queryKey: ["attendance"] });
|
queryClient.invalidateQueries({queryKey:["attendance"]})
|
||||||
return; // Exit to avoid mapping on undefined oldData
|
};
|
||||||
}
|
|
||||||
return oldData.map((record) =>
|
return oldData.map((record) =>
|
||||||
record.employeeId === msg.response.employeeId ? { ...record, ...msg.response } : record
|
record.employeeId === msg.response.employeeId ? { ...record, ...msg.response } : record
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[selectedProject, queryClient] // Added queryClient to dependencies
|
[selectedProject, attrecall]
|
||||||
);
|
);
|
||||||
|
|
||||||
const employeeHandler = useCallback(
|
const employeeHandler = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
if (attrecall) { // Check if attrecall function exists
|
if (attendances.some((item) => item.employeeId == msg.employeeId)) {
|
||||||
attrecall();
|
attrecall();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[attrecall] // Dependency should be attrecall, not `selectedProject` or `attendance` here
|
[selectedProject, attendance]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
eventBus.on("attendance", handler);
|
eventBus.on("attendance", handler);
|
||||||
return () => eventBus.off("attendance", handler);
|
return () => eventBus.off("attendance", handler);
|
||||||
@ -97,14 +100,13 @@ const Attendance = ({ getRole, handleModalData, attendance: filteredAndSearchedA
|
|||||||
role="switch"
|
role="switch"
|
||||||
id="inactiveEmployeesCheckbox"
|
id="inactiveEmployeesCheckbox"
|
||||||
disabled={isFetching}
|
disabled={isFetching}
|
||||||
checked={showOnlyCheckout} // Use prop for checked state
|
checked={ShowPending}
|
||||||
onChange={(e) => setshowOnlyCheckout(e.target.checked)} // Use prop for onChange
|
onChange={(e) => setShowPending(e.target.checked)}
|
||||||
/>
|
/>
|
||||||
<label className="form-check-label ms-0">Show Pending</label>
|
<label className="form-check-label ms-0">Show Pending</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/* Use `filteredAndSearchedAttendanceFromParent` for the initial check of data presence */}
|
{Array.isArray(attendance) && attendance.length > 0 ? (
|
||||||
{Array.isArray(filteredAndSearchedAttendanceFromParent) && filteredAndSearchedAttendanceFromParent.length > 0 ? (
|
|
||||||
<>
|
<>
|
||||||
<table className="table ">
|
<table className="table ">
|
||||||
<thead>
|
<thead>
|
||||||
@ -122,7 +124,7 @@ const Attendance = ({ getRole, handleModalData, attendance: filteredAndSearchedA
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="table-border-bottom-0 ">
|
<tbody className="table-border-bottom-0 ">
|
||||||
{currentItems && currentItems.length > 0 ? ( // Check currentItems length before mapping
|
{currentItems &&
|
||||||
currentItems
|
currentItems
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
const checkInA = a?.checkInTime
|
const checkInA = a?.checkInTime
|
||||||
@ -179,22 +181,18 @@ const Attendance = ({ getRole, handleModalData, attendance: filteredAndSearchedA
|
|||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))
|
))}
|
||||||
) : (
|
{!attendance && (
|
||||||
<tr>
|
<span className="text-secondary m-4">No employees assigned to the project!</span>
|
||||||
<td colSpan="6" className="text-center text-muted py-4">
|
|
||||||
No matching records found.
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
)}
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{!attLoading && finalFilteredDataForPagination.length > ITEMS_PER_PAGE && ( // Use the data before pagination for total count check
|
{!loading && filteredData.length > 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 ${
|
className={`page-item ${
|
||||||
currentPage === 1 ? "disabled" : ""
|
currentPage === 1 ? "disabled" : ""
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
@ -240,16 +238,14 @@ const Attendance = ({ getRole, handleModalData, attendance: filteredAndSearchedA
|
|||||||
<div>Loading...</div>
|
<div>Loading...</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="text-muted">
|
<div className="text-muted">
|
||||||
{/* Check the actual prop passed for initial data presence */}
|
{Array.isArray(attendance)
|
||||||
{Array.isArray(filteredAndSearchedAttendanceFromParent) && filteredAndSearchedAttendanceFromParent.length === 0
|
? "No employees assigned to the project"
|
||||||
? ""
|
: "Attendance data unavailable"}
|
||||||
: "Attendance data unavailable."}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* This condition should check `currentItems` or `finalFilteredDataForPagination` */}
|
{currentItems?.length == 0 && attendance.length > 0 && (
|
||||||
{currentItems?.length === 0 && finalFilteredDataForPagination.length > 0 && showOnlyCheckout && (
|
<div className="my-4"><span className="text-secondary">No Pending Record Available !</span></div>
|
||||||
<div className="my-4"><span className="text-secondary">No Pending Record Available for your search!</span></div>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -4,31 +4,24 @@ import Avatar from "../common/Avatar";
|
|||||||
import { convertShortTime } from "../../utils/dateUtils";
|
import { convertShortTime } from "../../utils/dateUtils";
|
||||||
import RenderAttendanceStatus from "./RenderAttendanceStatus";
|
import RenderAttendanceStatus from "./RenderAttendanceStatus";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { fetchAttendanceData, setAttendanceData } from "../../slices/apiSlice/attedanceLogsSlice";
|
import { fetchAttendanceData } from "../../slices/apiSlice/attedanceLogsSlice";
|
||||||
import DateRangePicker from "../common/DateRangePicker";
|
import DateRangePicker from "../common/DateRangePicker";
|
||||||
|
import { clearCacheKey, getCachedData } from "../../slices/apiDataManager";
|
||||||
import eventBus from "../../services/eventBus";
|
import eventBus from "../../services/eventBus";
|
||||||
|
import AttendanceRepository from "../../repositories/AttendanceRepository";
|
||||||
|
import { useAttendancesLogs } from "../../hooks/useAttendance";
|
||||||
|
import { queryClient } from "../../layouts/AuthLayout";
|
||||||
|
|
||||||
const usePagination = (data, itemsPerPage) => {
|
const usePagination = (data, itemsPerPage) => {
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const totalItems = Array.isArray(data) ? data.length : 0;
|
const maxPage = Math.ceil(data.length / itemsPerPage);
|
||||||
const maxPage = Math.ceil(totalItems / itemsPerPage);
|
|
||||||
|
|
||||||
const currentItems = useMemo(() => {
|
const currentItems = useMemo(() => {
|
||||||
if (!Array.isArray(data) || data.length === 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
const startIndex = (currentPage - 1) * itemsPerPage;
|
const startIndex = (currentPage - 1) * itemsPerPage;
|
||||||
const endIndex = startIndex + itemsPerPage;
|
const endIndex = startIndex + itemsPerPage;
|
||||||
return data.slice(startIndex, endIndex);
|
return data.slice(startIndex, endIndex);
|
||||||
}, [data, currentPage, itemsPerPage]);
|
}, [data, currentPage, itemsPerPage]);
|
||||||
|
|
||||||
const paginate = useCallback((pageNumber) => {
|
const paginate = useCallback((pageNumber) => setCurrentPage(pageNumber), []);
|
||||||
if (pageNumber > 0 && pageNumber <= maxPage) {
|
|
||||||
setCurrentPage(pageNumber);
|
|
||||||
}
|
|
||||||
}, [maxPage]);
|
|
||||||
|
|
||||||
// Ensure resetPage is returned by the hook
|
|
||||||
const resetPage = useCallback(() => setCurrentPage(1), []);
|
const resetPage = useCallback(() => setCurrentPage(1), []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -42,91 +35,60 @@ const usePagination = (data, itemsPerPage) => {
|
|||||||
|
|
||||||
const AttendanceLog = ({
|
const AttendanceLog = ({
|
||||||
handleModalData,
|
handleModalData,
|
||||||
projectId,
|
|
||||||
setshowOnlyCheckout,
|
|
||||||
showOnlyCheckout,
|
|
||||||
searchQuery, // Prop for search query
|
|
||||||
}) => {
|
}) => {
|
||||||
|
const selectedProject = useSelector(
|
||||||
|
(store) => store.localVariables.projectId
|
||||||
|
);
|
||||||
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 [loading, setLoading] = useState(false);
|
||||||
|
const [showPending,setShowPending] = useState(false)
|
||||||
|
|
||||||
const [isRefreshing, setIsRefreshing] = useState(false);
|
const [isRefreshing, setIsRefreshing] = useState(false);
|
||||||
|
const [processedData, setProcessedData] = useState([]);
|
||||||
|
|
||||||
const today = useMemo(() => {
|
const today = new Date();
|
||||||
const d = new Date();
|
today.setHours(0, 0, 0, 0);
|
||||||
d.setHours(0, 0, 0, 0);
|
|
||||||
return d;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const yesterday = useMemo(() => {
|
const yesterday = new Date();
|
||||||
const d = new Date();
|
yesterday.setDate(yesterday.getDate() - 1);
|
||||||
d.setDate(d.getDate() - 1);
|
|
||||||
return d;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const isSameDay = useCallback((dateStr) => {
|
const isSameDay = (dateStr) => {
|
||||||
if (!dateStr) return false;
|
if (!dateStr) return false;
|
||||||
const d = new Date(dateStr);
|
const d = new Date(dateStr);
|
||||||
d.setHours(0, 0, 0, 0);
|
d.setHours(0, 0, 0, 0);
|
||||||
return d.getTime() === today.getTime();
|
return d.getTime() === today.getTime();
|
||||||
}, [today]);
|
};
|
||||||
|
|
||||||
const isBeforeToday = useCallback((dateStr) => {
|
const isBeforeToday = (dateStr) => {
|
||||||
if (!dateStr) return false;
|
if (!dateStr) return false;
|
||||||
const d = new Date(dateStr);
|
const d = new Date(dateStr);
|
||||||
d.setHours(0, 0, 0, 0);
|
d.setHours(0, 0, 0, 0);
|
||||||
return d.getTime() < today.getTime();
|
return d.getTime() < today.getTime();
|
||||||
}, [today]);
|
};
|
||||||
|
|
||||||
const sortByName = useCallback((a, b) => {
|
const sortByName = (a, b) => {
|
||||||
const nameA = `${a.firstName || ""} ${a.lastName || ""}`.toLowerCase();
|
const nameA = a.firstName.toLowerCase() + a.lastName.toLowerCase();
|
||||||
const nameB = `${b.firstName || ""} ${b.lastName || ""}`.toLowerCase();
|
const nameB = b.firstName.toLowerCase() + b.lastName.toLowerCase();
|
||||||
return nameA.localeCompare(nameB);
|
return nameA?.localeCompare(nameB);
|
||||||
}, []);
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
const {
|
||||||
const { startDate, endDate } = dateRange;
|
data = [],
|
||||||
dispatch(
|
isLoading,
|
||||||
fetchAttendanceData({
|
error,
|
||||||
projectId,
|
refetch,
|
||||||
fromDate: startDate,
|
isFetching,
|
||||||
toDate: endDate,
|
} = useAttendancesLogs(
|
||||||
})
|
selectedProject,
|
||||||
);
|
dateRange.startDate,
|
||||||
setIsRefreshing(false);
|
dateRange.endDate
|
||||||
}, [dateRange, projectId, dispatch, isRefreshing]);
|
);
|
||||||
|
const filtering = (data) => {
|
||||||
const processedData = useMemo(() => {
|
const filteredData = showPending
|
||||||
let filteredData = showOnlyCheckout
|
|
||||||
? data.filter((item) => item.checkOutTime === null)
|
? data.filter((item) => item.checkOutTime === null)
|
||||||
: data;
|
: data;
|
||||||
|
|
||||||
// Apply search query filter
|
|
||||||
if (searchQuery) {
|
|
||||||
const lowerCaseSearchQuery = searchQuery.toLowerCase().trim(); // Trim whitespace
|
|
||||||
|
|
||||||
filteredData = filteredData.filter((att) => {
|
|
||||||
// Option 1: Combine firstName, middleName, lastName
|
|
||||||
const fullName = [att.firstName, att.middleName, att.lastName]
|
|
||||||
.filter(Boolean) // This removes null, undefined, or empty string parts
|
|
||||||
.join(" ")
|
|
||||||
.toLowerCase();
|
|
||||||
|
|
||||||
// Option 2: Check `employeeName` if it exists and is reliable
|
|
||||||
const employeeName = att.employeeName?.toLowerCase() || "";
|
|
||||||
|
|
||||||
// Option 3: Check `employeeId`
|
|
||||||
const employeeId = att.employeeId?.toLowerCase() || "";
|
|
||||||
|
|
||||||
// Check if the search query is included in any of the relevant fields
|
|
||||||
return (
|
|
||||||
fullName.includes(lowerCaseSearchQuery) ||
|
|
||||||
employeeName.includes(lowerCaseSearchQuery) ||
|
|
||||||
employeeId.includes(lowerCaseSearchQuery)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const group1 = filteredData
|
const group1 = filteredData
|
||||||
.filter((d) => d.activity === 1 && isSameDay(d.checkInTime))
|
.filter((d) => d.activity === 1 && isSameDay(d.checkInTime))
|
||||||
.sort(sortByName);
|
.sort(sortByName);
|
||||||
@ -165,46 +127,53 @@ const AttendanceLog = ({
|
|||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
// Sort dates in descending order
|
|
||||||
const sortedDates = Object.keys(groupedByDate).sort(
|
const sortedDates = Object.keys(groupedByDate).sort(
|
||||||
(a, b) => new Date(b) - new Date(a)
|
(a, b) => new Date(b) - new Date(a)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create the final sorted array
|
const finalData = sortedDates.flatMap((date) => groupedByDate[date]);
|
||||||
return sortedDates.flatMap((date) => groupedByDate[date]);
|
setProcessedData(finalData);
|
||||||
}, [data, showOnlyCheckout, searchQuery, isSameDay, isBeforeToday, sortByName]);
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
filtering(data);
|
||||||
|
}, [data, showPending]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
currentPage,
|
currentPage,
|
||||||
totalPages,
|
totalPages,
|
||||||
currentItems: paginatedAttendances,
|
currentItems: paginatedAttendances,
|
||||||
paginate,
|
paginate,
|
||||||
resetPage, // Destructure resetPage here
|
resetPage,
|
||||||
} = usePagination(processedData, 20);
|
} = usePagination(processedData, 20);
|
||||||
|
|
||||||
// Effect to reset pagination when search query changes
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
resetPage();
|
resetPage();
|
||||||
}, [searchQuery, resetPage]); // Add resetPage to dependencies
|
}, [processedData, resetPage]);
|
||||||
|
|
||||||
const handler = useCallback(
|
const handler = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
const { startDate, endDate } = dateRange;
|
const { startDate, endDate } = dateRange;
|
||||||
const checkIn = msg.response.checkInTime.substring(0, 10);
|
const checkIn = msg.response.checkInTime.substring(0, 10);
|
||||||
if (
|
if (
|
||||||
projectId === msg.projectId &&
|
selectedProject === msg.projectId &&
|
||||||
startDate <= checkIn &&
|
startDate <= checkIn &&
|
||||||
checkIn <= endDate
|
checkIn <= endDate
|
||||||
) {
|
) {
|
||||||
const updatedAttendance = data.map((item) =>
|
queryClient.setQueriesData(["attendanceLogs"],(oldData)=>{
|
||||||
item.id === msg.response.id
|
if(!oldData) {
|
||||||
? { ...item, ...msg.response }
|
queryClient.invalidateQueries({queryKey:["attendanceLogs"]})
|
||||||
: item
|
}
|
||||||
|
return oldData.map((record) =>
|
||||||
|
record.id === msg.response.id ? { ...record, ...msg.response } : record
|
||||||
);
|
);
|
||||||
dispatch(setAttendanceData(updatedAttendance)); // Update Redux store
|
})
|
||||||
|
|
||||||
|
filtering(updatedAttendance);
|
||||||
|
resetPage();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[projectId, dateRange, data, dispatch]
|
[selectedProject, dateRange, data, filtering, resetPage]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -215,15 +184,19 @@ const AttendanceLog = ({
|
|||||||
const employeeHandler = useCallback(
|
const employeeHandler = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
const { startDate, endDate } = dateRange;
|
const { startDate, endDate } = dateRange;
|
||||||
dispatch(
|
if (data.some((item) => item.employeeId == msg.employeeId)) {
|
||||||
fetchAttendanceData({
|
// dispatch(
|
||||||
projectId,
|
// fetchAttendanceData({
|
||||||
fromDate: startDate,
|
// ,
|
||||||
toDate: endDate,
|
// fromDate: startDate,
|
||||||
})
|
// toDate: endDate,
|
||||||
);
|
// })
|
||||||
|
// );
|
||||||
|
|
||||||
|
refetch()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[projectId, dateRange, dispatch]
|
[selectedProject, dateRange, data]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -247,27 +220,28 @@ const AttendanceLog = ({
|
|||||||
type="checkbox"
|
type="checkbox"
|
||||||
className="form-check-input"
|
className="form-check-input"
|
||||||
role="switch"
|
role="switch"
|
||||||
|
disabled={isFetching}
|
||||||
id="inactiveEmployeesCheckbox"
|
id="inactiveEmployeesCheckbox"
|
||||||
checked={showOnlyCheckout}
|
checked={showPending}
|
||||||
onChange={(e) => setshowOnlyCheckout(e.target.checked)}
|
onChange={(e) => setShowPending(e.target.checked)}
|
||||||
/>
|
/>
|
||||||
<label className="form-check-label ms-0">Show Pending</label>
|
<label className="form-check-label ms-0">Show Pending</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-md-2 m-0 text-end">
|
<div className="col-md-2 m-0 text-end">
|
||||||
<i
|
<i
|
||||||
className={`bx bx-refresh cursor-pointer fs-4 ${loading || isRefreshing ? "spin" : ""
|
className={`bx bx-refresh cursor-pointer fs-4 ${
|
||||||
}`}
|
isFetching ? "spin" : ""
|
||||||
|
}`}
|
||||||
title="Refresh"
|
title="Refresh"
|
||||||
onClick={() => setIsRefreshing(true)}
|
onClick={() => refetch()}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div className="table-responsive text-nowrap">
|
||||||
className="table-responsive text-nowrap"
|
{isLoading ? (
|
||||||
style={{ minHeight: "200px", display: 'flex' }}
|
<div><p className="text-secondary">Loading...</p></div>
|
||||||
>
|
) : data?.length > 0 ? (
|
||||||
{processedData && processedData.length > 0 ? (
|
|
||||||
<table className="table mb-0">
|
<table className="table mb-0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -286,96 +260,82 @@ const AttendanceLog = ({
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{(loading || isRefreshing) && (
|
{paginatedAttendances.reduce((acc, attendance, index, arr) => {
|
||||||
<tr>
|
const currentDate = moment(
|
||||||
<td colSpan={6}>Loading...</td>
|
attendance.checkInTime || attendance.checkOutTime
|
||||||
</tr>
|
).format("YYYY-MM-DD");
|
||||||
)}
|
const previousAttendance = arr[index - 1];
|
||||||
{!loading &&
|
const previousDate = previousAttendance
|
||||||
!isRefreshing &&
|
? moment(
|
||||||
paginatedAttendances.reduce((acc, attendance, index, arr) => {
|
|
||||||
const currentDate = moment(
|
|
||||||
attendance.checkInTime || attendance.checkOutTime
|
|
||||||
).format("YYYY-MM-DD");
|
|
||||||
const previousAttendance = arr[index - 1];
|
|
||||||
const previousDate = previousAttendance
|
|
||||||
? moment(
|
|
||||||
previousAttendance.checkInTime ||
|
previousAttendance.checkInTime ||
|
||||||
previousAttendance.checkOutTime
|
previousAttendance.checkOutTime
|
||||||
).format("YYYY-MM-DD")
|
).format("YYYY-MM-DD")
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
if (!previousDate || currentDate !== previousDate) {
|
if (!previousDate || currentDate !== previousDate) {
|
||||||
acc.push(
|
|
||||||
<tr
|
|
||||||
key={`header-${currentDate}`}
|
|
||||||
className="table-row-header"
|
|
||||||
>
|
|
||||||
<td colSpan={6} className="text-start">
|
|
||||||
<strong>
|
|
||||||
{moment(currentDate).format("DD-MM-YYYY")}
|
|
||||||
</strong>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
acc.push(
|
acc.push(
|
||||||
<tr key={attendance.id || index}>
|
<tr
|
||||||
<td colSpan={2}>
|
key={`header-${currentDate}`}
|
||||||
<div className="d-flex justify-content-start align-items-center">
|
className="table-row-header"
|
||||||
<Avatar
|
>
|
||||||
firstName={attendance.firstName}
|
<td colSpan={6} className="text-start">
|
||||||
lastName={attendance.lastName}
|
<strong>
|
||||||
/>
|
{moment(currentDate).format("DD-MM-YYYY")}
|
||||||
<div className="d-flex flex-column">
|
</strong>
|
||||||
<a href="#" className="text-heading text-truncate">
|
|
||||||
<span className="fw-normal">
|
|
||||||
{attendance.firstName} {attendance.lastName}
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{moment(
|
|
||||||
attendance.checkInTime || attendance.checkOutTime
|
|
||||||
).format("DD-MMM-YYYY")}
|
|
||||||
</td>
|
|
||||||
<td>{convertShortTime(attendance.checkInTime)}</td>
|
|
||||||
<td>
|
|
||||||
{attendance.checkOutTime
|
|
||||||
? convertShortTime(attendance.checkOutTime)
|
|
||||||
: "--"}
|
|
||||||
</td>
|
|
||||||
<td className="text-center">
|
|
||||||
<RenderAttendanceStatus
|
|
||||||
attendanceData={attendance}
|
|
||||||
handleModalData={handleModalData}
|
|
||||||
Tab={2}
|
|
||||||
currentDate={today.toLocaleDateString("en-CA")}
|
|
||||||
/>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
return acc;
|
}
|
||||||
}, [])}
|
acc.push(
|
||||||
|
<tr key={index}>
|
||||||
|
<td colSpan={2}>
|
||||||
|
<div className="d-flex justify-content-start align-items-center">
|
||||||
|
<Avatar
|
||||||
|
firstName={attendance.firstName}
|
||||||
|
lastName={attendance.lastName}
|
||||||
|
/>
|
||||||
|
<div className="d-flex flex-column">
|
||||||
|
<a href="#" className="text-heading text-truncate">
|
||||||
|
<span className="fw-normal">
|
||||||
|
{attendance.firstName} {attendance.lastName}
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{moment(
|
||||||
|
attendance.checkInTime || attendance.checkOutTime
|
||||||
|
).format("DD-MMM-YYYY")}
|
||||||
|
</td>
|
||||||
|
<td>{convertShortTime(attendance.checkInTime)}</td>
|
||||||
|
<td>
|
||||||
|
{attendance.checkOutTime
|
||||||
|
? convertShortTime(attendance.checkOutTime)
|
||||||
|
: "--"}
|
||||||
|
</td>
|
||||||
|
<td className="text-center">
|
||||||
|
<RenderAttendanceStatus
|
||||||
|
attendanceData={attendance}
|
||||||
|
handleModalData={handleModalData}
|
||||||
|
Tab={2}
|
||||||
|
currentDate={today.toLocaleDateString("en-CA")}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
return acc;
|
||||||
|
}, [])}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
) : (
|
) : (
|
||||||
!loading &&
|
<div className="my-4"><span className="text-secondary">No Record Available !</span></div>
|
||||||
!isRefreshing && (
|
|
||||||
<div
|
|
||||||
className="d-flex justify-content-center align-items-center text-muted"
|
|
||||||
style={{
|
|
||||||
width: "100%",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
No employee logs.
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{!loading && !isRefreshing && processedData.length > 20 && (
|
{paginatedAttendances?.length == 0 && data?.length > 0 && (
|
||||||
|
<div className="my-4"><span className="text-secondary">No Pending Record Available !</span></div>
|
||||||
|
)}
|
||||||
|
{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" : ""}`}>
|
||||||
@ -390,8 +350,9 @@ const AttendanceLog = ({
|
|||||||
(pageNumber) => (
|
(pageNumber) => (
|
||||||
<li
|
<li
|
||||||
key={pageNumber}
|
key={pageNumber}
|
||||||
className={`page-item ${currentPage === pageNumber ? "active" : ""
|
className={`page-item ${
|
||||||
}`}
|
currentPage === pageNumber ? "active" : ""
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="page-link"
|
className="page-link"
|
||||||
@ -403,8 +364,9 @@ const AttendanceLog = ({
|
|||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
<li
|
<li
|
||||||
className={`page-item ${currentPage === totalPages ? "disabled" : ""
|
className={`page-item ${
|
||||||
}`}
|
currentPage === totalPages ? "disabled" : ""
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="page-link"
|
className="page-link"
|
||||||
@ -420,4 +382,4 @@ const AttendanceLog = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AttendanceLog;
|
export default AttendanceLog;
|
||||||
|
|||||||
@ -10,12 +10,6 @@ import showToast from "../../services/toastService";
|
|||||||
import { checkIfCurrentDate } from "../../utils/dateUtils";
|
import { checkIfCurrentDate } from "../../utils/dateUtils";
|
||||||
import { useMarkAttendance } from "../../hooks/useAttendance";
|
import { useMarkAttendance } from "../../hooks/useAttendance";
|
||||||
|
|
||||||
|
|
||||||
// const schema = z.object({
|
|
||||||
// markTime: z.string().nonempty({ message: "Time is required" }),
|
|
||||||
// description: z.string().max(200, "description should less than 200 chracters").optional()
|
|
||||||
// });
|
|
||||||
|
|
||||||
const createSchema = (modeldata) => {
|
const createSchema = (modeldata) => {
|
||||||
return z
|
return z
|
||||||
.object({
|
.object({
|
||||||
@ -48,83 +42,74 @@ const createSchema = (modeldata) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm }) => {
|
||||||
const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
|
const projectId = useSelector((store) => store.localVariables.projectId);
|
||||||
|
const { mutate: MarkAttendance } = useMarkAttendance();
|
||||||
const projectId = useSelector((store) => store.localVariables.projectId)
|
|
||||||
const {mutate:MarkAttendance} = useMarkAttendance()
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const coords = usePositionTracker();
|
const coords = usePositionTracker();
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch();
|
||||||
const today = new Date().toISOString().split('T')[0];
|
const today = new Date().toISOString().split("T")[0];
|
||||||
|
|
||||||
const formatDate = (dateString) => {
|
const formatDate = (dateString) => {
|
||||||
if (!dateString) {
|
if (!dateString) {
|
||||||
return '';
|
return "";
|
||||||
}
|
}
|
||||||
const [year, month, day] = dateString.split('-');
|
const [year, month, day] = dateString.split("-");
|
||||||
return `${day}-${month}-${year}`;
|
return `${day}-${month}-${year}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
// const {
|
|
||||||
// register,
|
|
||||||
// handleSubmit,
|
|
||||||
// formState: { errors },
|
|
||||||
// reset,
|
|
||||||
// setValue,
|
|
||||||
// } = useForm({
|
|
||||||
// resolver: zodResolver(schema),
|
|
||||||
// mode: "onChange"
|
|
||||||
// });
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
reset,
|
reset,
|
||||||
setValue,
|
setValue,
|
||||||
} = useForm({
|
} = useForm({
|
||||||
resolver: zodResolver(createSchema(modeldata)),
|
resolver: zodResolver(createSchema(modeldata)),
|
||||||
mode: "onChange",
|
mode: "onChange",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const onSubmit = (data) => {
|
const onSubmit = (data) => {
|
||||||
let record = { ...data, date: new Date().toLocaleDateString(), latitude: coords.latitude, longitude: coords.longitude, employeeId: modeldata.employeeId, action: modeldata.action, id: modeldata?.id || null }
|
let record = {
|
||||||
if (modeldata.forWhichTab === 1) {
|
...data,
|
||||||
handleSubmitForm(record)
|
date: new Date().toLocaleDateString(),
|
||||||
} else {
|
latitude: coords.latitude,
|
||||||
|
longitude: coords.longitude,
|
||||||
dispatch(markAttendance(record))
|
employeeId: modeldata.employeeId,
|
||||||
.unwrap()
|
action: modeldata.action,
|
||||||
.then((data) => {
|
id: modeldata?.id || null,
|
||||||
|
};
|
||||||
// showToast("Attendance Marked Successfully", "success");
|
const payload = {
|
||||||
// })
|
Id: modeldata?.id || null,
|
||||||
// .catch((error) => {
|
comment: data.description,
|
||||||
|
employeeID: modeldata.employeeId,
|
||||||
// showToast(error, "error");
|
projectId: projectId,
|
||||||
|
date: new Date().toISOString(),
|
||||||
});
|
markTime: data.markTime,
|
||||||
}
|
latitude: coords.latitude.toString(),
|
||||||
|
longitude: coords.longitude.toString(),
|
||||||
closeModal()
|
action: modeldata.action,
|
||||||
|
image: null,
|
||||||
|
};
|
||||||
|
MarkAttendance({ payload, forWhichTab: modeldata.forWhichTab });
|
||||||
|
closeModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
|
|
||||||
<form className="row g-2" onSubmit={handleSubmit(onSubmit)}>
|
<form className="row g-2" onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
|
||||||
<div className="col-12 col-md-12">
|
<div className="col-12 col-md-12">
|
||||||
<label className="fs-5 text-dark text-center d-flex align-items-center flex-wrap">
|
<label className="fs-5 text-dark text-center d-flex align-items-center flex-wrap">
|
||||||
{modeldata?.checkInTime && !modeldata?.checkOutTime ? 'Check-out :' : 'Check-in :'}
|
{modeldata?.checkInTime && !modeldata?.checkOutTime
|
||||||
|
? "Check-out :"
|
||||||
|
: "Check-in :"}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="col-6 col-md-6 ">
|
<div className="col-6 col-md-6 ">
|
||||||
<label className="form-label" htmlFor="checkInDate">
|
<label className="form-label" htmlFor="checkInDate">
|
||||||
{modeldata?.checkInTime && !modeldata?.checkOutTime ? 'Check-out Date' : 'Check-in Date'}
|
{modeldata?.checkInTime && !modeldata?.checkOutTime
|
||||||
|
? "Check-out Date"
|
||||||
|
: "Check-in Date"}
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
@ -132,7 +117,7 @@ const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
|
|||||||
className="form-control"
|
className="form-control"
|
||||||
value={
|
value={
|
||||||
modeldata?.checkInTime && !modeldata?.checkOutTime
|
modeldata?.checkInTime && !modeldata?.checkOutTime
|
||||||
? formatDate(modeldata?.checkInTime?.split('T')[0]) || ''
|
? formatDate(modeldata?.checkInTime?.split("T")[0]) || ""
|
||||||
: formatDate(today)
|
: formatDate(today)
|
||||||
}
|
}
|
||||||
disabled
|
disabled
|
||||||
@ -147,7 +132,9 @@ const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
|
|||||||
checkOutTime={modeldata?.checkOutTime}
|
checkOutTime={modeldata?.checkOutTime}
|
||||||
checkInTime={modeldata?.checkInTime}
|
checkInTime={modeldata?.checkInTime}
|
||||||
/>
|
/>
|
||||||
{errors.markTime && <p className="text-danger">{errors.markTime.message}</p>}
|
{errors.markTime && (
|
||||||
|
<p className="text-danger">{errors.markTime.message}</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="col-12 col-md-12">
|
<div className="col-12 col-md-12">
|
||||||
@ -166,7 +153,6 @@ const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div className="col-12 text-center">
|
<div className="col-12 text-center">
|
||||||
<button type="submit" className="btn btn-sm btn-primary me-3">
|
<button type="submit" className="btn btn-sm btn-primary me-3">
|
||||||
{isLoading ? "Please Wait..." : "Submit"}
|
{isLoading ? "Please Wait..." : "Submit"}
|
||||||
@ -182,20 +168,15 @@ const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
);
|
||||||
)
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export default CheckCheckOutmodel;
|
export default CheckCheckOutmodel;
|
||||||
|
|
||||||
|
|
||||||
const schemaReg = z.object({
|
const schemaReg = z.object({
|
||||||
description: z.string().min(1, { message: "please give reason!" })
|
description: z.string().min(1, { message: "please give reason!" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const Regularization = ({ modeldata, closeModal, handleSubmitForm }) => {
|
export const Regularization = ({ modeldata, closeModal, handleSubmitForm }) => {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const coords = usePositionTracker();
|
const coords = usePositionTracker();
|
||||||
@ -210,21 +191,22 @@ export const Regularization = ({ modeldata, closeModal, handleSubmitForm }) => {
|
|||||||
|
|
||||||
const getCurrentDate = () => {
|
const getCurrentDate = () => {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
return today.toLocaleDateString('en-CA');
|
return today.toLocaleDateString("en-CA");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const onSubmit = (data) => {
|
const onSubmit = (data) => {
|
||||||
let record = { ...data, date: new Date().toLocaleDateString(), latitude: coords.latitude, longitude: coords.longitude, }
|
let record = {
|
||||||
handleSubmitForm(record)
|
...data,
|
||||||
closeModal()
|
date: new Date().toLocaleDateString(),
|
||||||
|
latitude: coords.latitude,
|
||||||
|
longitude: coords.longitude,
|
||||||
|
};
|
||||||
|
handleSubmitForm(record);
|
||||||
|
closeModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
|
|
||||||
<form className="row g-2" onSubmit={handleSubmit(onSubmit)}>
|
<form className="row g-2" onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
|
||||||
<div className="col-12 col-md-12">
|
<div className="col-12 col-md-12">
|
||||||
<p>Regularize Attendance</p>
|
<p>Regularize Attendance</p>
|
||||||
<label className="form-label" htmlFor="description">
|
<label className="form-label" htmlFor="description">
|
||||||
@ -241,7 +223,6 @@ export const Regularization = ({ modeldata, closeModal, handleSubmitForm }) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div className="col-12 text-center">
|
<div className="col-12 text-center">
|
||||||
<button type="submit" className="btn btn-sm btn-primary me-3">
|
<button type="submit" className="btn btn-sm btn-primary me-3">
|
||||||
{isLoading ? "Please Wait..." : "Submit"}
|
{isLoading ? "Please Wait..." : "Submit"}
|
||||||
@ -257,6 +238,5 @@ export const Regularization = ({ modeldata, closeModal, handleSubmitForm }) => {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
);
|
||||||
)
|
};
|
||||||
}
|
|
||||||
|
|||||||
@ -7,37 +7,56 @@ import { useRegularizationRequests } from "../../hooks/useAttendance";
|
|||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import usePagination from "../../hooks/usePagination";
|
import usePagination from "../../hooks/usePagination";
|
||||||
import eventBus from "../../services/eventBus";
|
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 Regularization = ({ handleRequest }) => {
|
||||||
const selectedProject = useSelector((store) => store.localVariables.projectId);
|
const queryClient = useQueryClient();
|
||||||
const [regularizesList, setRegularizedList] = useState([]);
|
var selectedProject = useSelector((store) => store.localVariables.projectId);
|
||||||
const { regularizes, loading, refetch } = useRegularizationRequests(selectedProject);
|
const [regularizesList, setregularizedList] = useState([]);
|
||||||
|
const { regularizes, loading, error, refetch } =
|
||||||
|
useRegularizationRequests(selectedProject);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setRegularizedList(regularizes);
|
setregularizedList(regularizes);
|
||||||
}, [regularizes]);
|
}, [regularizes]);
|
||||||
|
|
||||||
const sortByName = (a, b) => {
|
const sortByName = (a, b) => {
|
||||||
const nameA = (a.firstName + a.lastName).toLowerCase();
|
const nameA = a.firstName.toLowerCase() + a.lastName.toLowerCase();
|
||||||
const nameB = (b.firstName + b.lastName).toLowerCase();
|
const nameB = b.firstName.toLowerCase() + b.lastName.toLowerCase();
|
||||||
return nameA.localeCompare(nameB);
|
return nameA?.localeCompare(nameB);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handler = useCallback(
|
const handler = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
if (selectedProject == msg.projectId) {
|
if (selectedProject == msg.projectId) {
|
||||||
const updatedAttendance = regularizes?.filter(item => item.id !== msg.response.id);
|
|
||||||
cacheData("regularizedList", {
|
|
||||||
data: updatedAttendance,
|
queryClient.setQueryData(
|
||||||
projectId: selectedProject,
|
["regularizedList", selectedProject],
|
||||||
});
|
(oldData) => {
|
||||||
refetch();
|
if (!oldData) {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["regularizedList"] });
|
||||||
|
}
|
||||||
|
return oldData.filter((record) => record.id !== msg.response.id);
|
||||||
|
}
|
||||||
|
),
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["attendanceLogs"] });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[selectedProject, regularizes]
|
[selectedProject, regularizes]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const filteredData = [...regularizesList]?.sort(sortByName);
|
||||||
|
|
||||||
|
const { currentPage, totalPages, currentItems, paginate } = usePagination(
|
||||||
|
filteredData,
|
||||||
|
20
|
||||||
|
);
|
||||||
|
useEffect(() => {
|
||||||
|
eventBus.on("regularization", handler);
|
||||||
|
return () => eventBus.off("regularization", handler);
|
||||||
|
}, [handler]);
|
||||||
|
|
||||||
const employeeHandler = useCallback(
|
const employeeHandler = useCallback(
|
||||||
(msg) => {
|
(msg) => {
|
||||||
@ -48,57 +67,41 @@ const Regularization = ({ handleRequest, searchQuery }) => {
|
|||||||
[regularizes]
|
[regularizes]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
eventBus.on("regularization", handler);
|
|
||||||
return () => eventBus.off("regularization", handler);
|
|
||||||
}, [handler]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
eventBus.on("employee", employeeHandler);
|
eventBus.on("employee", employeeHandler);
|
||||||
return () => eventBus.off("employee", employeeHandler);
|
return () => eventBus.off("employee", employeeHandler);
|
||||||
}, [employeeHandler]);
|
}, [employeeHandler]);
|
||||||
|
|
||||||
// ✅ Search filter logic added here
|
|
||||||
const filteredData = [...regularizesList]
|
|
||||||
?.filter((item) => {
|
|
||||||
if (!searchQuery) return true;
|
|
||||||
const lowerSearch = searchQuery.toLowerCase();
|
|
||||||
const fullName = `${item.firstName || ""} ${item.lastName || ""}`.toLowerCase();
|
|
||||||
|
|
||||||
return (
|
|
||||||
item.firstName?.toLowerCase().includes(lowerSearch) ||
|
|
||||||
item.lastName?.toLowerCase().includes(lowerSearch) ||
|
|
||||||
fullName.includes(lowerSearch) ||
|
|
||||||
item.employeeId?.toLowerCase().includes(lowerSearch)
|
|
||||||
);
|
|
||||||
})
|
|
||||||
.sort(sortByName);
|
|
||||||
|
|
||||||
const { currentPage, totalPages, currentItems, paginate } = usePagination(filteredData, 20);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="table-responsive text-nowrap pb-4">
|
<div className="table-responsive text-nowrap pb-4">
|
||||||
<table className="table mb-0">
|
{loading ? (
|
||||||
<thead>
|
<div className="my-2">
|
||||||
<tr>
|
<p className="text-secondary">Loading...</p>
|
||||||
<th colSpan={2}>Name</th>
|
</div>
|
||||||
<th>Date</th>
|
) : currentItems?.length > 0 ? (
|
||||||
<th>
|
<table className="table mb-0">
|
||||||
<i className="bx bxs-down-arrow-alt text-success"></i>Check-In
|
<thead>
|
||||||
</th>
|
<tr>
|
||||||
<th>
|
<th colSpan={2}>Name</th>
|
||||||
<i className="bx bxs-up-arrow-alt text-danger"></i>Check-Out
|
<th>Date</th>
|
||||||
</th>
|
<th>
|
||||||
<th>Action</th>
|
<i className="bx bxs-down-arrow-alt text-success"></i>Check-In
|
||||||
</tr>
|
</th>
|
||||||
</thead>
|
<th>
|
||||||
<tbody>
|
<i className="bx bxs-up-arrow-alt text-danger"></i>Check-Out
|
||||||
{!loading && currentItems?.length > 0 ? (
|
</th>
|
||||||
currentItems.map((att, index) => (
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{currentItems?.map((att, index) => (
|
||||||
<tr key={index}>
|
<tr key={index}>
|
||||||
<td colSpan={2}>
|
<td colSpan={2}>
|
||||||
<div className="d-flex justify-content-start align-items-center">
|
<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">
|
<div className="d-flex flex-column">
|
||||||
<a href="#" className="text-heading text-truncate">
|
<a href="#" className="text-heading text-truncate">
|
||||||
<span className="fw-normal">
|
<span className="fw-normal">
|
||||||
@ -113,33 +116,24 @@ const Regularization = ({ handleRequest, searchQuery }) => {
|
|||||||
<td>
|
<td>
|
||||||
{att.checkOutTime ? convertShortTime(att.checkOutTime) : "--"}
|
{att.checkOutTime ? convertShortTime(att.checkOutTime) : "--"}
|
||||||
</td>
|
</td>
|
||||||
<td className="text-center">
|
<td className="text-center ">
|
||||||
<RegularizationActions
|
<RegularizationActions
|
||||||
attendanceData={att}
|
attendanceData={att}
|
||||||
handleRequest={handleRequest}
|
handleRequest={handleRequest}
|
||||||
refresh={refetch}
|
refresh={refetch}
|
||||||
/>
|
/>
|
||||||
|
{/* </div> */}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))
|
))}
|
||||||
) : (
|
</tbody>
|
||||||
<tr>
|
</table>
|
||||||
<td
|
) : (
|
||||||
colSpan={6}
|
<div className="my-4">
|
||||||
className="text-center"
|
{" "}
|
||||||
style={{
|
<span className="text-secondary">No Requests Found !</span>
|
||||||
height: "200px",
|
</div>
|
||||||
verticalAlign: "middle",
|
)}
|
||||||
borderBottom: "none",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{loading ? "Loading..." : "No Record Found"}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
)}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
{!loading && totalPages > 1 && (
|
{!loading && totalPages > 1 && (
|
||||||
<nav aria-label="Page ">
|
<nav aria-label="Page ">
|
||||||
<ul className="pagination pagination-sm justify-content-end py-1 mt-3">
|
<ul className="pagination pagination-sm justify-content-end py-1 mt-3">
|
||||||
@ -154,18 +148,25 @@ const Regularization = ({ handleRequest, searchQuery }) => {
|
|||||||
{[...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 className="page-link" onClick={() => paginate(index + 1)}>
|
<button
|
||||||
|
className="page-link "
|
||||||
|
onClick={() => paginate(index + 1)}
|
||||||
|
>
|
||||||
{index + 1}
|
{index + 1}
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
<li
|
<li
|
||||||
className={`page-item ${currentPage === totalPages ? "disabled" : ""}`}
|
className={`page-item ${
|
||||||
|
currentPage === totalPages ? "disabled" : ""
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="page-link"
|
className="page-link "
|
||||||
onClick={() => paginate(currentPage + 1)}
|
onClick={() => paginate(currentPage + 1)}
|
||||||
>
|
>
|
||||||
»
|
»
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import { useCreateTask } from "../../hooks/useTasks";
|
|||||||
const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
||||||
const maxPlanned =
|
const maxPlanned =
|
||||||
assignData?.workItem?.plannedWork - assignData?.workItem?.completedWork;
|
assignData?.workItem?.plannedWork - assignData?.workItem?.completedWork;
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
selectedEmployees: z
|
selectedEmployees: z
|
||||||
.array(z.string())
|
.array(z.string())
|
||||||
@ -48,9 +49,6 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
const infoRef = useRef(null);
|
const infoRef = useRef(null);
|
||||||
const infoRef1 = useRef(null);
|
const infoRef1 = useRef(null);
|
||||||
|
|
||||||
// State for search term
|
|
||||||
const [searchTerm, setSearchTerm] = useState("");
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof bootstrap !== "undefined") {
|
if (typeof bootstrap !== "undefined") {
|
||||||
if (infoRef.current) {
|
if (infoRef.current) {
|
||||||
@ -83,13 +81,9 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
recallEmployeeData,
|
recallEmployeeData,
|
||||||
} = useEmployeesAllOrByProjectId(false, selectedProject, false);
|
} = useEmployeesAllOrByProjectId(false, selectedProject, false);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { loading } = useMaster();
|
const { data: jobRoleData, loading } = useMaster();
|
||||||
const { data: jobRoleData } = useMaster();
|
|
||||||
|
|
||||||
// Changed to an array to hold multiple selected roles
|
const [selectedRole, setSelectedRole] = useState("all");
|
||||||
const [selectedRoles, setSelectedRoles] = useState(["all"]);
|
|
||||||
// Changed to an array to hold multiple selected roles
|
|
||||||
// const [selectedRoles, setSelectedRoles] = useState(["all"]);
|
|
||||||
const [displayedSelection, setDisplayedSelection] = useState("");
|
const [displayedSelection, setDisplayedSelection] = useState("");
|
||||||
const {
|
const {
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@ -127,79 +121,20 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(changeMaster("Job Role"));
|
dispatch(changeMaster("Job Role"));
|
||||||
// Initial state should reflect "All Roles" selected
|
|
||||||
setSelectedRoles(["all"]);
|
return () => setSelectedRole("all");
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
|
|
||||||
// Modified handleRoleChange to handle multiple selections
|
const handleRoleChange = (event) => {
|
||||||
const handleRoleChange = (event, roleId) => {
|
setSelectedRole(event.target.value);
|
||||||
// If 'all' is selected, clear other selections
|
|
||||||
if (roleId === "all") {
|
|
||||||
setSelectedRoles(["all"]);
|
|
||||||
} else {
|
|
||||||
setSelectedRoles((prevSelectedRoles) => {
|
|
||||||
// If "all" was previously selected, remove it
|
|
||||||
const newRoles = prevSelectedRoles.filter((role) => role !== "all");
|
|
||||||
if (newRoles.includes(roleId)) {
|
|
||||||
// If role is already selected, unselect it
|
|
||||||
return newRoles.filter((id) => id !== roleId);
|
|
||||||
} else {
|
|
||||||
// If role is not selected, add it
|
|
||||||
return [...newRoles, roleId];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
const filteredEmployees =
|
||||||
// Update displayedSelection based on selectedRoles
|
selectedRole === "all"
|
||||||
if (selectedRoles.includes("all")) {
|
? employees
|
||||||
setDisplayedSelection("All Roles");
|
: employees?.filter(
|
||||||
} else if (selectedRoles.length > 0) {
|
(emp) => String(emp.jobRoleId || "") === selectedRole
|
||||||
const selectedRoleNames = selectedRoles.map(roleId => {
|
);
|
||||||
const role = jobRoleData?.find(r => String(r.id) === roleId);
|
|
||||||
return role ? role.name : '';
|
|
||||||
}).filter(Boolean); // Filter out empty strings for roles not found
|
|
||||||
setDisplayedSelection(selectedRoleNames.join(', '));
|
|
||||||
} else {
|
|
||||||
setDisplayedSelection("Select Roles");
|
|
||||||
}
|
|
||||||
}, [selectedRoles, jobRoleData]);
|
|
||||||
|
|
||||||
|
|
||||||
const handleSearchChange = (event) => {
|
|
||||||
setSearchTerm(event.target.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Filter employees first by role, then by search term AND job role name
|
|
||||||
const filteredEmployees = employees?.filter((emp) => {
|
|
||||||
const matchesRole =
|
|
||||||
selectedRoles.includes("all") || selectedRoles.includes(String(emp.jobRoleId));
|
|
||||||
// Convert both first and last names and job role name to lowercase for case-insensitive matching
|
|
||||||
const fullName = `${emp.firstName} ${emp.lastName}`.toLowerCase();
|
|
||||||
|
|
||||||
const jobRoleName = jobRoleData?.find((role) => role.id === emp.jobRoleId)?.name?.toLowerCase() || "";
|
|
||||||
|
|
||||||
const searchLower = searchTerm.toLowerCase();
|
|
||||||
// Check if the full name OR job role name includes the search term
|
|
||||||
const matchesSearch = fullName.includes(searchLower) || jobRoleName.includes(searchLower);
|
|
||||||
return matchesRole && matchesSearch;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Determine unique job role IDs from the filtered employees (for dropdown options)
|
|
||||||
const uniqueJobRoleIdsInFilteredEmployees = new Set(
|
|
||||||
employees?.map(emp => emp.jobRoleId).filter(Boolean)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Filter jobRoleData to only include roles present in the uniqueJobRoleIdsInFilteredEmployees
|
|
||||||
const jobRolesForDropdown = jobRoleData?.filter(role =>
|
|
||||||
uniqueJobRoleIdsInFilteredEmployees.has(role.id)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Calculate the count of selected roles for display
|
|
||||||
const selectedRolesCount = selectedRoles.includes("all")
|
|
||||||
? 0 // "All Roles" doesn't contribute to a specific count
|
|
||||||
: selectedRoles.length;
|
|
||||||
|
|
||||||
const onSubmit = (data) => {
|
const onSubmit = (data) => {
|
||||||
const selectedEmployeeIds = data.selectedEmployees;
|
const selectedEmployeeIds = data.selectedEmployees;
|
||||||
@ -224,339 +159,226 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
reset();
|
reset();
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fs-5 text-dark text-center d-flex align-items-center justify-content-center flex-wrap">
|
<div className="fs-5 text-dark text-center d-flex align-items-center justify-content-center flex-wrap">
|
||||||
<p className="align-items-center flex-wrap m-0 ">Assign Task</p>
|
<p className="align-items-center flex-wrap m-0 ">Assign Task</p>
|
||||||
<div className="container my-3">
|
<div className="container my-3">
|
||||||
<div className="mb-1">
|
<div className="mb-1">
|
||||||
<p className="mb-0">
|
<p className="mb-0">
|
||||||
<span className="text-dark text-start d-flex align-items-center flex-wrap form-text">
|
<span className="text-dark text-start d-flex align-items-center flex-wrap form-text">
|
||||||
<span className="me-2 m-0 fw-bold">Work Location :</span> {/* Changed font-bold to fw-bold */}
|
<span className="me-2 m-0 font-bold">Work Location :</span>
|
||||||
{[
|
{[
|
||||||
assignData?.building?.buildingName,
|
assignData?.building?.buildingName,
|
||||||
assignData?.floor?.floorName,
|
assignData?.floor?.floorName,
|
||||||
assignData?.workArea?.areaName,
|
assignData?.workArea?.areaName,
|
||||||
assignData?.workItem?.activityMaster?.activityName,
|
assignData?.workItem?.activityMaster?.activityName,
|
||||||
]
|
]
|
||||||
.filter(Boolean) // Filter out any undefined/null values
|
.filter(Boolean) // Filter out any undefined/null values
|
||||||
.map((item, index, array) => (
|
.map((item, index, array) => (
|
||||||
<span key={index} className="d-flex align-items-center">
|
<span key={index} className="d-flex align-items-center">
|
||||||
{item}
|
{item}
|
||||||
{index < array.length - 1 && (
|
{index < array.length - 1 && (
|
||||||
<i className="bx bx-chevron-right mx-2"></i>
|
<i className="bx bx-chevron-right mx-2"></i>
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
))}
|
|
||||||
</span>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
|
||||||
<div className="form-label text-start">
|
|
||||||
<div className="row mb-1">
|
|
||||||
<div className="col-12">
|
|
||||||
<div className="form-text text-start">
|
|
||||||
<div className="d-flex align-items-center form-text fs-7">
|
|
||||||
<span className="text-dark">Select Team</span>
|
|
||||||
<div className="dropdown position-relative d-inline-block">
|
|
||||||
<a
|
|
||||||
className={`dropdown-toggle hide-arrow cursor-pointer ${
|
|
||||||
selectedRoles.includes("all") || selectedRoles.length === 0
|
|
||||||
? "text-secondary"
|
|
||||||
: "text-primary"
|
|
||||||
}`}
|
|
||||||
data-bs-toggle="dropdown"
|
|
||||||
role="button"
|
|
||||||
aria-expanded="false"
|
|
||||||
>
|
|
||||||
<i className="bx bx-slider-alt ms-2"></i>
|
|
||||||
</a>
|
|
||||||
|
|
||||||
{/* Badge */}
|
|
||||||
{selectedRolesCount > 0 && (
|
|
||||||
<span
|
|
||||||
className="position-absolute top-0 start-100 translate-middle badge rounded-circle bg-warning text-white"
|
|
||||||
style={{
|
|
||||||
fontSize: "0.65rem",
|
|
||||||
minWidth: "18px",
|
|
||||||
height: "18px",
|
|
||||||
padding: "0",
|
|
||||||
lineHeight: "18px",
|
|
||||||
textAlign: "center",
|
|
||||||
zIndex: 10,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{selectedRolesCount}
|
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
|
||||||
{/* Dropdown Menu - Corrected: Removed duplicate ul block */}
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<ul className="dropdown-menu p-2 text-capitalize" style={{ maxHeight: "300px", overflowY: "auto" }}>
|
<div className="form-label text-start">
|
||||||
<li> {/* Changed key="all" to a unique key if possible, or keep it if "all" is a unique identifier */}
|
<div className="row mb-1">
|
||||||
<div className="form-check dropdown-item py-0">
|
<div className="col-12">
|
||||||
<input
|
<div className="form-text text-start">
|
||||||
className="form-check-input"
|
<div className="d-flex align-items-center form-text fs-7">
|
||||||
type="checkbox"
|
<span className="text-dark">Select Team</span>
|
||||||
id="checkboxAllRoles" // Unique ID
|
<div className="me-2">{displayedSelection}</div>
|
||||||
value="all"
|
<a
|
||||||
checked={selectedRoles.includes("all")}
|
className="dropdown-toggle hide-arrow cursor-pointer"
|
||||||
onChange={(e) => handleRoleChange(e, e.target.value)}
|
data-bs-toggle="dropdown"
|
||||||
/>
|
aria-expanded="false"
|
||||||
<label className="form-check-label ms-2" htmlFor="checkboxAllRoles">
|
|
||||||
All Roles
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
{jobRolesForDropdown?.map((role) => (
|
|
||||||
<li key={role.id}>
|
|
||||||
<div className="form-check dropdown-item py-0">
|
|
||||||
<input
|
|
||||||
className="form-check-input"
|
|
||||||
type="checkbox"
|
|
||||||
id={`checkboxRole-${role.id}`} // Unique ID
|
|
||||||
value={role.id}
|
|
||||||
checked={selectedRoles.includes(String(role.id))}
|
|
||||||
onChange={(e) => handleRoleChange(e, e.target.value)}
|
|
||||||
/>
|
|
||||||
<label className="form-check-label ms-2" htmlFor={`checkboxRole-${role.id}`}>
|
|
||||||
{role.name}
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
className="form-control form-control-sm ms-auto mb-2 mt-2"
|
|
||||||
placeholder="Search employees or roles..."
|
|
||||||
value={searchTerm}
|
|
||||||
onChange={handleSearchChange}
|
|
||||||
style={{ maxWidth: "200px" }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className="col-12 mt-2"
|
|
||||||
style={{ maxHeight: "280px", overflowY: "auto", overflowX: "hidden" }}
|
|
||||||
>
|
|
||||||
{selectedRoles?.length > 0 && (
|
|
||||||
<div className="row">
|
|
||||||
{employeeLoading ? (
|
|
||||||
<div className="col-12">
|
|
||||||
<p className="text-center">Loading employees...</p>
|
|
||||||
</div>
|
|
||||||
) : filteredEmployees?.length > 0 ? (
|
|
||||||
filteredEmployees.map((emp) => {
|
|
||||||
const jobRole = jobRoleData?.find(
|
|
||||||
(role) => role?.id === emp?.jobRoleId
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
key={emp.id}
|
|
||||||
className="col-6 col-md-4 col-lg-3 mb-3"
|
|
||||||
>
|
>
|
||||||
<div className="form-check d-flex align-items-start">
|
<i className="bx bx-filter bx-lg text-primary"></i>
|
||||||
<Controller
|
</a>
|
||||||
name="selectedEmployees"
|
|
||||||
control={control}
|
|
||||||
render={({ field }) => (
|
|
||||||
<input
|
|
||||||
{...field}
|
|
||||||
className="form-check-input me-1 mt-1"
|
|
||||||
type="checkbox"
|
|
||||||
id={`employee-${emp?.id}`} // Unique ID
|
|
||||||
value={emp.id}
|
|
||||||
checked={field.value?.includes(emp.id)}
|
|
||||||
onChange={(e) => {
|
|
||||||
handleCheckboxChange(e, emp);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<div className="flex-grow-1">
|
|
||||||
<p
|
|
||||||
className="mb-0"
|
|
||||||
style={{ fontSize: "13px" }}
|
|
||||||
>
|
|
||||||
{emp.firstName} {emp.lastName}
|
|
||||||
</p>
|
|
||||||
<small
|
|
||||||
className="text-muted"
|
|
||||||
style={{ fontSize: "11px" }}
|
|
||||||
>
|
|
||||||
{loading ? (
|
|
||||||
<span className="placeholder-glow">
|
|
||||||
<span className="placeholder col-6"></span>
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
jobRole?.name || "Unknown Role"
|
|
||||||
)}
|
|
||||||
</small>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})
|
|
||||||
) : (
|
|
||||||
<div className="col-12">
|
|
||||||
<p className="text-center">
|
|
||||||
No employees found for the selected role(s).
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
<ul className="dropdown-menu p-2 text-capitalize">
|
||||||
className="col-12 h-25 overflow-auto"
|
<li key="all">
|
||||||
style={{ maxHeight: "200px" }}
|
|
||||||
>
|
|
||||||
{watch("selectedEmployees")?.length > 0 && (
|
|
||||||
<div className="mt-1">
|
|
||||||
<div className="text-start px-2">
|
|
||||||
{watch("selectedEmployees")?.map((empId) => {
|
|
||||||
const emp = employees.find((emp) => emp.id === empId);
|
|
||||||
return (
|
|
||||||
emp && (
|
|
||||||
<span
|
|
||||||
key={empId}
|
|
||||||
className="badge rounded-pill bg-label-primary d-inline-flex align-items-center me-1 mb-1"
|
|
||||||
>
|
|
||||||
{emp.firstName} {emp.lastName}
|
|
||||||
{/* Changed p tag to button for semantic correctness and accessibility */}
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="btn-close btn-close-white ms-1" // Added ms-1 for spacing, removed p-0 m-0
|
className="dropdown-item py-1"
|
||||||
aria-label="Remove employee" // More descriptive aria-label
|
onClick={() =>
|
||||||
onClick={() => {
|
handleRoleChange({
|
||||||
const updatedSelected = watch(
|
target: { value: "all" },
|
||||||
"selectedEmployees"
|
})
|
||||||
).filter((id) => id !== empId);
|
}
|
||||||
setValue(
|
|
||||||
"selectedEmployees",
|
|
||||||
updatedSelected
|
|
||||||
);
|
|
||||||
trigger("selectedEmployees");
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<i className="icon-base bx bx-x icon-md"></i>
|
All Roles
|
||||||
</button>
|
</button>
|
||||||
</span>
|
</li>
|
||||||
)
|
{jobRoleData?.map((user) => (
|
||||||
);
|
<li key={user.id}>
|
||||||
})}
|
<button
|
||||||
</div>
|
type="button"
|
||||||
</div>
|
className="dropdown-item py-1"
|
||||||
)}
|
value={user.id}
|
||||||
</div>
|
onClick={handleRoleChange}
|
||||||
|
>
|
||||||
{!loading && errors.selectedEmployees && (
|
{user.name}
|
||||||
<div className="danger-text mt-1">
|
</button>
|
||||||
<p>{errors.selectedEmployees.message}</p>{" "}
|
</li>
|
||||||
</div>
|
))}
|
||||||
)}
|
</ul>
|
||||||
|
</div>
|
||||||
<div className="col-md text-start mx-0 px-0">
|
|
||||||
<div className="form-check form-check-inline mt-3 px-1">
|
|
||||||
<label
|
|
||||||
className="form-text text-dark align-items-center d-flex"
|
|
||||||
htmlFor="inlineCheckbox1" // This htmlFor isn't linked to a checkbox in this context
|
|
||||||
>
|
|
||||||
Pending Task of Activity :
|
|
||||||
<label
|
|
||||||
className="form-check-label fs-7 ms-4"
|
|
||||||
htmlFor="inlineCheckbox1" // This htmlFor isn't linked to a checkbox in this context
|
|
||||||
>
|
|
||||||
<strong>
|
|
||||||
{assignData?.workItem?.plannedWork -
|
|
||||||
assignData?.workItem?.completedWork}
|
|
||||||
</strong>{" "}
|
|
||||||
<u>
|
|
||||||
{
|
|
||||||
assignData?.workItem?.activityMaster
|
|
||||||
?.unitOfMeasurement
|
|
||||||
}
|
|
||||||
</u>
|
|
||||||
</label>
|
|
||||||
<div style={{ display: "flex", alignItems: "center" }}>
|
|
||||||
<div
|
|
||||||
ref={infoRef}
|
|
||||||
tabIndex="0"
|
|
||||||
className="d-flex align-items-center avatar-group justify-content-center ms-2"
|
|
||||||
data-bs-toggle="popover"
|
|
||||||
data-bs-trigger="focus"
|
|
||||||
data-bs-placement="right"
|
|
||||||
data-bs-html="true"
|
|
||||||
style={{ cursor: "pointer" }}
|
|
||||||
>
|
|
||||||
|
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
width="13"
|
|
||||||
height="13"
|
|
||||||
fill="currentColor"
|
|
||||||
className="bi bi-info-circle"
|
|
||||||
viewBox="0 0 16 16"
|
|
||||||
>
|
|
||||||
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z" />
|
|
||||||
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.547 1.11l1.91-2.011c.241-.256.384-.592.287-.984-.172-.439-.58-.827-1.13-.967a.664.664 0 0 1-.58-.309l-.15-.241-.002-.002zM8 4c-.535 0-.943.372-.943.836 0 .464.408.836.943.836.535 0 .943-.372.943-.836 0-.464-.408-.836-.943-.836z" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Target for Today input and validation */}
|
<div className="row">
|
||||||
<div className="col-md text-start mx-0 px-0">
|
<div className="col-12 h-sm-25 overflow-auto mt-2" style={{height:"300px"}}>
|
||||||
<div className="form-check form-check-inline mt-2 px-1 mb-2 text-start">
|
{selectedRole !== "" && (
|
||||||
<label
|
<div className="row">
|
||||||
className="text-dark text-start d-flex align-items-center flex-wrap form-text"
|
{employeeLoading ? (
|
||||||
htmlFor="targetForTodayInput" // Added a unique htmlFor for clarity
|
<div className="col-12">
|
||||||
|
<p className="text-center">Loading employees...</p>
|
||||||
|
</div>
|
||||||
|
) : filteredEmployees?.length > 0 ? (
|
||||||
|
filteredEmployees.map((emp) => {
|
||||||
|
const jobRole = jobRoleData?.find(
|
||||||
|
(role) => role?.id === emp?.jobRoleId
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={emp.id}
|
||||||
|
className="col-6 col-md-4 col-lg-3 mb-3"
|
||||||
|
>
|
||||||
|
<div className="form-check d-flex align-items-start">
|
||||||
|
<Controller
|
||||||
|
name="selectedEmployees"
|
||||||
|
control={control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<input
|
||||||
|
{...field}
|
||||||
|
className="form-check-input me-1 mt-1"
|
||||||
|
type="checkbox"
|
||||||
|
id={`employee-${emp?.id}`}
|
||||||
|
value={emp.id}
|
||||||
|
checked={field.value?.includes(emp.id)}
|
||||||
|
onChange={(e) => {
|
||||||
|
handleCheckboxChange(e, emp);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<div className="flex-grow-1">
|
||||||
|
<p
|
||||||
|
className="mb-0"
|
||||||
|
style={{ fontSize: "13px" }}
|
||||||
|
>
|
||||||
|
{emp.firstName} {emp.lastName}
|
||||||
|
</p>
|
||||||
|
<small
|
||||||
|
className="text-muted"
|
||||||
|
style={{ fontSize: "11px" }}
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<span className="placeholder-glow">
|
||||||
|
<span className="placeholder col-6"></span>
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
jobRole?.name || "Unknown Role"
|
||||||
|
)}
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
) : (
|
||||||
|
<div className="col-12">
|
||||||
|
<p className="text-center">
|
||||||
|
No employees found for the selected role.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
className="col-12 h-25 overflow-auto"
|
||||||
|
style={{ maxHeight: "200px" }}
|
||||||
>
|
>
|
||||||
<span>Target for Today</span>
|
{watch("selectedEmployees")?.length > 0 && (
|
||||||
<span style={{ marginLeft: "46px" }}>:</span>
|
<div className="mt-1">
|
||||||
</label>
|
<div className="text-start px-2">
|
||||||
</div>
|
{watch("selectedEmployees")?.map((empId) => {
|
||||||
<div
|
const emp = employees.find((emp) => emp.id === empId);
|
||||||
className="form-check form-check-inline col-sm-3 mt-2"
|
return (
|
||||||
style={{ marginLeft: "-28px" }}
|
emp && (
|
||||||
>
|
<span
|
||||||
<Controller
|
key={empId}
|
||||||
name="plannedTask"
|
className="badge rounded-pill bg-label-primary d-inline-flex align-items-center me-1 mb-1"
|
||||||
control={control}
|
>
|
||||||
render={({ field }) => (
|
{emp.firstName} {emp.lastName}
|
||||||
<div className="d-flex align-items-center gap-1 ">
|
<p
|
||||||
<input
|
type="button"
|
||||||
type="text"
|
className=" btn-close-white p-0 m-0"
|
||||||
className="form-control form-control-sm"
|
aria-label="Close"
|
||||||
{...field}
|
onClick={() => {
|
||||||
id="defaultFormControlInput" // Consider a more descriptive ID if used elsewhere
|
const updatedSelected = watch(
|
||||||
aria-describedby="defaultFormControlHelp"
|
"selectedEmployees"
|
||||||
/>
|
).filter((id) => id !== empId);
|
||||||
<span style={{ paddingLeft: "6px", whiteSpace: "nowrap" }}>
|
setValue(
|
||||||
|
"selectedEmployees",
|
||||||
|
updatedSelected
|
||||||
|
);
|
||||||
|
trigger("selectedEmployees");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<i className="icon-base bx bx-x icon-md "></i>
|
||||||
|
</p>
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!loading && errors.selectedEmployees && (
|
||||||
|
<div className="danger-text mt-1">
|
||||||
|
<p>{errors.selectedEmployees.message}</p>{" "}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="col-md text-start mx-0 px-0">
|
||||||
|
<div className="form-check form-check-inline mt-3 px-1">
|
||||||
|
<label
|
||||||
|
className="form-text text-dark align-items-center d-flex"
|
||||||
|
htmlFor="inlineCheckbox1"
|
||||||
|
>
|
||||||
|
Pending Task of Activity :
|
||||||
|
<label
|
||||||
|
className="form-check-label fs-7 ms-4"
|
||||||
|
htmlFor="inlineCheckbox1"
|
||||||
|
>
|
||||||
|
<strong>
|
||||||
|
{assignData?.workItem?.plannedWork -
|
||||||
|
assignData?.workItem?.completedWork}
|
||||||
|
</strong>{" "}
|
||||||
<u>
|
<u>
|
||||||
{" "}
|
|
||||||
{
|
{
|
||||||
assignData?.workItem?.activityMaster
|
assignData?.workItem?.activityMaster
|
||||||
?.unitOfMeasurement
|
?.unitOfMeasurement
|
||||||
}
|
}
|
||||||
</u>
|
</u>
|
||||||
</span>
|
</label>
|
||||||
<div
|
<div style={{ display: "flex", alignItems: "center" }}>
|
||||||
style={{
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
ref={infoRef1}
|
ref={infoRef}
|
||||||
tabIndex="0"
|
tabIndex="0"
|
||||||
className="d-flex align-items-center avatar-group justify-content-center ms-2"
|
className="d-flex align-items-center avatar-group justify-content-center ms-2"
|
||||||
data-bs-toggle="popover"
|
data-bs-toggle="popover"
|
||||||
@ -565,89 +387,133 @@ const AssignTask = ({ assignData, onClose, setAssigned }) => {
|
|||||||
data-bs-html="true"
|
data-bs-html="true"
|
||||||
style={{ cursor: "pointer" }}
|
style={{ cursor: "pointer" }}
|
||||||
>
|
>
|
||||||
|
<i class='bx bx-info-circle bx-xs m-0 text-secondary'></i>
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
width="13"
|
|
||||||
height="13"
|
|
||||||
fill="currentColor"
|
|
||||||
className="bi bi-info-circle"
|
|
||||||
viewBox="0 0 16 16"
|
|
||||||
>
|
|
||||||
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z" />
|
|
||||||
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.547 1.11l1.91-2.011c.241-.256.384-.592.287-.984-.172-.439-.58-.827-1.13-.967a.664.664 0 0 1-.58-.309l-.15-.241-.002-.002zM8 4c-.535 0-.943.372-.943.836 0 .464.408.836.943.836.535 0 .943-.372.943-.836 0-.464-.408-.836-.943-.836z" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Target for Today input and validation */}
|
||||||
|
<div className="col-md text-start mx-0 px-0">
|
||||||
|
<div className="form-check form-check-inline mt-2 px-1 mb-2 text-start">
|
||||||
|
<label
|
||||||
|
className="text-dark text-start d-flex align-items-center flex-wrap form-text"
|
||||||
|
htmlFor="inlineCheckbox1"
|
||||||
|
>
|
||||||
|
<span>Target for Today</span>
|
||||||
|
<span style={{ marginLeft: "46px" }}>:</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="form-check form-check-inline col-sm-3 mt-2"
|
||||||
|
style={{ marginLeft: "-28px" }}
|
||||||
|
>
|
||||||
|
<Controller
|
||||||
|
name="plannedTask"
|
||||||
|
control={control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<div className="d-flex align-items-center gap-1 ">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="form-control form-control-sm"
|
||||||
|
{...field}
|
||||||
|
id="defaultFormControlInput"
|
||||||
|
aria-describedby="defaultFormControlHelp"
|
||||||
|
/>
|
||||||
|
<span style={{ paddingLeft: "6px" }}>
|
||||||
|
{
|
||||||
|
assignData?.workItem?.workItem?.activityMaster
|
||||||
|
?.unitOfMeasurement
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
<div
|
||||||
|
className="flex align-items-center"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
ref={infoRef1}
|
||||||
|
tabIndex="0"
|
||||||
|
className="d-flex align-items-center avatar-group justify-content-center ms-2 cursor-pointer"
|
||||||
|
data-bs-toggle="popover"
|
||||||
|
data-bs-trigger="focus"
|
||||||
|
data-bs-placement="right"
|
||||||
|
data-bs-html="true"
|
||||||
|
>
|
||||||
|
<i class='bx bx-info-circle bx-xs m-0 text-secondary'></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{errors.plannedTask && (
|
||||||
|
<div className="danger-text mt-1">
|
||||||
|
{errors.plannedTask.message}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{isHelpVisible && (
|
||||||
|
<div
|
||||||
|
className="position-absolute bg-white border p-2 rounded shadow"
|
||||||
|
style={{ zIndex: 10, marginLeft: "10px" }}
|
||||||
|
>
|
||||||
|
{/* Add your help content here */}
|
||||||
|
<p className="mb-0">
|
||||||
|
Enter the target value for today's task.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label
|
||||||
|
className="form-text fs-7 m-1 text-lg text-dark"
|
||||||
|
htmlFor="descriptionTextarea" // Changed htmlFor for better accessibility
|
||||||
|
>
|
||||||
|
Description
|
||||||
|
</label>
|
||||||
|
<Controller
|
||||||
|
name="description"
|
||||||
|
control={control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<textarea
|
||||||
|
{...field}
|
||||||
|
className="form-control"
|
||||||
|
id="descriptionTextarea" // Changed id for better accessibility
|
||||||
|
rows="2"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
|
{errors.description && (
|
||||||
|
<div className="danger-text">{errors.description.message}</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{errors.plannedTask && (
|
{/* Submit and Cancel buttons */}
|
||||||
<div className="danger-text mt-1">
|
<div className="col-12 d-flex justify-content-center align-items-center gap-sm-6 gap-8 text-center mt-1">
|
||||||
{errors.plannedTask.message}
|
<button
|
||||||
</div>
|
type="submit"
|
||||||
)}
|
className="btn btn-sm btn-primary "
|
||||||
|
disabled={isSubmitting || loading}
|
||||||
{isHelpVisible && (
|
|
||||||
<div
|
|
||||||
className="position-absolute bg-white border p-2 rounded shadow"
|
|
||||||
style={{ zIndex: 10, marginLeft: "10px" }}
|
|
||||||
>
|
>
|
||||||
<p className="mb-0">
|
{isSubmitting ? "Please Wait" : "Submit"}
|
||||||
Enter the target value for today's task.
|
</button>
|
||||||
</p>
|
<button
|
||||||
</div>
|
type="reset"
|
||||||
)}
|
className="btn btn-sm btn-label-secondary"
|
||||||
</div>
|
data-bs-dismiss="modal"
|
||||||
|
aria-label="Close"
|
||||||
<label
|
onClick={closedModel}
|
||||||
className="form-text fs-7 m-1 text-dark" // Removed duplicate htmlFor and text-lg
|
disabled={isSubmitting || loading}
|
||||||
htmlFor="descriptionTextarea"
|
>
|
||||||
>
|
Cancel
|
||||||
Description
|
</button>
|
||||||
</label>
|
</div>
|
||||||
<Controller
|
</form>
|
||||||
name="description"
|
|
||||||
control={control}
|
|
||||||
render={({ field }) => (
|
|
||||||
<textarea
|
|
||||||
{...field}
|
|
||||||
className="form-control"
|
|
||||||
id="descriptionTextarea" // Unique ID
|
|
||||||
rows="2"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
{errors.description && (
|
|
||||||
<div className="danger-text">{errors.description.message}</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div className="col-12 d-flex justify-content-center align-items-center gap-sm-6 gap-8 text-center mt-1">
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
className="btn btn-sm btn-primary "
|
|
||||||
disabled={isSubmitting || loading}
|
|
||||||
>
|
|
||||||
{isSubmitting ? "Please Wait" : "Submit"}
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="reset"
|
|
||||||
className="btn btn-sm btn-label-secondary"
|
|
||||||
data-bs-dismiss="modal"
|
|
||||||
aria-label="Close"
|
|
||||||
onClick={closedModel}
|
|
||||||
disabled={isSubmitting || loading}
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
);
|
||||||
</div> );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AssignTask;
|
export default AssignTask;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect,useCallback } from "react";
|
||||||
import { useFieldArray, useForm } from "react-hook-form";
|
import { useFieldArray, useForm } from "react-hook-form";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
|
import showToast from '../services/toastService';
|
||||||
|
|
||||||
export const usePositionTracker = () => {
|
export const usePositionTracker = () => {
|
||||||
const [coords, setCoords] = useState({ latitude: 0, longitude: 0 });
|
const [coords, setCoords] = useState({ latitude: 0, longitude: 0 });
|
||||||
@ -9,7 +10,7 @@ export const usePositionTracker = () => {
|
|||||||
setCoords(coords);
|
setCoords(coords);
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
alert(error.message);
|
showToast("Please Allow Location","warn");
|
||||||
},
|
},
|
||||||
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
|
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
|
||||||
);
|
);
|
||||||
|
|||||||
@ -8,35 +8,32 @@ import {
|
|||||||
import Breadcrumb from "../../components/common/Breadcrumb";
|
import Breadcrumb from "../../components/common/Breadcrumb";
|
||||||
import AttendanceLog from "../../components/Activities/AttendcesLogs";
|
import AttendanceLog from "../../components/Activities/AttendcesLogs";
|
||||||
import Attendance from "../../components/Activities/Attendance";
|
import Attendance from "../../components/Activities/Attendance";
|
||||||
import AttendanceModel from "../../components/Activities/AttendanceModel";
|
|
||||||
import showToast from "../../services/toastService";
|
|
||||||
import Regularization from "../../components/Activities/Regularization";
|
import Regularization from "../../components/Activities/Regularization";
|
||||||
import { useAttendance } from "../../hooks/useAttendance";
|
import { useAttendance } from "../../hooks/useAttendance";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { setProjectId } from "../../slices/localVariablesSlice";
|
import { setProjectId } from "../../slices/localVariablesSlice";
|
||||||
import { markCurrentAttendance } from "../../slices/apiSlice/attendanceAllSlice";
|
import { hasUserPermission } from "../../utils/authUtils";
|
||||||
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
import { REGULARIZE_ATTENDANCE } from "../../utils/constants";
|
import { REGULARIZE_ATTENDANCE } from "../../utils/constants";
|
||||||
import eventBus from "../../services/eventBus";
|
import eventBus from "../../services/eventBus";
|
||||||
import AttendanceRepository from "../../repositories/AttendanceRepository";
|
|
||||||
import { useProjectName } from "../../hooks/useProjects";
|
import { useProjectName } from "../../hooks/useProjects";
|
||||||
|
import GlobalModel from "../../components/common/GlobalModel";
|
||||||
|
import CheckCheckOutmodel from "../../components/Activities/CheckCheckOutForm";
|
||||||
|
import AttendLogs from "../../components/Activities/AttendLogs";
|
||||||
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
const AttendancePage = () => {
|
const AttendancePage = () => {
|
||||||
const [activeTab, setActiveTab] = useState("all");
|
const [activeTab, setActiveTab] = useState("all");
|
||||||
const [showPending, setShowPending] = useState(false);
|
const [ShowPending, setShowPending] = useState(false);
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
const queryClient = useQueryClient();
|
||||||
const loginUser = getCachedProfileData();
|
const loginUser = getCachedProfileData();
|
||||||
const selectedProject = useSelector((store) => store.localVariables.projectId);
|
var selectedProject = useSelector((store) => store.localVariables.projectId);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const {
|
|
||||||
attendance,
|
|
||||||
loading: attLoading,
|
|
||||||
recall: attrecall,
|
|
||||||
} = useAttendance(selectedProject);
|
|
||||||
const [attendances, setAttendances] = useState();
|
const [attendances, setAttendances] = useState();
|
||||||
const [empRoles, setEmpRoles] = useState(null);
|
const [empRoles, setEmpRoles] = useState(null);
|
||||||
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
||||||
const [modelConfig, setModelConfig] = useState(null); // Initialize as null
|
const [modelConfig, setModelConfig] = useState();
|
||||||
const DoRegularized = useHasUserPermission(REGULARIZE_ATTENDANCE);
|
const DoRegularized = useHasUserPermission(REGULARIZE_ATTENDANCE);
|
||||||
const { projectNames, loading: projectLoading, fetchData } = useProjectName();
|
const { projectNames, loading: projectLoading, fetchData } = useProjectName();
|
||||||
|
|
||||||
@ -46,172 +43,67 @@ const AttendancePage = () => {
|
|||||||
date: new Date().toLocaleDateString(),
|
date: new Date().toLocaleDateString(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const handler = useCallback(
|
useEffect(() => {
|
||||||
(msg) => {
|
if (selectedProject == null) {
|
||||||
if (selectedProject === msg.projectId) {
|
dispatch(setProjectId(projectNames[0]?.id));
|
||||||
const updatedAttendance = attendances
|
}
|
||||||
? attendances.map((item) =>
|
}, []);
|
||||||
item.employeeId === msg.response.employeeId
|
|
||||||
? { ...item, ...msg.response }
|
|
||||||
: item
|
|
||||||
)
|
|
||||||
: [msg.response];
|
|
||||||
|
|
||||||
cacheData("Attendance", {
|
|
||||||
data: updatedAttendance,
|
|
||||||
projectId: selectedProject,
|
|
||||||
});
|
|
||||||
setAttendances(updatedAttendance);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[selectedProject, attendances]
|
|
||||||
);
|
|
||||||
|
|
||||||
const employeeHandler = useCallback(
|
|
||||||
(msg) => {
|
|
||||||
// This logic seems fine for refetching if an employee ID exists in current attendances
|
|
||||||
if (attendances?.some((item) => item.employeeId === msg.employeeId)) {
|
|
||||||
AttendanceRepository.getAttendance(selectedProject)
|
|
||||||
.then((response) => {
|
|
||||||
cacheData("Attendance", { data: response.data, selectedProject });
|
|
||||||
setAttendances(response.data);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[selectedProject, attendances]
|
|
||||||
);
|
|
||||||
|
|
||||||
const getRole = (roleId) => {
|
const getRole = (roleId) => {
|
||||||
if (!empRoles) return "Unassigned";
|
if (!empRoles) return "Unassigned";
|
||||||
if (!roleId) return "Unassigned";
|
if (!roleId) return "Unassigned";
|
||||||
const role = empRoles.find((b) => b.id === roleId);
|
const role = empRoles.find((b) => b.id == roleId);
|
||||||
return role ? role.role : "Unassigned";
|
return role ? role.role : "Unassigned";
|
||||||
};
|
};
|
||||||
|
|
||||||
// Simplified and moved modal opening logic
|
const openModel = () => {
|
||||||
const handleModalData = useCallback((employee) => {
|
setIsCreateModalOpen(true);
|
||||||
setModelConfig(employee);
|
|
||||||
setIsCreateModalOpen(true); // Open the modal directly when data is set
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const closeModal = useCallback(() => {
|
|
||||||
setModelConfig(null);
|
|
||||||
setIsCreateModalOpen(false);
|
|
||||||
// Directly manipulating the DOM is generally not recommended in React.
|
|
||||||
// React handles modal visibility via state. If you must, ensure it's
|
|
||||||
// for external libraries or for very specific, controlled reasons.
|
|
||||||
// For a typical Bootstrap modal, just setting `isCreateModalOpen` to false
|
|
||||||
// should be enough if the modal component itself handles the Bootstrap classes.
|
|
||||||
const modalElement = document.getElementById("check-Out-modal");
|
|
||||||
if (modalElement) {
|
|
||||||
modalElement.classList.remove("show");
|
|
||||||
modalElement.style.display = "none";
|
|
||||||
document.body.classList.remove("modal-open");
|
|
||||||
const modalBackdrop = document.querySelector(".modal-backdrop");
|
|
||||||
if (modalBackdrop) {
|
|
||||||
modalBackdrop.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleSubmit = useCallback((formData) => {
|
|
||||||
dispatch(markCurrentAttendance(formData))
|
|
||||||
.then((action) => {
|
|
||||||
if (action.payload && action.payload.employeeId) {
|
|
||||||
const updatedAttendance = attendances
|
|
||||||
? attendances.map((item) =>
|
|
||||||
item.employeeId === action.payload.employeeId
|
|
||||||
? { ...item, ...action.payload }
|
|
||||||
: item
|
|
||||||
)
|
|
||||||
: [action.payload];
|
|
||||||
|
|
||||||
cacheData("Attendance", {
|
|
||||||
data: updatedAttendance,
|
|
||||||
projectId: selectedProject,
|
|
||||||
});
|
|
||||||
setAttendances(updatedAttendance);
|
|
||||||
showToast("Attendance Marked Successfully", "success");
|
|
||||||
} else {
|
|
||||||
showToast("Failed to mark attendance: Invalid response", "error");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
showToast(error.message, "error");
|
|
||||||
});
|
|
||||||
}, [dispatch, attendances, selectedProject]);
|
|
||||||
|
|
||||||
|
|
||||||
const handleToggle = (event) => {
|
|
||||||
setShowPending(event.target.checked);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleModalData = (employee) => {
|
||||||
|
setModelConfig(employee);
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeModal = () => {
|
||||||
|
setModelConfig(null);
|
||||||
|
setIsCreateModalOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleToggle = (event) => {
|
||||||
|
setShowOnlyCheckout(event.target.checked);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedProject === null && projectNames.length > 0) {
|
if (modelConfig !== null) {
|
||||||
dispatch(setProjectId(projectNames[0]?.id));
|
openModel();
|
||||||
}
|
}
|
||||||
}, [selectedProject, projectNames, dispatch]);
|
}, [modelConfig, isCreateModalOpen]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setAttendances(attendance);
|
|
||||||
}, [attendance]);
|
|
||||||
|
|
||||||
const filteredAndSearchedTodayAttendance = useCallback(() => {
|
|
||||||
let currentData = attendances;
|
|
||||||
|
|
||||||
if (showPending) {
|
|
||||||
currentData = currentData?.filter(
|
|
||||||
(att) => att?.checkInTime !== null && att?.checkOutTime === null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (searchQuery) {
|
|
||||||
const lowerCaseSearchQuery = searchQuery.toLowerCase();
|
|
||||||
currentData = currentData?.filter((att) => {
|
|
||||||
const fullName = [att.firstName, att.middleName, att.lastName]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join(" ")
|
|
||||||
.toLowerCase();
|
|
||||||
|
|
||||||
return (
|
|
||||||
att.employeeName?.toLowerCase().includes(lowerCaseSearchQuery) ||
|
|
||||||
att.employeeId?.toLowerCase().includes(lowerCaseSearchQuery) ||
|
|
||||||
fullName.includes(lowerCaseSearchQuery)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return currentData;
|
|
||||||
}, [attendances, showPending, searchQuery]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
eventBus.on("attendance", handler);
|
|
||||||
return () => eventBus.off("attendance", handler);
|
|
||||||
}, [handler]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
eventBus.on("employee", employeeHandler);
|
|
||||||
return () => eventBus.off("employee", employeeHandler);
|
|
||||||
}, [employeeHandler]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isCreateModalOpen && modelConfig && (
|
{isCreateModalOpen && modelConfig && (
|
||||||
<div
|
<GlobalModel
|
||||||
className="modal fade show"
|
isOpen={isCreateModalOpen}
|
||||||
style={{ display: "block" }}
|
size={modelConfig?.action === 6 && "lg"}
|
||||||
id="check-Out-modal"
|
closeModal={closeModal}
|
||||||
tabIndex="-1"
|
|
||||||
aria-hidden="true"
|
|
||||||
>
|
>
|
||||||
<AttendanceModel
|
{(modelConfig?.action === 0 ||
|
||||||
modelConfig={modelConfig}
|
modelConfig?.action === 1 ||
|
||||||
closeModal={closeModal}
|
modelConfig?.action === 2) && (
|
||||||
handleSubmitForm={handleSubmit}
|
<CheckCheckOutmodel
|
||||||
/>
|
modeldata={modelConfig}
|
||||||
</div>
|
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">
|
<div className="container-fluid">
|
||||||
@ -221,106 +113,69 @@ const AttendancePage = () => {
|
|||||||
{ label: "Attendance", link: null },
|
{ label: "Attendance", link: null },
|
||||||
]}
|
]}
|
||||||
></Breadcrumb>
|
></Breadcrumb>
|
||||||
<div className="nav-align-top nav-tabs-shadow">
|
<div className="nav-align-top nav-tabs-shadow" >
|
||||||
<ul
|
<ul className="nav nav-tabs" role="tablist">
|
||||||
className="nav nav-tabs d-flex justify-content-between align-items-center"
|
<li className="nav-item">
|
||||||
role="tablist"
|
<button
|
||||||
>
|
type="button"
|
||||||
<div className="d-flex">
|
className={`nav-link ${
|
||||||
<li className="nav-item">
|
activeTab === "all" ? "active" : ""
|
||||||
<button
|
} fs-6`}
|
||||||
type="button"
|
onClick={() => setActiveTab("all")}
|
||||||
className={`nav-link ${activeTab === "all" ? "active" : ""} fs-6`}
|
data-bs-toggle="tab"
|
||||||
onClick={() => setActiveTab("all")}
|
data-bs-target="#navs-top-home"
|
||||||
data-bs-toggle="tab"
|
>
|
||||||
data-bs-target="#navs-top-home"
|
Today's
|
||||||
>
|
</button>
|
||||||
Today's
|
</li>
|
||||||
</button>
|
<li className="nav-item">
|
||||||
</li>
|
<button
|
||||||
<li className="nav-item">
|
type="button"
|
||||||
<button
|
className={`nav-link ${
|
||||||
type="button"
|
activeTab === "logs" ? "active" : ""
|
||||||
className={`nav-link ${activeTab === "logs" ? "active" : ""} fs-6`}
|
} fs-6`}
|
||||||
onClick={() => setActiveTab("logs")}
|
onClick={() => setActiveTab("logs")}
|
||||||
data-bs-toggle="tab"
|
data-bs-toggle="tab"
|
||||||
data-bs-target="#navs-top-profile"
|
data-bs-target="#navs-top-profile"
|
||||||
>
|
>
|
||||||
Logs
|
Logs
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<li className={`nav-item ${!DoRegularized && "d-none"}`}>
|
<li className={`nav-item ${!DoRegularized && "d-none"}`}>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={`nav-link ${
|
className={`nav-link ${
|
||||||
activeTab === "regularization" ? "active" : ""
|
activeTab === "regularization" ? "active" : ""
|
||||||
} fs-6`}
|
} fs-6`}
|
||||||
onClick={() => setActiveTab("regularization")}
|
onClick={() => setActiveTab("regularization")}
|
||||||
data-bs-toggle="tab"
|
data-bs-toggle="tab"
|
||||||
data-bs-target="#navs-top-messages"
|
data-bs-target="#navs-top-messages"
|
||||||
>
|
>
|
||||||
Regularization
|
Regularization
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
</div>
|
|
||||||
<div className="p-2">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
className="form-control form-control-sm"
|
|
||||||
placeholder="Search employee..."
|
|
||||||
value={searchQuery}
|
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</ul>
|
</ul>
|
||||||
<div className="tab-content attedanceTabs py-0 px-1 px-sm-3">
|
<div className="tab-content attedanceTabs py-0 px-1 px-sm-3" >
|
||||||
{activeTab === "all" && (
|
{activeTab === "all" && (
|
||||||
<>
|
|
||||||
{!attLoading && (
|
|
||||||
<div className="tab-pane fade show active py-0">
|
<div className="tab-pane fade show active py-0">
|
||||||
<Attendance
|
<Attendance
|
||||||
attendance={filteredAndSearchedTodayAttendance()}
|
|
||||||
handleModalData={handleModalData}
|
handleModalData={handleModalData}
|
||||||
getRole={getRole}
|
getRole={getRole}
|
||||||
setshowOnlyCheckout={setShowPending}
|
|
||||||
showOnlyCheckout={showPending}
|
|
||||||
searchQuery={searchQuery}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
{!attLoading && filteredAndSearchedTodayAttendance()?.length === 0 && (
|
|
||||||
<p>
|
|
||||||
{" "}
|
|
||||||
{showPending
|
|
||||||
? "No Pending Available"
|
|
||||||
: "No Employee assigned yet."}{" "}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{activeTab === "logs" && (
|
{activeTab === "logs" && (
|
||||||
<div className="tab-pane fade show active py-0">
|
<div className="tab-pane fade show active py-0">
|
||||||
<AttendanceLog
|
<AttendanceLog
|
||||||
handleModalData={handleModalData}
|
handleModalData={handleModalData}
|
||||||
projectId={selectedProject}
|
|
||||||
setshowOnlyCheckout={setShowPending}
|
|
||||||
showOnlyCheckout={showPending}
|
|
||||||
searchQuery={searchQuery}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{activeTab === "regularization" && DoRegularized && (
|
{activeTab === "regularization" && DoRegularized && (
|
||||||
<div className="tab-pane fade show active py-0">
|
<div className="tab-pane fade show active py-0">
|
||||||
<Regularization
|
<Regularization />
|
||||||
handleRequest={handleSubmit}
|
|
||||||
searchQuery={searchQuery}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!attLoading && !attendances && <span>Not Found</span>}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -328,4 +183,4 @@ const AttendancePage = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AttendancePage;
|
export default AttendancePage;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user