refactor(subscription): 拆分 UpgradeSubscription 页面,抽离 Hook + UI 组件 #1020

Closed
xiaoxia wants to merge 2 commits from refactor/upgrade-subscription-split into develop
Owner

变更说明

拆分 UpgradeSubscription 页面(235 行),按职责拆分为:

  • constants - 套餐元数据 + 价格工具函数
  • SubscriptionUI - BillingCycleSwitch + Spinner 子组件
  • useSubscription - 订阅查询、变更、续费、取消等逻辑
  • UpgradeSubscription - 页面入口 + 布局 + 确认框交互

主文件 235 → 155 行(-34%)

导入路径保持不变,向后兼容。

## 变更说明 拆分 UpgradeSubscription 页面(235 行),按职责拆分为: - **constants** - 套餐元数据 + 价格工具函数 - **SubscriptionUI** - BillingCycleSwitch + Spinner 子组件 - **useSubscription** - 订阅查询、变更、续费、取消等逻辑 - **UpgradeSubscription** - 页面入口 + 布局 + 确认框交互 主文件 235 → 155 行(-34%) 导入路径保持不变,向后兼容。
xiaoxia added 1 commit 2026-07-27 09:28:33 +08:00
refactor(subscription): 拆分 UpgradeSubscription 页面,抽离 Hook + UI 组件
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 27s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m23s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m13s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m26s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 38s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 3m16s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 2m7s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 1m24s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m0s
AI Code Review / AI Code Review (pull_request) Successful in 3m20s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 6m15s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 16m1s
CI/CD Pipeline / Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 29s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
d438c1423f
主文件 235→155 行(-34%),拆分为:
- constants: 套餐元数据 + 价格工具函数
- SubscriptionUI: BillingCycleSwitch + Spinner 子组件
- useSubscription: 订阅查询、变更、续费、取消等逻辑
- UpgradeSubscription: 页面入口 + 布局 + 确认框交互

导入路径保持向后兼容
auto-approve-bot approved these changes 2026-07-27 09:50:52 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot approved these changes 2026-07-27 09:50:52 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。

🚀 预览环境已部署

项目 详情
PR号 #1020
预览链接 https://pr-1020.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1020 | | 预览链接 | [https://pr-1020.preview.xiaoxiajianji.com](https://pr-1020.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
Collaborator

代码审查结果 - PR #1020

⚠️ 问题(2个需要修改)

  1. apps/web/src/pages/subscription/UpgradeSubscription.tsx 第74行:变量 currentPlan 未定义

    • 问题描述:在重构过程中,原代码中定义的 const currentPlan = subscription?.plan_id ?? "free" 被移除,但组件中 PageHeaddescription、按钮的 disabled 属性以及卡片的 className 判断逻辑中仍在使用 currentPlan 变量。
    • 后果:导致代码运行时直接报错 ReferenceError: currentPlan is not defined,页面无法渲染。
    • 修改建议:在组件内补充定义 const currentPlan = subscription?.plan_id ?? "free";
  2. apps/web/src/pages/subscription/constants.ts 第4行PLANS_META 缺少类型约束

    • 问题描述PLANS_META 定义使用了 Record<string, ...>,虽然文件顶部导入了 PlanType 类型,但未将其应用于键名。
    • 后果:失去了 TypeScript 的类型检查保护,后续若拼写错误(如 PLANS_META['stadnard'])只能在运行时发现(返回 undefined),无法在编译时报错。
    • 修改建议:将类型定义为 Record<PlanType, { name: string; price: number; yearlyPrice: number }>

💡 建议(1个可选)

  1. apps/web/src/pages/subscription/hooks/useSubscription.ts 第44行:移除未使用的函数 handleUpgrade
    • 具体内容:Hook 中定义并导出了 handleUpgrade 函数,但在 UpgradeSubscription.tsx 中并未引入或使用该函数,且组件内部已实现了类似的逻辑(handleUpgradeClick)。建议移除以减少代码体积和混淆。

格式检查通过 | 逻辑审查需修改 | 性能良好


🤖 由 AI 代码审查机器人自动生成 | 2026-07-27 01:52:38 | 模型:

## 代码审查结果 - PR #1020 ### ⚠️ 问题(2个需要修改) 1. **apps/web/src/pages/subscription/UpgradeSubscription.tsx 第74行**:变量 `currentPlan` 未定义 - **问题描述**:在重构过程中,原代码中定义的 `const currentPlan = subscription?.plan_id ?? "free"` 被移除,但组件中 `PageHead` 的 `description`、按钮的 `disabled` 属性以及卡片的 `className` 判断逻辑中仍在使用 `currentPlan` 变量。 - **后果**:导致代码运行时直接报错 `ReferenceError: currentPlan is not defined`,页面无法渲染。 - **修改建议**:在组件内补充定义 `const currentPlan = subscription?.plan_id ?? "free";`。 2. **apps/web/src/pages/subscription/constants.ts 第4行**:`PLANS_META` 缺少类型约束 - **问题描述**:`PLANS_META` 定义使用了 `Record<string, ...>`,虽然文件顶部导入了 `PlanType` 类型,但未将其应用于键名。 - **后果**:失去了 TypeScript 的类型检查保护,后续若拼写错误(如 `PLANS_META['stadnard']`)只能在运行时发现(返回 undefined),无法在编译时报错。 - **修改建议**:将类型定义为 `Record<PlanType, { name: string; price: number; yearlyPrice: number }>`。 ### 💡 建议(1个可选) 1. **apps/web/src/pages/subscription/hooks/useSubscription.ts 第44行**:移除未使用的函数 `handleUpgrade` - **具体内容**:Hook 中定义并导出了 `handleUpgrade` 函数,但在 `UpgradeSubscription.tsx` 中并未引入或使用该函数,且组件内部已实现了类似的逻辑(`handleUpgradeClick`)。建议移除以减少代码体积和混淆。 --- ✅ 格式检查通过 | ❌ 逻辑审查需修改 | ✅ 性能良好 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-27 01:52:38 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
Collaborator

Auto merge skipped after multiple 405 errors: PR may have conflicts or unresolved checks. Please review manually. This is not a CI failure.

Auto merge skipped after multiple 405 errors: PR may have conflicts or unresolved checks. Please review manually. This is not a CI failure.
xiaoxia added 1 commit 2026-07-27 12:34:16 +08:00
Merge branch 'develop' into refactor/upgrade-subscription-split
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 30s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m18s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m19s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 48s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 37s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 22s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 2m30s
AI Code Review / AI Code Review (pull_request) Successful in 46s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 59s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m12s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 4m36s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m39s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Successful in 29s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Successful in 6m55s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m36s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 28s
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
b0035849cb
xiaoxia closed this pull request 2026-07-27 15:26:29 +08:00

🗑️ 预览环境已清理

PR #1020 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #1020 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Some checks are pending
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 30s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m18s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m19s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 48s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 37s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 22s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 2m30s
AI Code Review / AI Code Review (pull_request) Successful in 46s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 59s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m12s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 4m36s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m39s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Successful in 29s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Successful in 6m55s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m36s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 28s
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped

Pull request closed

Sign in to join this conversation.