2018-02-07 19:06:07 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2017-06-26 18:48:28 +02:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import { browserHistory } from 'react-router';
|
2020-08-18 11:07:27 +02:00
|
|
|
import { withTranslation } from 'react-i18next';
|
2017-06-26 18:48:28 +02:00
|
|
|
import get from 'lodash/get';
|
2018-02-23 17:31:41 +01:00
|
|
|
import { Helmet } from 'react-helmet';
|
2017-06-26 18:48:28 +02:00
|
|
|
import { verifyEmailConfirmation } from '../actions';
|
2019-09-19 19:38:27 +02:00
|
|
|
import Nav from '../../../components/Nav';
|
2017-06-26 18:48:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
class EmailVerificationView extends React.Component {
|
|
|
|
static defaultProps = {
|
|
|
|
emailVerificationTokenState: null,
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
const verificationToken = this.verificationToken();
|
|
|
|
if (verificationToken != null) {
|
|
|
|
this.props.verifyEmailConfirmation(verificationToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
verificationToken = () => get(this.props, 'location.query.t', null);
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let status = null;
|
|
|
|
const {
|
|
|
|
emailVerificationTokenState,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (this.verificationToken() == null) {
|
|
|
|
status = (
|
2020-08-18 11:07:27 +02:00
|
|
|
<p>{this.props.t('EmailVerificationView.InvalidTokenNull')}</p>
|
2017-06-26 18:48:28 +02:00
|
|
|
);
|
|
|
|
} else if (emailVerificationTokenState === 'checking') {
|
|
|
|
status = (
|
2020-08-18 11:07:27 +02:00
|
|
|
<p>{this.props.t('EmailVerificationView.Checking')}</p>
|
2017-06-26 18:48:28 +02:00
|
|
|
);
|
|
|
|
} else if (emailVerificationTokenState === 'verified') {
|
|
|
|
status = (
|
2020-08-18 11:07:27 +02:00
|
|
|
<p>{this.props.t('EmailVerificationView.Verified')}</p>
|
2017-06-26 18:48:28 +02:00
|
|
|
);
|
2019-09-19 19:38:27 +02:00
|
|
|
setTimeout(() => browserHistory.push('/'), 1000);
|
2017-06-26 18:48:28 +02:00
|
|
|
} else if (emailVerificationTokenState === 'invalid') {
|
|
|
|
status = (
|
2020-08-18 11:07:27 +02:00
|
|
|
<p>{this.props.t('EmailVerificationView.InvalidState')}</p>
|
2017-06-26 18:48:28 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-09-19 19:38:27 +02:00
|
|
|
<div className="email-verification">
|
|
|
|
<Nav layout="dashboard" />
|
2019-06-04 14:57:48 +02:00
|
|
|
<div className="form-container">
|
|
|
|
<Helmet>
|
2020-08-18 11:07:27 +02:00
|
|
|
<title>{this.props.t('EmailVerificationView.Title')}</title>
|
2019-06-04 14:57:48 +02:00
|
|
|
</Helmet>
|
|
|
|
<div className="form-container__content">
|
2020-08-18 11:07:27 +02:00
|
|
|
<h2 className="form-container__title">{this.props.t('EmailVerificationView.Verify')}</h2>
|
2019-06-04 14:57:48 +02:00
|
|
|
{status}
|
|
|
|
</div>
|
2017-06-26 18:48:28 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
emailVerificationTokenState: state.user.emailVerificationTokenState,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return bindActionCreators({
|
|
|
|
verifyEmailConfirmation,
|
|
|
|
}, dispatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EmailVerificationView.propTypes = {
|
|
|
|
emailVerificationTokenState: PropTypes.oneOf([
|
|
|
|
'checking', 'verified', 'invalid'
|
|
|
|
]),
|
|
|
|
verifyEmailConfirmation: PropTypes.func.isRequired,
|
2020-08-18 11:07:27 +02:00
|
|
|
t: PropTypes.func.isRequired
|
2017-06-26 18:48:28 +02:00
|
|
|
};
|
|
|
|
|
2020-08-18 11:07:27 +02:00
|
|
|
export default withTranslation()(connect(mapStateToProps, mapDispatchToProps)(EmailVerificationView));
|