import Button from '@app/components/Common/Button'; import ImageFader from '@app/components/Common/ImageFader'; import PageTitle from '@app/components/Common/PageTitle'; import LanguagePicker from '@app/components/Layout/LanguagePicker'; import defineMessages from '@app/utils/defineMessages'; import { ArrowLeftIcon, EnvelopeIcon } from '@heroicons/react/24/solid'; import { Field, Form, Formik } from 'formik'; import Image from 'next/image'; import Link from 'next/link'; import { useState } from 'react'; import { useIntl } from 'react-intl'; import * as Yup from 'yup'; const messages = defineMessages('components.ResetPassword', { passwordreset: 'Password Reset', resetpassword: 'Reset your password', emailresetlink: 'Email Recovery Link', email: 'Email Address', validationemailrequired: 'You must provide a valid email address', gobacklogin: 'Return to Sign-In Page', requestresetlinksuccessmessage: 'A password reset link will be sent to the provided email address if it is associated with a valid user.', }); const ResetPassword = () => { const intl = useIntl(); const [hasSubmitted, setSubmitted] = useState(false); const ResetSchema = Yup.object().shape({ email: Yup.string() .email(intl.formatMessage(messages.validationemailrequired)) .required(intl.formatMessage(messages.validationemailrequired)), }); return (
Logo

{intl.formatMessage(messages.resetpassword)}

{hasSubmitted ? ( <>

{intl.formatMessage(messages.requestresetlinksuccessmessage)}

) : ( { const res = await fetch(`/api/v1/auth/reset-password`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ email: values.email, }), }); if (!res.ok) throw new Error(); if (res.status === 200) { setSubmitted(true); } }} > {({ errors, touched, isSubmitting, isValid }) => { return (
{errors.email && touched.email && typeof errors.email === 'string' && (
{errors.email}
)}
); }}
)}
); }; export default ResetPassword;