@@ -10,10 +10,12 @@ import {
10
10
ProgressBar
11
11
} from 'react-bootstrap'
12
12
import { connect } from 'react-redux'
13
+ import { Prompt } from 'react-router'
13
14
import styled from 'styled-components'
14
15
15
16
import * as userActions from '../../../actions/user'
16
17
import { getErrorStates } from '../../../util/ui'
18
+
17
19
import TripStatus from './trip-status'
18
20
import TripSummary from './trip-summary'
19
21
@@ -87,9 +89,25 @@ class TripBasicsPane extends Component {
87
89
}
88
90
89
91
render ( ) {
90
- const { errors, isCreating, itineraryExistence, values : monitoredTrip } = this . props
92
+ const {
93
+ canceled,
94
+ dirty,
95
+ errors,
96
+ isCreating,
97
+ isSubmitting,
98
+ itineraryExistence,
99
+ values : monitoredTrip
100
+ } = this . props
91
101
const { itinerary } = monitoredTrip
92
102
103
+ // Prevent user from leaving when form has been changed,
104
+ // but don't show it when they click submit or cancel.
105
+ const unsavedChanges = dirty && ! isSubmitting && ! canceled
106
+ // Message changes depending on if the new or existing trip is being edited
107
+ const unsavedChangesNewTripMessage = 'You haven\'t saved your new trip yet. If you leave, it will be lost.'
108
+ const unsavedChangesExistingTripMessage = 'You haven\'t saved your trip yet. If you leave, changes will be lost.'
109
+ const unsavedChangesMessage = isCreating ? unsavedChangesNewTripMessage : unsavedChangesExistingTripMessage
110
+
93
111
if ( ! itinerary ) {
94
112
return < div > No itinerary to display.</ div >
95
113
} else {
@@ -107,6 +125,13 @@ class TripBasicsPane extends Component {
107
125
108
126
return (
109
127
< div >
128
+ { /* TODO: This component does not block navigation on reload or using the back button.
129
+ This will have to be done at a higher level. See #376 */ }
130
+ < Prompt
131
+ when = { unsavedChanges }
132
+ message = { unsavedChangesMessage }
133
+ />
134
+
110
135
{ /* Do not show trip status when saving trip for the first time
111
136
(it doesn't exist in backend yet). */ }
112
137
{ ! isCreating && < TripStatus monitoredTrip = { monitoredTrip } /> }
0 commit comments