-
Notifications
You must be signed in to change notification settings - Fork 0
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
Reset password - reset password dialog #278
Changes from 5 commits
3fa6de0
8f285fe
ed54d4b
93af449
60eec1e
ab0a3ed
d00e860
e73b53e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 interface ILoginFormWrapper { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. skor pouzivame |
||
closeOverlay: () => void | ||
} | ||
|
||
export const LoginFormWrapper: FC<ILoginFormWrapper> = ({closeOverlay}) => { | ||
const router = useRouter() | ||
const [form, changeForm] = useState('login') | ||
|
||
if (form === 'login') | ||
return ( | ||
<> | ||
<LoginForm closeOverlay={closeOverlay} /> | ||
<Button | ||
onClick={() => { | ||
changeForm('reset') | ||
}} | ||
> | ||
Zabudnuté heslo | ||
</Button> | ||
</> | ||
) | ||
|
||
return ( | ||
<PasswordResetRequestForm | ||
closeOverlay={() => { | ||
router.push('/verifikacia') | ||
}} | ||
/> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {ILoginFormWrapper} from '../LoginFormWrapper/LoginFormWrapper' | ||
|
||
type PasswordResetRequestFormValues = { | ||
email: string | ||
} | ||
|
||
const defaultValues: PasswordResetRequestFormValues = { | ||
email: '', | ||
} | ||
|
||
export const PasswordResetRequestForm: FC<ILoginFormWrapper> = ({closeOverlay}) => { | ||
const {handleSubmit, control} = useForm<PasswordResetRequestFormValues>({defaultValues}) | ||
|
||
const requiredRule = {required: '* Toto pole nemôže byť prázdne.'} | ||
|
||
const {mutate: submitFormData} = useMutation({ | ||
mutationFn: (data: PasswordResetRequestFormValues) => { | ||
return axios.post<IGeneralPostResponse>('/api/user/password/reset/', data) | ||
}, | ||
|
||
onError: (error, variables, context) => {}, | ||
Check warning on line 30 in src/components/PageLayout/PasswordReset/PasswordResetRequest.tsx GitHub Actions / branch-test
Check warning on line 30 in src/components/PageLayout/PasswordReset/PasswordResetRequest.tsx GitHub Actions / branch-test
Check warning on line 30 in src/components/PageLayout/PasswordReset/PasswordResetRequest.tsx GitHub Actions / branch-test
|
||
|
||
onSuccess: () => { | ||
closeOverlay() | ||
}, | ||
}) | ||
|
||
const onSubmit: SubmitHandler<PasswordResetRequestFormValues> = (data) => { | ||
submitFormData(data) | ||
} | ||
|
||
return ( | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<FormInput | ||
control={control} | ||
name="email" | ||
label="Email" | ||
rules={{ | ||
...requiredRule, | ||
pattern: { | ||
value: /^[\w%+.-]+@[\d.a-z-]+\.[a-z]{2,}$/iu, | ||
message: '* Vložte správnu emailovú adresu.', | ||
}, | ||
}} | ||
/> | ||
<Button type="submit">Resetovať heslo</Button> | ||
</form> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {ILoginFormWrapper} from '../LoginFormWrapper/LoginFormWrapper' | ||
|
||
type PasswordResetRequestFormValues = { | ||
email: string | ||
} | ||
|
||
const defaultValues: PasswordResetRequestFormValues = { | ||
email: '', | ||
} | ||
|
||
export const PasswordResetRequestForm: FC<ILoginFormWrapper> = ({closeOverlay}) => { | ||
const {handleSubmit, control} = useForm<PasswordResetRequestFormValues>({defaultValues}) | ||
|
||
const requiredRule = {required: '* Toto pole nemôže byť prázdne.'} | ||
|
||
const {mutate: submitFormData} = useMutation({ | ||
mutationFn: (data: PasswordResetRequestFormValues) => { | ||
return axios.post<IGeneralPostResponse>('/api/user/password/reset/', data) | ||
}, | ||
|
||
onError: (error, variables, context) => {}, | ||
Check warning on line 30 in src/components/PageLayout/PasswordResetRequest/PasswordResetRequest.tsx GitHub Actions / branch-test
Check warning on line 30 in src/components/PageLayout/PasswordResetRequest/PasswordResetRequest.tsx GitHub Actions / branch-test
Check warning on line 30 in src/components/PageLayout/PasswordResetRequest/PasswordResetRequest.tsx GitHub Actions / branch-test
|
||
|
||
onSuccess: () => { | ||
closeOverlay() | ||
}, | ||
}) | ||
|
||
const onSubmit: SubmitHandler<PasswordResetRequestFormValues> = (data) => { | ||
submitFormData(data) | ||
} | ||
|
||
return ( | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<FormInput | ||
control={control} | ||
name="email" | ||
label="Email" | ||
rules={{ | ||
...requiredRule, | ||
pattern: { | ||
value: /^[\w%+.-]+@[\d.a-z-]+\.[a-z]{2,}$/iu, | ||
message: '* Vložte správnu emailovú adresu.', | ||
}, | ||
}} | ||
/> | ||
<Button type="submit">Resetovať heslo</Button> | ||
</form> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nie som si isty, ci mozeme ratat s tym, ze toggleDisplayLoginOverlay unmountne LoginFormWrapper component. ked sa neunmountne a ostane len nejak invisible, tak pri znovuotvoreni loginu by som cakal zachovany stav, ze resetujeme heslo