refactor(充点弹窗): 升级报价状态改由具名函数返回

- 抽出 resolveMembershipQuoteErrorState,用提前返回替代嵌套三元,消除升级报价错误 / 加载 / 空三态的深层条件表达式。
This commit is contained in:
2026-10-03 17:28:55 +08:00
parent 2514759949
commit 803d5ccb0a
@@ -371,6 +371,41 @@ function resolveMembershipPlanAction(
return { disabled: false, label: '补差升级', mode: 'upgrade' };
}
/** 升级报价的加载 / 失败态;非升级流程不展示报价状态。 */
function resolveMembershipQuoteErrorState({
isUpgrade,
error,
isLoading,
onRetry,
}: {
isUpgrade: boolean;
error: string | null;
isLoading: boolean;
onRetry: () => void;
}): ReactNode {
if (!isUpgrade) {
return null;
}
if (error) {
return (
<PlatformRechargeStatusMessage className="rounded-2xl font-semibold">
<div>{error}</div>
<PlatformRechargeActionButton className="mt-3" onClick={onRetry}>
重新获取报价
</PlatformRechargeActionButton>
</PlatformRechargeStatusMessage>
);
}
if (isLoading) {
return (
<div className="rounded-xl px-3 py-2 text-xs font-semibold text-[var(--platform-text-soft)]">
正在获取升级报价…
</div>
);
}
return null;
}
function PlatformMudPointPoolOverview({
center,
}: {
@@ -1011,23 +1046,12 @@ function PlatformRechargeCheckoutDialog({
? '按剩余比例补差,保留现有余额,已用点不返还;升级后原刷新日与到期日不变。'
: `月度泥点按开通日自然月计期,当期未用完部分到期清零,不结转。当前选择 ${cycleLabel}。`
}
errorState={
isUpgrade && membershipQuoteError ? (
<PlatformRechargeStatusMessage className="rounded-2xl font-semibold">
<div>{membershipQuoteError}</div>
<PlatformRechargeActionButton
className="mt-3"
onClick={() => onRequestMembershipQuote(target.plan)}
>
重新获取报价
</PlatformRechargeActionButton>
</PlatformRechargeStatusMessage>
) : isUpgrade && isLoadingMembershipQuote ? (
<div className="rounded-xl px-3 py-2 text-xs font-semibold text-[var(--platform-text-soft)]">
正在获取升级报价…
</div>
) : null
}
errorState={resolveMembershipQuoteErrorState({
isUpgrade,
error: membershipQuoteError,
isLoading: isLoadingMembershipQuote,
onRetry: () => onRequestMembershipQuote(target.plan),
})}
/>
);
}