feat: error boundary, empty state, jwt interceptors, protected routes , admin shell#128
Merged
Merged
Conversation
|
@Ogstevyn Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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
Closes #8,
closes #11,
closes #12,
closes #16
This PR implements four foundational frontend features following the strict Component → Hook → Service layered architecture throughout.
#8 — Empty State & Error Boundary
components/ui/EmptyState.tsxReusable component accepting a Lucide icon, title, optional description, and an optional CTA action callback. Designed to be dropped into any list view that may return zero results.
app/error.tsxNext.js App Router global error boundary (Client Component). Catches render errors anywhere in the component tree, logs them to the console, and renders a full-screen recovery UI with a "Try again" button that calls
reset()to re-render the failed segment.#11 — JWT Axios Interceptor Setup
lib/api.tsSingleton Axios instance configured with two interceptors:
authTokenfromlocalStorageand injects it asAuthorization: Bearer <token>on every outgoing request.401 Unauthorizedresponses, removes the stale token from storage, and redirects the browser to/login.services/auth.service.tsThin auth service built on top of
lib/api.ts. Exposeslogin,logout, andgetCurrentUser— all requests automatically carry the bearer token via the shared interceptor. Imports shared types from the existingservices/authService.tsto avoid duplication.#12 — Protected Route Wrapper
hooks/useAuth.tsOn mount, reads
authTokenfromlocalStorage. If present, callsGET /auth/mevia the interceptor-enabled client to verify the token and populate the ZustandauthStore. On 401 or missing token, clears the store. Returns{ isAuthenticated, isLoading, user }.components/auth/ProtectedRoute.tsxClient component wrapper that:
useAuthresolves./loginviarouter.replace./.childrenonly when auth and role checks pass.Accepts an optional
requiredRoleprop for role-gated pages.#16 — Admin Dashboard Shell
services/adminService.tsService that calls
GET /admin/stats(via the JWT-bearinglib/api.tsclient) and returns platform-wide metrics: total users, active deliveries, revenue, active drivers, pending KYC, and escrow locked.hooks/useAdminDashboard.tsTanStack Query hook wrapping
adminService.getStats(). Caches for 30 seconds, retries once on failure, exposes{ stats, isLoading, isError, refetch }.components/admin/AdminSidebar.tsxFixed 256 px sidebar exclusively for admin pages. Contains navigation links (Overview, Users, Deliveries, KYC Review, Settings) with active-path highlighting and a sign-out button that clears the auth store and redirects to
/login. Completely separate from the standardAppLayoutsidebar.app/(admin)/layout.tsxRoute-group layout wrapping all pages under
(admin)/withProtectedRoute requiredRole="Admin". Admins who are not authenticated are redirected to/login; authenticated non-admins are redirected to/. RendersAdminSidebar+ a<main>content area.app/(admin)/admin/overview/page.tsx→ URL:/admin/overviewAdmin overview page with six metric cards (Total Users, Active Deliveries, Total Revenue, Active Drivers, Pending KYC, Escrow Locked). Shows skeleton loaders while data is in flight and a dismissible error banner on fetch failure. Data is sourced from the backend API via
useAdminDashboard.app/(dashboard)/admin/page.tsx— updated toredirect('/admin/overview')so legacy/adminlinks forward to the new isolated admin shell.middleware.ts— updated to redirect unauthenticated requests to/loginfor both/dashboard/*and/admin/*routes.