refactor(admin): consolidate fetch state machines into useApiResource#41
Merged
Merged
Conversation
…ub-project plan) Records the Next.js 16.2.4 research conclusions (PPR/cacheComponents and server-side streaming do not fit the current all-client-fetch + host-only cross-origin cookie architecture) and decomposes the work into three sequenced sub-projects: (1) client data-layer consolidation, (2) resilience + instant shell, (3) server-side data (BFF vs cross-subdomain cookie — its own design). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Shared read-only data primitives to consolidate admin's duplicated fetch
state machines:
- useApiResource<T>(path, {enabled}) — idle|loading|ok|error + reload(),
refetches when `path` changes (query string drives search/filter/page),
with the cancellation guard lifted from participant-detail-sheet.
Mutations are out of scope (read-only).
- DataError — the destructive Alert used for fetch errors.
- EmptyState — the centered "no results" placeholder (non-table).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replace the duplicated {loading|ok|error} useEffect+apiJson state
machines across the dashboard, participants, stats, mentors,
pre-registrations and the participant detail sheet with the shared
useApiResource hook, and the inline error Alerts / empty blocks with
DataError / EmptyState.
- Query-param-driven pages build the path (date / search+filter+page /
date-range) and rely on refetch-on-path-change; the refresh button and
post-mutation callbacks call reload().
- Mutation callbacks become () => void (reload is fire-and-forget); the
POST/PATCH/DELETE calls still use apiJson/apiFetch directly.
No UI/behavior change. Verified: load, reload, search refetch, detail
sheet, and DataError/EmptyState states all render as before.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Sub-project 1(データ層モダナイゼーション)。admin で 6 箇所に重複していた取得+状態機械を共通フックに集約する純粋リファクタ。UI・挙動は不変。
変更
@tecnova/uiにuseApiResource<T>(path, {enabled})(idle/loading/ok/error+reload()、path 変化で再取得、participant-detail-sheetの cancel ガードを踏襲、読み取り専用)+DataError/EmptyState。DataError、空ブロック →EmptyState。reload()。ミューテーション callback は() => void化(POST/PATCH/DELETE は従来どおりapiJson/apiFetch)。検証
reload()(更新)・検索での再取得(path 変化→一覧更新)・詳細シート・DataError(500+サーバ文言)・EmptyStateを実機確認。ハイドレーション警告なし。stacked PR
feat/admin-ui-responsive(#40)の上に積んでいる。#40 をマージ後、本PRは develop へ自動リターゲットされる(マージ順: #40 → 本PR → SP2)。🤖 Generated with Claude Code