Skip to content

Commit

Permalink
feat(page): add 404 error message
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Sep 5, 2024
1 parent 9a233ae commit 7c5dc5e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/app/(main)/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Metadata } from "next";
import { redirect } from "next/navigation";
import { Blog } from "src/blog/Blog";
import BlogPreview from "src/blog/BlogPreview";
import Compensations from "src/compensations/Compensations";
Expand All @@ -17,6 +16,8 @@ import {
} from "studio/lib/queries/pages";
import { loadQuery } from "studio/lib/store";
import CompensationsPreview from "src/compensations/CompensationsPreview";
import { homeLink } from "../../../blog/components/utils/linkTypes";
import CustomErrorMessage from "../../../blog/components/customErrorMessage/CustomErrorMessage";

export const dynamic = "force-dynamic";

Expand All @@ -32,6 +33,14 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
return generateMetadataFromSeo(seo);
}

const Page404 = (
<CustomErrorMessage
title="404 — Something went wrong"
body="The page you are looking for does not exist. There may be an error in the URL, or the page may have been moved or deleted."
link={homeLink}
/>
);

async function Page({ params }: Props) {
const { slug } = params;
const { perspective, isDraftMode } = getDraftModeInfo();
Expand Down Expand Up @@ -64,7 +73,6 @@ async function Page({ params }: Props) {
);
}

// TODO: fix error for when initialBlogPage.data is empty (say slug doesn't exists)
if (initialBlogPage.data) {
const initialPosts = await loadQuery<Post[]>(
POSTS_QUERY,
Expand All @@ -73,8 +81,7 @@ async function Page({ params }: Props) {
);

if (!initialPosts) {
console.log(`Posts for page: ${slug} not found`);
// TODO: ADD ERROR PAGE
return Page404;
}

return isDraftMode ? (
Expand All @@ -100,9 +107,7 @@ async function Page({ params }: Props) {
);
}

console.log(`Page ${slug} not found`);
// TODO: add error snackbar
redirect("/");
return Page404;
}

export default Page;

0 comments on commit 7c5dc5e

Please sign in to comment.