[TAN-7381] Undo button for single approve and add WarningModal for bulk approve/remove#13656
Open
AchrafGoVocal wants to merge 25 commits intomasterfrom
Open
[TAN-7381] Undo button for single approve and add WarningModal for bulk approve/remove#13656AchrafGoVocal wants to merge 25 commits intomasterfrom
AchrafGoVocal wants to merge 25 commits intomasterfrom
Conversation
…LabDotCo/citizenlab into TAN-7381-unfo-approval-form-sync
Collaborator
|
…LabDotCo/citizenlab into TAN-7381-unfo-approval-form-sync
AchrafGoVocal
commented
Apr 23, 2026
Comment on lines
130
to
146
| const autoSave = useCallback( | ||
| (id: string, formData: FormValues) => { | ||
| updateIdea({ id, requestBody: formData, skipRefetchCounts: true }); | ||
| const { publication_status: _omit, ...rest } = formData; | ||
| updateIdea({ id, requestBody: rest, skipRefetchCounts: true }); | ||
| }, | ||
| [updateIdea] | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| if (!ideaId || !(ideaId in ideaFormStatePerIdea)) return; | ||
|
|
||
| const timeout = setTimeout(() => { | ||
| autoSave(ideaId, ideaFormStatePerIdea[ideaId]); | ||
| }, 500); | ||
|
|
||
| return () => clearTimeout(timeout); | ||
| }, [ideaId, ideaFormStatePerIdea, autoSave]); |
Contributor
Author
There was a problem hiding this comment.
There is a race condition that can happen here between when an idea is patched and when it is approved.
This is what I think happens:
- Click an idea
- The form mounts and quietly normalizes its values, which looks to react-hook-form like a form edit
- That schedules a "save your edits" PATCH 500ms later
- The PATCH ships the whole form, including
publication_status: 'draft'.- If you click Approve just before that timer fires, the draft-PATCH lands right after the publish-PATCH and un-approves the idea.
- This leads to a bug where an idea is both in the "Recently approved" list while also being in the "Ideas list"
That's why I remove the publication_status from the autoSave and also because it should only be updated by approving or undoing the approval.
Contributor
There was a problem hiding this comment.
Sneaky! Nice catch! 💪
amanda-anderson
approved these changes
Apr 24, 2026
Contributor
amanda-anderson
left a comment
There was a problem hiding this comment.
Code LGTM! 🚀 (I didn't do a functional review though - just let me know if you need that too!)
…AN-7381-unfo-approval-form-sync
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changelog
Added
Changed
For translators