diff --git a/package.json b/package.json
index f85295fcc..fa0b65266 100644
--- a/package.json
+++ b/package.json
@@ -74,7 +74,7 @@
"motion": "^12.35.1",
"multer": "^1.4.5-lts.1",
"next-themes": "^0.4.6",
- "picgo": "^3.1.0",
+ "picgo": "^3.2.0",
"prismjs": "^1.30.0",
"qrcode.react": "^4.2.0",
"qrcode.vue": "^3.3.3",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 0e5de47c9..c6d221186 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -131,8 +131,8 @@ importers:
specifier: ^0.4.6
version: 0.4.6(react-dom@19.2.4(react@19.2.4))(react@19.2.4)
picgo:
- specifier: ^3.1.0
- version: 3.1.0
+ specifier: ^3.2.0
+ version: 3.2.0
prismjs:
specifier: ^1.30.0
version: 1.30.0
@@ -5745,8 +5745,8 @@ packages:
pend@1.2.0:
resolution: {integrity: sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==}
- picgo@3.1.0:
- resolution: {integrity: sha512-8GlFd7VaSs92MJpub/qW20Klbvx/FAe/V1MV29l6b2p5s66NTFKN73hqzWS2RZ/phTpjHNxycwq/96uXr6B8wg==}
+ picgo@3.2.0:
+ resolution: {integrity: sha512-wZINcVuF8oP5c7CFMzhegVjMj87GguG/VTJ13VGuPVkvzaNKyYsvGsB8h2zFLlm6Jc12QPbKb40oFHIPJ3sEoA==}
engines: {node: '>= 20.19.0'}
hasBin: true
@@ -13434,7 +13434,7 @@ snapshots:
pend@1.2.0: {}
- picgo@3.1.0:
+ picgo@3.2.0:
dependencies:
'@hono/node-server': 1.19.9(hono@4.12.3)
'@picgo/i18n': 1.0.0
diff --git a/public/i18n/en.yml b/public/i18n/en.yml
index af44a65d3..de51e7ddd 100644
--- a/public/i18n/en.yml
+++ b/public/i18n/en.yml
@@ -121,6 +121,18 @@ PICGO_CLOUD_PLAN_PERIOD_GRACE_LABEL: Grace Until
PICGO_CLOUD_PLAN_PERIOD_GRACE_TOOLTIP: "Your paid plan has expired and is now in the grace period. PicGo Cloud images remain accessible until this date, but quota is temporarily downgraded to free. Most paid features are temporarily unavailable. After this date, the account enters the frozen state."
PICGO_CLOUD_PLAN_PERIOD_FROZEN_LABEL: Frozen Until
PICGO_CLOUD_PLAN_PERIOD_FROZEN_TOOLTIP: "Your account is frozen. PicGo Cloud images return errors. After this date, data may be cleaned up. Renew to restore access."
+PICGO_CLOUD_PLAN_PERIOD_SUBSCRIPTION: "Subscription · ${plan}"
+PICGO_CLOUD_PLAN_PERIOD_SYNCING: "Active, renewal details syncing"
+PICGO_CLOUD_PLAN_PERIOD_FIXED_TERM: "Fixed-term membership"
+PICGO_CLOUD_PLAN_PERIOD_EXPIRING_SOON: "Expiring soon"
+PICGO_CLOUD_PLAN_PERIOD_IN_USE: "In use"
+PICGO_CLOUD_PLAN_PERIOD_TERM_VALID_UNTIL: "Valid until ${date} (${days} days left)"
+PICGO_CLOUD_PLAN_PERIOD_TIMELINE_CURRENT: "Current"
+PICGO_CLOUD_PLAN_PERIOD_TIMELINE_THEN: "Then"
+PICGO_CLOUD_PLAN_PERIOD_TIMELINE_UNTIL: "until ${date}"
+PICGO_CLOUD_PLAN_PERIOD_NO_RENEW: "Does not renew automatically."
+PICGO_CLOUD_PLAN_PERIOD_CONCURRENT: "${plan} is in use until ${date} and counts down alongside your subscription. After that you're back on ${subscription}."
+PICGO_CLOUD_PLAN_PERIOD_CONCURRENT_WASTED: "You're on ${subscription} through your subscription. ${plan} counts down at the same time until ${date} and is not saved for later."
PICGO_CLOUD_QUOTA_DOWNGRADED: "Quota temporarily downgraded to ${plan} during grace period. Renew to restore."
PICGO_CLOUD_LIFECYCLE_BANNER_GRACE_TITLE: Plan in grace period
PICGO_CLOUD_LIFECYCLE_BANNER_GRACE_DESC: "Your paid plan has expired and entered a ${days}-day grace period. Quota is temporarily downgraded to free, and most paid features are temporarily unavailable. Renew to restore full access."
diff --git a/public/i18n/ja.yml b/public/i18n/ja.yml
index f5549cbb7..52467d30c 100644
--- a/public/i18n/ja.yml
+++ b/public/i18n/ja.yml
@@ -121,6 +121,18 @@ PICGO_CLOUD_PLAN_PERIOD_GRACE_LABEL: 猶予期限
PICGO_CLOUD_PLAN_PERIOD_GRACE_TOOLTIP: "有料プランが期限切れとなり、現在猶予期間中です。この日付まではPicGo Cloud画像にアクセスできますが、使用量は一時的に無料枠に引き下げられます。ほとんどの有料機能は一時的に利用できません。この日付以降、アカウントは凍結状態になります。"
PICGO_CLOUD_PLAN_PERIOD_FROZEN_LABEL: 凍結期限
PICGO_CLOUD_PLAN_PERIOD_FROZEN_TOOLTIP: "アカウントが凍結されています。PicGo Cloud画像はエラーを返します。この日付以降、データが削除される場合があります。アクセスを復元するには更新してください。"
+PICGO_CLOUD_PLAN_PERIOD_SUBSCRIPTION: "サブスクリプション · ${plan}"
+PICGO_CLOUD_PLAN_PERIOD_SYNCING: "有効・更新情報を同期中"
+PICGO_CLOUD_PLAN_PERIOD_FIXED_TERM: "期間限定メンバーシップ"
+PICGO_CLOUD_PLAN_PERIOD_EXPIRING_SOON: "まもなく期限切れ"
+PICGO_CLOUD_PLAN_PERIOD_IN_USE: "利用中"
+PICGO_CLOUD_PLAN_PERIOD_TERM_VALID_UNTIL: "${date} まで有効(残り ${days} 日)"
+PICGO_CLOUD_PLAN_PERIOD_TIMELINE_CURRENT: "現在"
+PICGO_CLOUD_PLAN_PERIOD_TIMELINE_THEN: "その後"
+PICGO_CLOUD_PLAN_PERIOD_TIMELINE_UNTIL: "${date} まで"
+PICGO_CLOUD_PLAN_PERIOD_NO_RENEW: "自動更新されません。"
+PICGO_CLOUD_PLAN_PERIOD_CONCURRENT: "${plan} は ${date} まで有効で、その間サブスクリプションと同時に消化されます。その後はサブスクリプションの ${subscription} に戻ります。"
+PICGO_CLOUD_PLAN_PERIOD_CONCURRENT_WASTED: "現在はサブスクリプションの ${subscription} で利用中です。${plan} は ${date} まで同時に消化され、繰り越されません。"
PICGO_CLOUD_QUOTA_DOWNGRADED: "猶予期間中、使用量は一時的に${plan}に引き下げられています。復元するには更新してください。"
PICGO_CLOUD_LIFECYCLE_BANNER_GRACE_TITLE: プランが猶予期間中です
PICGO_CLOUD_LIFECYCLE_BANNER_GRACE_DESC: "有料プランが期限切れとなり、${days}日間の猶予期間に入りました。使用量は一時的に無料枠に引き下げられ、ほとんどの有料機能が一時的に利用できません。全機能を復元するには更新してください。"
diff --git a/public/i18n/ko.yml b/public/i18n/ko.yml
index 4abfbac50..4c5a3bd97 100644
--- a/public/i18n/ko.yml
+++ b/public/i18n/ko.yml
@@ -121,6 +121,18 @@ PICGO_CLOUD_PLAN_PERIOD_GRACE_LABEL: 유예 기간 종료일
PICGO_CLOUD_PLAN_PERIOD_GRACE_TOOLTIP: "유료 요금제가 만료되어 현재 유예 기간입니다. 이 날짜까지는 PicGo Cloud 이미지에 계속 접근할 수 있지만, 할당량은 일시적으로 무료 등급으로 낮아집니다. 대부분의 유료 기능은 일시적으로 사용할 수 없습니다. 이 날짜 이후에는 계정이 정지 상태가 됩니다."
PICGO_CLOUD_PLAN_PERIOD_FROZEN_LABEL: 정지 종료일
PICGO_CLOUD_PLAN_PERIOD_FROZEN_TOOLTIP: "계정이 정지되었습니다. PicGo Cloud 이미지는 오류를 반환합니다. 이 날짜 이후에는 데이터가 삭제될 수 있습니다. 접근 권한을 복구하려면 갱신해 주세요."
+PICGO_CLOUD_PLAN_PERIOD_SUBSCRIPTION: "구독 · ${plan}"
+PICGO_CLOUD_PLAN_PERIOD_SYNCING: "활성화됨, 갱신 정보 동기화 중"
+PICGO_CLOUD_PLAN_PERIOD_FIXED_TERM: "기간제 멤버십"
+PICGO_CLOUD_PLAN_PERIOD_EXPIRING_SOON: "곧 만료"
+PICGO_CLOUD_PLAN_PERIOD_IN_USE: "사용 중"
+PICGO_CLOUD_PLAN_PERIOD_TERM_VALID_UNTIL: "${date}까지 유효 (${days}일 남음)"
+PICGO_CLOUD_PLAN_PERIOD_TIMELINE_CURRENT: "현재"
+PICGO_CLOUD_PLAN_PERIOD_TIMELINE_THEN: "이후"
+PICGO_CLOUD_PLAN_PERIOD_TIMELINE_UNTIL: "${date}까지"
+PICGO_CLOUD_PLAN_PERIOD_NO_RENEW: "자동으로 갱신되지 않습니다."
+PICGO_CLOUD_PLAN_PERIOD_CONCURRENT: "${plan}은(는) ${date}까지 적용되며 그동안 구독과 동시에 차감됩니다. 이후에는 구독한 ${subscription}(으)로 돌아갑니다."
+PICGO_CLOUD_PLAN_PERIOD_CONCURRENT_WASTED: "현재 구독한 ${subscription}(으)로 이용 중입니다. ${plan}은(는) ${date}까지 동시에 차감되며 이월되지 않습니다."
PICGO_CLOUD_QUOTA_DOWNGRADED: "유예 기간 동안 할당량이 일시적으로 ${plan}(으)로 낮아졌습니다. 복구하려면 갱신해 주세요."
PICGO_CLOUD_LIFECYCLE_BANNER_GRACE_TITLE: 요금제가 유예 기간입니다
PICGO_CLOUD_LIFECYCLE_BANNER_GRACE_DESC: "유료 요금제가 만료되어 ${days}일간의 유예 기간에 들어갔습니다. 할당량은 일시적으로 무료 등급으로 낮아지고, 대부분의 유료 기능을 사용할 수 없습니다. 전체 기능을 복구하려면 갱신해 주세요."
diff --git a/public/i18n/zh-CN.yml b/public/i18n/zh-CN.yml
index 81e9e0898..89b877084 100644
--- a/public/i18n/zh-CN.yml
+++ b/public/i18n/zh-CN.yml
@@ -121,6 +121,18 @@ PICGO_CLOUD_PLAN_PERIOD_GRACE_LABEL: 宽限期至
PICGO_CLOUD_PLAN_PERIOD_GRACE_TOOLTIP: 付费套餐已过期,目前处于宽限期。该日期前 PicGo Cloud 图片仍可正常访问,但配额已临时降级到免费版。大部分付费功能将暂时不可使用。过期后账户将进入冻结状态。
PICGO_CLOUD_PLAN_PERIOD_FROZEN_LABEL: 冻结期至
PICGO_CLOUD_PLAN_PERIOD_FROZEN_TOOLTIP: 账户已冻结,PicGo Cloud 图片无法访问。该日期后数据可能被清理,请尽快续费以恢复权益。
+PICGO_CLOUD_PLAN_PERIOD_SUBSCRIPTION: "订阅 · ${plan}"
+PICGO_CLOUD_PLAN_PERIOD_SYNCING: "已生效,续费信息同步中"
+PICGO_CLOUD_PLAN_PERIOD_FIXED_TERM: "限时会员"
+PICGO_CLOUD_PLAN_PERIOD_EXPIRING_SOON: "即将到期"
+PICGO_CLOUD_PLAN_PERIOD_IN_USE: "当前生效"
+PICGO_CLOUD_PLAN_PERIOD_TERM_VALID_UNTIL: "有效期至 ${date}(剩余 ${days} 天)"
+PICGO_CLOUD_PLAN_PERIOD_TIMELINE_CURRENT: "当前"
+PICGO_CLOUD_PLAN_PERIOD_TIMELINE_THEN: "之后"
+PICGO_CLOUD_PLAN_PERIOD_TIMELINE_UNTIL: "至 ${date}"
+PICGO_CLOUD_PLAN_PERIOD_NO_RENEW: "到期后不会自动续费。"
+PICGO_CLOUD_PLAN_PERIOD_CONCURRENT: "${plan} 生效至 ${date},期间与订阅同时计时,之后回到订阅的 ${subscription}。"
+PICGO_CLOUD_PLAN_PERIOD_CONCURRENT_WASTED: "当前按订阅的 ${subscription} 使用;${plan} 同时计时至 ${date},不会顺延。"
PICGO_CLOUD_QUOTA_DOWNGRADED: 宽限期内配额已临时降级到 ${plan},续费后将恢复
PICGO_CLOUD_LIFECYCLE_BANNER_GRACE_TITLE: 套餐已进入宽限期
PICGO_CLOUD_LIFECYCLE_BANNER_GRACE_DESC: 你的付费套餐已过期,目前进入 ${days} 天宽限期。期间配额已临时降级到免费版,大部分付费功能将暂时不可使用。请尽快续费以恢复完整权益。
diff --git a/public/i18n/zh-TW.yml b/public/i18n/zh-TW.yml
index 6ec5523b1..cfdcae40d 100644
--- a/public/i18n/zh-TW.yml
+++ b/public/i18n/zh-TW.yml
@@ -121,6 +121,18 @@ PICGO_CLOUD_PLAN_PERIOD_GRACE_LABEL: 寬限期至
PICGO_CLOUD_PLAN_PERIOD_GRACE_TOOLTIP: 付費套餐已過期,目前處於寬限期。該日期前 PicGo Cloud 圖片仍可正常存取,但配額已暫時降級到免費版。大部分付費功能將暫時不可使用。過期後帳戶將進入凍結狀態。
PICGO_CLOUD_PLAN_PERIOD_FROZEN_LABEL: 凍結期至
PICGO_CLOUD_PLAN_PERIOD_FROZEN_TOOLTIP: 帳戶已凍結,PicGo Cloud 圖片無法存取。該日期後資料可能被清理,請儘快續費以恢復權益。
+PICGO_CLOUD_PLAN_PERIOD_SUBSCRIPTION: "訂閱 · ${plan}"
+PICGO_CLOUD_PLAN_PERIOD_SYNCING: "已生效,續費資訊同步中"
+PICGO_CLOUD_PLAN_PERIOD_FIXED_TERM: "限時會員"
+PICGO_CLOUD_PLAN_PERIOD_EXPIRING_SOON: "即將到期"
+PICGO_CLOUD_PLAN_PERIOD_IN_USE: "目前生效"
+PICGO_CLOUD_PLAN_PERIOD_TERM_VALID_UNTIL: "有效期至 ${date}(剩餘 ${days} 天)"
+PICGO_CLOUD_PLAN_PERIOD_TIMELINE_CURRENT: "目前"
+PICGO_CLOUD_PLAN_PERIOD_TIMELINE_THEN: "之後"
+PICGO_CLOUD_PLAN_PERIOD_TIMELINE_UNTIL: "至 ${date}"
+PICGO_CLOUD_PLAN_PERIOD_NO_RENEW: "到期後不會自動續費。"
+PICGO_CLOUD_PLAN_PERIOD_CONCURRENT: "${plan} 生效至 ${date},期間與訂閱同時計時,之後回到訂閱的 ${subscription}。"
+PICGO_CLOUD_PLAN_PERIOD_CONCURRENT_WASTED: "目前依訂閱的 ${subscription} 使用;${plan} 同時計時至 ${date},不會順延。"
PICGO_CLOUD_QUOTA_DOWNGRADED: 寬限期內配額已暫時降級到 ${plan},續費後將恢復
PICGO_CLOUD_LIFECYCLE_BANNER_GRACE_TITLE: 套餐已進入寬限期
PICGO_CLOUD_LIFECYCLE_BANNER_GRACE_DESC: 你的付費套餐已過期,目前進入 ${days} 天寬限期。期間配額已暫時降級到免費版,大部分付費功能將暫時不可使用。請儘快續費以恢復完整權益。
diff --git a/src/__tests__/renderer/components/cloud-plan-period-row.spec.tsx b/src/__tests__/renderer/components/cloud-plan-period-row.spec.tsx
new file mode 100644
index 000000000..919157b4b
--- /dev/null
+++ b/src/__tests__/renderer/components/cloud-plan-period-row.spec.tsx
@@ -0,0 +1,190 @@
+// @vitest-environment jsdom
+
+import { render, screen, within } from '@testing-library/react'
+import type { ReactNode } from 'react'
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+
+vi.mock('react-i18next', () => ({
+ useTranslation: () => ({ t: (key: string) => key })
+}))
+
+// Base UI tooltips only mount their popup on hover; render the content inline so its markup can be asserted directly.
+vi.mock('@/components/ui/tooltip', () => ({
+ Tooltip: ({ children }: { children: ReactNode }) =>
{children}
,
+ TooltipTrigger: ({ children }: { children: ReactNode }) => <>{children}>,
+ TooltipContent: ({ children }: { children: ReactNode }) => {children}
+}))
+
+vi.mock('@/components/main/cloud/cloud-plan-usage-helpers', () => ({
+ PLAN_PERIOD_PLACEHOLDER: '-',
+ PlanPeriodBadgeTone: { Neutral: 'neutral', Warning: 'warning' },
+ resolvePlanPeriodBlocks: vi.fn(),
+ resolvePlanPeriodTooltip: vi.fn(),
+ resolvePlanPeriodLabelInfo: vi.fn()
+}))
+
+import {
+ PlanPeriodBadgeTone,
+ resolvePlanPeriodBlocks,
+ resolvePlanPeriodLabelInfo,
+ resolvePlanPeriodTooltip
+} from '@/components/main/cloud/cloud-plan-usage-helpers'
+import { PlanPeriodRow } from '@/components/main/cloud/cloud-plan-period-row'
+
+const WARNING_CLASS = 'text-amber-600'
+
+describe('PlanPeriodRow', () => {
+ beforeEach(() => {
+ vi.clearAllMocks()
+ vi.mocked(resolvePlanPeriodLabelInfo).mockReturnValue({ labelKey: 'PICGO_CLOUD_PLAN_PERIOD_LABEL', tooltipKey: null })
+ vi.mocked(resolvePlanPeriodTooltip).mockReturnValue(null)
+ vi.mocked(resolvePlanPeriodBlocks).mockReturnValue([])
+ })
+
+ it('renders the skeleton while loading', () => {
+ const { container } = render()
+ expect(container.querySelector('[data-slot="skeleton"]')).not.toBeNull()
+ expect(screen.queryByText('-')).toBeNull()
+ })
+
+ it('renders the placeholder when there are no blocks and no info icon without tooltip data', () => {
+ render()
+ expect(screen.getByText('PICGO_CLOUD_PLAN_PERIOD_LABEL')).toBeInTheDocument()
+ expect(screen.getByText('-')).toBeInTheDocument()
+ expect(screen.queryByTestId('plan-period-block')).toBeNull()
+ expect(screen.queryByTestId('plan-period-info')).toBeNull()
+ })
+
+ it('renders a single block with primary and secondary lines', () => {
+ vi.mocked(resolvePlanPeriodBlocks).mockReturnValue([
+ { primary: 'Yearly', secondary: 'Renews on 2027-06-30', badges: [], chain: [], warning: false }
+ ])
+ render()
+
+ const blocks = screen.getAllByTestId('plan-period-block')
+ expect(blocks).toHaveLength(1)
+ const primary = screen.getByText('Yearly')
+ const secondary = screen.getByText('Renews on 2027-06-30')
+ expect(primary).toHaveClass('text-muted-foreground')
+ expect(primary).not.toHaveClass(WARNING_CLASS)
+ expect(secondary).toHaveClass('text-xs')
+ expect(secondary).not.toHaveClass(WARNING_CLASS)
+ expect(screen.queryByText('-')).toBeNull()
+ })
+
+ it('renders a block without primary using the primary style for its secondary text', () => {
+ vi.mocked(resolvePlanPeriodBlocks).mockReturnValue([
+ { primary: null, secondary: '2026-10-23', badges: [], chain: [], warning: false }
+ ])
+ render()
+
+ const only = screen.getByText('2026-10-23')
+ expect(only).toHaveClass('text-muted-foreground')
+ expect(only).not.toHaveClass('text-xs')
+ })
+
+ it('stacks multiple blocks with an expiring badge, warning date and plan chain', () => {
+ vi.mocked(resolvePlanPeriodBlocks).mockReturnValue([
+ {
+ primary: 'Fixed-term membership',
+ badges: [{ label: 'Expiring soon', tone: PlanPeriodBadgeTone.Warning }],
+ secondary: 'Valid until 2026-10-23 (4 days left)',
+ chain: [
+ { plan: 'Max', current: true },
+ { plan: 'Pro', current: false },
+ { plan: 'Starter', current: false }
+ ],
+ warning: true
+ },
+ { primary: 'Subscription · Pro', secondary: 'Renews on 2027-06-30', badges: [{ label: 'In use', tone: PlanPeriodBadgeTone.Neutral }], chain: [], warning: false }
+ ])
+ render()
+
+ const blocks = screen.getAllByTestId('plan-period-block')
+ expect(blocks).toHaveLength(2)
+
+ // The label and the badge are separate nowrap pieces, so the phrase never breaks mid-way.
+ expect(within(blocks[0]).getByText('Fixed-term membership')).toHaveClass('whitespace-nowrap')
+ expect(within(blocks[0]).getByTestId('plan-period-badge')).toHaveTextContent('Expiring soon')
+ expect(within(blocks[0]).getByText('Valid until 2026-10-23 (4 days left)')).toHaveClass(WARNING_CLASS)
+ const chain = within(blocks[0]).getByTestId('plan-period-chain')
+ expect(chain).toHaveTextContent('MaxProStarter')
+ expect(within(chain).getByText('Max')).toHaveClass('font-medium')
+ expect(within(chain).getByText('Pro')).not.toHaveClass('font-medium')
+
+ expect(within(blocks[0]).getByTestId('plan-period-badge')).toHaveAttribute('data-tone', 'warning')
+ expect(within(blocks[1]).getByTestId('plan-period-badge')).toHaveTextContent('In use')
+ expect(within(blocks[1]).getByTestId('plan-period-badge')).toHaveAttribute('data-tone', 'neutral')
+ expect(within(blocks[1]).queryByTestId('plan-period-chain')).toBeNull()
+ expect(within(blocks[1]).getByText('Renews on 2027-06-30')).not.toHaveClass(WARNING_CLASS)
+ })
+
+ it('truncates a long plan chain with an ellipsis', () => {
+ vi.mocked(resolvePlanPeriodBlocks).mockReturnValue([
+ {
+ primary: 'Fixed-term membership',
+ badges: [],
+ secondary: 'Valid until 2027-12-31 (438 days left)',
+ chain: ['Max', 'Pro', 'Starter', 'Lite'].map((plan, index) => ({ plan, current: index === 0 })),
+ warning: false
+ }
+ ])
+ render()
+
+ const chain = screen.getByTestId('plan-period-chain')
+ expect(chain).toHaveTextContent('MaxPro…')
+ expect(within(chain).queryByText('Starter')).toBeNull()
+ expect(within(chain).getByTestId('plan-period-chain-more')).toBeInTheDocument()
+ })
+
+ it('renders the rich tooltip with timeline rows and notes', () => {
+ vi.mocked(resolvePlanPeriodBlocks).mockReturnValue([
+ { primary: 'Max', secondary: 'Valid until 2026-10-23', badges: [], chain: [], warning: false }
+ ])
+ vi.mocked(resolvePlanPeriodTooltip).mockReturnValue({
+ timeline: [
+ { tag: 'Current', plan: 'Max', range: '→ 2026-10-20' },
+ { tag: 'Then', plan: 'Pro', range: '2026-10-20 → 2026-10-21' },
+ { tag: 'Then', plan: 'Starter', range: '2026-10-21 → 2026-10-23' }
+ ],
+ notes: ['Your subscription resumes after the membership ends.']
+ })
+ render()
+
+ expect(screen.getByTestId('plan-period-info')).toBeInTheDocument()
+ const content = screen.getByTestId('tooltip-content')
+ const rows = within(content).getAllByTestId('plan-period-timeline-row')
+ expect(rows).toHaveLength(3)
+ expect(within(rows[0]).getByText('Current')).toBeInTheDocument()
+ expect(within(rows[1]).getByText('Pro')).toBeInTheDocument()
+ expect(within(rows[2]).getByText('2026-10-21 → 2026-10-23')).toBeInTheDocument()
+ expect(within(content).getByText('Your subscription resumes after the membership ends.')).toBeInTheDocument()
+ })
+
+ it('hides the info icon when the rich tooltip is empty', () => {
+ vi.mocked(resolvePlanPeriodTooltip).mockReturnValue({ timeline: [], notes: [] })
+ render()
+ expect(screen.queryByTestId('plan-period-info')).toBeNull()
+ })
+
+ it('keeps the plain text tooltip in grace state and skips the rich tooltip', () => {
+ vi.mocked(resolvePlanPeriodLabelInfo).mockReturnValue({
+ labelKey: 'PICGO_CLOUD_PLAN_PERIOD_GRACE_LABEL',
+ tooltipKey: 'PICGO_CLOUD_PLAN_PERIOD_GRACE_TOOLTIP'
+ })
+ vi.mocked(resolvePlanPeriodTooltip).mockReturnValue({
+ timeline: [{ tag: 'Current', plan: 'Max', range: '→ 2026-10-20' }],
+ notes: []
+ })
+ vi.mocked(resolvePlanPeriodBlocks).mockReturnValue([
+ { primary: null, secondary: '2026-10-20', badges: [], chain: [], warning: false }
+ ])
+ render()
+
+ expect(screen.getByText('PICGO_CLOUD_PLAN_PERIOD_GRACE_LABEL')).toBeInTheDocument()
+ expect(screen.getAllByTestId('plan-period-info')).toHaveLength(1)
+ const content = screen.getByTestId('tooltip-content')
+ expect(within(content).getByText('PICGO_CLOUD_PLAN_PERIOD_GRACE_TOOLTIP')).toBeInTheDocument()
+ expect(screen.queryByTestId('plan-period-timeline-row')).toBeNull()
+ })
+})
diff --git a/src/__tests__/renderer/components/cloud-plan-period.spec.ts b/src/__tests__/renderer/components/cloud-plan-period.spec.ts
new file mode 100644
index 000000000..4808db659
--- /dev/null
+++ b/src/__tests__/renderer/components/cloud-plan-period.spec.ts
@@ -0,0 +1,300 @@
+import fs from 'node:fs'
+import path from 'node:path'
+import i18next, { type TFunction } from 'i18next'
+import { parse } from 'yaml'
+import { beforeAll, describe, expect, it } from 'vitest'
+import {
+ PicGoCloudFixedTermSource,
+ PicGoCloudSubscriptionStanding,
+ type IPicGoCloudBillingOverview,
+ type IPicGoCloudLifecyclePhase
+} from '#/types/cloud'
+import {
+ PlanPeriodBadgeTone,
+ resolvePlanPeriodBlocks,
+ resolvePlanPeriodTooltip
+} from '@/components/main/cloud/cloud-plan-usage-helpers'
+
+// 用真实的 en.yml + 与渲染进程相同的 `${var}` 插值配置,断言的就是用户最终看到的英文文案
+let t: TFunction
+
+beforeAll(async () => {
+ const raw = fs.readFileSync(path.resolve(__dirname, '../../../../public/i18n/en.yml'), 'utf8')
+ const instance = i18next.createInstance()
+ await instance.init({
+ resources: { en: { translation: parse(raw) } },
+ lng: 'en',
+ showSupportNotice: false,
+ interpolation: { escapeValue: false, prefix: '${', suffix: '}' }
+ })
+ t = instance.t
+})
+
+// 统一用 UTC 正午,避免本地时区把日期挪到前一天 / 后一天
+const day = (date: string) => `${date}T12:00:00.000Z`
+
+type BillingOverrides = {
+ paid?: string
+ capability?: string
+ billingPeriod?: string | null
+ subscriptionPlan?: string
+ phase?: IPicGoCloudLifecyclePhase
+ currentPhaseEndsAt?: string | null
+ subscription?: IPicGoCloudBillingOverview['subscription']
+ fixedTerms?: IPicGoCloudBillingOverview['fixedTerms']
+ redemptionQueue?: IPicGoCloudBillingOverview['redemptionQueue']
+ pendingSubscription?: IPicGoCloudBillingOverview['pendingSubscription']
+}
+
+function makeBilling (overrides: BillingOverrides = {}): IPicGoCloudBillingOverview {
+ const billing: IPicGoCloudBillingOverview = {
+ plan: {
+ paid: overrides.paid ?? 'pro',
+ capability: overrides.capability ?? overrides.paid ?? 'pro',
+ billingPeriod: overrides.billingPeriod === undefined ? 'yearly' : overrides.billingPeriod,
+ source: 'entitlement',
+ ...(overrides.subscriptionPlan ? { subscription: overrides.subscriptionPlan } : {})
+ },
+ lifecycle: {
+ phase: overrides.phase ?? 'active',
+ daysRemaining: null,
+ graceEndsAt: null,
+ freezeEndsAt: null,
+ currentPhaseEndsAt: overrides.currentPhaseEndsAt === undefined ? null : overrides.currentPhaseEndsAt,
+ flags: { customDomainDisabledByLifecycle: false, autoImportDisabledByLifecycle: false }
+ },
+ subscription: overrides.subscription === undefined ? null : overrides.subscription
+ }
+ if (overrides.fixedTerms !== undefined) billing.fixedTerms = overrides.fixedTerms
+ if (overrides.redemptionQueue !== undefined) billing.redemptionQueue = overrides.redemptionQueue
+ if (overrides.pendingSubscription !== undefined) billing.pendingSubscription = overrides.pendingSubscription
+ return billing
+}
+
+describe('resolvePlanPeriodBlocks / resolvePlanPeriodTooltip', () => {
+ it('free plan → no blocks and no tooltip', () => {
+ const billing = makeBilling({ paid: 'free', capability: 'free', billingPeriod: null })
+ expect(resolvePlanPeriodBlocks(billing, t)).toEqual([])
+ expect(resolvePlanPeriodTooltip(billing, t)).toBeNull()
+ expect(resolvePlanPeriodBlocks(null, t)).toEqual([])
+ })
+
+ it('plain live subscription keeps the previous single-block output', () => {
+ const billing = makeBilling({
+ currentPhaseEndsAt: day('2027-06-30'),
+ subscription: { status: 'active', standing: PicGoCloudSubscriptionStanding.Live, currentPeriodEnd: day('2027-06-30') },
+ fixedTerms: [],
+ redemptionQueue: [],
+ pendingSubscription: null
+ })
+ expect(resolvePlanPeriodBlocks(billing, t)).toEqual([
+ { primary: 'Yearly', secondary: 'Renews on 2027-06-30', badges: [], chain: [], warning: false }
+ ])
+ expect(resolvePlanPeriodTooltip(billing, t)).toBeNull()
+ })
+
+ it('ending subscription shows the cancel date', () => {
+ const billing = makeBilling({
+ subscription: { status: 'scheduled_cancel', standing: PicGoCloudSubscriptionStanding.Ending, currentPeriodEnd: day('2027-06-30') },
+ fixedTerms: [],
+ redemptionQueue: [],
+ pendingSubscription: null
+ })
+ expect(resolvePlanPeriodBlocks(billing, t)[0].secondary).toBe('Cancels on 2027-06-30')
+ })
+
+ it('old payload without standing / fixedTerms / queue / pending falls back to raw status', () => {
+ const live = makeBilling({ subscription: { status: 'trialing', currentPeriodEnd: day('2027-01-15') } })
+ expect(resolvePlanPeriodBlocks(live, t)).toEqual([
+ { primary: 'Yearly', secondary: 'Renews on 2027-01-15', badges: [], chain: [], warning: false }
+ ])
+ expect(resolvePlanPeriodTooltip(live, t)).toBeNull()
+
+ const canceled = makeBilling({
+ billingPeriod: 'monthly',
+ currentPhaseEndsAt: day('2027-02-01'),
+ subscription: { status: 'canceled', currentPeriodEnd: day('2026-09-01') }
+ })
+ expect(resolvePlanPeriodBlocks(canceled, t)).toEqual([
+ { primary: 'Monthly', secondary: 'Valid until 2027-02-01', badges: [], chain: [], warning: false }
+ ])
+
+ const lifetime = makeBilling({ billingPeriod: 'lifetime' })
+ expect(resolvePlanPeriodBlocks(lifetime, t)).toEqual([
+ { primary: 'Lifetime', secondary: 'Lifetime', badges: [], chain: [], warning: false }
+ ])
+ })
+
+ it('pending subscription without fixed terms says renewal details are syncing', () => {
+ const billing = makeBilling({
+ billingPeriod: null,
+ currentPhaseEndsAt: day('2027-10-19'),
+ subscription: null,
+ fixedTerms: [],
+ redemptionQueue: [],
+ pendingSubscription: { plan: 'pro' }
+ })
+ expect(resolvePlanPeriodBlocks(billing, t)).toEqual([
+ { primary: null, secondary: 'Active, renewal details syncing', badges: [], chain: [], warning: false }
+ ])
+ expect(resolvePlanPeriodTooltip(billing, t)).toBeNull()
+ })
+
+ it('stacked redemption with a queue: expiring badge, plan chain and a 3-item timeline', () => {
+ const billing = makeBilling({
+ paid: 'max',
+ billingPeriod: null,
+ currentPhaseEndsAt: day('2026-10-23'),
+ subscription: null,
+ fixedTerms: [{ source: PicGoCloudFixedTermSource.Redemption, plan: 'max', endsAt: day('2026-10-23'), daysRemaining: 4 }],
+ redemptionQueue: [
+ { plan: 'pro', startsAt: day('2026-10-20'), endsAt: day('2026-10-21') },
+ { plan: 'starter', startsAt: day('2026-10-21'), endsAt: day('2026-10-23') }
+ ],
+ pendingSubscription: null
+ })
+ expect(resolvePlanPeriodBlocks(billing, t)).toEqual([
+ {
+ primary: 'Fixed-term membership',
+ badges: [{ label: 'Expiring soon', tone: PlanPeriodBadgeTone.Warning }],
+ secondary: 'Valid until 2026-10-23 (4 days left)',
+ chain: [
+ { plan: 'Max', current: true },
+ { plan: 'Pro', current: false },
+ { plan: 'Starter', current: false }
+ ],
+ warning: true
+ }
+ ])
+ expect(resolvePlanPeriodTooltip(billing, t)).toEqual({
+ timeline: [
+ { tag: 'Current', plan: 'Max', range: 'until 2026-10-20' },
+ { tag: 'Then', plan: 'Pro', range: '2026-10-20 – 2026-10-21' },
+ { tag: 'Then', plan: 'Starter', range: '2026-10-21 – 2026-10-23' }
+ ],
+ notes: ['Does not renew automatically.']
+ })
+ })
+
+ it('live subscription + higher redemption: two blocks and the concurrent note', () => {
+ const billing = makeBilling({
+ paid: 'max',
+ subscriptionPlan: 'pro',
+ currentPhaseEndsAt: day('2027-06-30'),
+ subscription: { status: 'active', standing: PicGoCloudSubscriptionStanding.Live, currentPeriodEnd: day('2027-06-30') },
+ fixedTerms: [{ source: PicGoCloudFixedTermSource.Redemption, plan: 'max', endsAt: day('2026-12-31'), daysRemaining: 73 }],
+ redemptionQueue: [],
+ pendingSubscription: null
+ })
+ expect(resolvePlanPeriodBlocks(billing, t)).toEqual([
+ { primary: 'Subscription · Pro', secondary: 'Yearly · Renews on 2027-06-30', badges: [], chain: [], warning: false },
+ {
+ primary: 'Fixed-term membership · Max',
+ secondary: 'Valid until 2026-12-31 (73 days left)',
+ badges: [{ label: 'In use', tone: PlanPeriodBadgeTone.Neutral }],
+ chain: [],
+ warning: false
+ }
+ ])
+ expect(resolvePlanPeriodTooltip(billing, t)).toEqual({
+ timeline: [],
+ notes: ["Max is in use until 2026-12-31 and counts down alongside your subscription. After that you're back on Pro."]
+ })
+ })
+
+ it('live subscription + lower admin grant: the concurrentWasted note', () => {
+ const billing = makeBilling({
+ paid: 'max',
+ subscriptionPlan: 'max',
+ subscription: { status: 'active', standing: PicGoCloudSubscriptionStanding.Live, currentPeriodEnd: day('2027-06-30') },
+ fixedTerms: [{ source: PicGoCloudFixedTermSource.Admin, plan: 'starter', endsAt: day('2026-12-31'), daysRemaining: 73 }],
+ redemptionQueue: [],
+ pendingSubscription: null
+ })
+ // 订阅等级更高:「当前生效」落在订阅那一块
+ expect(resolvePlanPeriodBlocks(billing, t).map((block) => [block.primary, block.badges.map((badge) => badge.label)])).toEqual([
+ ['Subscription · Max', ['In use']],
+ ['Fixed-term membership · Starter', []]
+ ])
+ expect(resolvePlanPeriodTooltip(billing, t)?.notes).toEqual([
+ "You're on Max through your subscription. Starter counts down at the same time until 2026-12-31 and is not saved for later."
+ ])
+ })
+
+ it('pending subscription + fixed term shows the subscription block as syncing', () => {
+ const billing = makeBilling({
+ paid: 'max',
+ billingPeriod: null,
+ subscription: null,
+ fixedTerms: [{ source: PicGoCloudFixedTermSource.Purchase, plan: 'max', endsAt: day('2026-12-31'), daysRemaining: 73 }],
+ redemptionQueue: [],
+ pendingSubscription: { plan: 'starter' }
+ })
+ expect(resolvePlanPeriodBlocks(billing, t)[0]).toEqual({
+ primary: 'Subscription · Starter',
+ secondary: 'Active, renewal details syncing',
+ badges: [], chain: [],
+ warning: false
+ })
+ expect(resolvePlanPeriodBlocks(billing, t)[1].badges).toEqual([{ label: 'In use', tone: PlanPeriodBadgeTone.Neutral }])
+ expect(resolvePlanPeriodTooltip(billing, t)?.notes).toEqual([
+ "Max is in use until 2026-12-31 and counts down alongside your subscription. After that you're back on Starter."
+ ])
+ })
+
+ it('same plan on both: the subscription block is the one in use, an expiring term gets only its warning badge', () => {
+ const billing = makeBilling({
+ paid: 'pro',
+ subscriptionPlan: 'pro',
+ subscription: { status: 'active', standing: PicGoCloudSubscriptionStanding.Live, currentPeriodEnd: day('2027-06-30') },
+ fixedTerms: [{ source: PicGoCloudFixedTermSource.Redemption, plan: 'pro', endsAt: day('2026-10-22'), daysRemaining: 3 }],
+ redemptionQueue: [],
+ pendingSubscription: null
+ })
+ expect(resolvePlanPeriodBlocks(billing, t).map((block) => block.badges)).toEqual([
+ [{ label: 'In use', tone: PlanPeriodBadgeTone.Neutral }],
+ [{ label: 'Expiring soon', tone: PlanPeriodBadgeTone.Warning }]
+ ])
+ })
+
+ it('ended subscription + redemption hides the subscription and its billing period', () => {
+ const billing = makeBilling({
+ paid: 'pro',
+ billingPeriod: 'yearly',
+ currentPhaseEndsAt: day('2026-11-30'),
+ subscription: { status: 'canceled', standing: PicGoCloudSubscriptionStanding.Ended, currentPeriodEnd: day('2026-09-01') },
+ fixedTerms: [{ source: PicGoCloudFixedTermSource.Redemption, plan: 'pro', endsAt: day('2026-11-30'), daysRemaining: 42 }],
+ redemptionQueue: [],
+ pendingSubscription: null
+ })
+ const blocks = resolvePlanPeriodBlocks(billing, t)
+ expect(blocks).toEqual([
+ { primary: 'Fixed-term membership · Pro', secondary: 'Valid until 2026-11-30 (42 days left)', badges: [], chain: [], warning: false }
+ ])
+ expect(JSON.stringify(blocks)).not.toContain('Yearly')
+ expect(resolvePlanPeriodTooltip(billing, t)).toEqual({ timeline: [], notes: ['Does not renew automatically.'] })
+ })
+
+ it('grace / frozen keep the single bare-date block and never show a tooltip', () => {
+ const fixedTerms = [{ source: PicGoCloudFixedTermSource.Redemption, plan: 'pro', endsAt: day('2026-11-30'), daysRemaining: 42 }]
+ const grace = makeBilling({
+ capability: 'free',
+ currentPhaseEndsAt: day('2026-10-26'),
+ subscription: { status: 'canceled', standing: PicGoCloudSubscriptionStanding.Ended, currentPeriodEnd: day('2026-10-12') },
+ fixedTerms,
+ redemptionQueue: [],
+ pendingSubscription: null,
+ phase: 'grace'
+ })
+ expect(resolvePlanPeriodBlocks(grace, t)).toEqual([
+ { primary: null, secondary: '2026-10-26', badges: [], chain: [], warning: false }
+ ])
+ expect(resolvePlanPeriodTooltip(grace, t)).toBeNull()
+
+ const frozen = makeBilling({ capability: 'free', currentPhaseEndsAt: day('2026-11-09'), phase: 'frozen', fixedTerms })
+ expect(resolvePlanPeriodBlocks(frozen, t)).toEqual([
+ { primary: null, secondary: '2026-11-09', badges: [], chain: [], warning: false }
+ ])
+ expect(resolvePlanPeriodTooltip(frozen, t)).toBeNull()
+ })
+})
diff --git a/src/renderer/components/main/cloud/cloud-plan-period-row.tsx b/src/renderer/components/main/cloud/cloud-plan-period-row.tsx
index 42664de68..e6f181ec9 100644
--- a/src/renderer/components/main/cloud/cloud-plan-period-row.tsx
+++ b/src/renderer/components/main/cloud/cloud-plan-period-row.tsx
@@ -1,13 +1,20 @@
-import { InfoIcon } from 'lucide-react'
+import { ChevronRightIcon, InfoIcon } from 'lucide-react'
+import type { ReactNode } from 'react'
import { useTranslation } from 'react-i18next'
import type { IPicGoCloudBillingOverview } from '#/types/cloud'
+import { Badge } from '@/components/ui/badge'
import { Skeleton } from '@/components/ui/skeleton'
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
+import { cn } from '@/lib/utils'
import {
PLAN_PERIOD_PLACEHOLDER,
+ PlanPeriodBadgeTone,
+ resolvePlanPeriodBlocks,
resolvePlanPeriodLabelInfo,
- resolvePlanPeriodValue,
- type PlanPeriodValue
+ resolvePlanPeriodTooltip,
+ type PlanPeriodBlock,
+ type PlanPeriodChainItem,
+ type PlanPeriodTooltip
} from './cloud-plan-usage-helpers'
interface PlanPeriodRowProps {
@@ -15,44 +22,148 @@ interface PlanPeriodRowProps {
isLoading: boolean
}
+const WARNING_TEXT_CLASS = 'text-amber-600 dark:text-amber-400'
+
+const BADGE_TONE_CLASS: Record = {
+ [PlanPeriodBadgeTone.Neutral]: 'border-border bg-muted text-foreground',
+ [PlanPeriodBadgeTone.Warning]: 'border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-400'
+}
+
export function PlanPeriodRow ({ billing, isLoading }: PlanPeriodRowProps) {
const { t } = useTranslation()
- const value = resolvePlanPeriodValue(billing, t)
+ const blocks = resolvePlanPeriodBlocks(billing, t)
const { labelKey, tooltipKey } = resolvePlanPeriodLabelInfo(billing)
const tooltipText = tooltipKey ? t(tooltipKey) : null
+ // Grace / frozen keeps its plain text explanation; otherwise fall back to the rich timeline tooltip when it has anything to show.
+ const richTooltip = tooltipText ? null : resolvePlanPeriodTooltip(billing, t)
+ const hasRichTooltip = (richTooltip?.timeline.length ?? 0) > 0 || (richTooltip?.notes.length ?? 0) > 0
return (
-
+
{t(labelKey)}
{tooltipText
? (
-
-
-
-
-
- {tooltipText}
-
-
+
+ {tooltipText}
+
+ )
+ : null}
+ {richTooltip && hasRichTooltip
+ ? (
+
+
+
)
: null}
-
- {renderPlanPeriodValue(value, isLoading)}
+
+ {renderPlanPeriodBlocks(blocks, isLoading)}
)
}
-function renderPlanPeriodValue (value: PlanPeriodValue | null, isLoading: boolean) {
+function PlanPeriodInfoTooltip ({ children }: { children: ReactNode }) {
+ return (
+
+
+
+
+ {children}
+
+ )
+}
+
+function PlanPeriodTooltipBody ({ tooltip }: { tooltip: PlanPeriodTooltip }) {
+ const { timeline, notes } = tooltip
+ return (
+
+ {timeline.length > 0
+ ? (
+
+ {timeline.map((item, index) => (
+
+ {item.tag}
+ {item.plan}
+ {item.range}
+
+ ))}
+
+ )
+ : null}
+ {notes.length > 0
+ ? (
+
0 && 'border-t border-background/20 pt-2')}>
+ {notes.map((note, index) => (
+
{note}
+ ))}
+
+ )
+ : null}
+
+ )
+}
+
+function renderPlanPeriodBlocks (blocks: PlanPeriodBlock[], isLoading: boolean) {
if (isLoading) return
- if (!value) return {PLAN_PERIOD_PLACEHOLDER}
- if (!value.primary) return {value.secondary}
+ if (blocks.length === 0) return {PLAN_PERIOD_PLACEHOLDER}
+ return blocks.map((block, index) => (
+
+ ))
+}
+
+// The server merges back-to-back segments of the same plan and orders them by rank, so today the chain holds at most one entry per paid plan. Cap it anyway so a future longer chain stays on one line; the tooltip always lists every segment with dates.
+const PLAN_PERIOD_CHAIN_MAX_ITEMS = 3
+
+/** Keeps the first items and replaces the rest with a single ellipsis entry (null). */
+function truncateChain (chain: PlanPeriodChainItem[]): Array {
+ if (chain.length <= PLAN_PERIOD_CHAIN_MAX_ITEMS) return chain
+ return [...chain.slice(0, PLAN_PERIOD_CHAIN_MAX_ITEMS - 1), null]
+}
+
+// Each line keeps its words together and only wraps between whole pieces (label / badge / plan), so a narrow card never breaks a phrase like "Expiring soon" in the middle.
+function PlanPeriodBlockView ({ block }: { block: PlanPeriodBlock }) {
+ const secondaryClass = cn('text-muted-foreground/70 text-xs', block.warning && WARNING_TEXT_CLASS)
return (
- <>
- {value.primary}
- {value.secondary}
- >
+
+ {block.primary
+ ? (
+ <>
+
+ {block.primary}
+ {block.badges.map((badge) => (
+
+ {badge.label}
+
+ ))}
+
+ {block.secondary}
+ >
+ )
+ : {block.secondary}}
+ {block.chain.length > 0
+ ? (
+
+ {truncateChain(block.chain).map((item, index) => (
+
+ {index > 0 ? : null}
+ {item
+ ? {item.plan}
+ : …}
+
+ ))}
+
+ )
+ : null}
+
)
}
diff --git a/src/renderer/components/main/cloud/cloud-plan-usage-helpers.ts b/src/renderer/components/main/cloud/cloud-plan-usage-helpers.ts
index 5b9d442d6..fdf181f4f 100644
--- a/src/renderer/components/main/cloud/cloud-plan-usage-helpers.ts
+++ b/src/renderer/components/main/cloud/cloud-plan-usage-helpers.ts
@@ -1,10 +1,12 @@
import type { TFunction } from 'i18next'
-import type {
- IPicGoCloudBillingOverview,
- IPicGoCloudUsageDimension
+import {
+ PicGoCloudFixedTermSource,
+ PicGoCloudSubscriptionStanding,
+ type IPicGoCloudBillingOverview,
+ type IPicGoCloudUsageDimension
} from '#/types/cloud'
-import { formatBytes, formatDate } from '@/utils/format'
-import { capitalizePlanCode, getDisplayPlan, isAbnormalLifecyclePhase } from '@/utils/plan'
+import { formatBytes, formatDate, formatDateRange } from '@/utils/format'
+import { capitalizePlanCode, getDisplayPlan, getPlanRank, isAbnormalLifecyclePhase } from '@/utils/plan'
export const PLAN_PERIOD_PLACEHOLDER = '-'
@@ -31,46 +33,233 @@ export function resolvePlanPeriodLabelInfo (
}
}
-export type PlanPeriodValue = {
+export type PlanPeriodChainItem = {
+ /** 套餐展示名。 */
+ plan: string
+ /** 是否为当前生效的这一段。 */
+ current: boolean
+}
+
+export enum PlanPeriodBadgeTone {
+ /** 中性色,例如「当前生效」。 */
+ Neutral = 'neutral',
+ /** 警示色,例如「即将到期」。 */
+ Warning = 'warning'
+}
+
+export type PlanPeriodBadge = {
+ label: string
+ tone: PlanPeriodBadgeTone
+}
+
+export type PlanPeriodBlock = {
+ /** 顶行,例如「Yearly」「限时会员」「订阅 · Pro」;没有可展示的类型时为 null。 */
primary: string | null
+ /** 顶行右侧的小标签,例如「当前生效」「即将到期」;没有时为空数组。 */
+ badges: PlanPeriodBadge[]
+ /** 日期行,例如「续费日 2027-06-30」「有效期至 2026-10-23(剩余 4 天)」。 */
secondary: string
+ /** 叠加兑换的消耗顺序(当前段在前),例如 Max → Pro → Starter;没有排队时为空数组,具体日期见 tooltip。 */
+ chain: PlanPeriodChainItem[]
+ /** 限时会员剩余天数 <= PLAN_PERIOD_EXPIRING_SOON_DAYS 时为 true,UI 用警示色渲染。 */
+ warning: boolean
+}
+
+export type PlanPeriodTimelineItem = {
+ /** 当前段为「当前」,排队段为「之后」。 */
+ tag: string
+ /** 套餐展示名。 */
+ plan: string
+ /** 当前段为「至 {date}」,排队段为「{start} – {end}」。 */
+ range: string
+}
+
+export type PlanPeriodTooltip = {
+ /** 叠加兑换时间线;没有兑换排队时为空数组。 */
+ timeline: PlanPeriodTimelineItem[]
+ /** 每个限时会员一条:不自动续费 / 与订阅同时计时的说明。 */
+ notes: string[]
+}
+
+/** 限时会员剩余天数不超过该值时视为即将到期(与 portal 口径一致)。 */
+export const PLAN_PERIOD_EXPIRING_SOON_DAYS = 7
+
+const PLAN_PERIOD_SEPARATOR = ' · '
+
+function joinPlanPeriodParts (...parts: Array): string {
+ return parts.filter((part): part is string => Boolean(part)).join(PLAN_PERIOD_SEPARATOR)
+}
+
+/** 优先用服务端下发的 standing;旧服务端未下发时按 raw status 推导(与旧版 GUI 判定一致)。 */
+function resolveSubscriptionStanding (
+ billing: IPicGoCloudBillingOverview | null
+): PicGoCloudSubscriptionStanding | null {
+ const subscription = billing?.subscription
+ if (!subscription) return null
+ if (subscription.standing) return subscription.standing
+ const status = subscription.status?.toLowerCase() ?? ''
+ if (SUBSCRIPTION_ACTIVE_STATUSES.has(status)) return PicGoCloudSubscriptionStanding.Live
+ if (status === SUBSCRIPTION_SCHEDULED_CANCEL_STATUS) return PicGoCloudSubscriptionStanding.Ending
+ return PicGoCloudSubscriptionStanding.Ended
+}
+
+function isSubscriptionRecordLive (standing: PicGoCloudSubscriptionStanding | null): boolean {
+ return standing === PicGoCloudSubscriptionStanding.Live || standing === PicGoCloudSubscriptionStanding.Ending
}
-export function resolvePlanPeriodValue (
+/** 订阅续费 / 取消日期文案;只有 live / ending 且有账期终点时才有,避免展示已过期的账期。 */
+function resolveSubscriptionDateText (
billing: IPicGoCloudBillingOverview | null,
+ standing: PicGoCloudSubscriptionStanding | null,
t: TFunction
-): PlanPeriodValue | null {
- const paid = billing?.plan?.paid
- const capability = billing?.plan?.capability
- if (getDisplayPlan(paid, capability) === 'free') return null
+): string | null {
+ const date = formatDate(billing?.subscription?.currentPeriodEnd)
+ if (!date) return null
+ if (standing === PicGoCloudSubscriptionStanding.Live) return t('PICGO_CLOUD_PLAN_PERIOD_RENEWS', { date })
+ if (standing === PicGoCloudSubscriptionStanding.Ending) return t('PICGO_CLOUD_PLAN_PERIOD_CANCELS', { date })
+ return null
+}
+/** 没有限时会员(或处于 grace / frozen)时的单块展示,沿用旧版逻辑。 */
+function resolveSingleBlock (
+ billing: IPicGoCloudBillingOverview | null,
+ standing: PicGoCloudSubscriptionStanding | null,
+ t: TFunction
+): PlanPeriodBlock | null {
const phase = billing?.lifecycle?.phase
const isAbnormal = isAbnormalLifecyclePhase(phase)
- const planTypeLabel = isAbnormal ? null : capitalizePlanCode(billing?.plan?.billingPeriod)
- const subStatus = billing?.subscription?.status?.toLowerCase() ?? null
- const subEnd = billing?.subscription?.currentPeriodEnd ?? null
+ const primary = isAbnormal ? null : (capitalizePlanCode(billing?.plan?.billingPeriod) || null)
+ const toBlock = (secondary: string): PlanPeriodBlock => ({ primary, badges: [], secondary, chain: [], warning: false })
+
+ const subscriptionDate = resolveSubscriptionDateText(billing, standing, t)
+ if (subscriptionDate) return toBlock(subscriptionDate)
+ // 已付款但订阅记录还没写入:订阅已生效,只是续费信息未到,不能显示成「无订阅」
+ if (!isAbnormal && !isSubscriptionRecordLive(standing) && billing?.pendingSubscription) {
+ return toBlock(t('PICGO_CLOUD_PLAN_PERIOD_SYNCING'))
+ }
const phaseEnd = billing?.lifecycle?.currentPhaseEndsAt ?? null
+ const phaseEndDate = formatDate(phaseEnd)
+ if (phaseEndDate) {
+ // grace/frozen 期 label 已经是「宽限期至 / 冻结期至」,secondary 直接给日期避免双重前缀
+ return toBlock(isAbnormal ? phaseEndDate : t('PICGO_CLOUD_PLAN_PERIOD_UNTIL', { date: phaseEndDate }))
+ }
+ if (phase === 'active' && !phaseEnd && !billing?.subscription?.currentPeriodEnd) {
+ return toBlock(t('PICGO_CLOUD_PLAN_PERIOD_LIFETIME'))
+ }
+ return null
+}
+
+function resolveSubscriptionPlanCode (billing: IPicGoCloudBillingOverview | null): string {
+ return billing?.pendingSubscription?.plan ?? billing?.plan?.subscription ?? billing?.plan?.paid ?? 'free'
+}
+
+/**
+ * 「套餐周期」行的展示块。规则与 portal BillingOverviewCard 一致:
+ * - 免费 → [](UI 显示占位符);grace / frozen / 没有限时会员 → 旧版单块展示。
+ * - 有限时会员时:订阅仍有效(live / ending 或已付款待同步)才单独展示订阅块,已结束的订阅连同其 billingPeriod 一律不展示;之后每个限时会员一块。
+ */
+export function resolvePlanPeriodBlocks (
+ billing: IPicGoCloudBillingOverview | null,
+ t: TFunction
+): PlanPeriodBlock[] {
+ if (getDisplayPlan(billing?.plan?.paid, billing?.plan?.capability) === 'free') return []
- if (subEnd && subStatus && SUBSCRIPTION_ACTIVE_STATUSES.has(subStatus)) {
- const date = formatDate(subEnd)
- if (date) return { primary: planTypeLabel, secondary: t('PICGO_CLOUD_PLAN_PERIOD_RENEWS', { date }) }
+ const standing = resolveSubscriptionStanding(billing)
+ const fixedTerms = billing?.fixedTerms ?? []
+ if (isAbnormalLifecyclePhase(billing?.lifecycle?.phase) || fixedTerms.length === 0) {
+ const block = resolveSingleBlock(billing, standing, t)
+ return block ? [block] : []
}
- if (subEnd && subStatus === SUBSCRIPTION_SCHEDULED_CANCEL_STATUS) {
- const date = formatDate(subEnd)
- if (date) return { primary: planTypeLabel, secondary: t('PICGO_CLOUD_PLAN_PERIOD_CANCELS', { date }) }
+
+ const blocks: PlanPeriodBlock[] = []
+ // 与 blocks 一一对应的套餐等级,用来标出当前实际生效的那一块
+ const ranks: number[] = []
+ const pendingSubscription = billing?.pendingSubscription ?? null
+ const recordLive = isSubscriptionRecordLive(standing)
+ if (recordLive || pendingSubscription) {
+ const periodLabel = capitalizePlanCode(billing?.plan?.billingPeriod)
+ const dateText = !recordLive ? t('PICGO_CLOUD_PLAN_PERIOD_SYNCING') : resolveSubscriptionDateText(billing, standing, t)
+ blocks.push({
+ primary: t('PICGO_CLOUD_PLAN_PERIOD_SUBSCRIPTION', { plan: capitalizePlanCode(resolveSubscriptionPlanCode(billing)) }),
+ badges: [],
+ secondary: joinPlanPeriodParts(periodLabel, dateText) || PLAN_PERIOD_PLACEHOLDER,
+ chain: [],
+ warning: false
+ })
+ ranks.push(getPlanRank(resolveSubscriptionPlanCode(billing)))
}
- if (phaseEnd) {
- const date = formatDate(phaseEnd)
- if (date) {
- // grace/frozen 期 label 已经是「宽限期至 / 冻结期至」,secondary 直接给日期避免双重前缀
- const secondary = isAbnormal ? date : t('PICGO_CLOUD_PLAN_PERIOD_UNTIL', { date })
- return { primary: planTypeLabel, secondary }
- }
+
+ const queue = billing?.redemptionQueue ?? []
+ for (const term of fixedTerms) {
+ const showsQueue = term.source === PicGoCloudFixedTermSource.Redemption && queue.length > 0
+ const warning = term.daysRemaining <= PLAN_PERIOD_EXPIRING_SOON_DAYS
+ const plan = capitalizePlanCode(term.plan)
+ const date = formatDate(term.endsAt) ?? PLAN_PERIOD_PLACEHOLDER
+ const days = term.daysRemaining
+ blocks.push({
+ // 和订阅块的「订阅 · Pro」对称,套餐名放在顶行;有排队时当前套餐已经在下面的链条里加粗显示,顶行不再重复
+ primary: joinPlanPeriodParts(t('PICGO_CLOUD_PLAN_PERIOD_FIXED_TERM'), showsQueue ? null : plan),
+ badges: warning ? [{ label: t('PICGO_CLOUD_PLAN_PERIOD_EXPIRING_SOON'), tone: PlanPeriodBadgeTone.Warning }] : [],
+ secondary: t('PICGO_CLOUD_PLAN_PERIOD_TERM_VALID_UNTIL', { date, days }),
+ chain: showsQueue
+ ? [{ plan, current: true }, ...queue.map((segment) => ({ plan: capitalizePlanCode(segment.plan), current: false }))]
+ : [],
+ warning
+ })
+ ranks.push(getPlanRank(term.plan))
}
- if (phase === 'active' && !phaseEnd && !subEnd) {
- return { primary: planTypeLabel, secondary: t('PICGO_CLOUD_PLAN_PERIOD_LIFETIME') }
+ markBlockInUse(blocks, ranks, t)
+ return blocks
+}
+
+/**
+ * 有多块同时生效时(订阅 + 限时会员,或多种限时会员),给等级最高、也就是用户此刻实际在用的那一块加「当前生效」标签。等级相同时取靠前的一块(订阅在前),与 portal 的口径一致:同档位的限时会员只是与订阅同时消耗,不算在用。
+ */
+function markBlockInUse (blocks: PlanPeriodBlock[], ranks: number[], t: TFunction): void {
+ if (blocks.length < 2) return
+ const index = ranks.reduce((best, rank, i) => (rank > ranks[best] ? i : best), 0)
+ blocks[index].badges.unshift({ label: t('PICGO_CLOUD_PLAN_PERIOD_IN_USE'), tone: PlanPeriodBadgeTone.Neutral })
+}
+
+/** 「套餐周期」行的 tooltip:叠加兑换时间线 + 每个限时会员的续费 / 同时计时说明。没有限时会员或处于 grace / frozen 时为 null。 */
+export function resolvePlanPeriodTooltip (
+ billing: IPicGoCloudBillingOverview | null,
+ t: TFunction
+): PlanPeriodTooltip | null {
+ if (getDisplayPlan(billing?.plan?.paid, billing?.plan?.capability) === 'free') return null
+ if (isAbnormalLifecyclePhase(billing?.lifecycle?.phase)) return null
+ const fixedTerms = billing?.fixedTerms ?? []
+ if (fixedTerms.length === 0) return null
+
+ const queue = billing?.redemptionQueue ?? []
+ const redemption = fixedTerms.find((term) => term.source === PicGoCloudFixedTermSource.Redemption)
+ const timeline: PlanPeriodTimelineItem[] = []
+ if (redemption && queue.length > 0) {
+ timeline.push({
+ tag: t('PICGO_CLOUD_PLAN_PERIOD_TIMELINE_CURRENT'),
+ plan: capitalizePlanCode(redemption.plan),
+ range: t('PICGO_CLOUD_PLAN_PERIOD_TIMELINE_UNTIL', { date: formatDate(queue[0].startsAt) ?? PLAN_PERIOD_PLACEHOLDER })
+ })
+ for (const segment of queue) {
+ timeline.push({
+ tag: t('PICGO_CLOUD_PLAN_PERIOD_TIMELINE_THEN'),
+ plan: capitalizePlanCode(segment.plan),
+ range: formatDateRange(segment.startsAt, segment.endsAt) ?? PLAN_PERIOD_PLACEHOLDER
+ })
+ }
}
- return null
+
+ const subscriptionLive = isSubscriptionRecordLive(resolveSubscriptionStanding(billing)) || Boolean(billing?.pendingSubscription)
+ const subscriptionPlanCode = resolveSubscriptionPlanCode(billing)
+ const subscriptionPlan = capitalizePlanCode(subscriptionPlanCode)
+ const notes = fixedTerms.map((term) => {
+ if (!subscriptionLive) return t('PICGO_CLOUD_PLAN_PERIOD_NO_RENEW')
+ const args = { plan: capitalizePlanCode(term.plan), date: formatDate(term.endsAt) ?? PLAN_PERIOD_PLACEHOLDER, subscription: subscriptionPlan }
+ return getPlanRank(term.plan) > getPlanRank(subscriptionPlanCode)
+ ? t('PICGO_CLOUD_PLAN_PERIOD_CONCURRENT', args)
+ : t('PICGO_CLOUD_PLAN_PERIOD_CONCURRENT_WASTED', args)
+ })
+ return { timeline, notes }
}
export function formatStorageDimension (
diff --git a/src/universal/types/cloud.ts b/src/universal/types/cloud.ts
index e139fa2ee..a54bda004 100644
--- a/src/universal/types/cloud.ts
+++ b/src/universal/types/cloud.ts
@@ -48,6 +48,8 @@ export type IPicGoCloudBillingPlanInfo = {
capability: string
billingPeriod: string | null
source: 'entitlement' | 'admin_grant' | 'both' | 'free'
+ /** 订阅来源的 plan code;旧服务端不下发。 */
+ subscription?: string
}
export type IPicGoCloudLifecyclePhase = 'active' | 'grace' | 'frozen' | 'pending_cleanup'
@@ -73,15 +75,53 @@ export type IPicGoCloudLifecycleInfo = {
flags: IPicGoCloudLifecycleFlags
}
+/** 服务端由 raw status + 账期终点派生的订阅有效状态,判断续费 / 取消 / 已结束优先看它。 */
+export enum PicGoCloudSubscriptionStanding {
+ Live = 'live',
+ Ending = 'ending',
+ Ended = 'ended',
+ None = 'none'
+}
+
export type IPicGoCloudSubscriptionInfo = {
status: string
+ /** 旧服务端不下发,此时由客户端按 raw status 推导。 */
+ standing?: PicGoCloudSubscriptionStanding
currentPeriodEnd: string | null
}
+export enum PicGoCloudFixedTermSource {
+ Redemption = 'redemption',
+ Admin = 'admin',
+ Purchase = 'purchase'
+}
+
+/** 当前生效的一种限时会员来源(兑换 / 赠送 / 买断),不会自动续费,可与订阅同时计时。 */
+export type IPicGoCloudFixedTerm = {
+ source: PicGoCloudFixedTermSource
+ /** 该来源当前生效的 plan code(多段兑换时即当前这一段)。 */
+ plan: string
+ /** 该来源的结束时间;兑换来源为整条叠加时间线的终点。 */
+ endsAt: string
+ daysRemaining: number
+}
+
+/** 叠加兑换里排在当前这一段之后的一段,按消耗顺序排列;queue[0].startsAt 即当前段的结束时间。 */
+export type IPicGoCloudRedemptionSegment = {
+ plan: string
+ startsAt: string
+ endsAt: string
+}
+
export type IPicGoCloudBillingOverview = {
plan: IPicGoCloudBillingPlanInfo
lifecycle: IPicGoCloudLifecycleInfo
subscription: IPicGoCloudSubscriptionInfo | null
+ /** 以下字段由新版 PicGo-Core 填充;旧版 Core 不返回,读取时按 [] / null 兜底。 */
+ redemptionQueue?: IPicGoCloudRedemptionSegment[]
+ fixedTerms?: IPicGoCloudFixedTerm[]
+ /** 已付款但订阅记录尚未由 webhook 写入时,该订阅的 plan;否则为 null。 */
+ pendingSubscription?: { plan: string } | null
}
export enum IPicGoCloudErrorCode {
diff --git a/src/universal/types/i18n.d.ts b/src/universal/types/i18n.d.ts
index d44df79eb..d267119da 100644
--- a/src/universal/types/i18n.d.ts
+++ b/src/universal/types/i18n.d.ts
@@ -120,6 +120,18 @@ interface ILocales {
PICGO_CLOUD_PLAN_PERIOD_GRACE_TOOLTIP: string
PICGO_CLOUD_PLAN_PERIOD_FROZEN_LABEL: string
PICGO_CLOUD_PLAN_PERIOD_FROZEN_TOOLTIP: string
+ PICGO_CLOUD_PLAN_PERIOD_SUBSCRIPTION: string
+ PICGO_CLOUD_PLAN_PERIOD_SYNCING: string
+ PICGO_CLOUD_PLAN_PERIOD_FIXED_TERM: string
+ PICGO_CLOUD_PLAN_PERIOD_EXPIRING_SOON: string
+ PICGO_CLOUD_PLAN_PERIOD_IN_USE: string
+ PICGO_CLOUD_PLAN_PERIOD_TERM_VALID_UNTIL: string
+ PICGO_CLOUD_PLAN_PERIOD_TIMELINE_CURRENT: string
+ PICGO_CLOUD_PLAN_PERIOD_TIMELINE_THEN: string
+ PICGO_CLOUD_PLAN_PERIOD_TIMELINE_UNTIL: string
+ PICGO_CLOUD_PLAN_PERIOD_NO_RENEW: string
+ PICGO_CLOUD_PLAN_PERIOD_CONCURRENT: string
+ PICGO_CLOUD_PLAN_PERIOD_CONCURRENT_WASTED: string
PICGO_CLOUD_QUOTA_DOWNGRADED: string
PICGO_CLOUD_LIFECYCLE_BANNER_GRACE_TITLE: string
PICGO_CLOUD_LIFECYCLE_BANNER_GRACE_DESC: string