import React, { useState } from 'react'; import ImageFader from '../Common/ImageFader'; import { defineMessages, useIntl } from 'react-intl'; import LanguagePicker from '../Layout/LanguagePicker'; import Button from '../Common/Button'; import { Field, Form, Formik } from 'formik'; import * as Yup from 'yup'; import axios from 'axios'; import { useRouter } from 'next/router'; import Link from 'next/link'; const messages = defineMessages({ passwordreset: 'Password Reset', resetpassword: 'Reset your password', password: 'Password', confirmpassword: 'Confirm Password', validationpasswordrequired: 'You must provide a password', validationpasswordmatch: 'Passwords must match', validationpasswordminchars: 'Password is too short; should be a minimum of 8 characters', gobacklogin: 'Return to Sign-In Page', resetpasswordsuccessmessage: 'Password reset successfully!', }); const ResetPassword: React.FC = () => { const intl = useIntl(); const router = useRouter(); const [hasSubmitted, setSubmitted] = useState(false); const guid = router.query.guid; const ResetSchema = Yup.object().shape({ password: Yup.string() .required(intl.formatMessage(messages.validationpasswordrequired)) .min(8, intl.formatMessage(messages.validationpasswordminchars)), confirmPassword: Yup.string() .required(intl.formatMessage(messages.validationpasswordmatch)) .test( 'passwords-match', intl.formatMessage(messages.validationpasswordmatch), function (value) { return this.parent.password === value; } ), }); return (
Logo

{intl.formatMessage(messages.resetpassword)}

{hasSubmitted ? ( <>

{intl.formatMessage(messages.resetpasswordsuccessmessage)}

) : ( { const response = await axios.post( `/api/v1/auth/reset-password/${guid}`, { password: values.password, } ); if (response.status === 200) { setSubmitted(true); } }} > {({ errors, touched, isSubmitting, isValid }) => { return (
{errors.password && touched.password && (
{errors.password}
)}
{errors.confirmPassword && touched.confirmPassword && (
{errors.confirmPassword}
)}
); }}
)}
); }; export default ResetPassword;