<commit_before>import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux'
import { attemptLogin } from 'actions/AuthActions';

import LoginForm from './components/LoginForm';

class LoginFormContainer extends Component {
  constructor(props) {
    super(props);
  }

  hasErrors = false

  state = {
    email: '',
    password: '',
    emailErrorText: null,
    passwordErrorText: null,
  }
 
  handleInputChange = (event, type, value) => {
    this.setState(Object.assign({},
      this.state,
      { [type]: value }
    ));
  }

  // TODO: this is used in SignupForm as well - DRY it out
  validateString = (prop, errorProp, errorMsg) => {
    if (typeof this.state[prop] !== 'string' || 
        this.state[prop].trim() === '') {

      this.setState({ 
        [errorProp]: errorMsg 
      });

      this.hasErrors = true;

    } else {
      this.setState({ 
        [errorProp]: null 
      });
    }
  }

  formSubmit = (event) => {
    console.log(event);
    event.preventDefault();
    this.hasErrors = false;

    this.validateString('email', 'emailErrorText', 'Email is Required');
    this.validateString('password', 'passwordErrorText', 'Password is Required');
    console.log(this.state);

    if (!this.hasErrors) {
      this.props.dispatch(attemptLogin({
        email: this.state.email,
        password: this.state.password,
      }));
    }
  }

  render() {
    return (<commit_msg>Adding email validation to Login Page.<commit_after>import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux'
import isEmail from 'validator/lib/isEmail';

import { attemptLogin } from 'actions/AuthActions';

import LoginForm from './components/LoginForm';


class LoginFormContainer extends Component {
  constructor(props) {
    super(props);
  }

  hasErrors = false

  state = {
    email: '',
    password: '',
    emailErrorText: null,
    passwordErrorText: null,
  }
 
  handleInputChange = (event, type, value) => {
    this.setState(Object.assign({},
      this.state,
      { [type]: value }
    ));
  }

  // TODO: this is used in SignupForm as well - DRY it out
  validateString = (prop, errorProp, errorMsg) => {
    if (typeof this.state[prop] !== 'string' || 
        this.state[prop].trim() === '') {

      this.setState({ 
        [errorProp]: errorMsg 
      });

      this.hasErrors = true;

    } else {
      this.setState({ 
        [errorProp]: null 
      });
    }
  }

  validateEmail = () => {
    this.setState({
      emailErrorText: null,
    });

    this.validateString('email', 'emailErrorText', 'Email is Required');

    if (typeof this.state.email === 'string' &&
        !isEmail(this.state.email)) {

      this.setState({
        emailErrorText: 'Please enter a valid email'
      });
      this.hasErrors = true;
    }
  }

  formSubmit = (event) => {
    console.log(event);
    event.preventDefault();
    this.hasErrors = false;

    this.validateEmail();
    this.validateString('password', 'passwordErrorText', 'Password is Required');
    console.log(this.state);

    if (!this.hasErrors) {
      this.props.dispatch(attemptLogin({
        email: this.state.email,
        password: this.state.password,
      }));
    }
  }

  render() {
    return (
{'fraction_non_alphanumeric': 0.1463042150274893, 'fraction_numerical': 0.0, 'mean_word_length': 2.630820399113082, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, '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': '348676', 'n_tokens_mistral': 1009, 'n_tokens_neox': 980, 'n_words': 220}