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