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:
58
apps/web/app/(auth)/error.tsx
Normal file
58
apps/web/app/(auth)/error.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export default function AuthError({
|
||||
error,
|
||||
reset,
|
||||
}: {
|
||||
error: Error & { digest?: string };
|
||||
reset: () => void;
|
||||
}) {
|
||||
useEffect(() => {
|
||||
console.error('Auth error:', error);
|
||||
}, [error]);
|
||||
|
||||
return (
|
||||
<div className="rounded-lg border bg-card p-8 shadow-sm">
|
||||
<div className="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 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<h2 className="mt-4 text-xl font-semibold">Lỗi xác thực</h2>
|
||||
<p className="mt-2 text-sm text-muted-foreground">
|
||||
Đã xảy ra lỗi trong quá trình xác thực. Vui lòng thử lại.
|
||||
</p>
|
||||
{error.digest && (
|
||||
<p className="mt-1 text-xs text-muted-foreground">Mã 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="/login"
|
||||
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"
|
||||
>
|
||||
Về trang đăng nhập
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
export default function AuthLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-muted/40 px-4 py-12">
|
||||
<main id="main-content" className="flex min-h-screen items-center justify-center bg-muted/40 px-4 py-12">
|
||||
<div className="w-full max-w-md">{children}</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
40
apps/web/app/(auth)/loading.tsx
Normal file
40
apps/web/app/(auth)/loading.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
export default function AuthLoading() {
|
||||
return (
|
||||
<div className="rounded-lg border bg-card p-8 shadow-sm">
|
||||
<div className="space-y-6">
|
||||
{/* Logo / title skeleton */}
|
||||
<div className="text-center">
|
||||
<div className="mx-auto h-8 w-24 animate-pulse rounded bg-muted" />
|
||||
<div className="mx-auto mt-3 h-5 w-40 animate-pulse rounded bg-muted" />
|
||||
<div className="mx-auto mt-2 h-4 w-56 animate-pulse rounded bg-muted" />
|
||||
</div>
|
||||
|
||||
{/* Form fields skeleton */}
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<div className="h-4 w-16 animate-pulse rounded bg-muted" />
|
||||
<div className="mt-2 h-10 w-full animate-pulse rounded-md bg-muted" />
|
||||
</div>
|
||||
<div>
|
||||
<div className="h-4 w-20 animate-pulse rounded bg-muted" />
|
||||
<div className="mt-2 h-10 w-full animate-pulse rounded-md bg-muted" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Submit button skeleton */}
|
||||
<div className="h-10 w-full animate-pulse rounded-md bg-muted" />
|
||||
|
||||
{/* OAuth buttons skeleton */}
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-px flex-1 bg-muted" />
|
||||
<div className="h-3 w-12 animate-pulse rounded bg-muted" />
|
||||
<div className="h-px flex-1 bg-muted" />
|
||||
</div>
|
||||
<div className="h-10 w-full animate-pulse rounded-md bg-muted" />
|
||||
<div className="h-10 w-full animate-pulse rounded-md bg-muted" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user