|
|
|
@ -9,55 +9,28 @@ import {
|
|
|
|
|
deleteFareRule |
|
|
|
|
} from '../actions/fare' |
|
|
|
|
import store from '../store' |
|
|
|
|
import Input from './parts/Input' |
|
|
|
|
import AsyncSelect from 'react-select/lib/Async' |
|
|
|
|
import { components } from 'react-select' |
|
|
|
|
import { |
|
|
|
|
getStopsAsyncSelect, |
|
|
|
|
getFareAttrAsyncSelect, |
|
|
|
|
getRouteAsyncSelect |
|
|
|
|
} from '../utils' |
|
|
|
|
import { |
|
|
|
|
StopOption, FareAttrOption, RouteOption |
|
|
|
|
} from './parts/SelectOptions' |
|
|
|
|
|
|
|
|
|
const StyledFareRulesForm = styled.div` |
|
|
|
|
padding: 1rem; |
|
|
|
|
background: #fafafa; |
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StopOption = (props) => { |
|
|
|
|
const { stop_id, name } = props.data |
|
|
|
|
return ( |
|
|
|
|
<components.Option {...props}> |
|
|
|
|
<code>{stop_id}</code> {name} |
|
|
|
|
</components.Option> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const FareAttrOption = (props) => { |
|
|
|
|
const { fare_id, price, currency_type } = props.data |
|
|
|
|
return ( |
|
|
|
|
<components.Option {...props}> |
|
|
|
|
<code>{fare_id}</code> {price} {currency_type} |
|
|
|
|
</components.Option> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const RouteOption = (props) => { |
|
|
|
|
const { route_id, short_name, long_name} = props.data |
|
|
|
|
return ( |
|
|
|
|
<components.Option {...props}> |
|
|
|
|
<code>{route_id}</code> {short_name} |
|
|
|
|
<br/>{long_name} |
|
|
|
|
</components.Option> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FareRulesForm extends Component { |
|
|
|
|
|
|
|
|
|
state = { |
|
|
|
|
id: null, |
|
|
|
|
fare_id: "", |
|
|
|
|
route_id: "", // optinal
|
|
|
|
|
fare: null, |
|
|
|
|
route: null, // optinal
|
|
|
|
|
origin_id: "", |
|
|
|
|
destination_id: "", |
|
|
|
|
contains_id: "", |
|
|
|
@ -127,7 +100,7 @@ class FareRulesForm extends Component {
|
|
|
|
|
let evt = { |
|
|
|
|
target: { |
|
|
|
|
name: 'fare', |
|
|
|
|
value: resp, |
|
|
|
|
value: resp.value, |
|
|
|
|
}} |
|
|
|
|
this.handleChange(evt) |
|
|
|
|
} |
|
|
|
@ -136,19 +109,19 @@ class FareRulesForm extends Component {
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<div className="field"> |
|
|
|
|
<label className="label">Route</label> |
|
|
|
|
<label className="label">Route <i>optional</i></label> |
|
|
|
|
<AsyncSelect |
|
|
|
|
cacheOptions={true} |
|
|
|
|
defaultOptions |
|
|
|
|
defaultValue={one.route_id && {value: one.route_id, label: one.route_id}} |
|
|
|
|
defaultValue={one.route && {value: one.route, label: one.route.route_id}} |
|
|
|
|
loadOptions={getRouteAsyncSelect} |
|
|
|
|
components={{ Option: RouteOption }} |
|
|
|
|
onChange={(resp, evt) => { |
|
|
|
|
if (evt.action === 'select-option') { |
|
|
|
|
let evt = { |
|
|
|
|
target: { |
|
|
|
|
name: 'route_id', |
|
|
|
|
value: resp.route_id, |
|
|
|
|
name: 'route', |
|
|
|
|
value: resp.value, |
|
|
|
|
}} |
|
|
|
|
this.handleChange(evt) |
|
|
|
|
} |
|
|
|
@ -169,7 +142,7 @@ class FareRulesForm extends Component {
|
|
|
|
|
let evt = { |
|
|
|
|
target: { |
|
|
|
|
name: 'origin_id', |
|
|
|
|
value: resp.stop_id, |
|
|
|
|
value: resp.value.stop_id, |
|
|
|
|
}} |
|
|
|
|
this.handleChange(evt) |
|
|
|
|
} |
|
|
|
@ -178,9 +151,10 @@ class FareRulesForm extends Component {
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<div className="field"> |
|
|
|
|
<label className="label">Destination ID</label> |
|
|
|
|
<label className="label">Destination ID (or IDs)</label> |
|
|
|
|
<AsyncSelect |
|
|
|
|
cacheOptions={true} |
|
|
|
|
isMulti |
|
|
|
|
cacheOptions |
|
|
|
|
defaultOptions |
|
|
|
|
defaultValue={one.destination_id && {value: one.destination_id, label: one.destination_id}} |
|
|
|
|
loadOptions={getStopsAsyncSelect} |
|
|
|
@ -190,7 +164,7 @@ class FareRulesForm extends Component {
|
|
|
|
|
let evt = { |
|
|
|
|
target: { |
|
|
|
|
name: 'destination_id', |
|
|
|
|
value: resp.stop_id, |
|
|
|
|
value: resp.map(el => el.value.stop_id), |
|
|
|
|
}} |
|
|
|
|
this.handleChange(evt) |
|
|
|
|
} |
|
|
|
@ -199,8 +173,9 @@ class FareRulesForm extends Component {
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<div className="field"> |
|
|
|
|
<label className="label">Contains ID</label> |
|
|
|
|
<label className="label">Contains ID (or IDs)</label> |
|
|
|
|
<AsyncSelect |
|
|
|
|
isMulti |
|
|
|
|
cacheOptions={true} |
|
|
|
|
defaultOptions |
|
|
|
|
defaultValue={one.contains_id && {value: one.contains_id, label: one.contains_id}} |
|
|
|
@ -211,13 +186,15 @@ class FareRulesForm extends Component {
|
|
|
|
|
let evt = { |
|
|
|
|
target: { |
|
|
|
|
name: 'contains_id', |
|
|
|
|
value: resp.stop_id, |
|
|
|
|
value: resp.map(el => el.value.stop_id), |
|
|
|
|
}} |
|
|
|
|
this.handleChange(evt) |
|
|
|
|
} |
|
|
|
|
}} |
|
|
|
|
/> |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<p>When having multiple destinations or contains, multiple fare rule records will be created automatically. Nothing differs from adding multiple records manually, it only saves time. !! only works with CREATE, UPDATE will throw 500</p> |
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
<div className="field is-grouped"> |
|
|
|
|