|
|
@ -2,6 +2,7 @@ import React, { Component } from 'react' |
|
|
|
import styled from 'styled-components' |
|
|
|
import styled from 'styled-components' |
|
|
|
import AsyncSelect from 'react-select/lib/Async' |
|
|
|
import AsyncSelect from 'react-select/lib/Async' |
|
|
|
import { components } from 'react-select' |
|
|
|
import { components } from 'react-select' |
|
|
|
|
|
|
|
import { CancelToken } from 'axios' |
|
|
|
|
|
|
|
|
|
|
|
import Input from './parts/Input' |
|
|
|
import Input from './parts/Input' |
|
|
|
import OurSelect from './parts/Select' |
|
|
|
import OurSelect from './parts/Select' |
|
|
@ -9,11 +10,11 @@ import { |
|
|
|
updateStopTime, createStopTime, deleteStopTime |
|
|
|
updateStopTime, createStopTime, deleteStopTime |
|
|
|
} from '../actions/stoptime' |
|
|
|
} from '../actions/stoptime' |
|
|
|
import store from '../store' |
|
|
|
import store from '../store' |
|
|
|
import { API_URL } from '../constants/Api' |
|
|
|
|
|
|
|
import { |
|
|
|
import { |
|
|
|
PickUpTypes, DropOffTypes, TimePointChoices |
|
|
|
PickUpTypes, DropOffTypes, TimePointChoices |
|
|
|
} from '../constants/choices' |
|
|
|
} from '../constants/choices' |
|
|
|
import { getItemFromList } from '../utils' |
|
|
|
import { getItemFromList } from '../utils' |
|
|
|
|
|
|
|
import { apiClient } from '../utils/ApiClient' |
|
|
|
|
|
|
|
|
|
|
|
const StyleBox = styled.div` |
|
|
|
const StyleBox = styled.div` |
|
|
|
padding: 5px; |
|
|
|
padding: 5px; |
|
|
@ -32,8 +33,10 @@ const Option = (props) => { |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StopTimeForm extends Component { |
|
|
|
class StopTimeForm extends Component { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cancel = null |
|
|
|
state = { |
|
|
|
state = { |
|
|
|
editMode: false, |
|
|
|
editMode: false, |
|
|
|
trip: null, |
|
|
|
trip: null, |
|
|
@ -81,10 +84,16 @@ class StopTimeForm extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getStops = (inputValue, callback) => { |
|
|
|
getStops = (inputValue, callback) => { |
|
|
|
fetch(`${API_URL}/stop/?search=${inputValue}`) |
|
|
|
const that = this |
|
|
|
.then((response) => response.json()) |
|
|
|
const cancelToken = new CancelToken(function executor(c) { |
|
|
|
.then((json) => { |
|
|
|
// An executor function receives a cancel function as a parameter
|
|
|
|
callback(json.results.map(ele => Object.assign(ele, { |
|
|
|
if (that.cancel) |
|
|
|
|
|
|
|
that.cancel() |
|
|
|
|
|
|
|
that.cancel = c |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
apiClient(`/stop/?search=${inputValue}`, { cancelToken }) |
|
|
|
|
|
|
|
.then((resp) => { |
|
|
|
|
|
|
|
callback(resp.data.results.map(ele => Object.assign(ele, { |
|
|
|
value: ele.id, label: ele.name |
|
|
|
value: ele.id, label: ele.name |
|
|
|
}))) |
|
|
|
}))) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -153,7 +162,7 @@ class StopTimeForm extends Component { |
|
|
|
<OurSelect |
|
|
|
<OurSelect |
|
|
|
label="Drop off Type" |
|
|
|
label="Drop off Type" |
|
|
|
type="text" |
|
|
|
type="text" |
|
|
|
fieldName="pickup_type" |
|
|
|
fieldName="drop_off_type" |
|
|
|
value={getItemFromList(item.drop_off_type, DropOffTypes, '0')} |
|
|
|
value={getItemFromList(item.drop_off_type, DropOffTypes, '0')} |
|
|
|
handleChange={this.handleChange} |
|
|
|
handleChange={this.handleChange} |
|
|
|
choices={DropOffTypes} /> |
|
|
|
choices={DropOffTypes} /> |
|
|
|