metis-desk/packages/rdx-ui/src/components/confirm-delete-dialog.tsx
David a0f02ced6e Refactor form dialogs and UI components for improved consistency and usability
- Updated DeleteBrandDialog and DeleteCatalogDefinitionDialog to use FormBody and FormActions for better structure.
- Replaced DialogFooter with FormActions in various dialogs to standardize button layouts.
- Introduced FormSectionTitle in multiple components for consistent section headings.
- Adjusted grid layouts to use responsive design with @min-[560px] for better adaptability.
- Created SoftwareResourceCreateDialog and SoftwareInstallationEditorDialog for better separation of concerns in software installation management.
- Enhanced FormActions to support cancelDisabled prop for better control over button states.
- Refined FormSectionTitle to allow for additional HTML elements like "legend" and "span".
- Added EntityTableColumnsDialog for managing table column visibility in a more user-friendly manner.
2026-10-15 16:14:26 +02:00

74 lines
1.6 KiB
TypeScript

import { Button } from "@repo/shadcn-ui/components/button";
import { useState } from "react";
import { FormActions, FormBody, FormDialog } from "./form-dialog";
export function ConfirmDeleteDialog({
open,
onOpenChange,
title,
description,
cancelLabel,
confirmLabel,
pendingLabel,
errorLabel,
onConfirm,
}: {
open: boolean;
onOpenChange: (open: boolean) => void;
title: string;
description: string;
cancelLabel: string;
confirmLabel: string;
pendingLabel: string;
errorLabel: string;
onConfirm: () => Promise<unknown>;
}) {
const [pending, setPending] = useState(false);
const [failed, setFailed] = useState(false);
return (
<FormDialog
cancelLabel={cancelLabel}
formActions
onOpenChange={(value) => {
if (!pending) {
setFailed(false);
onOpenChange(value);
}
}}
open={open}
title={title}
>
<FormBody>
<p>{description}</p>
{failed && (
<p className="text-destructive" role="alert">
{errorLabel}
</p>
)}
</FormBody>
<FormActions cancelDisabled={pending}>
<Button
disabled={pending}
onClick={async () => {
setPending(true);
setFailed(false);
try {
await onConfirm();
onOpenChange(false);
} catch {
setFailed(true);
} finally {
setPending(false);
}
}}
variant="destructive"
>
{pending ? pendingLabel : confirmLabel}
</Button>
</FormActions>
</FormDialog>
);
}