<commit_before>import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Field, reduxForm } from 'redux-form'
import { PropTypes } from 'prop-types'
import { Button, Form, Divider } from 'semantic-ui-react'
import SemanticReduxFormField from './form/SemanticReduxFormField'
import ErrorMessage from './ErrorMessage'
import { updateProfile } from '../actions'

const form = reduxForm({
  form: 'editProfile',
  validate
})

function validate (formProps) {
  const errors = {}

  if (!formProps.email) {
    errors.email = 'Please enter an email'
  } else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(formProps.email)) {
    errors.email = 'Invalid email address.'
  }

  if (formProps.new_password && formProps.new_password.length < 8) {
    errors.new_password = 'Your password must be 8 characters or longer.'
  }

  return errors
}

class EntryForm extends Component {
  static propTypes = {
    handleSubmit: PropTypes.func.isRequired,
    errorMessage: PropTypes.string,
    updateProfile: PropTypes.func
  }

  constructor (props) {
    super(props)
    this.handleFormSubmit = this.handleFormSubmit.bind(this)
  }

  handleFormSubmit (formProps) {
    this.props.updateProfile(formProps)
  }
<commit_msg>Add password validation to profile edit form<commit_after>import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Field, reduxForm } from 'redux-form'
import { PropTypes } from 'prop-types'
import { Button, Form, Divider } from 'semantic-ui-react'
import SemanticReduxFormField from './form/SemanticReduxFormField'
import ErrorMessage from './ErrorMessage'
import { updateProfile } from '../actions'

const form = reduxForm({
  form: 'editProfile',
  validate
})

function validate (formProps) {
  const errors = {}

  if (!formProps.email) {
    errors.email = 'Please enter an email'
  } else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(formProps.email)) {
    errors.email = 'Invalid email address.'
  }

  if (formProps.new_password && formProps.new_password.length < 8) {
    errors.new_password = 'Your new password must be 8 characters or longer.'
  }

  if(!formProps.password) {
    errors.password = 'You must provide your password to edit your account.'
  }

  return errors
}

class EntryForm extends Component {
  static propTypes = {
    handleSubmit: PropTypes.func.isRequired,
    errorMessage: PropTypes.string,
    updateProfile: PropTypes.func
  }

  constructor (props) {
    super(props)
    this.handleFormSubmit = this.handleFormSubmit.bind(this)
  }

  handleFormSubmit (formProps) {
    this.props.updateProfile(formProps)
  }

{'fraction_non_alphanumeric': 0.1290200529701097, 'fraction_numerical': 0.006053726825576996, 'mean_word_length': 3.878228782287823, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3195875', 'n_tokens_mistral': 841, 'n_tokens_neox': 831, 'n_words': 210}