diff options
| author | Zog | 2018-01-10 15:59:17 +0100 | 
|---|---|---|
| committer | Zog | 2018-01-12 15:41:11 +0100 | 
| commit | 84f3edcfc7213d5a02f10ba002e091e1563f2e27 (patch) | |
| tree | bade2d2f0aa4ee2eb16b2f3bcaf65bf5bdafb5d2 /app/javascript/journey_patterns | |
| parent | 853c7494b908c8b9dea3b91332ab1265aa40f428 (diff) | |
| download | chouette-core-84f3edcfc7213d5a02f10ba002e091e1563f2e27.tar.bz2 | |
Refs #5529 @0.5h; Refactor buttons5529-prevent-double-submitting-of-react-forms
Diffstat (limited to 'app/javascript/journey_patterns')
| -rw-r--r-- | app/javascript/journey_patterns/components/SaveJourneyPattern.js | 45 | 
1 files changed, 8 insertions, 37 deletions
| diff --git a/app/javascript/journey_patterns/components/SaveJourneyPattern.js b/app/javascript/journey_patterns/components/SaveJourneyPattern.js index d973147a0..4bb6a73a0 100644 --- a/app/javascript/journey_patterns/components/SaveJourneyPattern.js +++ b/app/javascript/journey_patterns/components/SaveJourneyPattern.js @@ -1,48 +1,19 @@  import React, { Component } from 'react'  import PropTypes from 'prop-types' +import SaveButton from '../../helpers/save_button'  import actions from '../actions' -export default class SaveJourneyPattern extends Component { -  constructor(props){ -    super(props) +export default class SaveJourneyPattern extends SaveButton { +  hasPolicy(){ +    return this.props.status.policy['journey_patterns.update'] == true    } -  btnDisabled(){ -    return !this.props.status.fetchSuccess || this.props.status.isFetching +  formClassName(){ +    return 'jp_collection'    } -  btnClass(){ -    let className = ['btn btn-default'] -    if(this.btnDisabled()){ -      className.push('disabled') -    } -    return className.join(' ') -  } - -  render() { -    if(this.props.status.policy['journey_patterns.update'] == false) { -      return false -    }else{ -      return ( -        <div className='row mt-md'> -          <div className='col-lg-12 text-right'> -            <form className='jp_collection formSubmitr ml-xs' onSubmit={e => {e.preventDefault()}}> -              <button -                className={this.btnClass()} -                type='button' -                disabled={this.btnDisabled()} -                onClick={e => { -                  e.preventDefault() -                  this.props.editMode ? this.props.onSubmitJourneyPattern(this.props.dispatch, this.props.journeyPatterns) : this.props.onEnterEditMode() -                }} -                > -                {this.props.editMode ? "Valider" : "Editer"} -              </button> -            </form> -          </div> -        </div> -      ) -    } +  submitForm(){ +    this.props.onSubmitJourneyPattern(this.props.dispatch, this.props.journeyPatterns)    }  } | 
