diff --git a/src/components/Profile/ProfileForm.tsx b/src/components/Profile/ProfileForm.tsx index 5bb94267..5ac8557c 100644 --- a/src/components/Profile/ProfileForm.tsx +++ b/src/components/Profile/ProfileForm.tsx @@ -13,18 +13,13 @@ import {AuthContainer} from '@/utils/AuthContainer' import {useSeminarInfo} from '@/utils/useSeminarInfo' import {Button} from '../Clickable/Clickable' -import {SchoolSubForm} from '../SchoolSubForm/SchoolSubForm' +import {SchoolSubForm, SchoolSubFormValues} from '../SchoolSubForm/SchoolSubForm' -export type ProfileFormValues = { +interface ProfileFormValues extends SchoolSubFormValues { first_name?: string last_name?: string phone?: string parent_phone?: string - new_school_description?: string - without_school: boolean - school?: SelectOption | null - school_not_found: boolean - grade: number | '' } const defaultValues: ProfileFormValues = { @@ -65,6 +60,8 @@ export const ProfileForm: FC = () => { values: profileValues, }) + watch(['first_name']) + const scrollToTop = () => { window.scrollTo({ top: 0, diff --git a/src/components/RegisterForm/RegisterForm.tsx b/src/components/RegisterForm/RegisterForm.tsx index 58f78eae..44abb859 100644 --- a/src/components/RegisterForm/RegisterForm.tsx +++ b/src/components/RegisterForm/RegisterForm.tsx @@ -7,14 +7,13 @@ import {SubmitHandler, useForm} from 'react-hook-form' import styles from '@/components/FormItems/Form.module.scss' import {FormCheckbox} from '@/components/FormItems/FormCheckbox/FormCheckbox' import {FormInput} from '@/components/FormItems/FormInput/FormInput' -import {SelectOption} from '@/components/FormItems/FormSelect/FormSelect' import {IGeneralPostResponse} from '@/types/api/general' import {useSeminarInfo} from '@/utils/useSeminarInfo' import {Button} from '../Clickable/Clickable' -import {SchoolSubForm} from '../SchoolSubForm/SchoolSubForm' +import {SchoolSubForm, SchoolSubFormValues} from '../SchoolSubForm/SchoolSubForm' -export type RegisterFormValues = { +interface RegisterFormValues extends SchoolSubFormValues { email?: string password1?: string password2?: string @@ -22,12 +21,7 @@ export type RegisterFormValues = { last_name?: string phone?: string parent_phone?: string - new_school_description?: string - without_school: boolean - school?: SelectOption | null - school_not_found: boolean - grade: number | '' - gdpr: boolean + gdpr?: boolean } const defaultValues: RegisterFormValues = { @@ -47,7 +41,10 @@ const defaultValues: RegisterFormValues = { } export const RegisterForm: FC = () => { - const {handleSubmit, control, watch, setValue, getValues} = useForm({defaultValues}) + const {handleSubmit, control, watch, setValue, getValues} = useForm({ + defaultValues, + values: defaultValues, + }) const scrollToTop = () => { window.scrollTo({ diff --git a/src/components/SchoolSubForm/SchoolSubForm.tsx b/src/components/SchoolSubForm/SchoolSubForm.tsx index 10bd1d9b..62d817e4 100644 --- a/src/components/SchoolSubForm/SchoolSubForm.tsx +++ b/src/components/SchoolSubForm/SchoolSubForm.tsx @@ -12,20 +12,22 @@ 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 {ProfileFormValues} from '../Profile/ProfileForm' -import {RegisterFormValues} from '../RegisterForm/RegisterForm' -type SchoolSubFormProps = { +export type SchoolSubFormValues = { + new_school_description?: string + without_school: boolean + school?: SelectOption | null + school_not_found: boolean + grade: number | '' +} + +type SchoolSubFormProps = { control: Control watch: UseFormWatch setValue: UseFormSetValue } -export const SchoolSubForm = ({ - control, - watch, - setValue, -}: SchoolSubFormProps) => { +export const SchoolSubForm = ({control, watch, setValue}: SchoolSubFormProps) => { const [school_not_found, without_school] = watch(['school_not_found', 'without_school']) const otherSchoolItem = useRef()