<commit_before>import { Components, registerComponent, withCurrentUser } from 'meteor/vulcan:core';
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { intlShape } from 'meteor/vulcan:i18n';
import { withApollo } from 'react-apollo';

class AccountsVerifyEmail extends PureComponent {
  constructor(props) {
    super(props)
    this.state = {
      pending: true,
      error: null
    }
  }

  componentDidMount() {
    const token = this.props.params.token;
    Accounts.verifyEmail(token, (verifyEmailResult) => {
      if(verifyEmailResult && verifyEmailResult.error) {
        this.setState({
          pending: false,
          error: verifyEmailResult.reason
        });
      } else {
        this.setState({
          pending: false,
          error: null
        });

        // Reset the Apollo cache. Unfortunately there isn't
        // really a more granular way to do this (see
        // https://github.com/apollographql/apollo-feature-requests/issues/4 ).
        // For LW2, this ensures that, if you navigate from
        // the "Your email address has been verified" page
        // to the "Edit Account" page, you won't see a
        // widget telling you your address is still
        // unverified.
        this.props.client.resetStore();
      }
    });
  }

  render() {
    if(this.state.pending) {
      return <Components.Loading />
    } else if(this.state.error) {
      return (
        <div className='password-reset-form'>
          {this.state.error}
        </div>
      );
    } else {
      return (
        <div className='password-reset-form'>
          {this.context.intl.formatMessage({id: 'accounts.email_verified'})}
        </div>
      );
    }
  }
}

AccountsVerifyEmail.contextTypes = {
  intl: intlShape
}

AccountsVerifyEmail.propsTypes = {
  currentUser: PropTypes.object,
  params: PropTypes.object,
};

AccountsVerifyEmail.displayName = 'AccountsEnrollAccount';

// Shadows AccountsVerifyEmail in meteor/vulcan:accounts
registerComponent('AccountsVerifyEmail', AccountsVerifyEmail, withCurrentUser, withApollo);
<commit_msg>Refactor AccountsVerifyEmail<commit_after>import { Components, registerComponent, withCurrentUser } from 'meteor/vulcan:core';
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import { withApollo } from 'react-apollo';

const styles = theme => ({
  root: {
    textAlign: "center",
  }
});

class AccountsVerifyEmail extends PureComponent {
  constructor(props) {
    super(props)
    this.state = {
      pending: true,
      error: null
    }
  }

  componentDidMount() {
    const token = this.props.params.token;
    Accounts.verifyEmail(token, (verifyEmailResult) => {
      if(verifyEmailResult && verifyEmailResult.error) {
        this.setState({
          pending: false,
          error: verifyEmailResult.reason
        });
      } else {
        this.setState({
          pending: false,
          error: null
        });

        // Reset the Apollo cache. Unfortunately there isn't
        // really a more granular way to do this (see
        // https://github.com/apollographql/apollo-feature-requests/issues/4 ).
        // For LW2, this ensures that, if you navigate from
        // the "Your email address has been verified" page
        // to the "Edit Account" page, you won't see a
        // widget telling you your address is still
        // unverified.
        this.props.client.resetStore();
      }
    });
  }

  render() {
    const { classes } = this.props;
    
    if(this.state.pending) {
      return (
        <div className={classes.root}>
          <Components.Loading />
        </div>
      );
    } else if(this.state.error) {
      return (
        <div className={classes.root}>
          {this.state.error}
        </div>
      );
    } else {
      return (
        <div className={classes.root}>
          Your email address has been verified.
        </div>
      );
    }
  }
}

AccountsVerifyEmail.propTypes = {
  params: PropTypes.object,
};

AccountsVerifyEmail.displayName = 'AccountsEnrollAccount';

// Shadows AccountsVerifyEmail in meteor/vulcan:accounts
registerComponent('AccountsVerifyEmail', AccountsVerifyEmail,
  withApollo, withStyles(styles, { name: "AccountsVerifyEmail" }));

{'fraction_non_alphanumeric': 0.11602209944751381, 'fraction_numerical': 0.0013812154696132596, 'mean_word_length': 2.470447284345048, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 18, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3400148', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1265, 'n_words': 296}