2025-05-05 17:11:44 +00:00
|
|
|
import {
|
|
|
|
|
AlertDialog,
|
|
|
|
|
AlertDialogAction,
|
|
|
|
|
AlertDialogCancel,
|
|
|
|
|
AlertDialogContent,
|
|
|
|
|
AlertDialogDescription,
|
|
|
|
|
AlertDialogFooter,
|
|
|
|
|
AlertDialogHeader,
|
|
|
|
|
AlertDialogTitle,
|
|
|
|
|
} from "@repo/shadcn-ui/components";
|
2025-10-23 17:29:52 +00:00
|
|
|
import { useState } from 'react';
|
2025-05-05 17:11:44 +00:00
|
|
|
|
|
|
|
|
interface CustomDialogProps {
|
2025-09-23 08:59:15 +00:00
|
|
|
open: boolean;
|
|
|
|
|
onConfirm: (ok: boolean) => void;
|
|
|
|
|
title?: string;
|
|
|
|
|
description?: string;
|
|
|
|
|
cancelLabel?: string;
|
|
|
|
|
confirmLabel?: string;
|
2025-05-05 17:11:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const CustomDialog = ({
|
2025-09-23 08:59:15 +00:00
|
|
|
open,
|
2025-05-05 17:11:44 +00:00
|
|
|
onConfirm,
|
|
|
|
|
title,
|
|
|
|
|
description,
|
|
|
|
|
cancelLabel,
|
|
|
|
|
confirmLabel,
|
|
|
|
|
}: CustomDialogProps) => {
|
2025-10-23 17:29:52 +00:00
|
|
|
const [closedByAction, setClosedByAction] = useState(false);
|
|
|
|
|
|
|
|
|
|
const handleClose = (ok: boolean) => {
|
|
|
|
|
setClosedByAction(true);
|
|
|
|
|
onConfirm(ok);
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-05 17:11:44 +00:00
|
|
|
return (
|
2025-10-23 17:29:52 +00:00
|
|
|
<AlertDialog
|
|
|
|
|
open={open}
|
|
|
|
|
onOpenChange={(nextOpen) => {
|
|
|
|
|
if (!nextOpen && !closedByAction) onConfirm(false);
|
|
|
|
|
if (nextOpen) setClosedByAction(false);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<AlertDialogContent className="max-w-md rounded-2xl border border-border shadow-lg">
|
|
|
|
|
<AlertDialogHeader className="space-y-2">
|
|
|
|
|
<AlertDialogTitle className="text-lg font-semibold">{title}</AlertDialogTitle>
|
|
|
|
|
<AlertDialogDescription className="text-sm text-muted-foreground" aria-live="assertive">
|
|
|
|
|
{description}
|
|
|
|
|
</AlertDialogDescription>
|
2025-05-05 17:11:44 +00:00
|
|
|
</AlertDialogHeader>
|
2025-10-23 17:29:52 +00:00
|
|
|
<AlertDialogFooter className="mt-12">
|
|
|
|
|
<AlertDialogCancel autoFocus className="min-w-[120px]">{cancelLabel}</AlertDialogCancel>
|
|
|
|
|
<AlertDialogAction className="min-w-[120px] bg-destructive text-white hover:bg-destructive/90">
|
|
|
|
|
{confirmLabel}
|
|
|
|
|
</AlertDialogAction>
|
2025-05-05 17:11:44 +00:00
|
|
|
</AlertDialogFooter>
|
|
|
|
|
</AlertDialogContent>
|
|
|
|
|
</AlertDialog>
|
|
|
|
|
);
|
2025-10-23 17:29:52 +00:00
|
|
|
};
|