Skip to content

前端:邮件设置卡片新增「发送测试邮件」 - #133

Merged
todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a14ec8-3f54-79ac-8cde-9aaab8b4eb1a
Oct 18, 2026
Merged

todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a14ec8-3f54-79ac-8cde-9aaab8b4eb1a

Conversation

@todosdev

@todosdev todosdev Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • 管理后台「邮件设置」卡片新增「发送测试邮件」区,让管理员在保存 SMTP/Resend 配置后即时验证邮件能否发出。
  • 新增 adminApi.sendTestEmail(to) 调用 POST /api/admin/email/test,并按状态码(400/429/502)展示可读的错误提示。
  • 文案全部走 i18n(en / zh-CN),并新增 node --test 单测覆盖请求、错误映射与文案 key。

Changes

  • apps/web/src/api/client.ts — adminApi 增加 sendTestEmail(to),body { to },返回 { success: boolean }。
  • apps/web/src/pages/admin/AdminSettingsPage.tsx — 在「保存」按钮下方新增测试区:收件地址输入框(默认填入 useAuth().user.email,用 useRef 只预填一次)、「发送测试邮件」按钮(type="button",发送中 loading 并禁用)、成功用 toast.success 绿色提示、失败内联红色文案(复用「检查并升级数据库」的内联报错风格)。
  • apps/web/src/lib/testEmail.ts(新增)— 纯函数 resolveTestEmailError / formatTestEmailError:400 → 配置/地址问题、429 → 过于频繁(插值 Retry-After 秒数)、502 → 发送失败、其余 → 通用失败;会话过期返回 null 由 AuthProvider 统一提示。
  • apps/web/src/i18n/locales/en.ts / zh-CN.ts — 新增 8 个 admin.* key,无硬编码中文。
  • apps/web/src/lib/testEmail.test.ts(新增)+ apps/web/package.json — 单测纳入 pnpm test,覆盖请求/响应(stub fetch)、429/502 错误映射、两套 locale key 非空。

Testing

  • pnpm check(biome)、pnpm typecheck、pnpm build、pnpm test(54 项全部通过)。

注:依赖后端并行任务实现的 POST /api/admin/email/test;后端未就绪时前端会落入通用失败文案。

- add adminApi.sendTestEmail calling POST /api/admin/email/test
- add a test-email section under the save button, prefilled with the
  admin's email, with loading and status-based error messages
- extract pure error mapping into lib/testEmail.ts and cover it with
  node --test cases alongside new i18n keys in en and zh-CN

Checkpoint: jFaLA3kQxhfrG-jNW0mPh
@todosdev
todosdev Bot merged commit f6671e8 into main Oct 18, 2026
4 checks passed
@mapxn
mapxn deleted the tds/conv-01a14ec8-3f54-79ac-8cde-9aaab8b4eb1a branch November 8, 2026 11:30
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.

0 participants