Skip to content

fix: reset form values for delete role and delete permission dialogs#2529

Closed
ChaseNelson wants to merge 4 commits intounkeyed:mainfrom
ChaseNelson:fix/delete-dialogs-input-values
Closed

fix: reset form values for delete role and delete permission dialogs#2529
ChaseNelson wants to merge 4 commits intounkeyed:mainfrom
ChaseNelson:fix/delete-dialogs-input-values

Conversation

@ChaseNelson
Copy link

@ChaseNelson ChaseNelson commented Oct 21, 2024

What does this PR do?

Fixes #2521
ENG-1523

https://www.loom.com/share/1cf0dc720fc14f769873080764dff5fb?sid=5be4896c-b02b-498e-80a9-39c550d48dce

https://www.loom.com/share/544a3ab13abb483f949fd0fef7e54f34?sid=cbcc7ef0-b4a6-45b5-bd77-7d888e7b276d

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

Test Delete Role

  1. Navigate to Authorization > Roles > Role > Delete Role
  2. Enter some text into the input box.
  3. Close and then reopen the dialog box.
  4. Delete Role input should be empty.

Test Delete Permission

  1. Navigate to Authorization > Permissions > Permission > Delete Permission
  2. Enter some text into the input box.
  3. Close and then reopen the dialog box.
  4. Delete Permission input should be empty.

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

Summary by CodeRabbit

  • New Features

    • Enhanced dialog management in the Delete Permission and Delete Role components for better user experience.
    • Added toast notifications to display error messages when deletion fails.
  • Bug Fixes

    • Improved form reset functionality when the dialog opens or closes.

@changeset-bot
Copy link

changeset-bot bot commented Oct 21, 2024

⚠️ No Changeset found

Latest commit: 4fc41b4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Oct 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 28, 2024 1:18pm

@CLAassistant
Copy link

CLAassistant commented Oct 21, 2024

CLA assistant check
All committers have signed the CLA.

@vercel
Copy link

vercel bot commented Oct 21, 2024

@ChaseNelson is attempting to deploy a commit to the Unkey Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 21, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request introduce a new function handleDialogOpenChange in both the DeletePermission and DeleteRole components. This function manages the dialog's open state and resets the form when the dialog is opened or closed, replacing the previous inline state management. Additionally, the error handling for the deletePermission mutation has been updated to display error messages via toast notifications. The overall structure of both components remains largely unchanged.

Changes

File Change Summary
apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx, apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx Introduced handleDialogOpenChange(newState: boolean) function to manage dialog state and reset forms. Updated Dialog component to use this new function. Modified deletePermission mutation's onError callback for error handling.

Assessment against linked issues

Objective Addressed Explanation
Input fields in delete dialogs should reset on reopen (2521)

Possibly related PRs

Suggested labels

🕹️ oss.gg, :joystick: 150 points, hacktoberfest

Suggested reviewers

  • mcstepp
  • perkinsjr

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added Bug Something isn't working Needs Approval Needs approval from Unkey labels Oct 21, 2024
@github-actions
Copy link
Contributor

github-actions bot commented Oct 21, 2024

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Outside diff range and nitpick comments (3)
apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx (1)

78-78: Good use of the new handleDialogOpenChange function!

The Dialog component now correctly uses the handleDialogOpenChange function for its onOpenChange prop. This change effectively implements the form reset functionality when the dialog state changes.

For consistency, consider updating the "Cancel" button's onClick handler to use handleDialogOpenChange as well:

-onClick={() => setOpen(!open)}
+onClick={() => handleDialogOpenChange(false)}

This would ensure that the form reset logic is applied consistently across all dialog close actions.

apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx (2)

77-77: Good update to Dialog component!

The onOpenChange prop now uses the new handleDialogOpenChange function, which is a clean and maintainable approach. This ensures that the form reset occurs whenever the dialog's state changes.

For consistency, consider updating the onClick handler of the Cancel button (around line 120) to use handleDialogOpenChange(!open) instead of directly setting the state. This would centralize all dialog open state changes through the new function.


67-77: Excellent implementation addressing the reset issue!

The changes effectively solve the problem of input values not resetting in delete dialogs, as outlined in the PR objectives. The new handleDialogOpenChange function and its usage in the Dialog component create a robust solution that prevents user confusion and potential accidental deletions.

One minor suggestion for improvement: Consider enhancing the error handling in the deletePermission mutation's onError callback. Instead of just displaying the error message, you could add more context, like:

onError(err) {
  toast.error(`Failed to delete permission: ${err.message}`);
},

This would provide users with clearer information about what went wrong.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 34831dc and 8cc64bd.

📒 Files selected for processing (2)
  • apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx (1 hunks)
  • apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx (1 hunks)
🧰 Additional context used
🔇 Additional comments (4)
apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx (2)

68-71: Excellent addition to reset form on dialog state change!

The new handleDialogOpenChange function effectively addresses the issue of input values not resetting in delete dialogs. By calling form.reset() whenever the dialog's state changes, it ensures that the form is cleared each time the dialog is opened or closed. This implementation aligns perfectly with the PR objectives and resolves the problem described in issue #2521.


Line range hint 1-138: Overall, excellent implementation addressing the reported issue!

The changes in this file effectively solve the problem of input values not resetting in delete dialogs, as reported in issue #2521. The new handleDialogOpenChange function, combined with its usage in the Dialog component, ensures that the form is reset whenever the dialog is opened or closed. This implementation:

  1. Improves user experience by clearing previous inputs.
  2. Reduces the risk of accidental deletions.
  3. Maintains code clarity and maintainability.

The solution is well-integrated into the existing component structure and aligns perfectly with the PR objectives. Great job on this fix!

apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx (2)

67-70: Great addition to reset form on dialog state change!

The new handleDialogOpenChange function effectively addresses the issue of input values not resetting in delete dialogs. By resetting the form whenever the dialog's state changes, it ensures a clean slate for each interaction, preventing potential user confusion and accidental deletions.


Line range hint 1-140: Overall, great job on addressing the reset issue!

The changes in this file effectively solve the problem described in the PR objectives. The implementation is clean, maintainable, and significantly improves the user experience by preventing potential confusion and errors when deleting permissions.

A few minor suggestions have been made for further improvements, but these are not critical. The core functionality has been successfully implemented and meets the requirements outlined in the PR objectives.

@chronark
Copy link
Collaborator

looks like those new functions aren't used

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (4)
apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx (2)

Line range hint 134-138: Use handleDialogOpenChange in Cancel button.

For consistency, use the handleDialogOpenChange function instead of directly manipulating the open state. This ensures the form is properly reset when cancelled.

 <Button
   type="button"
   disabled={deleteRole.isLoading}
-  onClick={() => setOpen(!open)}
+  onClick={() => handleDialogOpenChange(false)}
   variant="secondary"
 >
🧰 Tools
🪛 Biome

[error] 68-68: This function is unused.

Unused variables usually are result of incomplete refactoring, typos and other source of bugs.

(lint/correctness/noUnusedVariables)


Line range hint 89-99: Consider adding loading state to form fields.

While the submit button shows a loading state, consider disabling the form input during submission to prevent multiple submissions and improve UX.

 <FormControl>
-  <Input {...field} autoComplete="off" />
+  <Input {...field} autoComplete="off" disabled={deleteRole.isLoading} />
 </FormControl>
🧰 Tools
🪛 Biome

[error] 68-68: This function is unused.

Unused variables usually are result of incomplete refactoring, typos and other source of bugs.

(lint/correctness/noUnusedVariables)

apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx (2)

Line range hint 60-63: Consider enhancing error handling.

While the current error handling works, consider these improvements:

  1. Use user-friendly error messages instead of raw error messages
  2. Add error logging for debugging purposes

Here's a suggested implementation:

  onError(err) {
+   console.error('Failed to delete permission:', err);
+   const userMessage = 'Failed to delete permission. Please try again or contact support.';
-   toast.error(err.message);
+   toast.error(userMessage);
  },
🧰 Tools
🪛 Biome

[error] 67-67: This function is unused.

Unused variables usually are result of incomplete refactoring, typos and other source of bugs.

(lint/correctness/noUnusedVariables)


Line range hint 124-131: Use handleDialogOpenChange for Cancel button.

The Cancel button directly toggles the open state using setOpen(!open), bypassing the form reset functionality. This should use handleDialogOpenChange for consistency.

Update the Cancel button's onClick handler:

  <Button
    type="button"
    disabled={deletePermission.isLoading}
-   onClick={() => setOpen(!open)}
+   onClick={() => handleDialogOpenChange(false)}
    variant="secondary"
  >
    Cancel
  </Button>
🧰 Tools
🪛 Biome

[error] 67-67: This function is unused.

Unused variables usually are result of incomplete refactoring, typos and other source of bugs.

(lint/correctness/noUnusedVariables)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8cc64bd and 4fc41b4.

📒 Files selected for processing (2)
  • apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx (1 hunks)
  • apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx (1 hunks)
🧰 Additional context used
🪛 Biome
apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx

[error] 67-67: This function is unused.

Unused variables usually are result of incomplete refactoring, typos and other source of bugs.

(lint/correctness/noUnusedVariables)

apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx

[error] 68-68: This function is unused.

Unused variables usually are result of incomplete refactoring, typos and other source of bugs.

(lint/correctness/noUnusedVariables)

🔇 Additional comments (2)
apps/dashboard/app/(app)/authorization/roles/[roleId]/delete-role.tsx (1)

Line range hint 101-104: LGTM: Form reset implementation.

The implementation of handleDialogOpenChange correctly addresses the PR objective by resetting the form values when the dialog's state changes. This ensures a clean form state each time the dialog is opened.

🧰 Tools
🪛 Biome

[error] 68-68: This function is unused.

Unused variables usually are result of incomplete refactoring, typos and other source of bugs.

(lint/correctness/noUnusedVariables)

apps/dashboard/app/(app)/authorization/permissions/[permissionId]/delete-permission.tsx (1)

Line range hint 77-80: LGTM: Form reset implementation addresses the issue.

The implementation correctly handles form reset when the dialog state changes, addressing the original issue where input values weren't clearing between dialog sessions.

🧰 Tools
🪛 Biome

[error] 67-67: This function is unused.

Unused variables usually are result of incomplete refactoring, typos and other source of bugs.

(lint/correctness/noUnusedVariables)

Comment on lines +68 to +71
function handleDialogOpenChange(newState: boolean) {
setOpen(newState);
form.reset();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove duplicate function declaration.

The handleDialogOpenChange function is declared twice in the component. Remove the first declaration to fix the error.

- function handleDialogOpenChange(newState: boolean) {
-   setOpen(newState);
-   form.reset();
- }

Also applies to: 101-104

🧰 Tools
🪛 Biome

[error] 68-68: This function is unused.

Unused variables usually are result of incomplete refactoring, typos and other source of bugs.

(lint/correctness/noUnusedVariables)

Comment on lines +67 to +70
function handleDialogOpenChange(newState: boolean) {
setOpen(newState);
form.reset();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove duplicate function definition.

The handleDialogOpenChange function is defined twice with identical implementation. This appears to be a merge or copy-paste error.

Remove one of the duplicate function definitions:

-  function handleDialogOpenChange(newState: boolean) {
-    setOpen(newState);
-    form.reset();
-  }

Also applies to: 77-80

🧰 Tools
🪛 Biome

[error] 67-67: This function is unused.

Unused variables usually are result of incomplete refactoring, typos and other source of bugs.

(lint/correctness/noUnusedVariables)

@ChaseNelson
Copy link
Author

Looks like #2546 fixed this issue

@chronark chronark closed this Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Needs Approval Needs approval from Unkey

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Input Values Not Resetting in Delete Dialogs

3 participants