Files
jiang13-bbs/frontend/components/AcceptedAnswerReopen.tsx

37 lines
993 B
TypeScript

"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { apiReopenQuestion } from "@/lib/api";
import { toast } from "@/lib/toast";
/** 已采纳答案卡上的「重新打开」——并入正文下方资料卡,避免与上方状态条重复 */
export default function AcceptedAnswerReopen({ postId }: { postId: number }) {
const router = useRouter();
const [busy, setBusy] = useState(false);
const reopen = async () => {
setBusy(true);
try {
const res = await apiReopenQuestion(String(postId));
if (res.post) {
toast("已重新打开", "ok");
router.refresh();
} else toast(res.error || "操作失败", "error");
} finally {
setBusy(false);
}
};
return (
<button
type="button"
className="btn btn-line btn-sm shrink-0 ml-auto"
disabled={busy}
onClick={() => void reopen()}
>
{busy ? "处理中…" : "重新打开"}
</button>
);
}