'use client'; import { Button } from "@/components/ui/button"; import { useCallback, useState } from "react"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { deleteConnection } from "@/actions"; import { Loader2 } from "lucide-react"; import { isServiceError } from "@/lib/utils"; import { useToast } from "@/components/hooks/use-toast"; import { useRouter } from "next/navigation"; interface DeleteConnectionSettingProps { connectionId: number; } export const DeleteConnectionSetting = ({ connectionId, }: DeleteConnectionSettingProps) => { const [isDialogOpen, setIsDialogOpen] = useState(false); const [isLoading, setIsLoading] = useState(false); const { toast } = useToast(); const router = useRouter(); const handleDelete = useCallback(() => { setIsDialogOpen(false); setIsLoading(true); deleteConnection(connectionId) .then((response) => { if (isServiceError(response)) { toast({ description: `❌ Failed to delete connection. Reason: ${response.message}` }); } else { toast({ description: `✅ Connection deleted successfully.` }); router.replace("/connections"); router.refresh(); } }) .finally(() => { setIsLoading(false); }); }, [connectionId]); return (
Permanently delete this connection from Sourcebot. All linked repositories that are not linked to any other connection will also be deleted.