This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix action form's .onSuccess behaviour
The `handleSuccess` function was mutating the response object (data) to add a `petitionForm` field with the values of the action form's elements. There are (at least) a couple of reasons why this was wrong: 1. It's bad practice to mutate a function parameter as we don't know where else it's going to be consumed, and how. It adds unnecessary complexity to the codebase and you're introducing side effects that may make debugging difficult in the future (case in point: now). 2. Not all action forms are petition forms. This side effect can cause issues in other types of forms, and also places limits on how we can extend action form's functionality. Furthermore, the reason why that code was added was simply to pass the data to the petition form's callback, so that it, in turn, could dispatch an action to the redux store so that we can "log in" a member. That was the only place where that extra field was being used. A better approach ----------------- This commit refactors the code to dispatch the action from the `handleSuccess` function in action_form.js, and make sure that the data is correctly serialised when we dispatch. In the reducer, we only pick the form values that are relevant to the fundraiser form[1]. Since both forms are different and may contain different required / optional fields, we only pick the relevant fields for our form, and check which ones are still outstanding. This is a cleaner way to copy data from one form to another, avoiding corrupted data. Notes ----- 1. Our codebase is still not "correct" in the sense that, if a page were to have _two_ donation forms (for example a normal fundraiser and an after-donate monthly upsell), the same reducer would kick in. We still need to refactor our fundraiser code, and separate forms from fundraisers.
- Loading branch information
Showing
4 changed files
with
32 additions
and
31 deletions.
There are no files selected for viewing
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
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
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
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