Skip to content

Commit

Permalink
Fix typescript errror and cyclic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Matushl committed Nov 11, 2023
1 parent babcd31 commit 90ad1c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
11 changes: 4 additions & 7 deletions src/components/Profile/ProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -65,6 +60,8 @@ export const ProfileForm: FC = () => {
values: profileValues,
})

watch(['first_name'])

const scrollToTop = () => {
window.scrollTo({
top: 0,
Expand Down
17 changes: 7 additions & 10 deletions src/components/RegisterForm/RegisterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,21 @@ 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
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 | ''
gdpr: boolean
gdpr?: boolean
}

const defaultValues: RegisterFormValues = {
Expand All @@ -47,7 +41,10 @@ const defaultValues: RegisterFormValues = {
}

export const RegisterForm: FC = () => {
const {handleSubmit, control, watch, setValue, getValues} = useForm<RegisterFormValues>({defaultValues})
const {handleSubmit, control, watch, setValue, getValues} = useForm<RegisterFormValues>({
defaultValues,
values: defaultValues,
})

const scrollToTop = () => {
window.scrollTo({
Expand Down
18 changes: 10 additions & 8 deletions src/components/SchoolSubForm/SchoolSubForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends RegisterFormValues | ProfileFormValues> = {
export type SchoolSubFormValues = {
new_school_description?: string
without_school: boolean
school?: SelectOption | null
school_not_found: boolean
grade: number | ''
}

type SchoolSubFormProps<T extends SchoolSubFormValues> = {
control: Control<T, unknown>
watch: UseFormWatch<T>
setValue: UseFormSetValue<T>
}

export const SchoolSubForm = ({
control,
watch,
setValue,
}: SchoolSubFormProps<RegisterFormValues | ProfileFormValues>) => {
export const SchoolSubForm = ({control, watch, setValue}: SchoolSubFormProps<SchoolSubFormValues>) => {
const [school_not_found, without_school] = watch(['school_not_found', 'without_school'])

const otherSchoolItem = useRef<SelectOption>()
Expand Down

0 comments on commit 90ad1c3

Please sign in to comment.