Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/actions/user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createAction } from 'redux-actions'

import { routeTo } from './ui'
import {
addTrip,
addUser,
Expand Down Expand Up @@ -154,6 +155,9 @@ export function createOrUpdateUserMonitoredTrip (tripData, isNew, silentOnSucces

// Reload user's monitored trips after add/update.
await dispatch(fetchUserMonitoredTrips(accessToken))

// Finally, navigate to the saved trips page.
dispatch(routeTo('/savedtrips'))
} else {
alert(`An error was encountered:\n${JSON.stringify(result)}`)
}
Expand Down
21 changes: 8 additions & 13 deletions lib/components/user/saved-trip-screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ function hasMaxTripCount (trips) {
*/
class SavedTripScreen extends Component {
/**
* Persists changes to edited trip.
* Persists changes to the edited trip.
* On success, this operation will also make the browser
* navigate to the Saved trips page.
* @param {*} monitoredTrip The trip edited state to be saved, provided by Formik.
*/
_updateMonitoredTrip = async monitoredTrip => {
_updateMonitoredTrip = monitoredTrip => {
const { isCreating, createOrUpdateUserMonitoredTrip } = this.props
await createOrUpdateUserMonitoredTrip(monitoredTrip, isCreating)
createOrUpdateUserMonitoredTrip(monitoredTrip, isCreating)
}

/**
Expand All @@ -92,15 +95,6 @@ class SavedTripScreen extends Component {
this.props.routeTo('/savedtrips')
}

/**
* Saves a trip and returns to the saved trips screen.
* @param {*} monitoredTrip The trip edited state to be saved, provided by Formik.
*/
_handleSaveTrip = async monitoredTrip => {
await this._updateMonitoredTrip(monitoredTrip)
this._goToSavedTrips()
}

// Make an index of pane components, so we don't render all panes at once on every render.
_panes = {
basics: TripBasicsPane,
Expand Down Expand Up @@ -166,7 +160,7 @@ class SavedTripScreen extends Component {
validateOnChange={false}
validateOnBlur
validationSchema={validationSchema}
onSubmit={this._handleSaveTrip}
onSubmit={this._updateMonitoredTrip}
initialValues={clone(monitoredTrip)}
>
{
Expand Down Expand Up @@ -202,6 +196,7 @@ const mapStateToProps = (state, ownProps) => {
const activeItinerary = activeSearch && activeSearch.activeItinerary
const itineraries = getActiveItineraries(state.otp) || []
return {
activeSearchId: state.otp.activeSearchId,
itinerary: itineraries[activeItinerary],
loggedInUser: state.user.loggedInUser,
monitoredTrips: state.user.loggedInUserMonitoredTrips,
Expand Down