TanStackIntermediate
Delete Confirmation Dialog
AlertDialog দিয়ে destructive action confirm — বাংলায়।
6টি অংশবাংলা ভাষায়
delete-alert-dialog.tsxtsx
tsx
"use client";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
interface DeleteDialogProps {
product: Product | null;
open: boolean;
onOpenChange: (open: boolean) => void;
onConfirm: () => void;
isDeleting?: boolean;
}
export function DeleteDialog({
product,
open,
onOpenChange,
onConfirm,
isDeleting,
}: DeleteDialogProps) {
return (
<AlertDialog open={open} onOpenChange={onOpenChange}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>নিশ্চিত?</AlertDialogTitle>
<AlertDialogDescription>
আপনি কি নিশ্চিত যে <b>{product?.name}</b> মুছে ফেলতে চান?
এই কাজটি পূর্বাবস্থায় ফেরানো যাবে না।
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={isDeleting}>বাতিল</AlertDialogCancel>
<AlertDialogAction
disabled={isDeleting}
onClick={(e) => {
e.preventDefault();
onConfirm();
}}
>
{isDeleting ? "মুছে ফেলা হচ্ছে…" : "হ্যাঁ, মুছে ফেলুন"}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
}কেন e.preventDefault
AlertDialogAction ডিফল্ট dialog বন্ধ করে দেয়। আমরা চাই disabling state-এর পরে delete শেষ হয়ে onOpenChange(false) ডাকা হোক — তাই onClick-এ preventDefault করে সেটা নিজে manage করছি। (যদি চাই তাৎক্ষণিক close, তবে ছাড়া concern নয়।.)
dashboard-এ wiring
Page-এtsx
tsx
const [deletingProduct, setDeletingProduct] = useState<Product | null>(null);
const deleteProduct = useDeleteProduct();
<DeleteDialog
product={deletingProduct}
open={deletingProduct !== null}
onOpenChange={(open) => {
if (!open && !deleteProduct.isPending) setDeletingProduct(null);
}}
isDeleting={deleteProduct.isPending}
onConfirm={() => {
deleteProduct.mutate(deletingProduct!.id, {
onSuccess: () => setDeletingProduct(null),
});
}}
/>destructive pattern
destructive action-এ সুস্পষ্ট শব্দ: 'হ্যাঁ, মুছে ফেলুন' — চোখে চলে। AlertDialogCancel সর্বদা keep করুন — user-কে ফাঁস বিহীন বিকল্প দিন।
শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।