Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Feature: 404 page (#946)

Shrikrishna Joisafaf71d2edf0e
diff --git a/apps/web/src/app/[locale]/not-found.tsx b/apps/web/src/app/[locale]/not-found.tsx
index 6abb7be9..7d8a32af 100644
--- a/apps/web/src/app/[locale]/not-found.tsx
+++ b/apps/web/src/app/[locale]/not-found.tsx
@@ -1,8 +1,48 @@
-export default function NotFound() {
+import { Button } from '@repo/ui/components/button';
+import { BackgroundGrid } from './_components/hero-illustration';
+import { getRandomChallenge } from '~/utils/server/get-random-challenge';
+
+export default async function NotFound() {
+ const randomChallengeSlug = await getRandomChallenge();
+
return (
- <div className="flex h-screen flex-col items-center justify-center">
- <h1 className="text-4xl font-bold">404</h1>
- <p className="text-2xl">The page you are looking for is in another castle</p>
+ <div className="flex h-full flex-col items-center justify-center gap-8">
+ <div className="absolute inset-10 -z-30 overflow-hidden rounded-full opacity-70 lg:hidden">
+ <BackgroundGrid />
+ </div>
+ <div className="flex flex-col items-center justify-center">
+ <h1 className="font-mono text-9xl font-bold leading-tight md:text-[12rem]">404</h1>
+ <p className=" px-6 text-center font-mono text-base md:px-0 md:text-xl">
+ Looks Like You Took a Wrong Turn at the Interface. <br className="hidden md:inline" />
+ Let's Get You Back on Track
+ </p>
+ </div>
+ {randomChallengeSlug !== null ? (
+ <div className="flex gap-4 ">
+ <a href="/explore">
+ <Button variant="default" size="lg">
+ Go to explore
+ </Button>
+ </a>
+ <a href={`/challenge/${randomChallengeSlug}`}>
+ <Button
+ variant="outline"
+ size="lg"
+ className="fancy-border-gradient hover:bg-background relative mx-auto flex gap-4 border-none"
+ >
+ I'm feeling lucky
+ </Button>
+ </a>
+ </div>
+ ) : (
+ <div>
+ <a href="/">
+ <Button variant="default" size="lg">
+ Go to home
+ </Button>
+ </a>
+ </div>
+ )}
</div>
);
}
diff --git a/apps/web/src/utils/server/get-random-challenge.ts b/apps/web/src/utils/server/get-random-challenge.ts
new file mode 100644
index 00000000..1db1cb42
--- /dev/null
+++ b/apps/web/src/utils/server/get-random-challenge.ts
@@ -0,0 +1,17 @@
+'use server';
+import { prisma } from '@repo/db';
+
+interface resultType {
+ slug: string;
+}
+
+export async function getRandomChallenge() {
+ const result: resultType[] =
+ await prisma.$queryRaw`SELECT slug FROM Challenge ORDER BY RAND() LIMIT 1`;
+
+ if (result.length > 0 && result[0] && Boolean(result[0].slug)) {
+ return result[0].slug;
+ }
+
+ return null;
+}