Fixed the bug where it passes projectId 1 to APIs when we refreshes the page #43
@ -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 };
|
||||
};
|
||||
|
||||
|
@ -92,9 +92,6 @@ const AttendancePage = () => {
|
||||
useEffect(() => {
|
||||
setAttendances(attendance);
|
||||
}, [attendance]);
|
||||
useEffect(() => {
|
||||
dispatch(setProjectId(projects[0]?.id));
|
||||
}, [projects]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
Loading…
x
Reference in New Issue
Block a user