Skip to content

feat(default): mode-picker dialog before Create API Key drawer - #2

Merged
hades217 merged 2 commits into
mainfrom
feat/api-key-mode-picker-dialog
May 16, 2026
Merged

feat(default): mode-picker dialog before Create API Key drawer#2
hades217 merged 2 commits into
mainfrom
feat/api-key-mode-picker-dialog

Conversation

@hades217

Copy link
Copy Markdown

Summary

  • 把 Simple/Advanced 切换从 drawer 顶部的 Tabs 改成创建前的小弹窗(两张大卡:💫 Simple — 推荐 / ⚙️ Advanced)
  • "+ Create" 按钮和空状态 CTA 现在先开弹窗,用户点哪张卡就以哪个 mode 打开 drawer
  • Drawer 头部仍有一个低调的 "Switch to {Simple/Advanced}" 链接,点了重新打开 picker(drawer 不关,react-hook-form 状态保留,切换 mode 不丢值)
  • 删掉之前 drawer body 顶部的 Tabs 那一坨
  • 删了不再用的 use-api-key-form-mode.ts hook,统一用 lib/api-key-form.ts 里的 loadPreferredMode / savePreferredMode

背景

原来 Simple/Advanced 是 drawer 顶部的 Tabs,用户一打开看到两个 tab 不知道是啥。改成弹窗先问一下"你想怎么建?"——两张卡片各带描述,对小白更友好。

Test plan

  • bun run typecheck 通过
  • 点 "+ Create" 出弹窗,选 Simple → drawer 在 Simple 模式打开
  • 选 Advanced → drawer 在 Advanced 模式打开
  • Drawer 头部点 "Switch to ..." → 弹窗再次出现,能切换
  • 切换 mode 后已填字段不丢
  • 空状态 "Get Started" 按钮也走同一个弹窗
  • 编辑已有 key 时弹窗 NOT 出现(直接 drawer,按 detectAdvancedMode 推断 mode)
  • localStorage 记住上次 mode,下次默认那一档

文件

  • 新增 api-key-mode-picker-dialog.tsx
  • api-keys-dialogs.tsxapi-keys-mutate-drawer.tsxapi-keys-primary-buttons.tsxapi-keys-table.tsxtypes.ts
  • hooks/use-api-key-form-mode.ts

🤖 Generated with Claude Code

hades217 and others added 2 commits May 16, 2026 16:57
User-facing: clicking "Create API Key" now shows a small dialog that asks
"Simple or Advanced?" with two large clickable cards explaining each
mode, instead of putting a Tabs toggle inside the drawer header. Cleaner
first-impression for the 90% of users who don't know what the modes mean.

- New ApiKeyModePickerDialog (2 cards: Simple recommended / Advanced)
- New ApiKeysDialogType 'mode-picker'
- "+ Create" button and empty-state CTA both open the picker first
- Picker persists choice via savePreferredMode() then setOpen('create')
- Drawer SheetHeader now shows the chosen mode + a discreet
  "Switch to {other}" link that re-opens the picker (drawer-state stays
  in form so toggling mid-flow doesn't lose typed values)
- Removed the Tabs toggle that lived inside the drawer body
- Removed unused use-api-key-form-mode hook (lib's load/save
  PreferredMode is the canonical mode-persistence path)

Update flow is unchanged: the picker only triggers for create, edit
still infers the right mode from the token's actual state via
detectAdvancedMode().

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Re-applies PRD §4.1 Simple-mode UI that a prior refactor had stripped to
"hide a few Advanced fields", and fixes adjacent end-user-facing ratio /
group leaks. All changes are additive to the mode-picker dialog flow
introduced in this branch.

Restore PRD §4.1 Simple body:
- ApiKeyPurposePicker (6 cards: 💬 Chat / 💻 Coding / 🎨 Image /
  🎬 Video / 🎙️ Voice / ⚡ All-Auto) is back in the drawer
- ApiKeyBrandFilter (Claude / OpenAI / Gemini / DeepSeek chips, optional)
- ApiKeyPriceTier (4 tiers, Standard default, Ultra requires confirm)
  when purpose = "all"
- ApiKeySuccessDialog on Simple-mode single-key create — reveals key +
  base URL + recommended model name + 6 client-tutorial chips

Backend-fallback for the picker:
- New lib/api-key-purposes-fallback.ts mirrors
  setting/alias_setting/seed/aliases.yaml as hardcoded constants
- getApiKeyPurposes() now falls through to the fallback when the Go
  backend hasn't shipped /api/user/self/api-key-purposes yet (binary
  needs rebuild) — frontend works regardless

End-user ratio / group hides:
- Hide the "用户分组" column from the /keys table for non-admin users
  (admin still sees it via the usual isAdmin >= 10 gate). The 1.2x /
  5x markup badge that was rendering next to user keys was leaking
  pricing internals to customers — same problem PR #0 fixed for the
  Create form, now resolved at the table too
- "Allowed models" promoted out of the Advanced Settings Collapsible
  into its own main-area section. The old "Model Limits" label was
  technical and buried — non-tech users couldn't find where to pick
  e.g. DeepSeek. Now it's a labelled section with a clear placeholder
  and a live count description

Other:
- Pin dev server to port 17231 in rsbuild.config.ts. 3000/3001/4200/
  5173/8000/8080 routinely collide with other Node/Vite/Next dev
  servers; 17231 is uncommon enough to own across dev boxes
- i18n: 5 new en + zh keys for the renamed model-limits section

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant