2024-02-15 17:17:26 -05:00
import React from "react" ;
2024-02-29 17:30:58 -05:00
import { Button , Container , FormControl , FormErrorMessage , Heading , Input , Text } from "@chakra-ui/react" ;
2024-02-15 17:17:26 -05:00
import { SubmitHandler , useForm } from "react-hook-form" ;
import { LoginService } from "../client" ;
2024-02-26 09:39:09 -05:00
import useCustomToast from "../hooks/useCustomToast" ;
2024-02-15 17:17:26 -05:00
interface FormData {
email : string ;
}
const RecoverPassword : React.FC = ( ) = > {
2024-02-29 17:30:58 -05:00
const { register , handleSubmit , formState : { errors , isSubmitting } } = useForm < FormData > ( ) ;
2024-02-26 09:39:09 -05:00
const showToast = useCustomToast ( ) ;
2024-02-15 17:17:26 -05:00
const onSubmit : SubmitHandler < FormData > = async ( data ) = > {
2024-02-29 17:30:58 -05:00
await LoginService . recoverPassword ( {
2024-02-15 17:17:26 -05:00
email : data.email ,
} ) ;
2024-02-26 09:39:09 -05:00
showToast ( "Email sent." , "We sent an email with a link to get back into your account." , "success" ) ;
2024-02-15 17:17:26 -05:00
} ;
return (
< Container
as = "form"
onSubmit = { handleSubmit ( onSubmit ) }
h = "100vh"
maxW = "sm"
alignItems = "stretch"
justifyContent = "center"
gap = { 4 }
centerContent
>
< Heading size = "xl" color = "ui.main" textAlign = "center" mb = { 2 } >
Password Recovery
< / Heading >
2024-02-29 17:30:58 -05:00
< Text align = "center" >
A password recovery email will be sent to the registered account .
< / Text >
< FormControl isInvalid = { ! ! errors . email } >
< Input id = 'email' { ...register ( 'email' , { required : 'Email is required' , pattern : { value : / ^ [ A - Z0 - 9._ % + - ] + @ [ A - Z0 - 9. - ] + \ . [ A - Z ] { 2 , 4 } $ / i , message : 'Invalid email address' } } ) } placeholder = 'Email' type = 'email' / >
{ errors . email && < FormErrorMessage > { errors . email . message } < / FormErrorMessage > }
2024-02-15 17:17:26 -05:00
< / FormControl >
2024-02-29 17:30:58 -05:00
< Button bg = "ui.main" color = "white" _hover = { { opacity : 0.8 } } type = "submit" isLoading = { isSubmitting } >
2024-02-15 17:17:26 -05:00
Continue
< / Button >
< / Container >
) ;
} ;
export default RecoverPassword ;