2016-09-16 13:55:46 +00:00
|
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
|
|
import { connect } from 'react-redux';
|
2016-12-06 16:55:48 +00:00
|
|
|
|
import { push } from 'react-router-redux';
|
2016-09-16 13:55:46 +00:00
|
|
|
|
import { noop } from 'lodash';
|
2016-10-19 20:22:18 +00:00
|
|
|
|
|
2016-09-16 13:55:46 +00:00
|
|
|
|
import {
|
|
|
|
|
|
clearForgotPasswordErrors,
|
|
|
|
|
|
forgotPasswordAction,
|
2016-11-28 19:20:15 +00:00
|
|
|
|
} from 'redux/nodes/components/ForgotPasswordPage/actions';
|
|
|
|
|
|
import debounce from 'utilities/debounce';
|
|
|
|
|
|
import ForgotPasswordForm from 'components/forms/ForgotPasswordForm';
|
2016-12-22 19:26:18 +00:00
|
|
|
|
import Icon from 'components/icons/Icon';
|
2016-11-28 19:20:15 +00:00
|
|
|
|
import StackedWhiteBoxes from 'components/StackedWhiteBoxes';
|
2016-09-16 13:55:46 +00:00
|
|
|
|
|
|
|
|
|
|
export class ForgotPasswordPage extends Component {
|
|
|
|
|
|
static propTypes = {
|
|
|
|
|
|
dispatch: PropTypes.func,
|
|
|
|
|
|
email: PropTypes.string,
|
2017-01-06 00:01:17 +00:00
|
|
|
|
errors: PropTypes.shape({
|
|
|
|
|
|
base: PropTypes.string,
|
|
|
|
|
|
}),
|
2016-09-16 13:55:46 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
|
|
dispatch: noop,
|
|
|
|
|
|
};
|
2016-09-14 20:31:54 +00:00
|
|
|
|
|
2017-01-06 00:01:17 +00:00
|
|
|
|
componentWillUnmount () {
|
|
|
|
|
|
return this.clearErrors();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-12-06 16:55:48 +00:00
|
|
|
|
handleLeave = (location) => {
|
|
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
|
|
|
|
|
|
return dispatch(push(location));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-11-21 15:43:08 +00:00
|
|
|
|
handleSubmit = debounce((formData) => {
|
2016-09-16 13:55:46 +00:00
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
|
2017-01-06 00:01:17 +00:00
|
|
|
|
return dispatch(forgotPasswordAction(formData))
|
|
|
|
|
|
.catch(() => false);
|
2016-09-19 18:41:47 +00:00
|
|
|
|
})
|
2016-09-16 13:55:46 +00:00
|
|
|
|
|
|
|
|
|
|
clearErrors = () => {
|
|
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
|
|
|
|
|
|
return dispatch(clearForgotPasswordErrors);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
renderContent = () => {
|
2016-11-21 15:43:08 +00:00
|
|
|
|
const { clearErrors, handleSubmit } = this;
|
2017-01-06 00:01:17 +00:00
|
|
|
|
const { email, errors } = this.props;
|
2016-11-03 19:40:54 +00:00
|
|
|
|
|
|
|
|
|
|
const baseClass = 'forgot-password';
|
2016-09-16 13:55:46 +00:00
|
|
|
|
|
|
|
|
|
|
if (email) {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div>
|
2016-11-03 19:40:54 +00:00
|
|
|
|
<div className={`${baseClass}__text-wrapper`}>
|
|
|
|
|
|
<p className={`${baseClass}__text`}>
|
2016-09-16 13:55:46 +00:00
|
|
|
|
An email was sent to
|
2016-11-03 19:40:54 +00:00
|
|
|
|
<span className={`${baseClass}__email`}> {email}</span>.
|
2016-09-16 13:55:46 +00:00
|
|
|
|
Click the link on the email to proceed with the password reset process.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
2016-11-03 19:40:54 +00:00
|
|
|
|
<div className={`${baseClass}__button`}>
|
2016-11-28 19:20:15 +00:00
|
|
|
|
<Icon name="success-check" className={`${baseClass}__icon`} />
|
2016-09-16 13:55:46 +00:00
|
|
|
|
EMAIL SENT
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<ForgotPasswordForm
|
2016-11-21 15:43:08 +00:00
|
|
|
|
handleSubmit={handleSubmit}
|
2017-01-06 00:01:17 +00:00
|
|
|
|
onChangeFunc={clearErrors}
|
|
|
|
|
|
serverErrors={errors}
|
2016-09-16 13:55:46 +00:00
|
|
|
|
/>
|
|
|
|
|
|
);
|
2016-09-14 20:31:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render () {
|
2016-12-06 16:55:48 +00:00
|
|
|
|
const { handleLeave } = this;
|
2016-09-16 21:19:37 +00:00
|
|
|
|
const leadText = 'If you’ve forgotten your password enter your email below and we will email you a link so that you can reset your password.';
|
2016-09-14 20:31:54 +00:00
|
|
|
|
|
|
|
|
|
|
return (
|
2016-09-16 21:19:37 +00:00
|
|
|
|
<StackedWhiteBoxes
|
|
|
|
|
|
headerText="Forgot Password"
|
|
|
|
|
|
leadText={leadText}
|
|
|
|
|
|
previousLocation="/login"
|
2016-12-06 16:55:48 +00:00
|
|
|
|
className="forgot-password"
|
|
|
|
|
|
onLeave={handleLeave}
|
2016-09-16 21:19:37 +00:00
|
|
|
|
>
|
|
|
|
|
|
{this.renderContent()}
|
|
|
|
|
|
</StackedWhiteBoxes>
|
2016-09-14 20:31:54 +00:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-16 13:55:46 +00:00
|
|
|
|
const mapStateToProps = (state) => {
|
|
|
|
|
|
return state.components.ForgotPasswordPage;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(ForgotPasswordPage);
|