2018-02-07 19:06:07 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2016-12-19 22:49:37 +01:00
|
|
|
import { reduxForm } from 'redux-form';
|
|
|
|
import classNames from 'classnames';
|
2017-02-22 20:29:35 +01:00
|
|
|
import { bindActionCreators } from 'redux';
|
2018-02-23 17:31:41 +01:00
|
|
|
import { Helmet } from 'react-helmet';
|
2020-08-13 14:25:57 +02:00
|
|
|
import { withTranslation } from 'react-i18next';
|
|
|
|
import i18next from 'i18next';
|
2017-02-22 20:29:35 +01:00
|
|
|
import NewPasswordForm from '../components/NewPasswordForm';
|
|
|
|
import * as UserActions from '../actions';
|
2019-09-19 19:38:27 +02:00
|
|
|
import Nav from '../../../components/Nav';
|
2017-02-22 20:29:35 +01:00
|
|
|
|
2019-09-19 19:38:27 +02:00
|
|
|
function NewPasswordView(props) {
|
|
|
|
const newPasswordClass = classNames({
|
|
|
|
'new-password': true,
|
|
|
|
'new-password--invalid': props.user.resetPasswordInvalid,
|
|
|
|
'form-container': true,
|
|
|
|
'user': true
|
|
|
|
});
|
|
|
|
return (
|
|
|
|
<div className="new-password-container">
|
|
|
|
<Nav layout="dashboard" />
|
|
|
|
<div className={newPasswordClass}>
|
|
|
|
<Helmet>
|
2020-08-13 14:25:57 +02:00
|
|
|
<title>{props.t('NewPasswordView.Title')}</title>
|
2019-09-19 19:38:27 +02:00
|
|
|
</Helmet>
|
|
|
|
<div className="form-container__content">
|
2020-08-13 14:25:57 +02:00
|
|
|
<h2 className="form-container__title">{props.t('NewPasswordView.Description')}</h2>
|
2019-09-19 19:38:27 +02:00
|
|
|
<NewPasswordForm {...props} />
|
|
|
|
<p className="new-password__invalid">
|
2020-08-13 14:25:57 +02:00
|
|
|
{props.t('NewPasswordView.TokenInvalidOrExpired')}
|
2019-09-19 19:38:27 +02:00
|
|
|
</p>
|
2016-12-19 22:49:37 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-09-19 19:38:27 +02:00
|
|
|
</div>
|
|
|
|
);
|
2016-12-19 22:49:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
NewPasswordView.propTypes = {
|
|
|
|
params: PropTypes.shape({
|
|
|
|
reset_password_token: PropTypes.string,
|
2017-02-22 20:29:35 +01:00
|
|
|
}).isRequired,
|
2016-12-19 22:49:37 +01:00
|
|
|
validateResetPasswordToken: PropTypes.func.isRequired,
|
|
|
|
user: PropTypes.shape({
|
|
|
|
resetPasswordInvalid: PropTypes.bool
|
2020-08-13 14:25:57 +02:00
|
|
|
}).isRequired,
|
|
|
|
t: PropTypes.func.isRequired
|
2016-12-19 22:49:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function validate(formProps) {
|
|
|
|
const errors = {};
|
|
|
|
|
|
|
|
if (!formProps.password) {
|
2020-08-13 14:25:57 +02:00
|
|
|
errors.password = i18next.t('NewPasswordView.EmptyPassword');
|
2016-12-19 22:49:37 +01:00
|
|
|
}
|
|
|
|
if (!formProps.confirmPassword) {
|
2020-08-13 14:25:57 +02:00
|
|
|
errors.confirmPassword = i18next.t('NewPasswordView.PasswordConfirmation');
|
2016-12-19 22:49:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (formProps.password !== formProps.confirmPassword) {
|
2020-08-13 14:25:57 +02:00
|
|
|
errors.password = i18next.t('NewPasswordView.PasswordMismatch');
|
2016-12-19 22:49:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
user: state.user
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return bindActionCreators(UserActions, dispatch);
|
|
|
|
}
|
|
|
|
|
2020-08-13 14:25:57 +02:00
|
|
|
export default withTranslation()(reduxForm({
|
2016-12-19 22:49:37 +01:00
|
|
|
form: 'new-password',
|
|
|
|
fields: ['password', 'confirmPassword'],
|
|
|
|
validate
|
2020-08-13 14:25:57 +02:00
|
|
|
}, mapStateToProps, mapDispatchToProps)(NewPasswordView));
|