fix: handle serverError in toast notifications for server actions#7612
fix: handle serverError in toast notifications for server actions#7612Ltbltbltbltb wants to merge 2 commits intoformbricks:mainfrom
Conversation
Several components showed success toasts even when server actions returned serverError (HTTP 200 with error payload from next-safe-action). Added serverError checks before success toasts in 6 components: - SingleResponseCard (deleteResponse) - EditProfileDetailsForm (updateUser) - edit-membership-role (updateMembership, updateInvite) - ResponseTable (deleteResponse callback) - contacts-table (deleteContact callback) - create-new-action-tab (createActionClass) Fixes formbricks#3302
|
Ltbltbltbltb seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
I have signed the CLA. |
WalkthroughThe changes implement consistent server-side error handling across multiple components by introducing validation of results returned from server actions. The 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/web/modules/survey/editor/components/create-new-action-tab.tsx (1)
82-91: 🧹 Nitpick | 🔵 TrivialTypo in variable name:
createActionClassResposneshould becreateActionClassResponse.The serverError handling logic is correct, but the variable name has a typo that impacts code readability and consistency.
✏️ Proposed fix for the typo
- const createActionClassResposne = await createActionClassAction({ + const createActionClassResponse = await createActionClassAction({ action: updatedAction, }); - if (createActionClassResposne?.serverError) { - toast.error(getFormattedErrorMessage(createActionClassResposne)); + if (createActionClassResponse?.serverError) { + toast.error(getFormattedErrorMessage(createActionClassResponse)); return; } - if (!createActionClassResposne?.data) return; + if (!createActionClassResponse?.data) return; - const newActionClass = createActionClassResposne.data; + const newActionClass = createActionClassResponse.data;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/web/modules/survey/editor/components/create-new-action-tab.tsx` around lines 82 - 91, There is a typo in the response variable name: rename all instances of createActionClassResposne to createActionClassResponse (the const assigned from await createActionClassAction({...}) and the subsequent checks createActionClassResponse?.serverError and createActionClassResponse?.data) so the variable name is consistent and readable; also update any other references in this file that use the misspelled identifier (e.g., the toast.error(getFormattedErrorMessage(...)) call) to use createActionClassResponse.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@apps/web/modules/survey/editor/components/create-new-action-tab.tsx`:
- Around line 82-91: There is a typo in the response variable name: rename all
instances of createActionClassResposne to createActionClassResponse (the const
assigned from await createActionClassAction({...}) and the subsequent checks
createActionClassResponse?.serverError and createActionClassResponse?.data) so
the variable name is consistent and readable; also update any other references
in this file that use the misspelled identifier (e.g., the
toast.error(getFormattedErrorMessage(...)) call) to use
createActionClassResponse.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 22e7a784-eb00-4353-b8d3-e775f29a1bfd
📒 Files selected for processing (6)
apps/web/app/(app)/environments/[environmentId]/settings/(account)/profile/components/EditProfileDetailsForm.tsxapps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponseTable.tsxapps/web/modules/analysis/components/SingleResponseCard/index.tsxapps/web/modules/ee/contacts/components/contacts-table.tsxapps/web/modules/ee/role-management/components/edit-membership-role.tsxapps/web/modules/survey/editor/components/create-new-action-tab.tsx
…s#3302) Two locations were missed in the original fix for formbricks#3302: - apps/web/modules/survey/list/components/survey-dropdown-menu.tsx: duplicateSurveyAndRefresh was showing success toast even when copySurveyToOtherEnvironmentAction returned a serverError. - apps/web/modules/survey/multi-language-surveys/components/edit-language.tsx: handleDeleteLanguage was showing success UI even when getSurveysUsingGivenLanguageAction returned a serverError. Both now follow the same pattern already used elsewhere in the codebase: check serverError first with getFormattedErrorMessage(), then check data.
Dhruwang
left a comment
There was a problem hiding this comment.
Thanks for the fix. Looks good. 🚀
|
Merging duplicate here, since CLA is not signed. |
Summary
Fixes #3302 — Several components showed success toasts even when server actions returned
serverError(HTTP 200 with error payload fromnext-safe-action).Changes
Added
serverErrorchecks before success toasts in 8 components:SingleResponseCarddeleteResponseActionserverErrorfirstEditProfileDetailsFormupdateUserActionserverErrorfirstedit-membership-roleupdateMembershipAction,updateInviteActionResponseTabledeleteResponseAction(callback)contacts-tabledeleteContactAction(callback)create-new-action-tabcreateActionClassActionsurvey-dropdown-menucopySurveyToOtherEnvironmentActiondataonly — serverError showed successserverErrorfirstedit-languagegetSurveysUsingGivenLanguageActiondataonly — serverError was silently ignoredserverErrorfirstPattern used
Follows the existing codebase pattern (~70% of components already use this):
Test plan
/claim #3302