fix: add isSaving to state, guard submit and catch errors#1010
Conversation
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
📝 WalkthroughWalkthrough
ChangesBadge settings save flow
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
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
src/components/forms/__tests__/badge-settings-form.test.jssrc/components/forms/badge-settings-form.js
| 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 }); | ||
| }); |
There was a problem hiding this comment.
🩺 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/**' || trueRepository: 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.
ref: https://app.clickup.com/t/9014802374/86batpx0h
Signed-off-by: Tomás Castillo tcastilloboireau@gmail.com
Summary by CodeRabbit