"use client"; import { useState } from "react"; import type { AccountRecord, AccountDeletionRequestRecord, BetaAccessRequestRecord, BetaRecord, FeedbackRecord, GrantRecord, LaunchGateRecord, RetentionMaintenanceResult, ServiceIncidentRecord, } from "@/db/repository"; type SubmitState = { loading: boolean; message: string; error: boolean }; const idle: SubmitState = { loading: false, message: "", error: false }; async function postJson = Record>(path: string, payload: Record): Promise { const response = await fetch(path, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ ...payload, idempotencyKey: crypto.randomUUID() }) }); const body = (await response.json()) as T & { message?: string }; if (!response.ok) throw new Error(body.message || "操作失败"); return body; } export function BetaAction({ beta, blockedP0 }: { beta: BetaRecord | null; blockedP0: number }) { const [enabled, setEnabled] = useState(beta?.state === "active"); const [capacity, setCapacity] = useState(beta?.capacity_slots?.toString() ?? ""); const [reason, setReason] = useState(""); const [state, setState] = useState(idle); async function submit(event: React.FormEvent) { event.preventDefault(); setState({ loading: true, message: "", error: false }); try { await postJson("/api/admin/beta", { enabled, capacitySlots: capacity ? Number(capacity) : null, reason }); setState({ loading: false, message: "新的公测政策版本已写入,页面即将刷新。", error: false }); window.setTimeout(() => window.location.reload(), 700); } catch (error) { setState({ loading: false, message: error instanceof Error ? error.message : "操作失败", error: true }); } } return
{blockedP0 > 0 &&

仍有 {blockedP0} 项 P0 未通过:可以预设免费政策,但新的公开配对继续冻结;只有明确签发的闭测邀请可继续使用。

}