-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pass-reset): added password reset request dialog
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/components/PageLayout/PasswordReset/PasswordResetRequest.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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/Clickable' | ||
import styles from '@/components/FormItems/Form.module.scss' | ||
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) | ||
}, | ||
}) | ||
|
||
const onSubmit: SubmitHandler<PasswordResetRequestFormValues> = (data) => { | ||
submitFormData(data) | ||
} | ||
|
||
return ( | ||
<form className={styles.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> | ||
) | ||
} |