74 lines
2.0 KiB
TypeScript
74 lines
2.0 KiB
TypeScript
import { Check, Trash2, X } from 'lucide-react';
|
|
import type { ReactNode } from 'react';
|
|
import { Button } from '@/components/ui/button';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from '@/components/ui/dialog';
|
|
|
|
type ConfirmDialogProps = {
|
|
open: boolean;
|
|
onOpenChange: (open: boolean) => void;
|
|
title: string;
|
|
description: string;
|
|
confirmLabel?: string;
|
|
confirmIcon?: ReactNode;
|
|
cancelLabel?: string;
|
|
variant?: 'default' | 'destructive';
|
|
onConfirm: () => void;
|
|
loading?: boolean;
|
|
};
|
|
|
|
export function ConfirmDialog({
|
|
open,
|
|
onOpenChange,
|
|
title,
|
|
description,
|
|
confirmLabel = 'Konfirmasi',
|
|
confirmIcon,
|
|
cancelLabel = 'Batal',
|
|
variant = 'destructive',
|
|
onConfirm,
|
|
loading = false,
|
|
}: ConfirmDialogProps) {
|
|
const icon =
|
|
confirmIcon ??
|
|
(variant === 'destructive' ? (
|
|
<Trash2 className="h-4 w-4" />
|
|
) : (
|
|
<Check className="h-4 w-4" />
|
|
));
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>{title}</DialogTitle>
|
|
<DialogDescription>{description}</DialogDescription>
|
|
</DialogHeader>
|
|
<DialogFooter>
|
|
<Button
|
|
variant="outline"
|
|
onClick={() => onOpenChange(false)}
|
|
>
|
|
<X className="h-4 w-4" />
|
|
{cancelLabel}
|
|
</Button>
|
|
<Button
|
|
variant={variant}
|
|
onClick={onConfirm}
|
|
disabled={loading}
|
|
>
|
|
{icon}
|
|
{confirmLabel}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|