From 84f3edcfc7213d5a02f10ba002e091e1563f2e27 Mon Sep 17 00:00:00 2001
From: Zog
Date: Wed, 10 Jan 2018 15:59:17 +0100
Subject: Refs #5529 @0.5h; Refactor buttons
---
app/javascript/helpers/save_button.js | 47 ++++++++++++++++++++++
.../components/SaveJourneyPattern.js | 45 ++++-----------------
.../components/SaveVehicleJourneys.js | 47 ++++------------------
3 files changed, 63 insertions(+), 76 deletions(-)
create mode 100644 app/javascript/helpers/save_button.js
(limited to 'app/javascript')
diff --git a/app/javascript/helpers/save_button.js b/app/javascript/helpers/save_button.js
new file mode 100644
index 000000000..7e0bd5bbe
--- /dev/null
+++ b/app/javascript/helpers/save_button.js
@@ -0,0 +1,47 @@
+import React, { PropTypes, Component } from 'react'
+
+export default class SaveButton extends Component{
+ constructor(props){
+ super(props)
+ }
+
+ btnDisabled(){
+ return !this.props.status.fetchSuccess || this.props.status.isFetching
+ }
+
+ btnClass(){
+ let className = ['btn btn-default']
+ if(this.btnDisabled()){
+ className.push('disabled')
+ }
+ return className.join(' ')
+ }
+
+ render() {
+ if (!this.hasPolicy()) {
+ return false
+ }else{
+ return (
+
+ )
+ }
+ }
+}
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 (
-
- )
- }
+ submitForm(){
+ this.props.onSubmitJourneyPattern(this.props.dispatch, this.props.journeyPatterns)
}
}
diff --git a/app/javascript/vehicle_journeys/components/SaveVehicleJourneys.js b/app/javascript/vehicle_journeys/components/SaveVehicleJourneys.js
index 64fd7310e..6e94b04a3 100644
--- a/app/javascript/vehicle_journeys/components/SaveVehicleJourneys.js
+++ b/app/javascript/vehicle_journeys/components/SaveVehicleJourneys.js
@@ -1,50 +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 SaveVehicleJourneys extends Component{
- constructor(props){
- super(props)
+export default class SaveVehicleJourneys extends SaveButton{
+ hasPolicy(){
+ return this.props.filters.policy['vehicle_journeys.update'] == true
}
- btnDisabled(){
- return !this.props.status.fetchSuccess || this.props.status.isFetching
+ formClassName(){
+ return 'vehicle_journeys'
}
- btnClass(){
- let className = ['btn btn-default']
- if(this.btnDisabled()){
- className.push('disabled')
- }
- return className.join(' ')
- }
-
- render() {
- if (this.props.filters.policy['vehicle_journeys.update'] == false) {
- return false
- }else{
- return (
-
- )
- }
+ submitForm(){
+ this.props.onSubmitVehicleJourneys(this.props.dispatch, this.props.vehicleJourneys)
}
}
--
cgit v1.2.3