This repository has been archived by the owner on Sep 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If this is not done, the form always exists and is not cleared when we close the dialog
Also refactor watchers to use takeEvery
Also fix watcher tests
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is quite a complex PR. I'll try to break it down below.
Note that this does not include styling. That will be added in a separate PR once we get the design mockups.
TODO:
Modal dialogs
react-modal is used to show a modal dialog. We keep track of what modal is being shown in the Redux state tree using the
modal
module. I crated one component for the new project modal dialog, and one component for the form that it includes (more below).In order for the modal to show on top of everything else, we needed to create a new stacking (z-index) context at the root App component. We also prevent scrolling on the App element when a modal is open.
Forms
redux-form is used to handle form validation and submission. It stores form data in the redux state tree. It's a rather complex solution, but the end result is pretty clean and redux-friendly. redux-form provides a higher-order component wrapper, which then injects props into our form component.
The thing that made this solution slightly complex is that
onSubmit
, the function that receives the form data and is called when the form is submitted, should return a Promise that's either resolved on a successful submission or rejected on a failure. If you're using redux-thunk, that fits in perfectly. However, since we use redux-saga, we had to use a slightly convoluted approach, which resulted in the newforms
module. It works like this:onSubmitActions
) that accepts three Redux action types: one that triggers the submission, one that we watch for to indicate that the submission succeeded, and one that we watch for to indicate that the submission failed. This action generator captures the values passed toonSubmit
, and returns a Promise that dispatches a redux action that captures theresolve
andreject
functions for that promise.watchForFormSubmit
saga catches the form submission and calls the genericformSubmitSaga
. This dispatches the passed in action type for triggering the submission along with the form payload, and then waits to see which type of action is received first: a success or failure action. Depending on the result, it calls resolve or reject to settle the Promise, and thus tells our form that the submission has completed.Note that the type definitions for redux-form are not up to date in NPM. There's a PR in progress where this is being fixed. Until then, I had to hack the in-progress version to make them work.