Skip to content

Add confirmation UI for deleting inactive hosts - #144

Open
samuelxanda wants to merge 2 commits into
Open-Source-Kigali:developfrom
samuelxanda:feat/126-delete-inactive-host-ui
Open

Add confirmation UI for deleting inactive hosts#144
samuelxanda wants to merge 2 commits into
Open-Source-Kigali:developfrom
samuelxanda:feat/126-delete-inactive-host-ui

Conversation

@samuelxanda

@samuelxanda samuelxanda commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Frontend-only for [Frontend] Add confirmation UI for deleting inactive hosts #126: host card menu shows Delete host for admins when the API sets canDelete: true.
  • Confirmation dialog is required; cancel leaves the host unchanged; API errors surface as toasts without dropping the list.
  • Successful deletes invalidate the hosts queries (inventory keys share that prefix) so the dashboard refreshes.

This PR does not include the backend deletion endpoint (#125). Until that lands, canDelete is absent and the action stays hidden.

Test plan

  • As ADMIN, eligible inactive host (canDelete: true): menu shows Delete host, confirm removes it from the dashboard.
  • As ADMIN, active / ineligible host: Delete host is not in the menu.
  • As VIEWER: Delete host is not in the menu.
  • Cancel on the confirm dialog does not call the API or change the list.
  • Failed delete shows an error toast and keeps the host list.
  • cd apps/web && npm test (52 passing locally).

Closes #126

Admins should confirm before removing a host the API marks deletable, and viewers should never see that action.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI lite review requested due to automatic review settings August 24, 2026 20:05
@samuelxanda
samuelxanda marked this pull request as draft August 24, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a frontend-only “Delete host” action for inactive hosts, gated by the server-provided canDelete flag and admin role, with a confirmation dialog and React Query invalidation to refresh host/inventory data after deletion.

Changes:

  • Introduces canDelete?: boolean on Host, plus a canShowDeleteHost helper and unit test.
  • Adds DELETE support to the API client, a deleteHost service, and a useDeleteHost mutation hook (with tests) that invalidates ['hosts']-prefixed queries.
  • Wires delete action + confirmation modal into HostCard, and passes admin/delete handlers from Dashboard and Hosts pages; adds UI tests.

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
package-lock.json Locks new test dependencies (Testing Library, user-event, jsdom) pulled in for UI/hook tests.
apps/web/vite.config.ts Adds Vitest type reference and a default test environment configuration.
apps/web/src/types/api.ts Extends Host with optional canDelete flag from the API.
apps/web/src/services/hosts.ts Adds deleteHost() service call.
apps/web/src/services/api.ts Extends request method union to include DELETE and exposes apiClient.delete.
apps/web/src/lib/hosts.ts Adds canShowDeleteHost() gating helper.
apps/web/src/lib/hosts.test.ts Unit test for canShowDeleteHost().
apps/web/src/hooks/useDeleteHost.ts Adds mutation hook that deletes hosts, shows toasts, and invalidates hosts queries.
apps/web/src/hooks/useDeleteHost.test.tsx Tests invalidation and error toast behavior for the delete hook.
apps/web/src/features/hosts/HostsPage.tsx Passes canManage (admin) and onDelete into HostCard.
apps/web/src/features/dashboard/DashboardPage.tsx Passes canManage (admin) and onDelete into HostCard on the dashboard view.
apps/web/src/components/HostCard.tsx Adds “Delete host” menu item (when eligible) and confirmation dialog flow.
apps/web/src/components/HostCard.test.tsx UI tests for eligibility gating, cancel, and confirm delete flows.
apps/web/src/components/DeleteHostDialog.tsx New confirmation dialog component rendered via portal.
apps/web/package.json Adds Testing Library, user-event, and jsdom devDependencies for web tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread apps/web/package.json
Comment on lines 31 to 34
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^6.0.3",
"jsdom": "^30.0.1",
"oxlint": "^1.71.0",
Comment on lines +19 to +42
useEffect(() => {
const onKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape' && !pending) {
onCancel()
}
}
document.addEventListener('keydown', onKeyDown)
return () => document.removeEventListener('keydown', onKeyDown)
}, [onCancel, pending])

return createPortal(
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
<div
className="animate-overlay-in absolute inset-0 bg-slate-950/40 backdrop-blur-[2px]"
onClick={pending ? undefined : onCancel}
aria-hidden
/>
<div
role="alertdialog"
aria-modal="true"
aria-labelledby="delete-host-title"
aria-describedby="delete-host-description"
className="animate-pop-in relative w-full max-w-md rounded-lg border border-border bg-card p-5 shadow-2xl"
>
jsdom 30 cannot run in CI, and the confirm dialog needs focus plus a scroll lock so keyboard users can actually use it.

Co-authored-by: Cursor <cursoragent@cursor.com>
@samuelxanda
samuelxanda marked this pull request as ready for review August 24, 2026 21:33

@rodriguecyber rodriguecyber left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The PR description mention Backend related issue but you worked on frontend part please update you r work description so it can be merged

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.

[Frontend] Add confirmation UI for deleting inactive hosts

3 participants