From 9713879fe74b138d652717dac1a9cf271efc48c2 Mon Sep 17 00:00:00 2001 From: sipp11 Date: Fri, 6 Jul 2018 22:18:22 +0700 Subject: [PATCH] Create new trip --- src/components/RouteDetail.js | 5 ++++- src/components/TripForm.js | 41 ++++++++++++++++++++++------------- src/container/Main.js | 1 + 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/components/RouteDetail.js b/src/components/RouteDetail.js index 3ee58fa..6664b67 100644 --- a/src/components/RouteDetail.js +++ b/src/components/RouteDetail.js @@ -47,7 +47,6 @@ const RouteDesc = (props) => ( ) - const TripList = (props) => (
{props.trips.map(ele => ( @@ -69,6 +68,10 @@ const TripList = (props) => ( {props.trips.length === 0 && No trip set } + + new Trip +
) diff --git a/src/components/TripForm.js b/src/components/TripForm.js index 2f29a5b..09ee185 100644 --- a/src/components/TripForm.js +++ b/src/components/TripForm.js @@ -28,13 +28,8 @@ class TripForm extends Component { state = { id: null, trip_id: "", - email: "", - fare_url: "", - lang: "", - name: "", - phone: "", - timezone: "", - url: "", + service: null, + frequency_set: [], newStopTime: false, } @@ -79,6 +74,15 @@ class TripForm extends Component { const { agencyId, routeId, tripId } = props.match.params if (!props.calendar.fetching && props.calendar.count === 0) store.dispatch(getCalendar()) + if (tripId === undefined) { + const { route } = props + const tRoute = route.results.filter(ele => ele.route_id === routeId) + if (tRoute.length > 0) { + return { route: tRoute[0].id } + } else { + store.dispatch(getRoute(`agency=${agencyId}`)) + } + } if (tripId !== undefined && state.id === null) { const { route } = props const tRoute = route.results.filter(ele => ele.route_id === routeId) @@ -130,7 +134,7 @@ class TripForm extends Component { label="Service" type="text" fieldName="service" - value={one.service ? one.service.id : ''} + value={one.service} handleChange={this.handleChange} choices={calendar.results.map(ele => ({ value: ele.id, label: ele.service_id }))} />} @@ -201,7 +205,7 @@ class TripForm extends Component { const one = this.state const { fetching } = this.props.trip // redirect to view page if no data - const { agencyId, routeId, tripId } = this.props.match.params + const { agencyId, routeId } = this.props.match.params // this is a create form // if (tripId === undefined) { // if (one.justSubmit === true && !fetching) { @@ -217,12 +221,10 @@ class TripForm extends Component { if (one.justSubmit === true && !fetching) { return } - return ( -
-
- {this.renderForm()} -
-
+ let StopTimePane = null + if (this.state.id !== null) { + StopTimePane = ( +
{!this.state.newStopTime && } {this.state.newStopTime && )}
+ ) + } + + return ( +
+
+ {this.renderForm()} +
+ {StopTimePane}
) } diff --git a/src/container/Main.js b/src/container/Main.js index 5d5acd1..edd7fda 100644 --- a/src/container/Main.js +++ b/src/container/Main.js @@ -39,6 +39,7 @@ class Main extends Component {