diff --git a/src/hooks/useAttendance.js b/src/hooks/useAttendance.js index 05937aa6..022db4c2 100644 --- a/src/hooks/useAttendance.js +++ b/src/hooks/useAttendance.js @@ -1,5 +1,5 @@ import { useEffect, useState } from "react"; -import { cacheData, getCachedData } from "../slices/apiDataManager"; +import { cacheData, getCachedData, useSelectedproject } from "../slices/apiDataManager"; import AttendanceRepository from "../repositories/AttendanceRepository"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import showToast from "../services/toastService"; @@ -7,111 +7,6 @@ import { useDispatch, useSelector } from "react-redux"; import { store } from "../store/store"; import { setDefaultDateRange } from "../slices/localVariablesSlice"; -// export const useAttendace =(projectId)=>{ - -// const [attendance, setAttendance] = useState([]); -// const[loading,setLoading] = useState(true) -// const [error, setError] = useState(null); - -// const fetchData = () => { -// const Attendance_cache = getCachedData("Attendance"); -// if(!Attendance_cache || Attendance_cache.projectId !== projectId){ - -// setLoading(true); -// AttendanceRepository.getAttendance(projectId) -// .then((response) => { -// setAttendance(response.data); -// cacheData( "Attendance", {data: response.data, projectId} ) -// setLoading(false) -// }) -// .catch((error) => { -// setLoading(false) -// setError("Failed to fetch data."); -// }) -// } else { -// setAttendance(Attendance_cache.data); -// setLoading(false) -// } -// }; - - -// useEffect(()=>{ -// if ( projectId && projectId != 1 ) -// { -// fetchData(projectId); -// } -// },[projectId]) - -// return {attendance,loading,error,recall:fetchData} -// } - -// export const useEmployeeAttendacesLog = (id) => { -// const [logs, setLogs] = useState([]); -// const [loading, setLoading] = useState(false); -// const [error, setError] = useState(null); - - -// const fetchData = () => { -// const AttendanceLog_cache = getCachedData("AttendanceLogs"); -// if(!AttendanceLog_cache || AttendanceLog_cache.id !== id ){ -// setLoading(true) -// AttendanceRepository.getAttendanceLogs(id).then((response)=>{ -// setLogs(response.data) -// cacheData("AttendanceLogs", { data: response.data, id }) -// setLoading(false) -// }).catch((error)=>{ -// setError("Failed to fetch data."); -// setLoading(false); -// }) -// }else{ - -// setLogs(AttendanceLog_cache.data); -// } -// }; - -// useEffect(() => { -// if (id) { -// fetchData(); -// } - -// }, [id]); - -// return { logs, loading, error }; -// }; - -// export const useRegularizationRequests = ( projectId ) => -// { -// const [regularizes, setregularizes] = useState([]); -// const [loading, setLoading] = useState(false); -// const [error, setError] = useState(null); - - -// const fetchData = () => { -// const regularizedList_cache = getCachedData("regularizedList"); -// if(!regularizedList_cache || regularizedList_cache.projectId !== projectId ){ -// setLoading(true) -// AttendanceRepository.getRegularizeList(projectId).then((response)=>{ -// setregularizes( response.data ) -// cacheData("regularizedList", { data: response.data, projectId }) -// setLoading(false) -// }).catch((error)=>{ -// setError("Failed to fetch data."); -// setLoading(false); -// }) -// }else{ - -// setregularizes(regularizedList_cache.data); -// } -// }; - -// useEffect(() => { -// if (projectId) { -// fetchData(); -// } - -// }, [ projectId ] ); -// return {regularizes,loading,error,refetch:fetchData} -// } // ----------------------------Query----------------------------- @@ -248,7 +143,8 @@ export const useRegularizationRequests = (projectId) => { export const useMarkAttendance = () => { const queryClient = useQueryClient(); - const selectedProject = useSelector((store)=>store.localVariables.projectId) + // const selectedProject = useSelector((store)=>store.localVariables.projectId) + const selectedProject = useSelectedproject(); const selectedDateRange = useSelector((store)=>store.localVariables.defaultDateRange) return useMutation({