feat(admin): 用户主页增加封禁与改角色快捷菜单
超管/站长可在他人主页就地管理账号;待审评论支持拒绝;角色弹窗前后台共用。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,13 +3,14 @@
|
||||
import { useRef, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
import { Trash2, MessagesSquare, ChevronRight, ChevronDown, BadgeCheck } from "lucide-react";
|
||||
import { Trash2, MessagesSquare, ChevronRight, ChevronDown, BadgeCheck, XCircle } from "lucide-react";
|
||||
import {
|
||||
apiCreateComment,
|
||||
apiDeleteComment,
|
||||
apiAcceptBounty,
|
||||
apiAcceptQuestion,
|
||||
apiAdminApproveComment,
|
||||
apiAdminRejectComment,
|
||||
type CommentNode,
|
||||
type User,
|
||||
} from "@/lib/api";
|
||||
@@ -18,6 +19,7 @@ import { toast } from "@/lib/toast";
|
||||
import Avatar from "./Avatar";
|
||||
import Pagination from "./Pagination";
|
||||
import MarkdownBodyClient from "@/components/MarkdownBodyClient";
|
||||
import ConfirmDialog from "@/components/ConfirmDialog";
|
||||
|
||||
interface CommentSectionProps {
|
||||
postId: string;
|
||||
@@ -68,6 +70,8 @@ export default function CommentSection({
|
||||
const [confirmingId, setConfirmingId] = useState<number | null>(null);
|
||||
const [acceptingId, setAcceptingId] = useState<number | null>(null);
|
||||
const [approvingId, setApprovingId] = useState<number | null>(null);
|
||||
const [rejectTargetId, setRejectTargetId] = useState<number | null>(null);
|
||||
const [rejecting, setRejecting] = useState(false);
|
||||
// 折叠状态:哪些楼层展开了子回复(默认全部折叠,SSR 初始为收起)
|
||||
const [expandedFloors, setExpandedFloors] = useState<Set<number>>(new Set());
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
@@ -185,6 +189,21 @@ export default function CommentSection({
|
||||
}
|
||||
};
|
||||
|
||||
const handleRejectConfirm = async () => {
|
||||
if (rejectTargetId == null) return;
|
||||
setRejecting(true);
|
||||
try {
|
||||
await apiAdminRejectComment(rejectTargetId);
|
||||
toast("已拒绝该评论", "ok");
|
||||
setRejectTargetId(null);
|
||||
router.refresh();
|
||||
} catch (e) {
|
||||
toast(e instanceof Error ? e.message : "拒绝失败");
|
||||
} finally {
|
||||
setRejecting(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 引用功能已移除:与"回复"功能重叠,且会割裂讨论上下文(抖音风格无此功能)
|
||||
|
||||
const canDelete = (comment: CommentNode) =>
|
||||
@@ -331,16 +350,28 @@ export default function CommentSection({
|
||||
</button>
|
||||
)}
|
||||
{canApprove(c) && (
|
||||
<button
|
||||
type="button"
|
||||
className="cmt-reply-btn !text-[var(--accent)] inline-flex items-center gap-1"
|
||||
disabled={approvingId === c.id}
|
||||
onClick={() => void handleApprove(c.id)}
|
||||
data-tip="通过评审,公开此评论"
|
||||
>
|
||||
<BadgeCheck size={13} />
|
||||
{approvingId === c.id ? "通过中…" : "通过评审"}
|
||||
</button>
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
className="cmt-reply-btn !text-[var(--accent)] inline-flex items-center gap-1"
|
||||
disabled={approvingId === c.id || rejecting}
|
||||
onClick={() => void handleApprove(c.id)}
|
||||
data-tip="通过评审,公开此评论"
|
||||
>
|
||||
<BadgeCheck size={13} />
|
||||
{approvingId === c.id ? "通过中…" : "通过评审"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="cmt-reply-btn !text-[var(--danger)] inline-flex items-center gap-1"
|
||||
disabled={approvingId === c.id || rejecting}
|
||||
onClick={() => setRejectTargetId(c.id)}
|
||||
data-tip="拒绝此评论,不公开"
|
||||
>
|
||||
<XCircle size={13} />
|
||||
拒绝
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{canDelete(c) && (
|
||||
@@ -436,16 +467,28 @@ export default function CommentSection({
|
||||
</button>
|
||||
)}
|
||||
{canApprove(c) && (
|
||||
<button
|
||||
type="button"
|
||||
className="cmt-reply-btn !text-[var(--accent)] inline-flex items-center gap-1"
|
||||
disabled={approvingId === c.id}
|
||||
onClick={() => void handleApprove(c.id)}
|
||||
data-tip="通过评审,公开此评论"
|
||||
>
|
||||
<BadgeCheck size={13} />
|
||||
{approvingId === c.id ? "通过中…" : "通过评审"}
|
||||
</button>
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
className="cmt-reply-btn !text-[var(--accent)] inline-flex items-center gap-1"
|
||||
disabled={approvingId === c.id || rejecting}
|
||||
onClick={() => void handleApprove(c.id)}
|
||||
data-tip="通过评审,公开此评论"
|
||||
>
|
||||
<BadgeCheck size={13} />
|
||||
{approvingId === c.id ? "通过中…" : "通过评审"}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="cmt-reply-btn !text-[var(--danger)] inline-flex items-center gap-1"
|
||||
disabled={approvingId === c.id || rejecting}
|
||||
onClick={() => setRejectTargetId(c.id)}
|
||||
data-tip="拒绝此评论,不公开"
|
||||
>
|
||||
<XCircle size={13} />
|
||||
拒绝
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{canDelete(c) && (
|
||||
@@ -565,6 +608,19 @@ export default function CommentSection({
|
||||
</div>
|
||||
|
||||
<Pagination total={total} page={page} size={size} basePath={`/post/${postId}`} />
|
||||
|
||||
<ConfirmDialog
|
||||
open={rejectTargetId != null}
|
||||
title="拒绝评论"
|
||||
message="确定拒绝这条待审评论?拒绝后不会公开,作者会收到通知。"
|
||||
confirmLabel="确认拒绝"
|
||||
danger
|
||||
busy={rejecting}
|
||||
onConfirm={handleRejectConfirm}
|
||||
onCancel={() => {
|
||||
if (!rejecting) setRejectTargetId(null);
|
||||
}}
|
||||
/>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user