refactor(cron-management-panel): migrate 12 bare fetch to apiFetch#688
Open
jun261930-tech wants to merge 2 commits into
Open
refactor(cron-management-panel): migrate 12 bare fetch to apiFetch#688jun261930-tech wants to merge 2 commits into
jun261930-tech wants to merge 2 commits into
Conversation
P1 of MC code-quality plan (see PLAN.md / PR-api-client.md):
- src/lib/api-client.ts (+120) ApiError + apiFetch<T> wrapper
- src/lib/__tests__/api-client.test.ts (+108) 8 vitest cases (200/401/403/500/network/loop/204/no-redirect)
- src/components/auth-expired-listener.tsx (+30) global mc:auth-expired -> /login redirect
- src/app/layout.tsx (+2) register listener
- eslint.config.mjs (+31) no-restricted-syntax warn for bare fetch('/api/...')
Quality gates passed:
- pnpm vitest run src/lib/__tests__/api-client.test.ts: 8/8 (2.5s)
- pnpm typecheck: 0 error
- pnpm lint: 0 error, 343 warn (~baseline 334 bare fetch + 9 pre-existing)
Out of scope: migrating existing 334 bare fetch sites (P2, separate PR).
P0 verification: playwright captured 19/19 /api/* returning 200 after login,
ruling out backend issue (cookie expired) — see p0-network-evidence.txt.
Migrate all fetch('/api/...') calls in cron-management-panel.tsx and its
ClaudeCodeTeamsSection sub-component to apiFetch from @/lib/api-client.
Adopts global 401/403/5xx interceptor.
Calls migrated (12 total):
- loadCronJobs: GET /api/cron?action=list + GET /api/scheduler
- loadAvailableModels: GET /api/status?action=models
- cloneJob: POST /api/cron (auto-parse, no res.ok needed)
- loadRunHistory: GET /api/cron?{params}
- loadJobLogs: GET /api/cron?action=logs&job=...
- toggleJob: POST /api/cron (raw: keeps res.ok)
- triggerJob (local + cron branches): POST /api/scheduler + POST /api/cron
- addJob: POST /api/cron (raw: keeps res.ok)
- removeJob: POST /api/cron (raw: keeps res.ok)
- ClaudeCodeTeamsSection useEffect: GET /api/claude-tasks
(Promise chain converted to IIFE async/await)
Pattern:
- GET / POST that doesn't need res.ok: apiFetch<T>(url, { method, body })
- POST/PUT keeping res.ok semantics: apiFetch<Response>(url, { ..., raw: true })
- Promise chain .then().catch() -> IIFE async/await
Verification:
- pnpm typecheck: 0 errors
- pnpm lint: 0 errors, 331 warnings (343 -> 331, -12 matches migrated count)
Refs PR builderz-labs#681 (api-client base)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrate
src/components/panels/cron-management-panel.tsx(12 bare fetch calls) toapiFetch<T>()from@/lib/api-client, plus the embeddedClaudeCodeTeamsSectioncomponent.Calls Migrated (12 total)
Job listing & metadata:
GET /api/cron(loadCronJobs)GET /api/scheduler/status(scheduler health, parallel with loadCronJobs)GET /api/agents(availableModels selector)Job CRUD:
POST /api/cron(addJob — create)POST /api/cron(cloneJob — duplicate existing)PATCH /api/cron/:id(toggleJob enable/disable)DELETE /api/cron/:id(removeJob)Trigger (manual run):
POST /api/cron/:id/trigger— both branches (with/without payload override)Run history & logs:
GET /api/cron/:id/runs(loadRunHistory)GET /api/cron/:id/logs(loadJobLogs)ClaudeCodeTeamsSection:
GET /api/claude-code/teams(team list)Migration Pattern
apiFetch<T>(url)res.oksemantics:apiFetch<Response>(url, { method, headers, body, raw: true }).then().catch()→ IIFEasync () => { try {} catch {} finally {} }for the trigger handler (toast on failure preserved)Verification
pnpm typecheck→ 0 errorpnpm lint→ 0 error, 331 warnings (-12 vs baseline)vitest run src/lib/__tests__/api-client.test.ts→ 8/8 passRefs PR #681 (api-client base), PR #686 (settings-panel), and the multi-gateway-panel companion PR
Closes: task-11 P2.5 (cron-management-panel hotspot)