Login screen improvements

This commit is contained in:
adam-skowronek 2023-01-12 20:38:36 +01:00
parent 3be0d04f28
commit 3d389b606f
2 changed files with 13 additions and 9 deletions

View File

@ -22,11 +22,9 @@ const TopBar = ({
isActive ? 'underline font-bold' : '' isActive ? 'underline font-bold' : ''
const [yearGroupId, setYearGroupId] = useLocalStorageState('yearGroupId', { const [yearGroupId, setYearGroupId] = useLocalStorageState('yearGroupId', {
defaultValue: -1, defaultValue: 0,
})
const [userType, setUserType] = useLocalStorageState('userType', {
defaultValue: 'coordinator',
}) })
const [userType, setUserType] = useLocalStorageState('userType')
const [yearGroupOptions, setYearGroupOptions] = useState<SelectValue[]>() const [yearGroupOptions, setYearGroupOptions] = useState<SelectValue[]>()
const onYearChange = (v: any) => { const onYearChange = (v: any) => {

View File

@ -17,10 +17,10 @@ const Login = () => {
const navigate = useNavigate() const navigate = useNavigate()
const [yearGroupId, setYearGroupId] = useLocalStorageState('yearGroupId', { const [yearGroupId, setYearGroupId] = useLocalStorageState('yearGroupId', {
defaultValue: -1, defaultValue: 0,
}) })
const [userId, setUserId] = useLocalStorageState('userId', { const [userId, setUserId] = useLocalStorageState('userId', {
defaultValue: -1, defaultValue: 0,
}) })
const [studentId, setStudentId] = useLocalStorageState('studentId') const [studentId, setStudentId] = useLocalStorageState('studentId')
@ -42,11 +42,14 @@ const Login = () => {
} }
}), }),
) )
if (yearGroupId === 0 && data?.data.year_groups.length) {
setYearGroupId(1)
}
}, },
}) })
useQuery( useQuery(
'students', ['students', yearGroupId],
() => getStudents({ year_group_id: yearGroupId, per_page: 1000 }), () => getStudents({ year_group_id: yearGroupId, per_page: 1000 }),
{ {
onSuccess: (data) => { onSuccess: (data) => {
@ -59,11 +62,12 @@ const Login = () => {
}), }),
) )
}, },
enabled: yearGroupId > 0,
}, },
) )
useQuery( useQuery(
'project_supervisors', ['project_supervisors', yearGroupId],
() => getLeaders({ year_group_id: yearGroupId, per_page: 1000 }), () => getLeaders({ year_group_id: yearGroupId, per_page: 1000 }),
{ {
onSuccess: (data) => { onSuccess: (data) => {
@ -78,6 +82,7 @@ const Login = () => {
), ),
) )
}, },
enabled: yearGroupId > 0,
}, },
) )
@ -116,6 +121,7 @@ const Login = () => {
borderRadius: '0.5rem', borderRadius: '0.5rem',
}), }),
}} }}
value={yearGroupOptions?.find((year) => year.value === yearGroupId)}
/> />
<label className="label">Student</label> <label className="label">Student</label>
<Select <Select
@ -161,7 +167,7 @@ const Login = () => {
</div> */} </div> */}
<button <button
className="btn mt-5 text-lg" className="btn mt-5 text-lg"
disabled={userId < 0 || selectedYear < 0} disabled={userId === 0 || selectedYear === 0}
onClick={() => navigate('/' + userType)} onClick={() => navigate('/' + userType)}
> >
Zaloguj Zaloguj