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 { isLoading: areStudentsLoading, data: students } = useQuery(
|
||||
const { isLoading: areStudentsLoading } = useQuery(
|
||||
'students',
|
||||
() => getStudents({ per_page: 1000 }),
|
||||
{
|
||||
onSuccess: () => {
|
||||
if (students?.data) {
|
||||
onSuccess: (data) => {
|
||||
setStudentOptions(
|
||||
students.data.students.map(({ first_name, last_name, index }) => {
|
||||
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 (
|
||||
|
Loading…
Reference in New Issue
Block a user