Set default project to the first one associated with the logged-in user.

This commit is contained in:
Pramod Mahajan 2025-04-22 13:00:32 +05:30
parent d4fed67912
commit a096f3d743

View File

@ -7,6 +7,7 @@ import { setProjectId } from "../slices/localVariablesSlice";
export const useProjects = () => export const useProjects = () =>
{ {
const {profile} = useProfile()
const dispatch = useDispatch(); const dispatch = useDispatch();
const [projects, setProjects] = useState([]); const [projects, setProjects] = useState([]);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
@ -48,9 +49,19 @@ export const useProjects = () =>
fetchData(); fetchData();
}, []); }, []);
useEffect(() => { useEffect( () =>
dispatch(setProjectId(projects[0]?.id)); {
}, [projects]); if (projects )
{
if ( profile?.projects && profile?.projects?.length > 0 )
{
dispatch(setProjectId(profile?.projects[0]))
} else
{
dispatch(setProjectId(1))
}
}
}, [profile]);
return { projects, loading, error, refetch: fetchData }; return { projects, loading, error, refetch: fetchData };
}; };