2018-02-07 18:06:07 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2017-06-26 16:48:28 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import { browserHistory } from 'react-router';
|
|
|
|
import get from 'lodash/get';
|
2018-02-23 16:31:41 +00:00
|
|
|
import { Helmet } from 'react-helmet';
|
2017-06-26 16:48:28 +00:00
|
|
|
import { verifyEmailConfirmation } from '../actions';
|
2019-09-19 17:38:27 +00:00
|
|
|
import Nav from '../../../components/Nav';
|
2017-06-26 16:48:28 +00: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 = (
|
2019-09-19 17:38:27 +00:00
|
|
|
<p>That link is invalid.</p>
|
2017-06-26 16:48:28 +00:00
|
|
|
);
|
|
|
|
} else if (emailVerificationTokenState === 'checking') {
|
|
|
|
status = (
|
|
|
|
<p>Validating token, please wait...</p>
|
|
|
|
);
|
|
|
|
} else if (emailVerificationTokenState === 'verified') {
|
|
|
|
status = (
|
|
|
|
<p>All done, your email address has been verified.</p>
|
|
|
|
);
|
2019-09-19 17:38:27 +00:00
|
|
|
setTimeout(() => browserHistory.push('/'), 1000);
|
2017-06-26 16:48:28 +00:00
|
|
|
} else if (emailVerificationTokenState === 'invalid') {
|
|
|
|
status = (
|
|
|
|
<p>Something went wrong.</p>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-09-19 17:38:27 +00:00
|
|
|
<div className="email-verification">
|
|
|
|
<Nav layout="dashboard" />
|
2019-06-04 12:57:48 +00:00
|
|
|
<div className="form-container">
|
|
|
|
<Helmet>
|
|
|
|
<title>p5.js Web Editor | Email Verification</title>
|
|
|
|
</Helmet>
|
|
|
|
<div className="form-container__content">
|
|
|
|
<h2 className="form-container__title">Verify your email</h2>
|
|
|
|
{status}
|
|
|
|
</div>
|
2017-06-26 16:48:28 +00: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,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(EmailVerificationView);
|