2016-10-18 20:07:25 +00:00
|
|
|
import React, { PropTypes } from 'react';
|
|
|
|
import { reduxForm } from 'redux-form';
|
|
|
|
import NewPasswordForm from './NewPasswordForm';
|
|
|
|
import * as UserActions from '../../User/actions';
|
|
|
|
import { bindActionCreators } from 'redux';
|
2016-10-18 21:06:53 +00:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import { Link } from 'react-router';
|
2016-10-18 20:07:25 +00:00
|
|
|
|
|
|
|
class NewPasswordView extends React.Component {
|
|
|
|
componentDidMount() {
|
|
|
|
this.refs.newPassword.focus();
|
|
|
|
// need to check if this is a valid token
|
|
|
|
this.props.validateResetPasswordToken(this.props.token);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-10-18 21:06:53 +00:00
|
|
|
const newPasswordClass = classNames({
|
|
|
|
'new-password': true,
|
|
|
|
'new-password--invalid': this.props.user.resetPasswordInvalid
|
|
|
|
});
|
|
|
|
console.log(this.props.user);
|
|
|
|
console.log('rerendering!!');
|
2016-10-18 20:07:25 +00:00
|
|
|
return (
|
2016-10-18 21:06:53 +00:00
|
|
|
<div className={newPasswordClass} ref="newPassword" tabIndex="0">
|
2016-10-18 20:07:25 +00:00
|
|
|
<h1>Set a New Password</h1>
|
|
|
|
<NewPasswordForm {...this.props} />
|
2016-10-18 21:06:53 +00:00
|
|
|
<p className="new-password__invalid">
|
|
|
|
The password reset token is invalid or has expired.
|
|
|
|
</p>
|
|
|
|
<Link className="form__cancel-button" to="/">Close</Link>
|
2016-10-18 20:07:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NewPasswordView.propTypes = {
|
|
|
|
token: PropTypes.string.isRequired,
|
2016-10-18 21:06:53 +00:00
|
|
|
validateResetPasswordToken: PropTypes.func.isRequired,
|
|
|
|
user: PropTypes.shape({
|
|
|
|
resetPasswordInvalid: PropTypes.bool
|
|
|
|
})
|
2016-10-18 20:07:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function validate(formProps) {
|
|
|
|
const errors = {};
|
|
|
|
|
|
|
|
if (!formProps.password) {
|
|
|
|
errors.password = 'Please enter a password';
|
|
|
|
}
|
|
|
|
if (!formProps.confirmPassword) {
|
|
|
|
errors.confirmPassword = 'Please enter a password confirmation';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (formProps.password !== formProps.confirmPassword) {
|
|
|
|
errors.password = 'Passwords must match';
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state, ownProps) {
|
|
|
|
return {
|
|
|
|
user: state.user,
|
|
|
|
token: ownProps.token
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return bindActionCreators(UserActions, dispatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default reduxForm({
|
|
|
|
form: 'new-password',
|
|
|
|
fields: ['password', 'confirmPassword'],
|
|
|
|
validate
|
|
|
|
}, mapStateToProps, mapDispatchToProps)(NewPasswordView);
|