-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve access control invites error handling to show single snackbar #469
Conversation
WalkthroughThe pull request introduces modifications to the user invitation process in the Changes
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/api/users.js (1)
11-21
: LGTM! Consider adding JSDoc documentation.The changes to add
suppressErrorSnackbar
parameter look good and align well with the PR objective. The implementation correctly uses axios configuration to control error handling behavior.Consider adding JSDoc documentation to clarify the parameter's purpose:
+/** + * Invites a user to a subscription + * @param {string} subscriptionId - The ID of the subscription + * @param {Object} payload - The invitation payload + * @param {boolean} [suppressErrorSnackbar=false] - When true, suppresses global error notifications + * @returns {Promise} Axios promise + */ export const inviteSubscriptionUser = ( subscriptionId, payload, suppressErrorSnackbar = false ) =>pages/access/[serviceId]/[environmentId]/access-control.js (2)
129-169
: LGTM! Consider improving error message formatting.The enhanced error handling looks good:
- Suppressing global errors prevents duplicate notifications
- Success and error callbacks are well-defined
- Backend error details help users understand failures better
Consider extracting the error message to a separate component or using template literals for better readability:
- snackbar.showError( - <> - Some invites were not sent. Please retry - {backendErrorMessage ? ( - <> - <br /> - Error details: {backendErrorMessage}{" "} - </> - ) : ( - "" - )} - </> - ); + const errorMessage = backendErrorMessage + ? `Some invites were not sent. Please retry\nError details: ${backendErrorMessage}` + : "Some invites were not sent. Please retry"; + snackbar.showError(errorMessage);
Line range hint
214-227
: Consider extracting role type normalization logic.The form submission changes look good, but the role type normalization logic could be more maintainable.
Consider extracting the role type normalization to a utility function:
+const normalizeRoleType = (roleType) => { + const roleMap = { + 'Editor': 'editor', + 'Reader': 'reader' + }; + return roleMap[roleType] || roleType; +}; onSubmit: (values) => { const valuesToBeSubmitted = structuredClone(values); - for (let i = 0; i < valuesToBeSubmitted?.userInvite?.length; i++) { - if (valuesToBeSubmitted.userInvite[i]["roleType"] === "Editor") { - valuesToBeSubmitted.userInvite[i]["roleType"] = "editor"; - } - if (valuesToBeSubmitted.userInvite[i]["roleType"] === "Reader") { - valuesToBeSubmitted.userInvite[i]["roleType"] = "reader"; - } - } + valuesToBeSubmitted.userInvite = valuesToBeSubmitted.userInvite.map(invite => ({ + ...invite, + roleType: normalizeRoleType(invite.roleType) + })); createUserInvitesMutation.mutate(valuesToBeSubmitted); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
pages/access/[serviceId]/[environmentId]/access-control.js
(1 hunks)src/api/users.js
(1 hunks)
Summary by CodeRabbit
New Features
Bug Fixes
Chores