Files
kandev/apps/web/components/gitlab/delete-watch-dialog.tsx
T
2026-07-21 23:24:22 +01:00

74 lines
2.1 KiB
TypeScript

"use client";
import { useEffect, useState } from "react";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@kandev/ui/alert-dialog";
export function DeleteWatchDialog({
open,
onOpenChange,
watchLabel,
onConfirm,
}: {
open: boolean;
onOpenChange: (open: boolean) => void;
watchLabel: string;
onConfirm: () => Promise<void>;
}) {
const [deleting, setDeleting] = useState(false);
const [error, setError] = useState("");
useEffect(() => {
if (open) setError("");
}, [open]);
return (
<AlertDialog open={open} onOpenChange={onOpenChange}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete {watchLabel}?</AlertDialogTitle>
<AlertDialogDescription>
This will delete every task created by this watch, including archived tasks, and remove
its polling history. This cannot be undone.
</AlertDialogDescription>
{error && (
<p className="text-sm text-destructive" role="alert">
{error}
</p>
)}
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={deleting} className="cursor-pointer">
Cancel
</AlertDialogCancel>
<AlertDialogAction
disabled={deleting}
className="cursor-pointer bg-destructive text-destructive-foreground hover:bg-destructive/90"
onClick={async (event) => {
event.preventDefault();
setDeleting(true);
setError("");
try {
await onConfirm();
onOpenChange(false);
} catch (cause) {
setError(cause instanceof Error ? cause.message : "Watch deletion failed");
} finally {
setDeleting(false);
}
}}
>
{deleting ? "Deleting..." : "Delete watch"}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
}