diff --git a/lib/actions/user.js b/lib/actions/user.js index 61c43ffd7..348d39628 100644 --- a/lib/actions/user.js +++ b/lib/actions/user.js @@ -1,5 +1,6 @@ import { createAction } from 'redux-actions' +import { routeTo } from './ui' import { addTrip, addUser, @@ -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)}`) } diff --git a/lib/components/user/saved-trip-screen.js b/lib/components/user/saved-trip-screen.js index 6ca6cb255..a8b6bed2c 100644 --- a/lib/components/user/saved-trip-screen.js +++ b/lib/components/user/saved-trip-screen.js @@ -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) } /** @@ -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, @@ -166,7 +160,7 @@ class SavedTripScreen extends Component { validateOnChange={false} validateOnBlur validationSchema={validationSchema} - onSubmit={this._handleSaveTrip} + onSubmit={this._updateMonitoredTrip} initialValues={clone(monitoredTrip)} > { @@ -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,