Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegisterForm already used email address error #180

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/components/RegisterForm/RegisterForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useMutation} from '@tanstack/react-query'
import axios from 'axios'
import axios, {AxiosError} from 'axios'
import {useRouter} from 'next/router'
import {FC} from 'react'
import {SubmitHandler, useForm} from 'react-hook-form'
Expand All @@ -24,6 +24,10 @@ interface RegisterFormValues extends SchoolSubFormValues {
gdpr?: boolean
}

interface RegisterErrorResponseData {
email?: string[]
}

const defaultValues: RegisterFormValues = {
email: '',
password1: '',
Expand All @@ -41,7 +45,7 @@ const defaultValues: RegisterFormValues = {
}

export const RegisterForm: FC = () => {
const {handleSubmit, control, watch, setValue, getValues} = useForm<RegisterFormValues>({
const {handleSubmit, control, watch, setValue, getValues, setError} = useForm<RegisterFormValues>({
defaultValues,
values: defaultValues,
})
Expand Down Expand Up @@ -78,6 +82,15 @@ export const RegisterForm: FC = () => {
return axios.post<IGeneralPostResponse>(`/api/user/registration?seminar=${seminar}`, transformFormData(data))
},
onSuccess: () => router.push(`${router.asPath}/../verifikacia`),
onError: (error: AxiosError<RegisterErrorResponseData>) => {
if (error.response?.status === 400) {
if (error.response.data.email) {
setError('email', {type: 'custom', message: `* ${error.response.data.email[0]}`})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

``* A USER IS ALREADY REGISTERED WITH THIS E-MAIL ADDRESS.`

ale uz som sa dohodol s BE ze nam poslu slovensky message, takze je to v poriadku

}
} else {
alert('Neznáma chyba pri registrácii. Skúste to prosím neskôr.')
}
},
})

const onSubmit: SubmitHandler<RegisterFormValues> = (data) => {
Expand Down
Loading