54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
"use client";
|
|
|
|
import type { ComponentProps, ReactNode } from "react";
|
|
|
|
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogDescription,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
AlertDialogTrigger,
|
|
} from "@/components/ui/alert-dialog";
|
|
|
|
interface DeleteConfirmationDialogProps {
|
|
title: ReactNode;
|
|
description: ReactNode;
|
|
onConfirm: () => void | Promise<void>;
|
|
confirmLabel?: ReactNode;
|
|
trigger?: ComponentProps<typeof AlertDialogTrigger>["render"];
|
|
children?: ReactNode;
|
|
open?: ComponentProps<typeof AlertDialog>["open"];
|
|
onOpenChange?: ComponentProps<typeof AlertDialog>["onOpenChange"];
|
|
}
|
|
|
|
export function DeleteConfirmationDialog({
|
|
title,
|
|
description,
|
|
onConfirm,
|
|
confirmLabel = "ยืนยันลบ",
|
|
trigger,
|
|
children,
|
|
open,
|
|
onOpenChange,
|
|
}: DeleteConfirmationDialogProps) {
|
|
return (
|
|
<AlertDialog open={open} onOpenChange={onOpenChange}>
|
|
{trigger ? <AlertDialogTrigger render={trigger}>{children}</AlertDialogTrigger> : null}
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>{title}</AlertDialogTitle>
|
|
<AlertDialogDescription>{description}</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>ยกเลิก</AlertDialogCancel>
|
|
<AlertDialogAction variant="destructive" onClick={onConfirm}>{confirmLabel}</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
);
|
|
}
|