diff --git a/frontend/src/components/TopBar.tsx b/frontend/src/components/TopBar.tsx index 57091e4..1592d4f 100644 --- a/frontend/src/components/TopBar.tsx +++ b/frontend/src/components/TopBar.tsx @@ -22,11 +22,9 @@ const TopBar = ({ isActive ? 'underline font-bold' : '' const [yearGroupId, setYearGroupId] = useLocalStorageState('yearGroupId', { - defaultValue: -1, - }) - const [userType, setUserType] = useLocalStorageState('userType', { - defaultValue: 'coordinator', + defaultValue: 0, }) + const [userType, setUserType] = useLocalStorageState('userType') const [yearGroupOptions, setYearGroupOptions] = useState() const onYearChange = (v: any) => { diff --git a/frontend/src/views/Login.tsx b/frontend/src/views/Login.tsx index 5d2693d..40b05de 100644 --- a/frontend/src/views/Login.tsx +++ b/frontend/src/views/Login.tsx @@ -17,10 +17,10 @@ const Login = () => { const navigate = useNavigate() const [yearGroupId, setYearGroupId] = useLocalStorageState('yearGroupId', { - defaultValue: -1, + defaultValue: 0, }) const [userId, setUserId] = useLocalStorageState('userId', { - defaultValue: -1, + defaultValue: 0, }) const [studentId, setStudentId] = useLocalStorageState('studentId') @@ -42,11 +42,14 @@ const Login = () => { } }), ) + if (yearGroupId === 0 && data?.data.year_groups.length) { + setYearGroupId(1) + } }, }) useQuery( - 'students', + ['students', yearGroupId], () => getStudents({ year_group_id: yearGroupId, per_page: 1000 }), { onSuccess: (data) => { @@ -59,11 +62,12 @@ const Login = () => { }), ) }, + enabled: yearGroupId > 0, }, ) useQuery( - 'project_supervisors', + ['project_supervisors', yearGroupId], () => getLeaders({ year_group_id: yearGroupId, per_page: 1000 }), { onSuccess: (data) => { @@ -78,6 +82,7 @@ const Login = () => { ), ) }, + enabled: yearGroupId > 0, }, ) @@ -116,6 +121,7 @@ const Login = () => { borderRadius: '0.5rem', }), }} + value={yearGroupOptions?.find((year) => year.value === yearGroupId)} />