mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2025-03-13 08:41:41 +01:00
91 lines
2.8 KiB
TypeScript
91 lines
2.8 KiB
TypeScript
import React, { useState, useEffect } from 'react';
|
|
import { FormattedMessage, useIntl } from 'react-intl';
|
|
import { useHistory } from 'react-router-dom';
|
|
import Client, { ErrorInfo } from '../../classes/client';
|
|
|
|
import Header from '../layout/header';
|
|
import Footer from '../layout/footer';
|
|
import FormContainer from '../layout/form-container';
|
|
import { useSelector } from 'react-redux';
|
|
import { useMutation } from 'react-query';
|
|
import { activeInstance } from '../../redux/clientSlice';
|
|
import Input from '../form/input';
|
|
import GlobalError from '../form/global-error';
|
|
import SubmitButton from '../form/submit-button';
|
|
|
|
import Typography from '@material-ui/core/Typography';
|
|
|
|
const ForgotPassword = () => {
|
|
const [email, setEmail] = useState<string>('');
|
|
const [error, setError] = useState<ErrorInfo>();
|
|
const history = useHistory();
|
|
const intl = useIntl();
|
|
|
|
const service: Client = useSelector(activeInstance);
|
|
const mutation = useMutation<void, ErrorInfo, string>(
|
|
(email: string) => service.resetPassword(email),
|
|
{
|
|
onSuccess: () => history.push('/c/forgot-password-success'),
|
|
onError: (error) => {
|
|
setError(error);
|
|
},
|
|
}
|
|
);
|
|
|
|
const handleOnSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
|
event.preventDefault();
|
|
mutation.mutate(email);
|
|
};
|
|
|
|
return (
|
|
<FormContainer>
|
|
<Typography variant="h4" component="h1">
|
|
<FormattedMessage id="forgot.title" defaultMessage="Reset your password" />
|
|
</Typography>
|
|
|
|
<Typography>
|
|
<FormattedMessage
|
|
id="forgot.desc"
|
|
defaultMessage="We will send you an email to reset your password"
|
|
/>
|
|
</Typography>
|
|
|
|
<GlobalError error={error} />
|
|
|
|
<form onSubmit={handleOnSubmit}>
|
|
<Input
|
|
type="email"
|
|
name="email"
|
|
label={intl.formatMessage({ id: 'forgot.email', defaultMessage: 'Email' })}
|
|
autoComplete="email"
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
error={error}
|
|
/>
|
|
|
|
<SubmitButton
|
|
value={intl.formatMessage({
|
|
id: 'forgot.register',
|
|
defaultMessage: 'Send recovery link',
|
|
})}
|
|
/>
|
|
</form>
|
|
</FormContainer>
|
|
);
|
|
};
|
|
|
|
const ForgotPasswordPage = (): React.ReactElement => {
|
|
useEffect(() => {
|
|
document.title = 'Reset Password | WiseMapping';
|
|
});
|
|
|
|
return (
|
|
<div>
|
|
<Header type="only-signin" />
|
|
<ForgotPassword />
|
|
<Footer />
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export { ForgotPasswordPage };
|