Skip to content

fix: add isSaving to state, guard submit and catch errors#1010

Open
tomrndom wants to merge 1 commit into
masterfrom
fix/badge-settings-double-save
Open

fix: add isSaving to state, guard submit and catch errors#1010
tomrndom wants to merge 1 commit into
masterfrom
fix/badge-settings-double-save

Conversation

@tomrndom

@tomrndom tomrndom commented Jul 15, 2026

Copy link
Copy Markdown

ref: https://app.clickup.com/t/9014802374/86batpx0h

Signed-off-by: Tomás Castillo tcastilloboireau@gmail.com

Summary by CodeRabbit

  • Bug Fixes
    • Prevented duplicate submissions when Save is clicked multiple times.
    • Kept the Save button disabled while changes are being submitted.
    • Re-enabled the Save button if saving fails, preventing the form from becoming stuck.

Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

BadgeSettingsForm now prevents concurrent saves, manages asynchronous submission state, handles rejected submissions, and disables the Save button during saves. Tests cover duplicate clicks and button re-enablement after rejection.

Changes

Badge settings save flow

Layer / File(s) Summary
Save state and submission flow
src/components/forms/badge-settings-form.js
Adds isSaving, prevents concurrent submissions, handles success and rejection, resets state in finally, and disables the Save button while saving.
Save flow interaction tests
src/components/forms/__tests__/badge-settings-form.test.js
Mocks integrations and tests duplicate-click prevention plus Save button re-enablement after rejection.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BadgeSettingsForm
  participant onSubmit
  participant Swal.fire
  BadgeSettingsForm->>BadgeSettingsForm: Set isSaving to true
  BadgeSettingsForm->>onSubmit: Submit updated entity fields
  onSubmit-->>BadgeSettingsForm: Resolve or reject
  BadgeSettingsForm->>Swal.fire: Show success alert on resolve
  BadgeSettingsForm->>BadgeSettingsForm: Reset isSaving in finally
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: saving-state guard and error handling for form submission.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/badge-settings-double-save

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/forms/badge-settings-form.js`:
- Around line 172-188: Update handleSubmit’s onSubmit flow to create a Promise
boundary with Promise.resolve().then(() => this.props.onSubmit(settingsToSave)),
preserving the existing success, catch, and finally handlers so synchronous
throws or non-Promise returns always reset isSaving.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bd39d0f8-2444-4382-9089-0b940b4d0b5f

📥 Commits

Reviewing files that changed from the base of the PR and between 662c1d2 and a473878.

📒 Files selected for processing (2)
  • src/components/forms/__tests__/badge-settings-form.test.js
  • src/components/forms/badge-settings-form.js

Comment on lines +172 to +188
this.setState({ isSaving: true });

Swal.fire(success_message);
});
this.props
.onSubmit(settingsToSave)
.then(() => {
const success_message = {
title: T.translate("general.done"),
html: T.translate("badge_settings.badge_template_settings_updated"),
type: "success"
};

Swal.fire(success_message);
})
.catch(() => {})
.finally(() => {
this.setState({ isSaving: false });
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- file outline ---'
ast-grep outline src/components/forms/badge-settings-form.js --view expanded || true

echo '--- relevant slice ---'
sed -n '140,220p' src/components/forms/badge-settings-form.js

echo '--- search onSubmit usages ---'
rg -n "onSubmit\s*[:=]" src -g '!**/node_modules/**' || true
rg -n "<BadgeSettingsForm|badge-settings-form|onSubmit=" src -g '!**/node_modules/**' || true

Repository: fntechgit/summit-admin

Length of output: 42278


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n## badge-settings-form.js excerpt\n'
sed -n '1,260p' src/components/forms/badge-settings-form.js

printf '\n## BadgeSettingsForm usages\n'
rg -n "BadgeSettingsForm|badge-settings-form|onSubmit=" src

printf '\n## onSubmit prop types / docs in surrounding components\n'
rg -n "onSubmit.*PropTypes|PropTypes.*onSubmit|onSubmit:" src/components src/pages src -g '!**/node_modules/**'

Repository: fntechgit/summit-admin

Length of output: 33762


Use a Promise boundary around onSubmit
handleSubmit still depends on onSubmit(settingsToSave) returning a thenable. If a caller throws synchronously or returns a non-Promise, isSaving can remain stuck true. Wrapping the call with Promise.resolve().then(() => this.props.onSubmit(settingsToSave)) makes the save state recoverable.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/forms/badge-settings-form.js` around lines 172 - 188, Update
handleSubmit’s onSubmit flow to create a Promise boundary with
Promise.resolve().then(() => this.props.onSubmit(settingsToSave)), preserving
the existing success, catch, and finally handlers so synchronous throws or
non-Promise returns always reset isSaving.

@tomrndom tomrndom requested a review from smarcet July 15, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant