From 19bf295e2df2d71e81fd88f2505a01f23b9a2dd2 Mon Sep 17 00:00:00 2001 From: adam-skowronek Date: Sat, 11 Jun 2022 14:02:52 +0200 Subject: [PATCH] Fix fetching students for select component --- frontend/src/views/coordinator/AddGroup.tsx | 24 ++++++++++----------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/frontend/src/views/coordinator/AddGroup.tsx b/frontend/src/views/coordinator/AddGroup.tsx index 9998587..bf47710 100644 --- a/frontend/src/views/coordinator/AddGroup.tsx +++ b/frontend/src/views/coordinator/AddGroup.tsx @@ -32,21 +32,19 @@ const AddGroup = () => { const [studentOptions, setStudentOptions] = useState([]) - 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 (