84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
export type PairingAccessState =
|
|
| "available"
|
|
| "request_pending"
|
|
| "gated"
|
|
| "inactive"
|
|
| "full";
|
|
|
|
export type BetaOnboardingState =
|
|
| "request_needed"
|
|
| "request_pending"
|
|
| "ready"
|
|
| "full";
|
|
|
|
export type BetaOnboarding = {
|
|
state: BetaOnboardingState;
|
|
pairingAccessState: PairingAccessState;
|
|
primaryHref: string;
|
|
primaryLabel: string;
|
|
tone: "good" | "warn" | "neutral" | "info";
|
|
title: string;
|
|
detail: string;
|
|
};
|
|
|
|
export function deriveBetaOnboarding(input: {
|
|
entitlement: {
|
|
mode: "public_beta" | "grant" | "none";
|
|
publicBetaState: "open" | "gated" | "inactive";
|
|
unlimited: boolean;
|
|
availableSlots: number | null;
|
|
};
|
|
hasPendingRequest: boolean;
|
|
}): BetaOnboarding {
|
|
const { entitlement } = input;
|
|
if (entitlement.mode === "none") {
|
|
if (input.hasPendingRequest) {
|
|
return {
|
|
state: "request_pending",
|
|
pairingAccessState: "request_pending",
|
|
primaryHref: "/dashboard/billing",
|
|
primaryLabel: "查看申请进度",
|
|
tone: "warn",
|
|
title: "免费闭测申请正在审核",
|
|
detail: "处理结果会显示在公测权益页;审核期间不需要重复申请。",
|
|
};
|
|
}
|
|
const gated = entitlement.publicBetaState === "gated";
|
|
return {
|
|
state: "request_needed",
|
|
pairingAccessState: gated ? "gated" : "inactive",
|
|
primaryHref: "/dashboard/billing",
|
|
primaryLabel: "申请免费闭测",
|
|
tone: gated ? "warn" : "neutral",
|
|
title: gated ? "公开接入尚未开放" : "当前没有免费测试资格",
|
|
detail: gated
|
|
? "安全门禁仍在核对,可以先申请小范围免费闭测。"
|
|
: "可以提交免费闭测申请;不会绑定支付方式或自动转为付费。",
|
|
};
|
|
}
|
|
|
|
if (!entitlement.unlimited && (entitlement.availableSlots ?? 0) < 1) {
|
|
return {
|
|
state: "full",
|
|
pairingAccessState: "full",
|
|
primaryHref: "/dashboard/hosts",
|
|
primaryLabel: "管理已接入主机",
|
|
tone: "neutral",
|
|
title: "当前免费主机名额已用完",
|
|
detail: "可以取消等待中的配对、撤销不再使用的主机,或等待管理员调整闭测名额。",
|
|
};
|
|
}
|
|
|
|
return {
|
|
state: "ready",
|
|
pairingAccessState: "available",
|
|
primaryHref: "/dashboard/hosts/new",
|
|
primaryLabel: "连接主机",
|
|
tone: "good",
|
|
title: entitlement.mode === "grant" ? "闭测资格已生效" : "免费公测资格已生效",
|
|
detail: entitlement.unlimited
|
|
? "当前策略不按主机槽位限额,可以开始连接主机。"
|
|
: `还可以连接 ${entitlement.availableSlots ?? 0} 台主机。`,
|
|
};
|
|
}
|