Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trip page: Add warning about navigating away with unsaved changes #400

Merged
merged 9 commits into from
Jul 7, 2021

Conversation

miles-grant-ibigroup
Copy link
Collaborator

When a user is adding or editing a trip, they will now be prompted to confirm they really want to leave if they try to navigate away.

If they haven't made any changes or if they haven't made any changes, they aren't prompted.

@miles-grant-ibigroup miles-grant-ibigroup marked this pull request as ready for review June 30, 2021 21:47
Copy link
Contributor

@evansiroky evansiroky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 1 comment.

Comment on lines 115 to 116
when={this.props.dirty && !this.props.isSubmitting && !this.props.canceled}
message={`You have haven't saved your ${this.props.isCreating ? 'new ' : ''}trip yet. If you leave, ${this.props.isCreating ? 'it' : 'changes'} will be lost.`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines are too long. Please split up these long lines. A boolean variable could be created for the first one. The second one could also be calculated separately before returning this JSX. Also, please restructure these props at the very beginning of the render method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm not entirely happy with the unsavedChangesMessage line break, but that's the only way I could think of that doesn't create a break in the popup.

// 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 unsavedChangesMessage = `You have haven't saved your ${
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const unsavedChangesMessage = `You have haven't saved your ${
const unsavedChangesMessage = `You haven't saved your ${

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For internationalization, we should stay away from these string concats. I recommend we just display one string for when you create a trip and one other string for when you modify a trip.

Copy link
Member

@landonreed landonreed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Just one tweak for a typo. Also, I noticed an issue when clicking the <- Back button, where it updated the URL even if I press "Cancel" in the prompt, but that may be more related to #376

Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditional approval subject to using different prompt messages for new and existing trips.

// 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 unsavedChangesMessage = `You have haven't saved your ${
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For internationalization, we should stay away from these string concats. I recommend we just display one string for when you create a trip and one other string for when you modify a trip.


<FormNavigationButtons
backButton={{
onClick: () => { updateBeingCanceled(true); onCancel() },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What formatting do @landonreed and @evansiroky prefer regarding the semicolon? Spread over multiple lines?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was created by prettier -- ambiguities like this should be resolved in the future once we get the new version of mastarm up and running (which should include auto formatting).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I was stuck on this a bit also, @binh-dam-ibigroup. Let's just go ahead and move to multiple lines, since we tend not to include semicolons anywhere in this code base.

…ed trip changes

resolve typos, remove string assembly for internationalization
@miles-grant-ibigroup
Copy link
Collaborator Author

@landonreed have played around with this and I definitely think it is to do with #376. I can register the onbeforeunload listener which is supposed to intercept browser navigation. Reload is intercepted, but back is ignored. This to me says that somewhere higher up something is doing something fishy with react-router?

Should I try to address this in this pr or should we just expand #376?

@landonreed
Copy link
Member

@miles-grant-ibigroup, can you document your findings in #376? We can handle the back button stuff altogether in that issue (so we can continue with the merge for this one).

@landonreed landonreed removed their assignment Jul 7, 2021
@landonreed landonreed merged commit fb581ac into dev Jul 7, 2021
@landonreed landonreed deleted the trip-navigation-away-warning branch July 7, 2021 14:23
@github-actions
Copy link
Contributor

github-actions bot commented Jul 7, 2021

🎉 This PR is included in version 3.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants