Fixed the bug where it passes projectId 1 to APIs when we refreshes the page #43

Merged
vikas.nale merged 1 commits from Ashutosh_Bug#96_Passing_Incorrect_ProjectId into Issues_April_4W 2025-04-21 07:04:01 +00:00
2 changed files with 6 additions and 6 deletions

View File

@ -3,10 +3,11 @@ import { cacheData, getCachedData } from "../slices/apiDataManager";
import ProjectRepository from "../repositories/ProjectRepository";
import { useProfile } from "./useProfile";
import {useDispatch} from "react-redux";
import { setProjectId } from "../slices/localVariablesSlice";
export const useProjects = () =>
{
const dispatch = useDispatch
const dispatch = useDispatch();
const [projects, setProjects] = useState([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
@ -24,9 +25,7 @@ export const useProjects = () =>
);
setProjects(sortedProject);
cacheData( "projectslist", sortedProject );
setLoading(false);
})
.catch((error) => {
@ -49,6 +48,10 @@ export const useProjects = () =>
fetchData();
}, []);
useEffect(() => {
dispatch(setProjectId(projects[0]?.id));
}, [projects]);
return { projects, loading, error, refetch: fetchData };
};

View File

@ -92,9 +92,6 @@ const AttendancePage = () => {
useEffect(() => {
setAttendances(attendance);
}, [attendance]);
useEffect(() => {
dispatch(setProjectId(projects[0]?.id));
}, [projects]);
return (
<>