35 lines
637 B
TypeScript
35 lines
637 B
TypeScript
|
|
'use client'
|
||
|
|
|
||
|
|
import { useRouter } from "next/navigation"
|
||
|
|
|
||
|
|
export default function DeleteButton({ id }: { id: number }) {
|
||
|
|
const router = useRouter()
|
||
|
|
|
||
|
|
const handleDelete = async () => {
|
||
|
|
if (!confirm("确定要删除这个智能体吗?")) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
try {
|
||
|
|
const res = await fetch(`/api/admin/agents/${id}`, {
|
||
|
|
method: "DELETE",
|
||
|
|
})
|
||
|
|
|
||
|
|
if (res.ok) {
|
||
|
|
router.refresh()
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
alert("删除失败")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return (
|
||
|
|
<button
|
||
|
|
onClick={handleDelete}
|
||
|
|
className="text-red-600 hover:text-red-700 text-sm"
|
||
|
|
>
|
||
|
|
删除
|
||
|
|
</button>
|
||
|
|
)
|
||
|
|
}
|