- 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.
74 lines
1.6 KiB
TypeScript
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>
|
|
);
|
|
}
|