feat : update
This commit is contained in:
@@ -1,74 +1,3 @@
|
||||
"use client";
|
||||
|
||||
import type { ComponentProps, ReactNode } from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { SimpleTooltip } from "@/components/tooltip";
|
||||
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"];
|
||||
showSuccessToast?: boolean;
|
||||
triggerTooltip?: ReactNode;
|
||||
}
|
||||
|
||||
export function DeleteConfirmationDialog({
|
||||
title,
|
||||
description,
|
||||
onConfirm,
|
||||
confirmLabel = "ยืนยันลบ",
|
||||
trigger,
|
||||
children,
|
||||
open,
|
||||
onOpenChange,
|
||||
showSuccessToast = true,
|
||||
triggerTooltip,
|
||||
}: DeleteConfirmationDialogProps) {
|
||||
const handleConfirm = async () => {
|
||||
await onConfirm();
|
||||
if (showSuccessToast) toast.success("ลบสำเร็จ!");
|
||||
};
|
||||
|
||||
return (
|
||||
<AlertDialog open={open} onOpenChange={onOpenChange}>
|
||||
{trigger ? (
|
||||
triggerTooltip ? (
|
||||
<SimpleTooltip text={triggerTooltip}>
|
||||
<AlertDialogTrigger render={trigger}>{children}</AlertDialogTrigger>
|
||||
</SimpleTooltip>
|
||||
) : (
|
||||
<AlertDialogTrigger render={trigger}>{children}</AlertDialogTrigger>
|
||||
)
|
||||
) : null}
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{title}</AlertDialogTitle>
|
||||
<AlertDialogDescription>{description}</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>ยกเลิก</AlertDialogCancel>
|
||||
<AlertDialogAction variant="destructive" onClick={handleConfirm}>
|
||||
{confirmLabel}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
);
|
||||
}
|
||||
export { DeleteConfirmationDialog } from "@/components/admin/ui/delete-confirmation-dialog";
|
||||
|
||||
Reference in New Issue
Block a user