buzz icon indicating copy to clipboard operation
buzz copied to clipboard

fix(desktop): surface leave-channel rejection in sidebar dialog

Open iroiro147 opened this issue 4 months ago • 0 comments

Problem

Leaving a channel you solely own looks like a broken button. You confirm the dialog, it closes, and the channel is still sitting in the sidebar — no toast, no error, no explanation. The relay is refusing on purpose (it won't remove a channel's last owner), but the reason never reaches the UI.

Closes #3605

Root Cause

The sidebar's LeaveChannelAlertDialog (in ChannelSectionDialogs.tsx) called leaveChannel.mutate() and immediately cleared the target — closing the dialog regardless of success or failure. The mutation's .error field was never read or displayed.

In contrast, the ChannelManagementSheet leave button does surface errors via leaveChannelMutation.error.message. The two entry points disagreed about whether failures are worth mentioning.

Solution

Added error and pending state to the sidebar's leave dialog:

Change Detail
LeaveChannelAlertDialog props Added error?: Error | null and isPending?: boolean
Error display Renders error.message as a text-destructive paragraph inside the dialog
Dialog close behavior Dialog stays open on mutation failure; only closes on success
Button states Cancel and Leave disabled while isPending; Leave shows "Leaving..."
Mutation call Switched from .mutate() (fire-and-forget) to .mutateAsync().then(() => close)
Dismiss guard onOpenChange blocked while isPending to prevent premature dismissal

Acceptance Criteria

  • [x] The rejection surfaces wherever leave is offered (sidebar now matches management sheet)
  • [x] The error message from the relay is displayed to the user
  • [x] The dialog stays open on failure so the user can read the error
  • [x] The dialog closes on success
  • [x] Buttons are disabled during the pending request
  • [x] Existing manual Mark unread behavior remains coherent

Test Plan

cd desktop
node --test src/features/sidebar/ui/leaveChannelDialog.test.mjs

All 6 tests pass:

  • dialog stays open when leave mutation fails
  • dialog closes when leave mutation succeeds
  • dismiss is blocked while mutation is pending
  • dismiss works when not pending
  • error is cleared on a new leave request
  • isPending is true during mutation and false after

iroiro147 avatar Jul 30 '26 05:07 iroiro147