import PropTypes from 'prop-types'; import React from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { browserHistory } from 'react-router'; import InlineSVG from 'react-inlinesvg'; import get from 'lodash/get'; import { verifyEmailConfirmation } from '../actions'; const exitUrl = require('../../../images/exit.svg'); const logoUrl = require('../../../images/p5js-logo.svg'); class EmailVerificationView extends React.Component { static defaultProps = { emailVerificationTokenState: null, } constructor(props) { super(props); this.closeLoginPage = this.closeLoginPage.bind(this); this.gotoHomePage = this.gotoHomePage.bind(this); this.state = { error: null, }; } componentWillMount() { const verificationToken = this.verificationToken(); if (verificationToken != null) { this.props.verifyEmailConfirmation(verificationToken); } } verificationToken = () => get(this.props, 'location.query.t', null); closeLoginPage() { browserHistory.push(this.props.previousPath); } gotoHomePage() { browserHistory.push('/'); } render() { let status = null; const { emailVerificationTokenState, } = this.props; if (this.verificationToken() == null) { status = (

That link is invalid

); } else if (emailVerificationTokenState === 'checking') { status = (

Validating token, please wait...

); } else if (emailVerificationTokenState === 'verified') { status = (

All done, your email address has been verified.

); } else if (emailVerificationTokenState === 'invalid') { status = (

Something went wrong.

); } return (

Verify your email

{status}
); } } function mapStateToProps(state) { return { emailVerificationTokenState: state.user.emailVerificationTokenState, previousPath: state.ide.previousPath }; } function mapDispatchToProps(dispatch) { return bindActionCreators({ verifyEmailConfirmation, }, dispatch); } EmailVerificationView.propTypes = { previousPath: PropTypes.string.isRequired, emailVerificationTokenState: PropTypes.oneOf([ 'checking', 'verified', 'invalid' ]), verifyEmailConfirmation: PropTypes.func.isRequired, }; export default connect(mapStateToProps, mapDispatchToProps)(EmailVerificationView);