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