diff --git a/lib/components/user/monitored-trip/trip-basics-pane.js b/lib/components/user/monitored-trip/trip-basics-pane.js index fa0210d43..6d782cc56 100644 --- a/lib/components/user/monitored-trip/trip-basics-pane.js +++ b/lib/components/user/monitored-trip/trip-basics-pane.js @@ -10,10 +10,12 @@ import { ProgressBar } from 'react-bootstrap' import { connect } from 'react-redux' +import { Prompt } from 'react-router' import styled from 'styled-components' import * as userActions from '../../../actions/user' import { getErrorStates } from '../../../util/ui' + import TripStatus from './trip-status' import TripSummary from './trip-summary' @@ -87,9 +89,25 @@ class TripBasicsPane extends Component { } render () { - const { errors, isCreating, itineraryExistence, values: monitoredTrip } = this.props + const { + canceled, + dirty, + errors, + isCreating, + isSubmitting, + itineraryExistence, + values: monitoredTrip + } = this.props const { itinerary } = monitoredTrip + // Prevent user from leaving when form has been changed, + // but don't show it when they click submit or cancel. + const unsavedChanges = dirty && !isSubmitting && !canceled + // Message changes depending on if the new or existing trip is being edited + const unsavedChangesNewTripMessage = 'You haven\'t saved your new trip yet. If you leave, it will be lost.' + const unsavedChangesExistingTripMessage = 'You haven\'t saved your trip yet. If you leave, changes will be lost.' + const unsavedChangesMessage = isCreating ? unsavedChangesNewTripMessage : unsavedChangesExistingTripMessage + if (!itinerary) { return
No itinerary to display.
} else { @@ -107,6 +125,13 @@ class TripBasicsPane extends Component { return (
+ {/* TODO: This component does not block navigation on reload or using the back button. + This will have to be done at a higher level. See #376 */} + + {/* Do not show trip status when saving trip for the first time (it doesn't exist in backend yet). */} {!isCreating && } diff --git a/lib/components/user/stacked-pane-display.js b/lib/components/user/stacked-pane-display.js index 529fb1964..8db7380b9 100644 --- a/lib/components/user/stacked-pane-display.js +++ b/lib/components/user/stacked-pane-display.js @@ -1,5 +1,5 @@ import PropTypes from 'prop-types' -import React from 'react' +import React, {useState} from 'react' import FormNavigationButtons from './form-navigation-buttons' import { PageHeading, StackedPaneContainer } from './styled' @@ -7,30 +7,38 @@ import { PageHeading, StackedPaneContainer } from './styled' /** * This component handles the flow between screens for new OTP user accounts. */ -const StackedPaneDisplay = ({ onCancel, paneSequence, title }) => ( - <> - {title && {title}} - { - paneSequence.map(({ pane: Pane, props, title }, index) => ( +const StackedPaneDisplay = ({ onCancel, paneSequence, title }) => { + // Create indicator of if cancel button was clicked so that child components can know + const [isBeingCanceled, updateBeingCanceled] = useState(false) + + return ( + <> + {title && {title}} + {paneSequence.map(({ pane: Pane, props, title }, index) => (

{title}

-
+
+ +
- )) - } + ))} - - -) + { + updateBeingCanceled(true) + onCancel() + }, + text: 'Cancel' + }} + okayButton={{ + text: 'Save Preferences', + type: 'submit' + }} + /> + + ) +} StackedPaneDisplay.propTypes = { onCancel: PropTypes.func.isRequired,