|
|
@ -9,55 +9,28 @@ import { |
|
|
|
deleteFareRule |
|
|
|
deleteFareRule |
|
|
|
} from '../actions/fare' |
|
|
|
} from '../actions/fare' |
|
|
|
import store from '../store' |
|
|
|
import store from '../store' |
|
|
|
import Input from './parts/Input' |
|
|
|
|
|
|
|
import AsyncSelect from 'react-select/lib/Async' |
|
|
|
import AsyncSelect from 'react-select/lib/Async' |
|
|
|
import { components } from 'react-select' |
|
|
|
|
|
|
|
import { |
|
|
|
import { |
|
|
|
getStopsAsyncSelect, |
|
|
|
getStopsAsyncSelect, |
|
|
|
getFareAttrAsyncSelect, |
|
|
|
getFareAttrAsyncSelect, |
|
|
|
getRouteAsyncSelect |
|
|
|
getRouteAsyncSelect |
|
|
|
} from '../utils' |
|
|
|
} from '../utils' |
|
|
|
|
|
|
|
import { |
|
|
|
|
|
|
|
StopOption, FareAttrOption, RouteOption |
|
|
|
|
|
|
|
} from './parts/SelectOptions' |
|
|
|
|
|
|
|
|
|
|
|
const StyledFareRulesForm = styled.div` |
|
|
|
const StyledFareRulesForm = styled.div` |
|
|
|
padding: 1rem; |
|
|
|
padding: 1rem; |
|
|
|
background: #fafafa; |
|
|
|
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 { |
|
|
|
class FareRulesForm extends Component { |
|
|
|
|
|
|
|
|
|
|
|
state = { |
|
|
|
state = { |
|
|
|
id: null, |
|
|
|
id: null, |
|
|
|
fare_id: "", |
|
|
|
fare: null, |
|
|
|
route_id: "", // optinal
|
|
|
|
route: null, // optinal
|
|
|
|
origin_id: "", |
|
|
|
origin_id: "", |
|
|
|
destination_id: "", |
|
|
|
destination_id: "", |
|
|
|
contains_id: "", |
|
|
|
contains_id: "", |
|
|
@ -127,7 +100,7 @@ class FareRulesForm extends Component { |
|
|
|
let evt = { |
|
|
|
let evt = { |
|
|
|
target: { |
|
|
|
target: { |
|
|
|
name: 'fare', |
|
|
|
name: 'fare', |
|
|
|
value: resp, |
|
|
|
value: resp.value, |
|
|
|
}} |
|
|
|
}} |
|
|
|
this.handleChange(evt) |
|
|
|
this.handleChange(evt) |
|
|
|
} |
|
|
|
} |
|
|
@ -136,19 +109,19 @@ class FareRulesForm extends Component { |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
<div className="field"> |
|
|
|
<div className="field"> |
|
|
|
<label className="label">Route</label> |
|
|
|
<label className="label">Route <i>optional</i></label> |
|
|
|
<AsyncSelect |
|
|
|
<AsyncSelect |
|
|
|
cacheOptions={true} |
|
|
|
cacheOptions={true} |
|
|
|
defaultOptions |
|
|
|
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} |
|
|
|
loadOptions={getRouteAsyncSelect} |
|
|
|
components={{ Option: RouteOption }} |
|
|
|
components={{ Option: RouteOption }} |
|
|
|
onChange={(resp, evt) => { |
|
|
|
onChange={(resp, evt) => { |
|
|
|
if (evt.action === 'select-option') { |
|
|
|
if (evt.action === 'select-option') { |
|
|
|
let evt = { |
|
|
|
let evt = { |
|
|
|
target: { |
|
|
|
target: { |
|
|
|
name: 'route_id', |
|
|
|
name: 'route', |
|
|
|
value: resp.route_id, |
|
|
|
value: resp.value, |
|
|
|
}} |
|
|
|
}} |
|
|
|
this.handleChange(evt) |
|
|
|
this.handleChange(evt) |
|
|
|
} |
|
|
|
} |
|
|
@ -169,7 +142,7 @@ class FareRulesForm extends Component { |
|
|
|
let evt = { |
|
|
|
let evt = { |
|
|
|
target: { |
|
|
|
target: { |
|
|
|
name: 'origin_id', |
|
|
|
name: 'origin_id', |
|
|
|
value: resp.stop_id, |
|
|
|
value: resp.value.stop_id, |
|
|
|
}} |
|
|
|
}} |
|
|
|
this.handleChange(evt) |
|
|
|
this.handleChange(evt) |
|
|
|
} |
|
|
|
} |
|
|
@ -178,9 +151,10 @@ class FareRulesForm extends Component { |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
<div className="field"> |
|
|
|
<div className="field"> |
|
|
|
<label className="label">Destination ID</label> |
|
|
|
<label className="label">Destination ID (or IDs)</label> |
|
|
|
<AsyncSelect |
|
|
|
<AsyncSelect |
|
|
|
cacheOptions={true} |
|
|
|
isMulti |
|
|
|
|
|
|
|
cacheOptions |
|
|
|
defaultOptions |
|
|
|
defaultOptions |
|
|
|
defaultValue={one.destination_id && {value: one.destination_id, label: one.destination_id}} |
|
|
|
defaultValue={one.destination_id && {value: one.destination_id, label: one.destination_id}} |
|
|
|
loadOptions={getStopsAsyncSelect} |
|
|
|
loadOptions={getStopsAsyncSelect} |
|
|
@ -190,7 +164,7 @@ class FareRulesForm extends Component { |
|
|
|
let evt = { |
|
|
|
let evt = { |
|
|
|
target: { |
|
|
|
target: { |
|
|
|
name: 'destination_id', |
|
|
|
name: 'destination_id', |
|
|
|
value: resp.stop_id, |
|
|
|
value: resp.map(el => el.value.stop_id), |
|
|
|
}} |
|
|
|
}} |
|
|
|
this.handleChange(evt) |
|
|
|
this.handleChange(evt) |
|
|
|
} |
|
|
|
} |
|
|
@ -199,8 +173,9 @@ class FareRulesForm extends Component { |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
<div className="field"> |
|
|
|
<div className="field"> |
|
|
|
<label className="label">Contains ID</label> |
|
|
|
<label className="label">Contains ID (or IDs)</label> |
|
|
|
<AsyncSelect |
|
|
|
<AsyncSelect |
|
|
|
|
|
|
|
isMulti |
|
|
|
cacheOptions={true} |
|
|
|
cacheOptions={true} |
|
|
|
defaultOptions |
|
|
|
defaultOptions |
|
|
|
defaultValue={one.contains_id && {value: one.contains_id, label: one.contains_id}} |
|
|
|
defaultValue={one.contains_id && {value: one.contains_id, label: one.contains_id}} |
|
|
@ -211,13 +186,15 @@ class FareRulesForm extends Component { |
|
|
|
let evt = { |
|
|
|
let evt = { |
|
|
|
target: { |
|
|
|
target: { |
|
|
|
name: 'contains_id', |
|
|
|
name: 'contains_id', |
|
|
|
value: resp.stop_id, |
|
|
|
value: resp.map(el => el.value.stop_id), |
|
|
|
}} |
|
|
|
}} |
|
|
|
this.handleChange(evt) |
|
|
|
this.handleChange(evt) |
|
|
|
} |
|
|
|
} |
|
|
|
}} |
|
|
|
}} |
|
|
|
/> |
|
|
|
/> |
|
|
|
</div> |
|
|
|
</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> |
|
|
|
|
|
|
|
|
|
|
|
<div className="field is-grouped"> |
|
|
|
<div className="field is-grouped"> |
|
|
|