Browse Source

Fare WIP

dev
sipp11 6 years ago
parent
commit
cd9cc45901
  1. 2
      src/components/FareAttributesDetail.js
  2. 6
      src/components/FareRulesDetail.js
  3. 11
      src/components/FareRulesForm.js
  4. 11
      src/reducers/farerule.js

2
src/components/FareAttributesDetail.js

@ -118,7 +118,7 @@ class FareAttributesDetail extends Component {
<Link className="link is-info" to={`/fare/rules/new?fareattr=${ones[0].id}`}>
<i className="fas fa-plus" /> New fare rule
</Link>
{farerule.results.map(ele => <FareRulesOne item={ele} />)}
{farerule.results && farerule.results.map(ele => <FareRulesOne item={ele} />)}
</div>
)
}

6
src/components/FareRulesDetail.js

@ -3,10 +3,10 @@ import styled from 'styled-components'
import { Link } from 'react-router-dom'
const FakeRow = styled.nav`
padding-top: 5px;
padding-bottom: 5px;
padding-top: 3px;
padding-bottom: 3px;
background: white;
margin-bottom: 1rem;
margin-bottom: 5px !important;
`
export const FareRulesOne = (props) => {

11
src/components/FareRulesForm.js

@ -186,7 +186,7 @@ class FareRulesForm extends Component {
result = {
target: {
name: fieldName,
value: resp.map(el => el.value.stop_id),
value: resp.map(el => el.value.stop_id).join(','),
}
}
} else if (evt.action === 'clear') {
@ -215,7 +215,7 @@ class FareRulesForm extends Component {
result = {
target: {
name: fieldName,
value: resp.map(el => el.value.stop_id),
value: resp.map(el => el.value.stop_id).join(','),
}
}
} else if (evt.action === 'clear') {
@ -244,7 +244,8 @@ class FareRulesForm extends Component {
DELETE</button>
</div>}
<div className="control">
<Link to={`/fare`} className="button is-text">Cancel</Link>
<Link to={`/fare${one.fare ? `/attributes/${one.fare.id}` : ''}`}
className="button is-text">Cancel</Link>
</div>
</div>
</StyledFareRulesForm>
@ -259,7 +260,7 @@ class FareRulesForm extends Component {
// this is a create form
if (ruleID === undefined) {
if (one.justSubmit === true && !fetching) {
return <Redirect to={`/fare`} />
return <Redirect to={`/fare/attributes/${one.fare.id}`} />
}
return this.renderForm()
}
@ -269,7 +270,7 @@ class FareRulesForm extends Component {
// redirect to fare list if submitted
if (one.justSubmit === true && !fetching) {
return <Redirect to={`/fare`} />
return <Redirect to={`/fare/attributes/${one.fare.id}`} />
}
return this.renderForm()
}

11
src/reducers/farerule.js

@ -14,14 +14,17 @@ const fareRuleInitState = {
const fareRule = (state = fareRuleInitState, action) => {
switch(action.type) {
case FARERULE_REQUEST:
let resetResult = state.query !== action.meta.query ? [] : state.results
let resetCount = state.query !== action.meta.query ? 0 : state.count
let resetResult, resetCount
if (action.meta !== undefined) {
resetResult = state.query !== action.meta.query ? [] : state.results
resetCount = state.query !== action.meta.query ? 0 : state.count
}
return {
...state,
fetching: true,
query: action.meta !== undefined ? action.meta.query : state.query,
results: resetResult,
count: resetCount,
results: action.meta !== undefined ? resetResult : state.results,
count: action.meta !== undefined ? resetCount : state.count,
}
case FARERULE_SUCCESS:
const { count, next, prev, results } = action.payload

Loading…
Cancel
Save