p5.js-web-editor/client/modules/IDE/components/NewPasswordView.js

75 lines
2 KiB
JavaScript
Raw Normal View History

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';
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
});
return (
2016-10-18 21:06:53 +00:00
<div className={newPasswordClass} ref="newPassword" tabIndex="0">
<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>
</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
})
};
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);