feat(web): add loading skeletons, error boundaries, and accessibility improvements

- Add segment-level loading.tsx for dashboard, search, admin, and auth routes
- Add segment-level error.tsx with Vietnamese error messages for all route groups
- Add skip-to-content navigation link in root layout
- Add id="main-content" to all layout main elements
- Add aria-label to nav elements and mobile menu buttons
- Improve dashboard nav responsiveness (icon-only on mobile)
- Hide user name on small screens in dashboard layout

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-08 13:48:33 +07:00
parent 400a75845c
commit a590a41e73
13 changed files with 498 additions and 13 deletions

View File

@@ -0,0 +1,58 @@
'use client';
import { useEffect } from 'react';
export default function AdminError({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
useEffect(() => {
console.error('Admin error:', error);
}, [error]);
return (
<div className="flex min-h-[400px] flex-col items-center justify-center px-4">
<div className="mx-auto max-w-md text-center">
<div className="mx-auto flex h-14 w-14 items-center justify-center rounded-full bg-destructive/10">
<svg
className="h-7 w-7 text-destructive"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"
/>
</svg>
</div>
<h2 className="mt-4 text-xl font-semibold">Lỗi trang quản trị</h2>
<p className="mt-2 text-sm text-muted-foreground">
Không thể tải trang quản trị. Vui lòng thử lại sau.
</p>
{error.digest && (
<p className="mt-1 text-xs text-muted-foreground"> lỗi: {error.digest}</p>
)}
<div className="mt-6 flex justify-center gap-3">
<button
onClick={reset}
className="inline-flex h-9 items-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground shadow transition-colors hover:bg-primary/90"
>
Thử lại
</button>
<a
href="/admin"
className="inline-flex h-9 items-center rounded-md border border-input bg-background px-4 text-sm font-medium shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground"
>
Tải lại trang
</a>
</div>
</div>
</div>
);
}

View File

@@ -72,6 +72,7 @@ export default function AdminLayout({ children }: { children: React.ReactNode })
</span>
</Link>
<button
aria-label="Đóng menu"
className="ml-auto lg:hidden"
onClick={() => setSidebarOpen(false)}
>
@@ -79,7 +80,7 @@ export default function AdminLayout({ children }: { children: React.ReactNode })
</button>
</div>
<nav className="flex flex-col gap-1 p-3">
<nav aria-label="Quản trị" className="flex flex-col gap-1 p-3">
{adminNavItems.map((item) => {
const Icon = item.icon;
const isActive =
@@ -124,13 +125,13 @@ export default function AdminLayout({ children }: { children: React.ReactNode })
{/* Main content */}
<div className="flex flex-1 flex-col">
<header className="sticky top-0 z-30 flex h-14 items-center border-b bg-background/95 px-4 backdrop-blur lg:hidden">
<button onClick={() => setSidebarOpen(true)}>
<button aria-label="Mở menu" onClick={() => setSidebarOpen(true)}>
<Menu className="h-5 w-5" />
</button>
<span className="ml-3 text-sm font-semibold">GoodGo Admin</span>
</header>
<main className="flex-1 p-4 md:p-6">{children}</main>
<main id="main-content" className="flex-1 p-4 md:p-6">{children}</main>
</div>
</div>
);

View File

@@ -0,0 +1,60 @@
export default function AdminLoading() {
return (
<div className="space-y-6">
{/* Header skeleton */}
<div className="flex items-center justify-between">
<div>
<div className="h-7 w-36 animate-pulse rounded bg-muted" />
<div className="mt-2 h-4 w-48 animate-pulse rounded bg-muted" />
</div>
<div className="h-9 w-24 animate-pulse rounded-md bg-muted" />
</div>
{/* Stats grid skeleton */}
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
{Array.from({ length: 4 }).map((_, i) => (
<div key={i} className="rounded-lg border bg-card p-6 shadow-sm">
<div className="flex items-center justify-between">
<div className="h-4 w-24 animate-pulse rounded bg-muted" />
<div className="h-4 w-4 animate-pulse rounded bg-muted" />
</div>
<div className="mt-3 h-7 w-20 animate-pulse rounded bg-muted" />
<div className="mt-2 h-3 w-28 animate-pulse rounded bg-muted" />
</div>
))}
</div>
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
{Array.from({ length: 3 }).map((_, i) => (
<div key={i} className="rounded-lg border bg-card p-6 shadow-sm">
<div className="flex items-center justify-between">
<div className="h-4 w-24 animate-pulse rounded bg-muted" />
<div className="h-4 w-4 animate-pulse rounded bg-muted" />
</div>
<div className="mt-3 h-7 w-20 animate-pulse rounded bg-muted" />
</div>
))}
</div>
{/* Revenue chart skeleton */}
<div className="rounded-lg border bg-card shadow-sm">
<div className="p-6">
<div className="h-5 w-48 animate-pulse rounded bg-muted" />
</div>
<div className="px-6 pb-6">
<div className="space-y-4">
{Array.from({ length: 6 }).map((_, i) => (
<div key={i} className="space-y-2">
<div className="flex items-center justify-between">
<div className="h-3 w-20 animate-pulse rounded bg-muted" />
<div className="h-3 w-28 animate-pulse rounded bg-muted" />
</div>
<div className="h-2 w-full animate-pulse rounded-full bg-muted" />
</div>
))}
</div>
</div>
</div>
</div>
);
}