diff --git a/src/components/PageLayout/Authentication/Authentication.tsx b/src/components/PageLayout/Authentication/Authentication.tsx index efe7b608..c03849ed 100644 --- a/src/components/PageLayout/Authentication/Authentication.tsx +++ b/src/components/PageLayout/Authentication/Authentication.tsx @@ -6,7 +6,7 @@ import {AuthContainer} from '@/utils/AuthContainer' import {useSeminarInfo} from '@/utils/useSeminarInfo' import {Overlay} from '../../Overlay/Overlay' -import {LoginForm} from '../LoginForm/LoginForm' +import {LoginFormWrapper} from '../LoginFormWrapper/LoginFormWrapper' import styles from './Authentication.module.scss' export const Authentication: FC = () => { @@ -38,7 +38,7 @@ export const Authentication: FC = () => {
- +
diff --git a/src/components/PageLayout/LoginForm/LoginForm.tsx b/src/components/PageLayout/LoginForm/LoginForm.tsx index 0c6a14da..aa6d493f 100644 --- a/src/components/PageLayout/LoginForm/LoginForm.tsx +++ b/src/components/PageLayout/LoginForm/LoginForm.tsx @@ -7,6 +7,8 @@ import {Button} from '@/components/Clickable/Button' import {FormInput} from '@/components/FormItems/FormInput/FormInput' import {AuthContainer} from '@/utils/AuthContainer' +import {LoginFormWrapperProps} from '../LoginFormWrapper/LoginFormWrapper' + type LoginFormValues = { email: string password: string @@ -17,11 +19,7 @@ const defaultValues: LoginFormValues = { password: '', } -interface ILoginForm { - closeOverlay: () => void -} - -export const LoginForm: FC = ({closeOverlay}) => { +export const LoginForm: FC = ({closeOverlay}) => { const {login} = AuthContainer.useContainer() const {handleSubmit, control} = useForm({defaultValues}) diff --git a/src/components/PageLayout/LoginFormWrapper/LoginFormWrapper.tsx b/src/components/PageLayout/LoginFormWrapper/LoginFormWrapper.tsx new file mode 100644 index 00000000..c8f5453f --- /dev/null +++ b/src/components/PageLayout/LoginFormWrapper/LoginFormWrapper.tsx @@ -0,0 +1,38 @@ +import {useRouter} from 'next/router' +import {FC, useState} from 'react' + +import {Button} from '@/components/Clickable/Button' + +import {LoginForm} from '../LoginForm/LoginForm' +import {PasswordResetRequestForm} from '../PasswordResetRequest/PasswordResetRequest' + +export type LoginFormWrapperProps = { + closeOverlay: () => void +} + +export const LoginFormWrapper: FC = ({closeOverlay}) => { + const router = useRouter() + const [form, changeForm] = useState('login') + + if (form === 'login') + return ( + <> + + + + ) + + return ( + { + router.push('/verifikacia') + }} + /> + ) +} diff --git a/src/components/PageLayout/PasswordResetRequest/PasswordResetRequest.tsx b/src/components/PageLayout/PasswordResetRequest/PasswordResetRequest.tsx new file mode 100644 index 00000000..2d6f2eef --- /dev/null +++ b/src/components/PageLayout/PasswordResetRequest/PasswordResetRequest.tsx @@ -0,0 +1,58 @@ +import {useMutation} from '@tanstack/react-query' +import axios from 'axios' +import {FC} from 'react' +import {SubmitHandler, useForm} from 'react-hook-form' + +import {Button} from '@/components/Clickable/Button' +import {FormInput} from '@/components/FormItems/FormInput/FormInput' +import {IGeneralPostResponse} from '@/types/api/general' + +import {LoginFormWrapperProps} from '../LoginFormWrapper/LoginFormWrapper' + +type PasswordResetRequestFormValues = { + email: string +} + +const defaultValues: PasswordResetRequestFormValues = { + email: '', +} + +export const PasswordResetRequestForm: FC = ({closeOverlay}) => { + const {handleSubmit, control} = useForm({defaultValues}) + + const requiredRule = {required: '* Toto pole nemôže byť prázdne.'} + + const {mutate: submitFormData} = useMutation({ + mutationFn: (data: PasswordResetRequestFormValues) => { + return axios.post('/api/user/password/reset/', data) + }, + + onError: (error, variables, context) => {}, + + onSuccess: () => { + closeOverlay() + }, + }) + + const onSubmit: SubmitHandler = (data) => { + submitFormData(data) + } + + return ( +
+ + + + ) +}