Fix fetching students for select component
This commit is contained in:
parent
1bd50e6bfc
commit
19bf295e2d
@ -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(
|
data?.data.students.map(({ first_name, last_name, index }) => {
|
||||||
students.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 (
|
||||||
|
Loading…
Reference in New Issue
Block a user