Skip to content

fix: remaining issue#3278

Merged
ogzhanolguncu merged 2 commits intomainfrom
fix-remaining-issue
May 28, 2025
Merged

fix: remaining issue#3278
ogzhanolguncu merged 2 commits intomainfrom
fix-remaining-issue

Conversation

@ogzhanolguncu
Copy link
Contributor

@ogzhanolguncu ogzhanolguncu commented May 28, 2025

What does this PR do?

  • Fix credit balance not updating correctly
  • Fix missing confirmation when navigating to key details
  • Prevent data loss from accidental tab/window closure

Fixes # (issue)

If there is not an issue for this, please create one first. This is used to tracking purposes and also helps use understand why this PR exists

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 key creation success dialog confirmation popovers
  • Test tab close on key creation success dialog
  • Test remaining_credit=0 case on key details page. On prod it says Disabled when credit is 0, but it should Enabled and should be disabled only if its null

Fixed version:
image

Prod:
image

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

This is how it looks when you try to close the tab on key success dialog
image

@changeset-bot
Copy link

changeset-bot bot commented May 28, 2025

⚠️ No Changeset found

Latest commit: a074703

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 28, 2025

📝 Walkthrough

Walkthrough

The changes update a dialog component to centralize and unify close-related logic, add navigation with error handling, and prevent accidental tab or window closure while the dialog is open. Separately, the logic for determining if credits are enabled for API keys is modified to consider all non-null values as enabled.

Changes

File(s) Change Summary
.../key-created-success-dialog.tsx Refactored dialog close logic to use a unified pendingAction state; added navigation support and error handling; added prevention of accidental unload; removed unused state and refs.
.../lib/trpc/routers/api/keys/query-api-keys/get-all-keys.ts Changed logic to set "credits enabled" flag for API keys to true for any non-null remaining value, not just non-zero.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Dialog
    participant Router
    participant Toast

    User->>Dialog: Clicks close/create-another/go-to-details
    Dialog->>Dialog: handleCloseAttempt(action)
    Dialog->>User: Shows confirmation popover
    User->>Dialog: Confirms close
    Dialog->>Dialog: handleConfirmClose()
    alt action is "create-another"
        Dialog->>Dialog: Calls onCreateAnother
    else action is "go-to-details"
        Dialog->>Router: Navigates to key details
        alt Navigation error
            Router->>Toast: Show error
        end
    else action is "close"
        Dialog->>Dialog: Closes dialog
    end
    Note over Dialog: Dialog prevents accidental unload while open
Loading

Suggested labels

Bug

Suggested reviewers

  • perkinsjr
  • mcstepp
  • chronark
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@vercel
Copy link

vercel bot commented May 28, 2025

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

Name Status Preview Comments Updated (UTC)
dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 28, 2025 3:07pm
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 28, 2025 3:07pm

@github-actions
Copy link
Contributor

github-actions bot commented May 28, 2025

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

@vercel vercel bot temporarily deployed to Preview – engineering May 28, 2025 15:05 Inactive
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

🧹 Nitpick comments (1)
apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/components/key-created-success-dialog.tsx (1)

79-82: Consider early return after error logging.

When pendingAction is null, the function logs an error but continues execution. Consider adding an early return to prevent potential issues.

 if (!pendingAction) {
   console.error("No pending action when confirming close");
+  setIsConfirmOpen(false);
+  setPendingAction(null);
   return;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7579a55 and a074703.

📒 Files selected for processing (2)
  • apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/components/key-created-success-dialog.tsx (5 hunks)
  • apps/dashboard/lib/trpc/routers/api/keys/query-api-keys/get-all-keys.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Test Packages / Test ./internal/id
  • GitHub Check: Test Packages / Test ./packages/cache
  • GitHub Check: Test Packages / Test ./internal/clickhouse
  • GitHub Check: Test Packages / Test ./packages/hono
  • GitHub Check: Test Packages / Test ./internal/billing
  • GitHub Check: autofix
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
apps/dashboard/lib/trpc/routers/api/keys/query-api-keys/get-all-keys.ts (1)

248-249: LGTM! Improved credit status logic.

The change from checking truthy values to checking for non-null properly distinguishes between keys without credit configuration (null) and keys with zero remaining credits. This provides more accurate credit status representation in the API response.

apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/components/key-created-success-dialog.tsx (2)

37-52: Good UX improvement with the beforeunload handler.

The addition of the beforeunload event listener prevents users from accidentally losing the key secret by closing the tab/window. This is a thoughtful enhancement since the key won't be shown again.


73-126: Well-structured centralized close handling.

The refactored close handling with handleCloseAttempt and handleConfirmClose provides:

  • Clear separation of concerns between intent and execution
  • Proper error handling for missing keyspaceId
  • Helpful error messages with support links
  • Consistent state management

The implementation is clean and maintainable.

@vercel vercel bot temporarily deployed to Preview – dashboard May 28, 2025 15:07 Inactive
@chronark
Copy link
Collaborator

why did we go from the custom alert dialog to a browser alert?

@ogzhanolguncu
Copy link
Contributor Author

why did we go from the custom alert dialog to a browser alert?

Custom alert still exists. I just added some extra protection against unwanted close tabs, Like cmd+w

@chronark
Copy link
Collaborator

I see, nice

@ogzhanolguncu ogzhanolguncu added this pull request to the merge queue May 28, 2025
Merged via the queue into main with commit 51768aa May 28, 2025
34 checks passed
@ogzhanolguncu ogzhanolguncu deleted the fix-remaining-issue branch May 28, 2025 15:29
@coderabbitai coderabbitai bot mentioned this pull request Sep 29, 2025
18 tasks
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.

2 participants