diff --git a/src/components/Profile/ProfileForm.tsx b/src/components/Profile/ProfileForm.tsx index 6df9ad1b..05384d45 100644 --- a/src/components/Profile/ProfileForm.tsx +++ b/src/components/Profile/ProfileForm.tsx @@ -31,7 +31,7 @@ const defaultValues: ProfileFormValues = { without_school: false, school: null, school_not_found: false, - grade: '', + grade: null, } export const ProfileForm: FC = () => { @@ -52,7 +52,7 @@ export const ProfileForm: FC = () => { without_school: profile?.school_id === 1, school: ({id: profile?.school.code, label: profile?.school.verbose_name} as SelectOption) ?? null, school_not_found: profile?.school_id === 0, - grade: profile?.grade ?? '', + grade: ({id: profile?.grade, label: profile?.grade_name} as SelectOption) ?? null, } const {handleSubmit, control, watch, setValue} = useForm({ @@ -80,7 +80,7 @@ export const ProfileForm: FC = () => { school: data.school?.id, phone: data.phone?.replaceAll(/\s+/gu, ''), parent_phone: data.parent_phone?.replaceAll(/\s+/gu, ''), - grade: data.grade, + grade: data.grade?.id, }, new_school_description: data.new_school_description || '', }) diff --git a/src/components/RegisterForm/RegisterForm.tsx b/src/components/RegisterForm/RegisterForm.tsx index e0bf3f08..0729de4f 100644 --- a/src/components/RegisterForm/RegisterForm.tsx +++ b/src/components/RegisterForm/RegisterForm.tsx @@ -39,7 +39,7 @@ const defaultValues: RegisterFormValues = { without_school: false, school: null, school_not_found: false, - grade: '', + grade: null, } export const RegisterForm: FC = () => { @@ -69,7 +69,7 @@ export const RegisterForm: FC = () => { school: data.school?.id, phone: data.phone?.replaceAll(/\s+/gu, ''), parent_phone: data.parent_phone?.replaceAll(/\s+/gu, ''), - grade: data.grade, + grade: data.grade?.id, }, new_school_description: data.new_school_description || '', }) diff --git a/src/components/SchoolSubForm/SchoolSubForm.tsx b/src/components/SchoolSubForm/SchoolSubForm.tsx index b3c71bbe..e299307d 100644 --- a/src/components/SchoolSubForm/SchoolSubForm.tsx +++ b/src/components/SchoolSubForm/SchoolSubForm.tsx @@ -11,14 +11,14 @@ import {ISchool} from '@/types/api/personal' import {FormAutocomplete} from '../FormItems/FormAutocomplete/FormAutocomplete' import {FormCheckbox} from '../FormItems/FormCheckbox/FormCheckbox' import {FormInput} from '../FormItems/FormInput/FormInput' -import {FormSelect, SelectOption} from '../FormItems/FormSelect/FormSelect' +import {SelectOption} from '../FormItems/FormSelect/FormSelect' export type SchoolSubFormValues = { new_school_description?: string without_school: boolean school?: SelectOption | null school_not_found: boolean - grade: number | '' + grade: SelectOption | null } type SchoolSubFormProps = { @@ -33,6 +33,7 @@ export const SchoolSubForm = ({control, watch, setValue, gap}: SchoolSubFormProp const otherSchoolItem = useRef() const withoutSchoolItem = useRef() + const noGradeItem = useRef() // načítanie ročníkov z BE, ktorými vyplníme FormSelect s ročníkmi const {data: gradesData} = useQuery({ @@ -56,16 +57,18 @@ export const SchoolSubForm = ({control, watch, setValue, gap}: SchoolSubFormProp otherSchoolItem.current = emptySchoolItems.find(({id}) => id === 0) withoutSchoolItem.current = emptySchoolItems.find(({id}) => id === 1) const schoolItems = allSchoolItems.filter(({id}) => ![0, 1].includes(id)) + noGradeItem.current = gradeItems.find(({id}) => id === 13) // predvyplnenie/zmazania hodnôt pri zakliknutí checkboxu pre užívateľa po škole useUpdateEffect(() => { if (without_school) { setValue('school', withoutSchoolItem.current) - setValue('grade', 13) + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + setValue('grade', noGradeItem.current!) setValue('school_not_found', false) } else { setValue('school', null) - setValue('grade', '') + setValue('grade', null) } }, [without_school]) @@ -105,7 +108,7 @@ export const SchoolSubForm = ({control, watch, setValue, gap}: SchoolSubFormProp sx={{mb: '1rem'}} /> )} -