react-query-v2 : react-query intergrated inside attendance and gallery module #270

Merged
vikas.nale merged 16 commits from react-query-v2 into main 2025-07-24 09:41:21 +00:00
4 changed files with 78 additions and 85 deletions
Showing only changes of commit 92568039eb - Show all commits

View File

@ -24,6 +24,7 @@ const Attendance = ({ getRole, handleModalData }) => {
attendance, attendance,
loading: attLoading, loading: attLoading,
recall: attrecall, recall: attrecall,
isFetching
} = useAttendance(selectedProject); } = useAttendance(selectedProject);
const filteredAttendance = ShowPending const filteredAttendance = ShowPending
? attendance?.filter( ? attendance?.filter(
@ -100,6 +101,7 @@ const Attendance = ({ getRole, handleModalData }) => {
className="form-check-input" className="form-check-input"
role="switch" role="switch"
id="inactiveEmployeesCheckbox" id="inactiveEmployeesCheckbox"
disabled={isFetching}
checked={ShowPending} checked={ShowPending}
onChange={(e) => setShowPending(e.target.checked)} onChange={(e) => setShowPending(e.target.checked)}
/> />

View File

@ -214,6 +214,7 @@ 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={showOnlyCheckout}
onChange={(e) => setshowOnlyCheckout(e.target.checked)} onChange={(e) => setshowOnlyCheckout(e.target.checked)}
@ -233,7 +234,7 @@ const AttendanceLog = ({
</div> </div>
<div className="table-responsive text-nowrap"> <div className="table-responsive text-nowrap">
{isLoading ? ( {isLoading ? (
<div>Loading...</div> <div><p className="text-secondary">Loading...</p></div>
) : data?.length > 0 ? ( ) : data?.length > 0 ? (
<table className="table mb-0"> <table className="table mb-0">
<thead> <thead>

View File

@ -28,12 +28,13 @@ const Regularization = ({ handleRequest }) => {
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 ); const updatedAttendance = regularizes?.filter(
(item) => item.id !== msg.response.id
);
cacheData("regularizedList", { cacheData("regularizedList", {
data: updatedAttendance, data: updatedAttendance,
projectId: selectedProject, projectId: selectedProject,
}); });
// clearCacheKey("regularizedList")
refetch(); refetch();
} }
}, },
@ -66,10 +67,12 @@ const Regularization = ({ handleRequest }) => {
}, [employeeHandler]); }, [employeeHandler]);
return ( return (
<div <div className="table-responsive text-nowrap pb-4">
className="table-responsive text-nowrap pb-4" {loading ? (
<div className="my-2">
> <p className="text-secondary">Loading...</p>
</div>
) : currentItems?.length > 0 ? (
<table className="table mb-0"> <table className="table mb-0">
<thead> <thead>
<tr> <tr>
@ -85,15 +88,7 @@ const Regularization = ({ handleRequest }) => {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{/* {loading && ( {currentItems?.map((att, index) => (
<td colSpan={6} className="text-center py-5">
Loading...
</td>
)} */}
{!loading &&
(currentItems?.length > 0 ? (
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">
@ -113,12 +108,9 @@ const Regularization = ({ handleRequest }) => {
<td>{moment(att.checkOutTime).format("DD-MMM-YYYY")}</td> <td>{moment(att.checkOutTime).format("DD-MMM-YYYY")}</td>
<td>{convertShortTime(att.checkInTime)}</td> <td>{convertShortTime(att.checkInTime)}</td>
<td> <td>
{att.checkOutTime {att.checkOutTime ? convertShortTime(att.checkOutTime) : "--"}
? convertShortTime(att.checkOutTime)
: "--"}
</td> </td>
<td className="text-center "> <td className="text-center ">
{/* <div className='d-flex justify-content-center align-items-center gap-3'> */}
<RegularizationActions <RegularizationActions
attendanceData={att} attendanceData={att}
handleRequest={handleRequest} handleRequest={handleRequest}
@ -127,24 +119,12 @@ const Regularization = ({ handleRequest }) => {
{/* </div> */} {/* </div> */}
</td> </td>
</tr> </tr>
))
) : (
<tr>
<td
colSpan={6}
className="text-center"
style={{
height: "200px",
verticalAlign: "middle",
borderBottom: "none",
}}
>
No Record Found
</td>
</tr>
))} ))}
</tbody> </tbody>
</table> </table>
) : (
<div className="my-4"> <span className="text-muted">No Requests Found</span></div>
)}
{!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">

View File

@ -124,6 +124,7 @@ export const useAttendance = (projectId) => {
isLoading: loading, isLoading: loading,
error, error,
refetch: recall, refetch: recall,
isFetching
} = useQuery({ } = useQuery({
queryKey: ["attendance", projectId], queryKey: ["attendance", projectId],
queryFn: async () => { queryFn: async () => {
@ -141,6 +142,7 @@ export const useAttendance = (projectId) => {
loading, loading,
error, error,
recall, recall,
isFetching
}; };
}; };
@ -263,17 +265,25 @@ export const useMarkAttendance = () => {
emp.employeeId === data.employeeId ? { ...emp, ...data } : emp emp.employeeId === data.employeeId ? { ...emp, ...data } : emp
); );
}); });
}else{ }else if(variables.forWhichTab == 2){
// queryClient.invalidateQueries({ // queryClient.invalidateQueries({
// queryKey: ["attendanceLogs"], // queryKey: ["attendanceLogs"],
// }); // });
queryClient.setQueryData(["attendanceLogs",selectedProject,selectedDateRange.startDate,selectedDateRange.endDate], (oldData) => { queryClient.setQueryData(["attendanceLogs",selectedProject,selectedDateRange.startDate,selectedDateRange.endDate], (oldData) => {
if (!oldData) return oldData; if (!oldData) return oldData;
return oldData.map((emp) => return oldData.map((record) =>
emp.id === data.id ? { ...emp, ...data } : emp record.id === data.id ? { ...record, ...data } : record
); );
}); });
} queryClient.invalidateQueries({queryKey:["regularizedList"]})
}else(
queryClient.setQueryData(["regularizedList",selectedProject], (oldData) => {
if (!oldData) return oldData;
return oldData.filter((record) => record.id !== data.id)
}),
queryClient.invalidateQueries({queryKey:["attendanceLogs"]})
)
if(variables.forWhichTab !== 3) showToast("Attendance marked successfully", "success"); if(variables.forWhichTab !== 3) showToast("Attendance marked successfully", "success");
}, },
onError: (error) => { onError: (error) => {