Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 取消订阅后购买弹窗显示到期时间而非误导提示 (#2488)

GaoWei Liud09a1e028ec6
diff --git a/apps/desktop/src/renderer/features/billing/BillingPage.tsx b/apps/desktop/src/renderer/features/billing/BillingPage.tsx
index 288dfd0264..7c1d3d93bc 100644
--- a/apps/desktop/src/renderer/features/billing/BillingPage.tsx
+++ b/apps/desktop/src/renderer/features/billing/BillingPage.tsx
@@ -1089,6 +1089,8 @@ export function BillingSettingsSection({ accountId }: { accountId: string | null
amountError={amountError}
subscriptionPurchaseBlocked={subscriptionPurchaseBlocked}
currentSubscriptionOfferCode={currentSubscriptionOfferCode}
+ subscriptionCancelAtPeriodEnd={currentSubscription?.cancelAtPeriodEnd ?? false}
+ subscriptionPeriodEndAt={currentSubscription?.currentPeriodEndAt ?? null}
canCheckout={canCheckout}
onClose={closeSubscriptionDialog}
onRetry={() => void loadBillingState()}
@@ -1113,6 +1115,8 @@ export function BillingSettingsSection({ accountId }: { accountId: string | null
amountError={amountError}
subscriptionPurchaseBlocked={false}
currentSubscriptionOfferCode={null}
+ subscriptionCancelAtPeriodEnd={false}
+ subscriptionPeriodEndAt={null}
canCheckout={canCheckout}
onClose={closeTopupDialog}
onRetry={() => void loadBillingState()}
@@ -1774,6 +1778,8 @@ function BillingOfferDialog({
amountError,
subscriptionPurchaseBlocked,
currentSubscriptionOfferCode,
+ subscriptionCancelAtPeriodEnd,
+ subscriptionPeriodEndAt,
canCheckout,
onClose,
onRetry,
@@ -1796,6 +1802,8 @@ function BillingOfferDialog({
amountError: string | null;
subscriptionPurchaseBlocked: boolean;
currentSubscriptionOfferCode: string | null;
+ subscriptionCancelAtPeriodEnd: boolean;
+ subscriptionPeriodEndAt: string | null;
canCheckout: boolean;
onClose: () => void;
onRetry: () => void;
@@ -1807,6 +1815,10 @@ function BillingOfferDialog({
}) {
const { t, i18n } = useTranslation();
const billingLocale = i18n.resolvedLanguage ?? i18n.language;
+ const formattedSubscriptionPeriodEndAt = formatBillingDate(
+ subscriptionPeriodEndAt,
+ billingLocale,
+ );
const title =
kind === 'SUBSCRIPTION'
? t('billing.dialogs.subscription.title')
@@ -2057,7 +2069,11 @@ function BillingOfferDialog({
{kind === 'SUBSCRIPTION' && selected && subscriptionPurchaseBlocked && (
<p className="mt-4 text-12 leading-5 text-[var(--text-secondary)]">
- {t('billing.currentSubscription.purchaseBlocked')}
+ {subscriptionCancelAtPeriodEnd && formattedSubscriptionPeriodEndAt
+ ? t('billing.currentSubscription.purchaseBlockedUntilPeriodEnd', {
+ date: formattedSubscriptionPeriodEndAt,
+ })
+ : t('billing.currentSubscription.purchaseBlocked')}
</p>
)}
</div>
diff --git a/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx b/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
index 3326447ec3..b3fdd98614 100644
--- a/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
+++ b/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
@@ -2487,6 +2487,48 @@ describe('BillingPage plan change', () => {
expect(screen.getByText('billing.currentSubscription.purchaseBlocked')).toBeTruthy();
});
+ it('shows the period-end copy in the purchase dialog when the live subscription is scheduled to cancel', async () => {
+ const billing = billingMocks();
+ billing.getCurrentSubscription = vi.fn(async () => ({
+ subscription: { ...activeSubscription(null, 'MONTH', 'ACTIVE', true), effectivePlan: null },
+ }));
+ install(billing);
+
+ render(<BillingPage />);
+
+ await selectSubscriptionManagementAction('billing.settings.subscriptionCard.action');
+ fireEvent.click((await screen.findAllByText('Plus plan'))[0].closest('button')!);
+ fireEvent.click(screen.getByText('stripe').closest('button')!);
+ expect(screen.getByText('billing.actions.pay').closest('button')).toHaveProperty(
+ 'disabled',
+ true,
+ );
+ expect(
+ screen.getByText(/billing\.currentSubscription\.purchaseBlockedUntilPeriodEnd/),
+ ).toBeTruthy();
+ expect(screen.queryByText('billing.currentSubscription.purchaseBlocked')).toBeNull();
+ });
+
+ it('falls back to the generic copy when the scheduled-cancel subscription has an unparseable period end', async () => {
+ const billing = billingMocks();
+ billing.getCurrentSubscription = vi.fn(async () => ({
+ subscription: {
+ ...activeSubscription(null, 'MONTH', 'ACTIVE', true),
+ effectivePlan: null,
+ currentPeriodEndAt: 'not-a-valid-date',
+ },
+ }));
+ install(billing);
+
+ render(<BillingPage />);
+
+ await selectSubscriptionManagementAction('billing.settings.subscriptionCard.action');
+ fireEvent.click((await screen.findAllByText('Plus plan'))[0].closest('button')!);
+ fireEvent.click(screen.getByText('stripe').closest('button')!);
+ expect(screen.getByText('billing.currentSubscription.purchaseBlocked')).toBeTruthy();
+ expect(screen.queryByText(/purchaseBlockedUntilPeriodEnd/)).toBeNull();
+ });
+
it('explains a rejected quote and returns to the candidate list', async () => {
const billing = install(billingMocks());
billing.quotePlanChange.mockRejectedValue(
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index de13341f42..87d5f49a29 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -9393,7 +9393,8 @@
},
"currentSubscription": {
"title": "Current subscription",
- "purchaseBlocked": "You already have an unfinished subscription. Manage it before purchasing another plan."
+ "purchaseBlocked": "You already have an unfinished subscription. Manage it before purchasing another plan.",
+ "purchaseBlockedUntilPeriodEnd": "Your current plan ends {{date}}. You can purchase a new plan after it ends."
},
"subscriptionStatus": {
"INCOMPLETE": "Awaiting payment",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index e1c7e0f9be..183fc4d1f8 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -9379,7 +9379,8 @@
},
"currentSubscription": {
"title": "現在のサブスクリプション",
- "purchaseBlocked": "未終了のサブスクリプションがあります。既存のサブスクリプションを処理してから新しいプランを購入してください。"
+ "purchaseBlocked": "未終了のサブスクリプションがあります。既存のサブスクリプションを処理してから新しいプランを購入してください。",
+ "purchaseBlockedUntilPeriodEnd": "現在のプランは {{date}} に終了します。終了後に新しいプランを購入できます。"
},
"subscriptionStatus": {
"INCOMPLETE": "支払い待ち",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index ad5ac0bd79..76679f8b1c 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -9379,7 +9379,8 @@
},
"currentSubscription": {
"title": "현재 구독",
- "purchaseBlocked": "종료되지 않은 구독이 있습니다. 기존 구독을 처리한 후 새 요금제를 구매하세요."
+ "purchaseBlocked": "종료되지 않은 구독이 있습니다. 기존 구독을 처리한 후 새 요금제를 구매하세요.",
+ "purchaseBlockedUntilPeriodEnd": "현재 요금제는 {{date}}에 종료됩니다. 종료 후 새 요금제를 구매할 수 있습니다."
},
"subscriptionStatus": {
"INCOMPLETE": "결제 대기",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 38a03f4ef9..c406f0cae9 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -9375,7 +9375,8 @@
},
"currentSubscription": {
"title": "当前订阅",
- "purchaseBlocked": "当前已有未结束的订阅,请先处理现有订阅后再购买新套餐。"
+ "purchaseBlocked": "当前已有未结束的订阅,请先处理现有订阅后再购买新套餐。",
+ "purchaseBlockedUntilPeriodEnd": "当前套餐将于 {{date}} 结束,届时可购买新套餐。"
},
"subscriptionStatus": {
"INCOMPLETE": "等待完成支付",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 08f049977d..598c18fc68 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -9378,7 +9378,8 @@
},
"currentSubscription": {
"title": "當前訂閱",
- "purchaseBlocked": "當前已有未結束的訂閱,請先處理現有訂閱後再購買新套餐。"
+ "purchaseBlocked": "當前已有未結束的訂閱,請先處理現有訂閱後再購買新套餐。",
+ "purchaseBlockedUntilPeriodEnd": "當前套餐將於 {{date}} 結束,屆時可購買新套餐。"
},
"subscriptionStatus": {
"INCOMPLETE": "等待完成支付",