Files
buzz-sheet/components/admin/delete-confirmation-dialog.tsx
gunshiz e0794822b1
CI / Verify (push) Successful in 1m18s
CI / Build immutable images and deploy (push) Successful in 1m57s
feat(i18n) : add personal languages and compact weapon exports
2026-09-14 16:44:44 +07:00

77 lines
2.3 KiB
TypeScript

"use client";
import { useTranslation } from "@/components/i18n/locale-provider";
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 { t } = useTranslation();
const handleConfirm = async () => {
await onConfirm();
if (showSuccessToast) toast.success(t("ลบสำเร็จ!"));
};
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>{typeof title === "string" ? t(title) : title}</AlertDialogTitle>
<AlertDialogDescription>{typeof description === "string" ? t(description) : description}</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t("ยกเลิก")}</AlertDialogCancel>
<AlertDialogAction variant="destructive" onClick={handleConfirm}>
{typeof confirmLabel === "string" ? t(confirmLabel) : confirmLabel}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
}