import React, { useState } from 'react'; import { RouteComponentProps } from 'react-router'; import { parse } from 'query-string'; import { Link } from 'react-router-dom'; import performPasswordReset from '@/api/auth/performPasswordReset'; import { httpErrorToHuman } from '@/api/http'; import LoginFormContainer from '@/components/auth/LoginFormContainer'; import FlashMessageRender from '@/components/FlashMessageRender'; import { Actions, useStoreActions } from 'easy-peasy'; import { ApplicationStore } from '@/state'; import Spinner from '@/components/elements/Spinner'; type Props = Readonly & {}>; export default (props: Props) => { const [ isLoading, setIsLoading ] = useState(false); const [ email, setEmail ] = useState(''); const [ password, setPassword ] = useState(''); const [ passwordConfirm, setPasswordConfirm ] = useState(''); const { clearFlashes, addFlash } = useStoreActions((actions: Actions) => actions.flashes); const parsed = parse(props.location.search); if (email.length === 0 && parsed.email) { setEmail(parsed.email as string); } const canSubmit = () => password && email && password.length >= 8 && password === passwordConfirm; const submit = (e: React.FormEvent) => { e.preventDefault(); if (!password || !email || !passwordConfirm) { return; } setIsLoading(true); clearFlashes(); performPasswordReset(email, { token: props.match.params.token, password, passwordConfirmation: passwordConfirm, }) .then(() => { addFlash({ type: 'success', message: 'Your password has been reset, please login to continue.' }); props.history.push('/auth/login'); }) .catch(error => { console.error(error); addFlash({ type: 'error', title: 'Error', message: httpErrorToHuman(error) }); }) .then(() => setIsLoading(false)); }; return (

Reset Password

setPassword(e.target.value)} />

Passwords must be at least 8 characters in length.

setPasswordConfirm(e.target.value)} />
Return to Login
); };