Skip to content

Commit a01b437

Browse files
committed
clarify renewal duration menu
1 parent e880c5b commit a01b437

1 file changed

Lines changed: 38 additions & 6 deletions

File tree

src/pages/user.tsx

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ function formatExpireDate(expiresAt?: string) {
126126
return expiresAt ? dayjs(expiresAt).format('YYYY年MM月DD日') : '当前到期日';
127127
}
128128

129+
function formatRenewedExpireDate({
130+
expiresAt,
131+
months,
132+
now,
133+
}: {
134+
expiresAt?: string;
135+
months: number;
136+
now?: string;
137+
}) {
138+
const currentExpireDay = expiresAt ? dayjs(expiresAt) : null;
139+
const nowDay = dayjs(now);
140+
const baseDay = currentExpireDay?.isAfter(nowDay) ? currentExpireDay : nowDay;
141+
return baseDay.add(months, 'month').format('YYYY年MM月DD日');
142+
}
143+
129144
function getUpgradeProrationDetail({
130145
currentAnnualPrice,
131146
expiresAt,
@@ -405,10 +420,14 @@ function getRenewalPrices({
405420

406421
const RenewalPurchaseButton = ({
407422
quota,
423+
serverTime,
408424
tier,
425+
tierExpiresAt,
409426
}: {
410427
quota?: Quota;
428+
serverTime?: string;
411429
tier: Tier;
430+
tierExpiresAt?: string;
412431
}) => {
413432
const [loadingPlan, setLoadingPlan] = useState<string | null>(null);
414433
const billingConfig = useOrderBillingConfig();
@@ -432,7 +451,11 @@ const RenewalPurchaseButton = ({
432451
}
433452
options.push({
434453
amountText: formatMoney(amount),
435-
description: `到期日顺延 ${months} 个月`,
454+
description: `续费后到期日 ${formatRenewedExpireDate({
455+
expiresAt: tierExpiresAt,
456+
months,
457+
now: serverTime,
458+
})}`,
436459
key: `month-${months}`,
437460
onClick: async () => {
438461
setLoadingPlan(`month-${months}`);
@@ -442,13 +465,17 @@ const RenewalPurchaseButton = ({
442465
setLoadingPlan(null);
443466
}
444467
},
445-
title: months === 1 ? '月付' : `月付 ${months} 个月`,
468+
title: `${months} 个月`,
446469
});
447470
}
448471

449472
options.push({
450473
amountText: formatMoney(prices.annualPrice),
451-
description: `到期日顺延 ${billingConfig.annualBillingMonths} 个月`,
474+
description: `续费后到期日 ${formatRenewedExpireDate({
475+
expiresAt: tierExpiresAt,
476+
months: billingConfig.annualBillingMonths,
477+
now: serverTime,
478+
})}`,
452479
key: 'year',
453480
onClick: async () => {
454481
setLoadingPlan('year');
@@ -470,7 +497,7 @@ const RenewalPurchaseButton = ({
470497
),
471498
)}折优惠`
472499
: undefined,
473-
title: '年付',
500+
title: `${billingConfig.annualBillingMonths} 个月(年付)`,
474501
});
475502

476503
return options;
@@ -488,7 +515,7 @@ const RenewalPurchaseButton = ({
488515
return (
489516
<PurchaseActionPopover
490517
buttonLabel={loadingPlan ? '跳转中' : '续费'}
491-
hint="续费会在当前到期日后顺延对应时长,月付累计达到年付价后直接选择年付。"
518+
hint="选择续费时长;月付累计达到年付价后直接选择年付。"
492519
loading={loadingPlan !== null}
493520
title="续费"
494521
options={renewalOptions}
@@ -758,7 +785,12 @@ function UserPanel() {
758785
<div></div>
759786
)}
760787
</div>
761-
<RenewalPurchaseButton quota={quota} tier={tier} />
788+
<RenewalPurchaseButton
789+
quota={quota}
790+
serverTime={user.serverTime}
791+
tier={tier}
792+
tierExpiresAt={user.tierExpiresAt}
793+
/>
762794
</div>
763795
</Descriptions.Item>
764796
<Descriptions.Item label="购买说明">

0 commit comments

Comments
 (0)