Browse Source

Create new trip

master v0.1
sipp11 6 years ago
parent
commit
9713879fe7
  1. 5
      src/components/RouteDetail.js
  2. 41
      src/components/TripForm.js
  3. 1
      src/container/Main.js

5
src/components/RouteDetail.js

@ -47,7 +47,6 @@ const RouteDesc = (props) => (
</div> </div>
) )
const TripList = (props) => ( const TripList = (props) => (
<div> <div>
{props.trips.map(ele => ( {props.trips.map(ele => (
@ -69,6 +68,10 @@ const TripList = (props) => (
{props.trips.length === 0 && <span key="empty-trips" className="panel-block"> {props.trips.length === 0 && <span key="empty-trips" className="panel-block">
No trip set No trip set
</span>} </span>}
<span key="trip-list-0" className="panel-block">
<Link className="button is-outlined"
to={`/trip/${props.agencyId}/${props.routeId}/new`}>new Trip</Link>
</span>
</div> </div>
) )

41
src/components/TripForm.js

@ -28,13 +28,8 @@ class TripForm extends Component {
state = { state = {
id: null, id: null,
trip_id: "", trip_id: "",
email: "", service: null,
fare_url: "", frequency_set: [],
lang: "",
name: "",
phone: "",
timezone: "",
url: "",
newStopTime: false, newStopTime: false,
} }
@ -79,6 +74,15 @@ class TripForm extends Component {
const { agencyId, routeId, tripId } = props.match.params const { agencyId, routeId, tripId } = props.match.params
if (!props.calendar.fetching && props.calendar.count === 0) if (!props.calendar.fetching && props.calendar.count === 0)
store.dispatch(getCalendar()) 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) { if (tripId !== undefined && state.id === null) {
const { route } = props const { route } = props
const tRoute = route.results.filter(ele => ele.route_id === routeId) const tRoute = route.results.filter(ele => ele.route_id === routeId)
@ -130,7 +134,7 @@ class TripForm extends Component {
label="Service" label="Service"
type="text" type="text"
fieldName="service" fieldName="service"
value={one.service ? one.service.id : ''} value={one.service}
handleChange={this.handleChange} handleChange={this.handleChange}
choices={calendar.results.map(ele => ({ value: ele.id, label: ele.service_id }))} />} 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 one = this.state
const { fetching } = this.props.trip const { fetching } = this.props.trip
// redirect to view page if no data // 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 // this is a create form
// if (tripId === undefined) { // if (tripId === undefined) {
// if (one.justSubmit === true && !fetching) { // if (one.justSubmit === true && !fetching) {
@ -217,12 +221,10 @@ class TripForm extends Component {
if (one.justSubmit === true && !fetching) { if (one.justSubmit === true && !fetching) {
return <Redirect to={`/map/${agencyId}/route/${routeId}/trip`} /> return <Redirect to={`/map/${agencyId}/route/${routeId}/trip`} />
} }
return ( let StopTimePane = null
<div className="columns"> if (this.state.id !== null) {
<div className="column is-half"> StopTimePane = (
{this.renderForm()} <div className="column is-half">
</div>
<div className="column is-half">
<StyleBox> <StyleBox>
{!this.state.newStopTime && <button className="button is-outlined" onClick={this.toggleNewStopTime}>new StopTime</button>} {!this.state.newStopTime && <button className="button is-outlined" onClick={this.toggleNewStopTime}>new StopTime</button>}
{this.state.newStopTime && <StopTimeForm {...this.props} {this.state.newStopTime && <StopTimeForm {...this.props}
@ -232,6 +234,15 @@ class TripForm extends Component {
{this.props.stoptime.results.map( {this.props.stoptime.results.map(
ele => <StopTimeOne key={`stb-${ele.id}`} item={ele} />)} ele => <StopTimeOne key={`stb-${ele.id}`} item={ele} />)}
</div> </div>
)
}
return (
<div className="columns">
<div className="column is-half">
{this.renderForm()}
</div>
{StopTimePane}
</div> </div>
) )
} }

1
src/container/Main.js

@ -39,6 +39,7 @@ class Main extends Component {
<Nav loggedIn={loggedIn} /> <Nav loggedIn={loggedIn} />
<div className="container is-widescreen"> <div className="container is-widescreen">
<Switch> <Switch>
<Route exact path={`${match.url}trip/:agencyId/:routeId/new`} component={TripForm} />
<Route exact path={`${match.url}trip/:agencyId/:routeId/:tripId`} component={TripForm} /> <Route exact path={`${match.url}trip/:agencyId/:routeId/:tripId`} component={TripForm} />
<Route exact path={`${match.url}agency/new`} component={AgencyForm} /> <Route exact path={`${match.url}agency/new`} component={AgencyForm} />
<Route exact path={`${match.url}agency/:agencyId`} component={AgencyItem} /> <Route exact path={`${match.url}agency/:agencyId`} component={AgencyItem} />

Loading…
Cancel
Save