feat: add loading, error, not found page

This commit is contained in:
Sosokker 2024-11-03 00:39:13 +07:00
parent e29eeab868
commit e183d3ddeb
3 changed files with 64 additions and 0 deletions

19
src/app/error.tsx Normal file
View File

@ -0,0 +1,19 @@
"use client";
interface ErrorProps {
error: Error;
reset: () => void;
}
export default function Error({ error, reset }: ErrorProps) {
return (
<main className="flex justify-center items-center flex-col gap-6">
<h1 className="text-3xl font-semibold">Something went wrong!</h1>
<p className="text-lg">{error.message}</p>
<button className="inline-block bg-accent-500 text-primary-800 px-6 py-3 text-lg" onClick={reset}>
Try again
</button>
</main>
);
}

22
src/app/loading.tsx Normal file
View File

@ -0,0 +1,22 @@
export default function Loading() {
return (
<div className="container flex items-center justify-center h-screen">
<div className="text-center">
<svg
className="animate-spin h-12 w-12 text-gray-600 mx-auto mb-4"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291l-2.832 2.832A10.003 10.003 0 0112 22v-4a8.001 8.001 0 01-6-5.709z"
></path>
</svg>
<p className="text-lg font-semibold text-gray-600">Loading data...</p>
</div>
</div>
);
}

23
src/app/not-found.tsx Normal file
View File

@ -0,0 +1,23 @@
import Link from "next/link";
function NotFound() {
return (
<main className="flex flex-col items-center justify-center min-h-screen bg-gray-100 text-gray-800 dark:bg-gray-900 dark:text-gray-200">
<div className="max-w-md text-center p-6 bg-white rounded-lg shadow-lg dark:bg-gray-800">
<h1 className="text-4xl font-bold mb-4">404</h1>
<h2 className="text-2xl font-semibold mb-4">This page could not be found :(</h2>
<p className="mb-6 text-gray-600 dark:text-gray-400">
Sorry, the page you are looking for does not exist or has been moved.
</p>
<Link
href="/"
className="inline-block bg-accent-500 text-primary-800 px-8 py-4 text-lg font-medium rounded transition duration-200 hover:bg-accent-600 dark:bg-accent-400 dark:text-primary-800 dark:hover:bg-accent-500"
>
Go back home
</Link>
</div>
</main>
);
}
export default NotFound;