<commit_before>import React, { Component } from 'react'
import Container from './Container'
import Formsy from 'formsy-react'
import { FormsyDate,
         FormsySelect,
         FormsyText,
         FormsyTime,
         FormsyToggle } from 'formsy-material-ui/lib'

import { RaisedButton,
         MenuItem     } from 'material-ui'


const errorMessages = {
    wordsError: "Please only use letters",
    numericError: "Please provide a number",
    urlError: "Please provide a valid URL"
  }

  const style = {
      referralOptions :{
          display: 'flex',
          justifyContent: 'space-between',
          alignItems: 'center',
      },
      uploadButton :{
          display: 'flex',
          justifyContent: 'center',
          alignItems: 'center'
      },
      card :{
          marginBottom : 15
      },
      cardActions :{
          textAlign: 'right'
      },
      paperStyle: {
      //   width: 300,
        margin: 'auto',
        padding: 20,
      },
      switchStyle: {
        marginBottom: 16,
      },
      submitStyle: {
        marginTop: 32,
      },
      chip: {
          margin: 4,
      },
      wrapper: {
          display: 'flex',
          flexWrap: 'wrap',
        }
  }



class ReferralForm extends Component {
  constructor(props) {
      super(props)
      this.enableButton = this.enableButton.bind(this)
      this.disableButton = this.disableButton.bind(this)
      this.submitForm = this.submitForm.bind(this)
      this.notifyFormError = this.notifyFormError.bind(this)

      this.state = {
          canSubmit: true,
          isFormDisabled: true
      }
  }

  disableButton = () => {
      this.setState({canSubmit: false})
  }

  enableButton = () => {
      this.setState({canSubmit: true})
  }

  submitForm = (data) => {
      console.log(JSON.stringify(data,null,2))
  }

  notifyFormError = (data) => {
      console.error('Form error:', data)
  }

  render(){
      return(
          <Container>
            <Formsy.Form
                onValid={this.enableButton}
                onInvalid={this.disableButton}
                onValidSubmit={this.submitForm}
                onInvalidSubmit={this.notifyFormError}
            >

                <div style={style.referralOptions}>
                    <RaisedButton label="Edit details" primary={true} style={style.uploadButton} />
                    <FormsySelect
                        name="referralStatus"
                        floatingLabelText="Status"
                        disabled={this.state.isFormDisabled}<commit_msg>added enable/disable function to referral form<commit_after>import React, { Component } from 'react'
import Container from './Container'
import Formsy from 'formsy-react'
import { FormsyDate,
         FormsySelect,
         FormsyText,
         FormsyTime,
         FormsyToggle } from 'formsy-material-ui/lib'

import { RaisedButton,
         MenuItem     } from 'material-ui'


const errorMessages = {
    wordsError: "Please only use letters",
    numericError: "Please provide a number",
    urlError: "Please provide a valid URL"
  }

  const style = {
      referralOptions :{
          display: 'flex',
          justifyContent: 'space-between',
          alignItems: 'center',
      },
      uploadButton :{
          display: 'flex',
          justifyContent: 'center',
          alignItems: 'center'
      },
      card :{
          marginBottom : 15
      },
      cardActions :{
          textAlign: 'right'
      },
      paperStyle: {
      //   width: 300,
        margin: 'auto',
        padding: 20,
      },
      switchStyle: {
        marginBottom: 16,
      },
      submitStyle: {
        marginTop: 32,
      },
      chip: {
          margin: 4,
      },
      wrapper: {
          display: 'flex',
          flexWrap: 'wrap',
        }
  }



class ReferralForm extends Component {
  constructor(props) {
      super(props)
      this.enableButton = this.enableButton.bind(this)
      this.disableButton = this.disableButton.bind(this)
      this.submitForm = this.submitForm.bind(this)
      this.notifyFormError = this.notifyFormError.bind(this)
      this.enableButton = this.enableButton.bind(this)

      this.state = {
          canSubmit: true,
          isFormDisabled: true,
          formDisabledStatus : 1
      }
  }

  disableButton = () => {
      this.setState({canSubmit: false})
  }

  enableButton = () => {
      this.setState({canSubmit: true})
  }

  enableEdit = () => {
      this.setState( { isFormDisabled: this.state.formDisabledStatus ? false : true  })
      this.setState( { formDisabledStatus: this.state.isFormDisabled ? 0 : 1  })
  }

  submitForm = (data) => {
      console.log(JSON.stringify(data,null,2))
  }

  notifyFormError = (data) => {
      console.error('Form error:', data)
  }

  render(){
      return(
          <Container>
            <Formsy.Form
                onValid={this.enableButton}
                onInvalid={this.disableButton}
                onValidSubmit={this.submitForm}
                onInvalidSubmit={this.notifyFormError}
            >

                <div style={style.referralOptions}>
                    <RaisedButton 
                        label="Edit details" 
                        primary={true} 
                        style={style.uploadButton} 
                        onClick={this.enableEdit}
                    />

                    <FormsySelect
                        name="referralStatus"
                        floatingLabelText="Status"
                        disabled={this.state.isFormDisabled}
{'fraction_non_alphanumeric': 0.1093974175035868, 'fraction_numerical': 0.005200860832137733, 'mean_word_length': 1.7311459353574927, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 20, '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': '1779161', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1511, 'n_words': 298}