126 lines
7.7 KiB
TypeScript
126 lines
7.7 KiB
TypeScript
import { requireCloudViewer } from "../../cloud-auth";
|
|
import { DashboardShell, PageHeading, StatusPill, formatDate } from "../../components/Shells";
|
|
import { getDashboardSnapshot, getOrCreateAccount } from "@/db/repository";
|
|
import { getBillingEntitlementPresentation } from "@/db/domain";
|
|
import { deriveInvitationDisplayState } from "@/db/invitations";
|
|
import { AccessRequestForm } from "./AccessRequestForm";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function BillingPage() {
|
|
const viewer = await requireCloudViewer("/dashboard/billing");
|
|
const account = await getOrCreateAccount(viewer);
|
|
const snapshot = await getDashboardSnapshot(account);
|
|
const billingCopy = getBillingEntitlementPresentation(
|
|
snapshot.entitlement.mode,
|
|
snapshot.entitlement.publicBetaState,
|
|
);
|
|
const now = new Date();
|
|
const nowIso = now.toISOString();
|
|
const invitations = snapshot.grants.filter((grant) => grant.source === "admin_exemption");
|
|
const pendingAccessRequest = snapshot.accessRequests.find((request) => request.status === "requested") ?? null;
|
|
const endingSoon = invitations.find((invitation) => {
|
|
if (deriveInvitationDisplayState(invitation, nowIso) !== "active" || !invitation.ends_at) return false;
|
|
const remaining = new Date(invitation.ends_at).getTime() - now.getTime();
|
|
return remaining > 0 && remaining <= 7 * 24 * 60 * 60_000;
|
|
});
|
|
const available = snapshot.entitlement.unlimited
|
|
? "当前不按槽位限额"
|
|
: `${snapshot.entitlement.availableSlots ?? 0} 个`;
|
|
|
|
return (
|
|
<DashboardShell viewer={viewer} active="/dashboard/billing">
|
|
<div className="cloud-page">
|
|
<PageHeading
|
|
eyebrow="PUBLIC BETA / 公测权益"
|
|
title={snapshot.entitlement.mode === "none" ? "这里说明当前免费资格状态。" : "当前免费,不需要处理账单。"}
|
|
description="这里仅显示公测资格、主机占用和透明容量规则。报价、订单与支付功能暂不开放。"
|
|
/>
|
|
|
|
<section className="billing-status-panel">
|
|
<div>
|
|
<StatusPill tone={billingCopy.tone}>{billingCopy.status}</StatusPill>
|
|
<h2>{billingCopy.title}</h2>
|
|
<p>{billingCopy.description}</p>
|
|
</div>
|
|
<dl>
|
|
<div><dt>启用主机</dt><dd>{snapshot.entitlement.activeSlots}</dd></div>
|
|
<div><dt>等待配对</dt><dd>{snapshot.entitlement.reservedSlots}</dd></div>
|
|
<div><dt>剩余容量</dt><dd>{available}</dd></div>
|
|
<div><dt>下次资格变化</dt><dd>{formatDate(snapshot.entitlement.effectiveUntil)}</dd></div>
|
|
</dl>
|
|
</section>
|
|
|
|
{endingSoon && (
|
|
<section className="panel full-panel attention-panel" role="status">
|
|
<div className="panel-heading"><div><span>CLOSED BETA NOTICE</span><h2>闭测邀请即将到期</h2></div><StatusPill tone="warn">请留意</StatusPill></div>
|
|
<p>当前邀请将在 {formatDate(endingSoon.ends_at, true)} 到期。到期后不能新增或重新认领主机;既有主机不会被自动断开,也不会因此产生账单。</p>
|
|
</section>
|
|
)}
|
|
|
|
<div className="dashboard-columns billing-columns">
|
|
<section className="panel">
|
|
<div className="panel-heading"><div><span>当前政策</span><h2>免费公测</h2></div></div>
|
|
<div className="billing-rules">
|
|
<span>✓ 不绑定支付方式</span>
|
|
<span>✓ 不生成报价或订单</span>
|
|
<span>✓ 公测结束不自动扣款</span>
|
|
<span>✓ 容量限制提前明示</span>
|
|
</div>
|
|
</section>
|
|
<section className="panel">
|
|
<div className="panel-heading"><div><span>未来安排</span><h2>收费以后再决定</h2></div></div>
|
|
<p>当前先验证连接成功率、稳定性、资源成本和个人用户的真实使用频率。等数据足够,再单独设计并通知收费方案。</p>
|
|
<div className="empty-inline">现在没有需要确认、支付或续费的项目。</div>
|
|
</section>
|
|
</div>
|
|
|
|
<section className="panel full-panel">
|
|
<div className="panel-heading">
|
|
<div><span>CLOSED BETA / 申请测试</span><h2>申请免费闭测资格</h2></div>
|
|
<StatusPill tone={pendingAccessRequest ? "warn" : snapshot.entitlement.mode === "none" ? "neutral" : "good"}>{pendingAccessRequest ? "等待处理" : snapshot.entitlement.mode === "none" ? "可申请" : "已有资格"}</StatusPill>
|
|
</div>
|
|
{snapshot.entitlement.mode !== "none" ? (
|
|
<div className="empty-inline">当前账户已经具备免费测试资格,不需要重复申请。</div>
|
|
) : (
|
|
<AccessRequestForm pendingRequest={pendingAccessRequest} />
|
|
)}
|
|
{snapshot.accessRequests.length > 0 && (
|
|
<div className="admin-gate-table invitation-history">
|
|
{snapshot.accessRequests.map((request) => (
|
|
<article key={request.id}>
|
|
<StatusPill tone={request.status === "approved" ? "good" : request.status === "requested" ? "warn" : "neutral"}>{request.status === "approved" ? "已批准" : request.status === "requested" ? "审核中" : request.status === "declined" ? "暂未批准" : "已撤回"}</StatusPill>
|
|
<div><strong>{request.requested_slots} 台 · {request.preferred_os === "both" ? "Windows 和 Linux" : request.preferred_os === "windows" ? "Windows" : "Linux"}</strong><small>{request.id}</small></div>
|
|
<span>申请:{formatDate(request.requested_at, true)}</span>
|
|
<span>{request.admin_response || "尚无处理说明"}</span>
|
|
</article>
|
|
))}
|
|
</div>
|
|
)}
|
|
</section>
|
|
|
|
<section className="panel full-panel">
|
|
<div className="panel-heading"><div><span>CLOSED BETA / 我的邀请</span><h2>闭测邀请记录</h2></div><StatusPill tone={invitations.some((invitation) => deriveInvitationDisplayState(invitation, nowIso) === "active") ? "good" : "neutral"}>{invitations.filter((invitation) => deriveInvitationDisplayState(invitation, nowIso) === "active").length} 个有效</StatusPill></div>
|
|
<p>邀请是有期限的免费接入资格,与报价、订单或支付账户无关。</p>
|
|
<div className="admin-gate-table invitation-history">
|
|
{invitations.length ? invitations.map((invitation) => {
|
|
const state = deriveInvitationDisplayState(invitation, nowIso);
|
|
return <article key={invitation.id}><StatusPill tone={state === "active" ? "good" : "neutral"}>{state === "active" ? "有效" : state === "expired" ? "已到期" : "已撤销"}</StatusPill><div><strong>{invitation.capacity_slots === null ? "当前不按主机槽位限额" : `${invitation.capacity_slots} 个主机槽位`}</strong><small>{invitation.id}</small></div><span>开始:{formatDate(invitation.starts_at, true)}</span><span>结束:{formatDate(invitation.ends_at, true)}</span></article>;
|
|
}) : <div className="empty-inline">该账户没有闭测邀请;公开公测开放状态以页面上方为准。</div>}
|
|
</div>
|
|
</section>
|
|
|
|
<section className="panel full-panel">
|
|
<div className="panel-heading"><div><span>边界</span><h2>公测结束会发生什么?</h2></div></div>
|
|
<div className="billing-rules">
|
|
<span>1. 免费资格按后台发布的政策变化</span>
|
|
<span>2. 新配对和未完成认领停止,既有主机不自动断开</span>
|
|
<span>3. 未主动确认前,不创建任何付费关系</span>
|
|
<span>4. 撤销设备和必要的数据退出能力继续可用</span>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</DashboardShell>
|
|
);
|
|
}
|