Set default project to the first one associated with the logged-in user.
This commit is contained in:
parent
d4fed67912
commit
a096f3d743
@ -7,6 +7,7 @@ import { setProjectId } from "../slices/localVariablesSlice";
|
||||
|
||||
export const useProjects = () =>
|
||||
{
|
||||
const {profile} = useProfile()
|
||||
const dispatch = useDispatch();
|
||||
const [projects, setProjects] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
@ -48,9 +49,19 @@ export const useProjects = () =>
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(setProjectId(projects[0]?.id));
|
||||
}, [projects]);
|
||||
useEffect( () =>
|
||||
{
|
||||
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 };
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user