/** * Reusable confirmation dialog with inline error display. * * Handles the common pattern: title, description, optional error banner, * cancel/confirm buttons with pending state. Dialog stays open on error. */ import { Button, Dialog } from "@cloudflare/kumo"; import { useLingui } from "@lingui/react/macro"; import * as React from "react"; import { DialogError, getMutationError } from "./DialogError.js"; export interface ConfirmDialogProps { open: boolean; onClose: () => void; title: string; /** Static description or dynamic JSX content */ description: React.ReactNode; /** Label for the confirm button (e.g. "Delete", "Disable User") */ confirmLabel: string; /** Label shown while the action is pending (e.g. "Deleting...") */ pendingLabel: string; /** Button variant — defaults to "destructive" */ variant?: "destructive" | "primary"; isPending: boolean; /** Error from a mutation — pass mutation.error directly */ error: unknown; onConfirm: () => void; /** Extra content rendered between description and buttons (e.g. a checkbox) */ children?: React.ReactNode; } export function ConfirmDialog({ open, onClose, title, description, confirmLabel, pendingLabel, variant = "destructive", isPending, error, onConfirm, children, }: ConfirmDialogProps) { const { t } = useLingui(); return ( !o && onClose()} disablePointerDismissal> {title} {description} {children}
); }