Admin Portal M2: /admin shell, guard, dashboard (Issue #1254) - #1
Closed
Veekshitha11 wants to merge 1 commit into
Closed
Conversation
…1254, M2)
Admin Portal v1, Milestone 2 (the /admin shell, guarded, empty) — frontend.
/admin renders an admin-only sidebar shell for platform admins; non-admins
never see it and are bounced. Dashboard shows real total-orgs / total-users.
- components/client-layout.tsx: new /admin pathname branch ->
<AuthGuard><AdminGuard><AdminLayout>{children}</AdminLayout></AdminGuard></AuthGuard>.
AdminGuard sits inside AuthGuard so children only evaluate once authenticated.
- components/admin/AdminGuard.tsx: client access gate. Reads is_platform_admin
straight from the /currentuserv2 SWR data (shared cache key, no extra request,
no store-hydration race). While that data resolves it shows a loading state —
never a flash of the shell before redirecting a non-admin to '/'.
- components/admin/AdminLayout.tsx: admin sidebar. Home is live; Organizations is
disabled ONLY until M3 (TODO(M3) in-code); Notifications + Feature Flags are
deferred features (plan.md "Later").
- components/admin/ComingSoonBadge.tsx: one shared "coming soon" placeholder
(badge + dim) used by BOTH the sidebar and the dashboard cards, so the two
surfaces read as one deliberate pattern rather than two half-finished features.
- app/admin/page.tsx: dashboard. Total Orgs + Total Users are real (from
/api/v1/admin/stats); Notifications Sent + Feature Flags ON are placeholders.
- components/main-layout.tsx: "Admin Portal" nav item gated hide:!isPlatformAdmin
(via useUserPermissions); getNavItems exported for unit testing.
- hooks/api/useAdminPortal.ts: useAdminStats() SWR hook -> /api/v1/admin/stats.
Tests (Jest + Playwright):
- components/admin/__tests__/AdminGuard.test.tsx: loading -> no redirect/spinner;
non-admin -> router.replace('/'); admin -> renders shell. (3)
- components/__tests__/getNavItems.test.ts: Admin Portal link hidden when not a
platform admin, shown when one, hidden by default. (3)
- e2e/admin-portal.spec.ts: non-admin bounced from /admin (Playwright; skips
without E2E_NONADMIN creds + a running server, per login.spec.ts convention).
- Jest: 6 passed. tsc: no new errors. prettier: clean.
Stacked on feature/admin-portal-m1-platform-admin-gate (needs M1's is_platform_admin).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Milestone 2 of the Admin Portal plan (features/admin-portal/v1/plan.md) -- the /admin route shell: AdminGuard (with explicit loading state to avoid a flash-of-sidebar race), AdminLayout sidebar, Admin Portal nav link, and the dashboard with real Total Orgs/Total Users counts. Notifications/Feature Flags cards are 'coming soon' placeholders per plan.md; Organizations sidebar link is a temporary placeholder until M3. Stacked on DalgoT4D#342 (M1) -- base branch is feature/admin-portal-m1-platform-admin-gate, not main, until M1 merges. 6/6 Jest passing, Playwright e2e spec included (requires seeded creds, skips otherwise).