* reorganize folder structure * move folders from merge * fix import issue * run format * update configs
86 lines
2 KiB
TypeScript
86 lines
2 KiB
TypeScript
"use client";
|
|
|
|
import React from "react";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from "./ui/dialog";
|
|
import { Button } from "./ui/button";
|
|
import { AlertTriangle } from "lucide-react";
|
|
|
|
interface DeleteConfirmationDialogProps {
|
|
open: boolean;
|
|
onOpenChange: (open: boolean) => void;
|
|
title?: string;
|
|
description?: string;
|
|
confirmText?: string;
|
|
cancelText?: string;
|
|
onConfirm: () => void | Promise<void>;
|
|
isLoading?: boolean;
|
|
variant?: "destructive" | "default";
|
|
}
|
|
|
|
export const DeleteConfirmationDialog: React.FC<
|
|
DeleteConfirmationDialogProps
|
|
> = ({
|
|
open,
|
|
onOpenChange,
|
|
title = "Are you sure?",
|
|
description = "This action cannot be undone.",
|
|
confirmText = "Confirm",
|
|
cancelText = "Cancel",
|
|
onConfirm,
|
|
isLoading = false,
|
|
variant = "destructive",
|
|
}) => {
|
|
const handleConfirm = async () => {
|
|
try {
|
|
await onConfirm();
|
|
} finally {
|
|
// Only close if not in loading state (let the parent handle this)
|
|
if (!isLoading) {
|
|
onOpenChange(false);
|
|
}
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogContent className="sm:max-w-[425px]">
|
|
<DialogHeader>
|
|
<div className="flex items-center gap-3">
|
|
{variant === "destructive" && (
|
|
<AlertTriangle className="h-6 w-6 text-destructive" />
|
|
)}
|
|
<DialogTitle>{title}</DialogTitle>
|
|
</div>
|
|
<DialogDescription>{description}</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<DialogFooter>
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
onClick={() => onOpenChange(false)}
|
|
disabled={isLoading}
|
|
>
|
|
{cancelText}
|
|
</Button>
|
|
<Button
|
|
type="button"
|
|
variant={variant}
|
|
onClick={handleConfirm}
|
|
loading={isLoading}
|
|
disabled={isLoading}
|
|
>
|
|
{confirmText}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
};
|