import { useCallback, useState } from 'react' import { Link } from 'react-router-dom' import { Button, FormControl, FormErrorMessage, Input, Link as ChakraLink, Heading, } from '@chakra-ui/react' import { Field, FieldAttributes, FieldProps, Form, Formik, FormikHelpers, } from 'formik' import * as Yup from 'yup' import cx from 'classnames' import { Helmet } from 'react-helmet-async' import AccountAPI from '@/client/idp/account' import Logo from '@/components/common/logo' import LayoutFull from '@/components/layout/layout-full' type FormValues = { email: string } const ForgotPasswordPage = () => { const formSchema = Yup.object().shape({ email: Yup.string() .email('Email is not valid') .required('Email is required'), }) const [isCompleted, setIsCompleted] = useState(false) const handleSubmit = useCallback( async ( { email }: FormValues, { setSubmitting }: FormikHelpers, ) => { try { await AccountAPI.sendResetPasswordEmail({ email, }) setIsCompleted(true) } finally { setSubmitting(false) } }, [], ) return ( <> Forgot Password
Forgot Password {isCompleted ? ( If your email belongs to an account, you will receive the recovery instructions in your inbox shortly. ) : ( <> Please provide your account Email where we can send you the password recovery instructions. {({ errors, touched, isSubmitting }) => (
{({ field }: FieldAttributes) => ( {errors.email} )}
)}
Password recovered? Sign In
)}
) } export default ForgotPasswordPage