Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 标识当前订阅套餐
liugaowei35d2dd3c4778
diff --git a/apps/desktop/src/renderer/features/billing/BillingPage.tsx b/apps/desktop/src/renderer/features/billing/BillingPage.tsxindex 87e1f9619c..be95abccac 100644--- a/apps/desktop/src/renderer/features/billing/BillingPage.tsx+++ b/apps/desktop/src/renderer/features/billing/BillingPage.tsx@@ -374,12 +374,24 @@ export function BillingSettingsSection({ accountId }: { accountId: string | null[offers],);+ const subscriptionPurchaseBlocked =+ currentSubscription !== null &&+ SUBSCRIPTION_PURCHASE_BLOCKING_STATUSES.includes(currentSubscription.status);+ const currentSubscriptionOfferCode = subscriptionPurchaseBlocked+ ? (currentSubscription.effectivePlan?.offer.code ?? null)+ : null;const selected = useMemo(() =>offers.find(- (entry) => entry.offer.code === selectedOfferCode && isCatalogOfferPurchasable(entry),+ (entry) =>+ entry.offer.code === selectedOfferCode &&+ isCatalogOfferPurchasable(entry) &&+ !(+ entry.product.kind === 'SUBSCRIPTION' &&+ entry.offer.code === currentSubscriptionOfferCode+ ),) ?? null,- [offers, selectedOfferCode],+ [currentSubscriptionOfferCode, offers, selectedOfferCode],);const selectedOption = useMemo(() =>@@ -390,10 +402,15 @@ export function BillingSettingsSection({ accountId }: { accountId: string | nulluseEffect(() => {if (!selectedOfferCode) return;const selectedEntry = offers.find(({ offer }) => offer.code === selectedOfferCode);- if (!selectedEntry || !isCatalogOfferPurchasable(selectedEntry)) {+ if (+ !selectedEntry ||+ !isCatalogOfferPurchasable(selectedEntry) ||+ (selectedEntry.product.kind === 'SUBSCRIPTION' &&+ selectedEntry.offer.code === currentSubscriptionOfferCode)+ ) {resetSelection();}- }, [offers, resetSelection, selectedOfferCode]);+ }, [currentSubscriptionOfferCode, offers, resetSelection, selectedOfferCode]);useEffect(() => {if (!selectedPurchaseOptionId) return;@@ -428,9 +445,6 @@ export function BillingSettingsSection({ accountId }: { accountId: string | nullreturn null;}, [billingLocale, customAmount, selected, t]);- const subscriptionPurchaseBlocked =- currentSubscription !== null &&- SUBSCRIPTION_PURCHASE_BLOCKING_STATUSES.includes(currentSubscription.status);const canCheckout =!checkout.recovering &&selected !== null &&@@ -558,7 +572,13 @@ export function BillingSettingsSection({ accountId }: { accountId: string | nullconst selectOffer = (offerCode: string) => {if (selectedOfferCode === offerCode) return;const entry = offers.find(({ offer }) => offer.code === offerCode);- if (!entry || !isCatalogOfferPurchasable(entry)) return;+ if (+ !entry ||+ !isCatalogOfferPurchasable(entry) ||+ (entry.product.kind === 'SUBSCRIPTION' && entry.offer.code === currentSubscriptionOfferCode)+ ) {+ return;+ }setSelectedOfferCode(offerCode);// 只有一种支付方式时默认选中,免去一次多余点击。setSelectedPurchaseOptionId(@@ -744,6 +764,7 @@ export function BillingSettingsSection({ accountId }: { accountId: string | nullcustomAmount={customAmount}amountError={amountError}subscriptionPurchaseBlocked={subscriptionPurchaseBlocked}+ currentSubscriptionOfferCode={currentSubscriptionOfferCode}canCheckout={canCheckout}onClose={closeSubscriptionDialog}onRetry={() => void loadBillingState()}@@ -764,6 +785,7 @@ export function BillingSettingsSection({ accountId }: { accountId: string | nullcustomAmount={customAmount}amountError={amountError}subscriptionPurchaseBlocked={false}+ currentSubscriptionOfferCode={null}canCheckout={canCheckout}onClose={closeTopupDialog}onRetry={() => void loadBillingState()}@@ -1338,6 +1360,7 @@ function BillingOfferDialog({customAmount,amountError,subscriptionPurchaseBlocked,+ currentSubscriptionOfferCode,canCheckout,onClose,onRetry,@@ -1356,6 +1379,7 @@ function BillingOfferDialog({customAmount: string;amountError: string | null;subscriptionPurchaseBlocked: boolean;+ currentSubscriptionOfferCode: string | null;canCheckout: boolean;onClose: () => void;onRetry: () => void;@@ -1428,21 +1452,28 @@ function BillingOfferDialog({const { product, offer } = entry;const active = selected?.offer.code === offer.code;const unavailableReason = catalogOfferUnavailableReason(entry);+ const currentPlan =+ kind === 'SUBSCRIPTION' && offer.code === currentSubscriptionOfferCode;return (<buttonkey={offer.code}type="button"onClick={() => onSelectOffer(offer.code)}- disabled={unavailableReason !== null}+ disabled={currentPlan || unavailableReason !== null}aria-pressed={active}+ aria-current={currentPlan ? 'true' : undefined}className={cn('flex w-full items-center justify-between gap-4 px-4 py-3 text-left transition-colors','focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset','focus-visible:ring-[var(--text-primary)]',- 'disabled:cursor-not-allowed disabled:opacity-55 disabled:hover:bg-transparent',- active+ 'disabled:cursor-not-allowed disabled:hover:bg-transparent',+ currentPlan? 'bg-[var(--surface-chip)]'- : 'hover:bg-[var(--surface-hover-soft)]',+ : unavailableReason+ ? 'opacity-55'+ : active+ ? 'bg-[var(--surface-chip)]'+ : 'hover:bg-[var(--surface-hover-soft)]',)}><div className="min-w-0 flex-1">@@ -1450,6 +1481,11 @@ function BillingOfferDialog({<p className="truncate text-13 font-medium text-[var(--text-primary)]">{product.name}</p>+ {currentPlan && (+ <span className="rounded-full bg-[var(--surface)] px-2 py-0.5 text-10 font-medium text-[var(--text-secondary)]">+ {t('billing.catalog.currentPlan')}+ </span>+ )}{unavailableReason && (<span className="rounded-full bg-[var(--surface-chip)] px-2 py-0.5 text-10 font-medium text-[var(--text-secondary)]">{t(`billing.catalog.unavailableReasons.${unavailableReason}`)}@@ -1475,7 +1511,9 @@ function BillingOfferDialog({</p>)}</div>- {unavailableReason === null && <SelectionMark active={active} />}+ {!currentPlan && unavailableReason === null && (+ <SelectionMark active={active} />+ )}</div></button>);diff --git a/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx b/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsxindex b91c60a13a..a9f76ce8cd 100644--- a/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx+++ b/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx@@ -852,6 +852,47 @@ describe('BillingPage remote catalog rendering', () => {expect(checkout.startSubscription).not.toHaveBeenCalled();});+ it('marks the current subscription offer and prevents selecting it again', async () => {+ window.electronAPI.billing.getCurrentSubscription = vi.fn(async () => ({+ subscription: {+ subscriptionId: 'subscription_fixture',+ status: 'ACTIVE' as const,+ currentPeriodStartAt: '2026-07-01T00:00:00.000Z',+ currentPeriodEndAt: '2026-08-01T00:00:00.000Z',+ entitlementValidUntil: '2026-08-02T00:00:00.000Z',+ cancelAtPeriodEnd: true,+ effectivePlan: {+ version: 1 as const,+ product: { code: 'plus', kind: 'SUBSCRIPTION' as const, level: 1 },+ offer: { code: 'plus_month', interval: 'MONTH' as const },+ terms: {+ amount: '9',+ currency: 'usd',+ creditAmount: '100',+ rolloverCap: '0',+ },+ capturedAt: '2026-07-01T00:00:00.000Z',+ },+ purchaseAttemptId: null,+ paymentAction: null,+ },+ }));++ render(<BillingPage />);+ fireEvent.click(await screen.findByText('billing.settings.subscriptionCard.action'));++ const dialog = await screen.findByRole('dialog');+ const currentPlan = within(dialog).getByRole('button', { name: /Configured subscription/ });+ expect(currentPlan).toHaveProperty('disabled', true);+ expect(currentPlan.getAttribute('aria-current')).toBe('true');+ expect(within(dialog).getByText('billing.catalog.currentPlan')).toBeTruthy();+ expect(within(dialog).queryByText('billing.steps.channel.title')).toBeNull();+ expect(within(dialog).queryByText('stripe')).toBeNull();++ fireEvent.click(currentPlan);+ expect(checkout.startSubscription).not.toHaveBeenCalled();+ });+it('keeps subscription purchases disabled when subscription status is unavailable', async () => {window.electronAPI.billing.getCurrentSubscription = vi.fn(async () => {throw new Error('subscription status unavailable');diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex 6090dde0a8..5ef6b1fa91 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -7225,6 +7225,7 @@"errorDescription": "Check your connection and retry. Local fallback plans will not be used.","emptyTitle": "No Plans Available","emptyDescription": "The server has not published any plans yet.",+ "currentPlan": "Current Plan","unavailableReasons": {"OFFER_COMING_SOON": "Coming Soon","NO_AVAILABLE_PAYMENT_CHANNEL": "No Payment Method Available"diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex 28253c7a0c..34e34eae6f 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -7214,6 +7214,7 @@"errorDescription": "接続を確認して再試行してください。ローカルの代替プランは表示しません。","emptyTitle": "プランはまだありません","emptyDescription": "サーバーで公開中のプランはまだありません。",+ "currentPlan": "現在のプラン","unavailableReasons": {"OFFER_COMING_SOON": "近日提供","NO_AVAILABLE_PAYMENT_CHANNEL": "利用可能な支払い方法なし"diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex ce8b2f6033..27054f2958 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -7214,6 +7214,7 @@"errorDescription": "네트워크를 확인하고 다시 시도하세요. 로컬 대체 요금제는 표시하지 않습니다.","emptyTitle": "요금제가 없습니다","emptyDescription": "서버에서 공개한 요금제가 아직 없습니다.",+ "currentPlan": "현재 요금제","unavailableReasons": {"OFFER_COMING_SOON": "출시 예정","NO_AVAILABLE_PAYMENT_CHANNEL": "사용 가능한 결제 수단 없음"diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 982f9b81ca..2611d50f0c 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -7214,6 +7214,7 @@"errorDescription": "请检查网络后重试。不会使用本地套餐替代。","emptyTitle": "当前暂无套餐","emptyDescription": "服务端尚未配置公开的套餐。",+ "currentPlan": "当前套餐","unavailableReasons": {"OFFER_COMING_SOON": "敬请期待","NO_AVAILABLE_PAYMENT_CHANNEL": "暂无可用支付方式"