2019-06-12 05:02:18 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import requestPasswordResetEmail from '@/api/auth/requestPasswordResetEmail';
|
2019-06-12 06:12:03 +00:00
|
|
|
import { httpErrorToHuman } from '@/api/http';
|
2019-06-22 20:53:41 +00:00
|
|
|
import LoginFormContainer from '@/components/auth/LoginFormContainer';
|
2019-06-22 23:45:51 +00:00
|
|
|
import { Actions, useStoreActions } from 'easy-peasy';
|
|
|
|
import { ApplicationState } from '@/state/types';
|
|
|
|
import FlashMessageRender from '@/components/FlashMessageRender';
|
2019-06-12 05:02:18 +00:00
|
|
|
|
2019-06-22 23:45:51 +00:00
|
|
|
export default () => {
|
|
|
|
const [ isSubmitting, setSubmitting ] = React.useState(false);
|
|
|
|
const [ email, setEmail ] = React.useState('');
|
2019-06-12 05:02:18 +00:00
|
|
|
|
2019-06-22 23:45:51 +00:00
|
|
|
const { clearFlashes, addFlash } = useStoreActions((actions: Actions<ApplicationState>) => actions.flashes);
|
2019-06-12 05:02:18 +00:00
|
|
|
|
2019-06-22 23:45:51 +00:00
|
|
|
const handleFieldUpdate = (e: React.ChangeEvent<HTMLInputElement>) => setEmail(e.target.value);
|
2019-06-16 22:24:20 +00:00
|
|
|
|
2019-06-22 23:45:51 +00:00
|
|
|
const handleSubmission = (e: React.FormEvent<HTMLFormElement>) => {
|
2019-06-12 05:02:18 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
2019-06-22 23:45:51 +00:00
|
|
|
setSubmitting(true);
|
|
|
|
clearFlashes();
|
|
|
|
requestPasswordResetEmail(email)
|
|
|
|
.then(response => {
|
|
|
|
setEmail('');
|
|
|
|
addFlash({ type: 'success', title: 'Success', message: response });
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
addFlash({ type: 'error', title: 'Error', message: httpErrorToHuman(error) });
|
|
|
|
})
|
|
|
|
.then(() => setSubmitting(false));
|
2019-06-12 06:12:03 +00:00
|
|
|
};
|
2019-06-12 05:02:18 +00:00
|
|
|
|
2019-06-22 23:45:51 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h2 className={'text-center text-neutral-100 font-medium py-4'}>
|
|
|
|
Request Password Reset
|
|
|
|
</h2>
|
|
|
|
<FlashMessageRender/>
|
|
|
|
<LoginFormContainer onSubmit={handleSubmission}>
|
|
|
|
<label htmlFor={'email'}>Email</label>
|
|
|
|
<input
|
|
|
|
id={'email'}
|
|
|
|
type={'email'}
|
|
|
|
required={true}
|
|
|
|
className={'input'}
|
|
|
|
value={email}
|
|
|
|
onChange={handleFieldUpdate}
|
|
|
|
autoFocus={true}
|
|
|
|
/>
|
|
|
|
<p className={'input-help'}>
|
|
|
|
Enter your account email address to receive instructions on resetting your password.
|
|
|
|
</p>
|
|
|
|
<div className={'mt-6'}>
|
|
|
|
<button
|
|
|
|
className={'btn btn-primary btn-jumbo flex justify-center'}
|
|
|
|
disabled={isSubmitting || email.length < 5}
|
|
|
|
>
|
|
|
|
{isSubmitting ?
|
|
|
|
<div className={'spinner-circle spinner-sm spinner-white'}></div>
|
|
|
|
:
|
|
|
|
'Send Email'
|
|
|
|
}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div className={'mt-6 text-center'}>
|
|
|
|
<Link
|
2019-06-23 01:09:42 +00:00
|
|
|
to={'/auth/login'}
|
2019-06-22 23:45:51 +00:00
|
|
|
className={'text-xs text-neutral-500 tracking-wide uppercase no-underline hover:text-neutral-700'}
|
|
|
|
>
|
|
|
|
Return to Login
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
</LoginFormContainer>
|
|
|
|
</div>
|
|
|
|
);
|
2019-06-12 06:12:03 +00:00
|
|
|
};
|