mirror of
https://github.com/hex248/sprint.git
synced 2026-02-07 18:23:03 +00:00
58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
import { useState } from "react";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Dialog, DialogClose, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
|
|
|
export function ConfirmDialog({
|
|
open,
|
|
onOpenChange,
|
|
onConfirm,
|
|
title,
|
|
message,
|
|
processingText = "Processing...",
|
|
confirmText = "Confirm",
|
|
cancelText = "Cancel",
|
|
variant = "default",
|
|
}: {
|
|
open: boolean;
|
|
onOpenChange: (open: boolean) => void;
|
|
onConfirm: () => void;
|
|
title: string;
|
|
message: string;
|
|
processingText?: string;
|
|
confirmText?: string;
|
|
cancelText?: string;
|
|
variant?: "default" | "destructive";
|
|
}) {
|
|
const [submitting, setSubmitting] = useState(false);
|
|
|
|
const handleConfirm = async () => {
|
|
setSubmitting(true);
|
|
try {
|
|
await onConfirm();
|
|
} finally {
|
|
setSubmitting(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>{title}</DialogTitle>
|
|
</DialogHeader>
|
|
<p className="text-sm text-muted-foreground">{message}</p>
|
|
<div className="flex gap-2 justify-end mt-4">
|
|
<DialogClose asChild>
|
|
<Button variant="outline" type="button">
|
|
{cancelText}
|
|
</Button>
|
|
</DialogClose>
|
|
<Button variant={variant} onClick={handleConfirm} disabled={submitting}>
|
|
{submitting ? processingText : confirmText}
|
|
</Button>
|
|
</div>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|