<commit_before>import React, { Component, PropTypes } from 'react'
import { connect } from 'react-redux'
import { GiftedForm, GiftedFormManager } from 'react-native-gifted-form'
import Store from 'react-native-simple-store'
import Routes from '../Navigation/Routes'
import styles from '../Styles/SettingsScreenStyle'
import Actions from '../Actions/Creators'

export default class SettingsScreen extends React.Component {

  static propTypes = {
    navigator: PropTypes.object.isRequired,
    dispatch: PropTypes.func,
  }

  constructor (props) {
    super(props)
    this.state = {}
  }

  componentDidMount(props) {
    console.log("giftedform mounted!")
    this.props.navigator.state.tappedBack = this.tappedBack.bind(this)
  }

  tappedBack() {
    const { dispatch } = this.props
    dispatch(Actions.saveSettings(GiftedFormManager.getValues('settingsForm')))
  }

  showTaxElements(){
    if(this.refs && this.refs.taxEnabled) {
      return this.refs.taxEnabled.state.value
    } else{
      return this.props.currentSettings.taxEnabled
    }
  }

  showShippingElements(){
    if(this.refs && this.refs.shippingEnabled) {
      return this.refs.shippingEnabled.state.value
    } else{
      return this.props.currentSettings.shippingEnabled
    }
  }

  _renderTax1(){
    if (this.showTaxElements()) {
      return (
        <GiftedForm.SwitchWidget
          name='taxPreDiscountedPrice'
          title='Tax pre-discounted price?' />
      )
    }
  }

  _renderTax2() {
    if (this.showTaxElements()) {
      return (
        <GiftedForm.TextInputWidget
          name='taxRate'
          title='Tax Rate (%):'
          keyboardType='numeric' />
      )
    }
  }

  _renderShipping1() {
    if (this.showShippingElements()) {
      return (
        <GiftedForm.TextInputWidget
          name='shippingRate'
          title='Flat Rate ($):'
          keyboardType='numeric' />
      )
    }
  }

  _renderShipping2() {
    if (this.showShippingElements()) {
      return (
        <GiftedForm.TextInputWidget
          name='shippingRatePct'
          title='% Rate:'
          keyboardType='numeric' />
      )
    }
  }

  _renderShipping3() {
    if (this.showShippingElements()) {
      return (
        <GiftedForm.TextInputWidget
          name='shippingNotToExceed'
          title='Not to exceed:'
          keyboardType='numeric' />
      )
    }
  }

  _renderShipping4() {
    if (this.showShippingElements()) {
      return (
        <GiftedForm.TextInputWidget
          name='shippingMinimum'
          title='Minimum:'
          keyboardType='numeric' />
      )
    }
  }

  _renderShipping5() {
    if (this.showShippingElements()) {
      return (
        <GiftedForm.SwitchWidget
          name='shippingTaxEnabled'
          title='Tax Shipping?' />
      )
    }
  }

  render() {
    return (
      <GiftedForm
        formName='setingsForm'
        clearOnClose={false} // delete the values of the form when unmounted
        defaults={this.props.currentSettings}
        style={styles.content}>

        <GiftedForm.SeparatorWidget />
        <GiftedForm.GroupWidget title='Tax'>
          <GiftedForm.SwitchWidget
            name='taxEnabled'
            title='Charge Tax?'
            ref='taxEnabled'
            onChange={(value) => {
              this.forceUpdate()
            }}
          />
        {this._renderTax1()}
        {this._renderTax2()}
        </GiftedForm.GroupWidget>

        <GiftedForm.SeparatorWidget />
        <GiftedForm.GroupWidget title='Shipping'><commit_msg>Fix form data saving.<commit_after>import React, { Component, PropTypes } from 'react'
import { connect } from 'react-redux'
import { GiftedForm, GiftedFormManager } from 'react-native-gifted-form'
import Store from 'react-native-simple-store'
import Routes from '../Navigation/Routes'
import styles from '../Styles/SettingsScreenStyle'
import Actions from '../Actions/Creators'

export default class SettingsScreen extends React.Component {

  static propTypes = {
    navigator: PropTypes.object.isRequired,
    dispatch: PropTypes.func,
  }

  constructor (props) {
    super(props)
  }

  componentDidMount(props) {
    console.log("giftedform mounted!")
  }

  handleValueChange(values) {
    const { dispatch } = this.props
    dispatch(Actions.saveSettings(values))
  }

  showTaxElements(){
    if(this.refs && this.refs.taxEnabled) {
      return this.refs.taxEnabled.state.value
    } else{
      return this.props.currentSettings.taxEnabled
    }
  }

  showShippingElements(){
    if(this.refs && this.refs.shippingEnabled) {
      return this.refs.shippingEnabled.state.value
    } else{
      return this.props.currentSettings.shippingEnabled
    }
  }

  _renderTax1(){
    if (this.showTaxElements()) {
      return (
        <GiftedForm.SwitchWidget
          name='taxPreDiscountedPrice'
          title='Tax pre-discounted price?' />
      )
    }
  }

  _renderTax2() {
    if (this.showTaxElements()) {
      return (
        <GiftedForm.TextInputWidget
          name='taxRate'
          title='Tax Rate (%):'
          keyboardType='numeric' />
      )
    }
  }

  _renderShipping1() {
    if (this.showShippingElements()) {
      return (
        <GiftedForm.TextInputWidget
          name='shippingRate'
          title='Flat Rate ($):'
          keyboardType='numeric' />
      )
    }
  }

  _renderShipping2() {
    if (this.showShippingElements()) {
      return (
        <GiftedForm.TextInputWidget
          name='shippingRatePct'
          title='% Rate:'
          keyboardType='numeric' />
      )
    }
  }

  _renderShipping3() {
    if (this.showShippingElements()) {
      return (
        <GiftedForm.TextInputWidget
          name='shippingNotToExceed'
          title='Not to exceed:'
          keyboardType='numeric' />
      )
    }
  }

  _renderShipping4() {
    if (this.showShippingElements()) {
      return (
        <GiftedForm.TextInputWidget
          name='shippingMinimum'
          title='Minimum:'
          keyboardType='numeric' />
      )
    }
  }

  _renderShipping5() {
    if (this.showShippingElements()) {
      return (
        <GiftedForm.SwitchWidget
          name='shippingTaxEnabled'
          title='Tax Shipping?' />
      )
    }
  }

  render() {
    return (
      <GiftedForm
        formName='setingsForm'
        clearOnClose={false} // delete the values of the form when unmounted
        defaults={this.props.currentSettings}
        style={styles.content}
        onValueChange={this.handleValueChange.bind(this)}>

        <GiftedForm.SeparatorWidget />
        <GiftedForm.GroupWidget title='Tax'>
          <GiftedForm.SwitchWidget
            name='taxEnabled'
            title='Charge Tax?'
            ref='taxEnabled'
            onChange={(value) => {
              this.forceUpdate()
            }}
          />
        {this._renderTax1()}
        {this._renderTax2()}
        </GiftedForm.GroupWidget>

        <GiftedForm.SeparatorWidget />
        <GiftedForm.GroupWidget title='Shipping'>
{'fraction_non_alphanumeric': 0.1187526697992311, 'fraction_numerical': 0.0025630072618539087, 'mean_word_length': 2.2639405204460967, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, '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': '6322085', 'n_tokens_mistral': 2132, 'n_tokens_neox': 2101, 'n_words': 332}