Fix fetching students for select component

This commit is contained in:
adam-skowronek 2022-06-11 14:02:52 +02:00
parent 1bd50e6bfc
commit 19bf295e2d

View File

@ -32,21 +32,19 @@ const AddGroup = () => {
const [studentOptions, setStudentOptions] = useState<SelectValue[]>([]) const [studentOptions, setStudentOptions] = useState<SelectValue[]>([])
const { isLoading: areStudentsLoading, data: students } = useQuery( const { isLoading: areStudentsLoading } = useQuery(
'students', 'students',
() => getStudents({ per_page: 1000 }), () => getStudents({ per_page: 1000 }),
{ {
onSuccess: () => { onSuccess: (data) => {
if (students?.data) {
setStudentOptions( setStudentOptions(
students.data.students.map(({ first_name, last_name, index }) => { data?.data.students.map(({ first_name, last_name, index }) => {
return { return {
value: index, value: index,
label: `${first_name} ${last_name} (${index})`, label: `${first_name} ${last_name} (${index})`,
} }
}), }),
) )
}
}, },
}, },
) )
@ -60,7 +58,7 @@ const AddGroup = () => {
{ value: '6', label: 'Marcin Witkowski' }, { value: '6', label: 'Marcin Witkowski' },
] ]
if (areStudentsLoading && !students) { if (areStudentsLoading) {
return <>Ładowanie</> return <>Ładowanie</>
} }
return ( return (