2026-03-08 01:02:57 +01:00
|
|
|
import { TriangleAlertIcon } from "lucide-react";
|
2025-08-28 18:27:07 +02:00
|
|
|
import type { ReactNode } from "react";
|
2025-08-04 17:45:44 +02:00
|
|
|
import {
|
2025-08-28 18:27:07 +02:00
|
|
|
AlertDialog,
|
|
|
|
|
AlertDialogAction,
|
|
|
|
|
AlertDialogCancel,
|
|
|
|
|
AlertDialogContent,
|
|
|
|
|
AlertDialogDescription,
|
|
|
|
|
AlertDialogFooter,
|
|
|
|
|
AlertDialogHeader,
|
|
|
|
|
AlertDialogTitle,
|
|
|
|
|
AlertDialogTrigger,
|
2025-08-04 17:45:44 +02:00
|
|
|
} from "~/components/ui/alert-dialog";
|
|
|
|
|
export const Confirm = ({
|
2025-08-28 18:27:07 +02:00
|
|
|
children,
|
|
|
|
|
title,
|
|
|
|
|
description,
|
|
|
|
|
onConfirm,
|
|
|
|
|
onCancel,
|
|
|
|
|
open,
|
|
|
|
|
setOpen,
|
|
|
|
|
onlyHedless,
|
|
|
|
|
cancelText,
|
|
|
|
|
confirmText,
|
2025-08-04 17:45:44 +02:00
|
|
|
}: {
|
2025-08-28 18:27:07 +02:00
|
|
|
children: ReactNode;
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
title: string;
|
|
|
|
|
description: string;
|
|
|
|
|
onConfirm: () => void;
|
|
|
|
|
onCancel?: () => void;
|
|
|
|
|
open?: boolean;
|
|
|
|
|
setOpen?: (open: boolean) => void;
|
|
|
|
|
onlyHedless?: boolean;
|
|
|
|
|
cancelText?: string;
|
|
|
|
|
confirmText?: string;
|
2025-08-04 17:45:44 +02:00
|
|
|
}) => {
|
2025-08-28 18:27:07 +02:00
|
|
|
return (
|
2025-08-29 16:18:32 +02:00
|
|
|
<AlertDialog onOpenChange={setOpen} open={open}>
|
2025-08-28 18:27:07 +02:00
|
|
|
{onlyHedless ? null : (
|
|
|
|
|
<AlertDialogTrigger asChild>{children}</AlertDialogTrigger>
|
|
|
|
|
)}
|
|
|
|
|
<AlertDialogContent>
|
2026-03-08 01:02:57 +01:00
|
|
|
<AlertDialogHeader className="place-items-center! items-center">
|
|
|
|
|
<div className="mx-auto mb-2 flex size-12 items-center justify-center rounded-full bg-destructive/10">
|
|
|
|
|
<TriangleAlertIcon className="size-6 text-destructive" />
|
|
|
|
|
</div>
|
2025-08-28 18:27:07 +02:00
|
|
|
<AlertDialogTitle>{title}</AlertDialogTitle>
|
2026-03-08 01:02:57 +01:00
|
|
|
<AlertDialogDescription className="text-center">
|
|
|
|
|
{description}
|
|
|
|
|
</AlertDialogDescription>
|
2025-08-28 18:27:07 +02:00
|
|
|
</AlertDialogHeader>
|
|
|
|
|
<AlertDialogFooter>
|
|
|
|
|
<AlertDialogCancel onClick={() => onCancel?.()}>
|
|
|
|
|
{cancelText || "Annulla"}
|
|
|
|
|
</AlertDialogCancel>
|
2026-03-08 01:02:57 +01:00
|
|
|
<AlertDialogAction onClick={() => onConfirm()} variant="destructive">
|
2025-08-28 18:27:07 +02:00
|
|
|
{confirmText || "Conferma"}
|
|
|
|
|
</AlertDialogAction>
|
|
|
|
|
</AlertDialogFooter>
|
|
|
|
|
</AlertDialogContent>
|
|
|
|
|
</AlertDialog>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|