"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { useToast } from "@/hooks/use-toast"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { Button } from "@/components/ui/button"; interface DeleteClientButtonProps { clientId: string; clientName: string; } export function DeleteClientButton({ clientId, clientName, }: DeleteClientButtonProps) { const [isLoading, setIsLoading] = useState(false); const { toast } = useToast(); const router = useRouter(); async function onDelete() { setIsLoading(true); try { const response = await fetch(`/api/clients/${clientId}`, { method: "DELETE", }); if (!response.ok) { throw new Error("删除失败"); } router.refresh(); toast({ title: "删除成功", description: "应用已成功删除", }); } catch (error) { toast({ variant: "destructive", title: "删除失败", description: error instanceof Error ? error.message : "未知错误", }); } finally { setIsLoading(false); } } return ( 确认删除应用? 您确定要删除应用"{clientName}"吗?此操作不可撤销,删除后将无法恢复。 取消 删除 ); }