Skip to content

Commit 4478c8e

Browse files
committed
Unpublished product's page redirects to notFound
1 parent 7262c00 commit 4478c8e

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

apps/web/app/(with-contexts)/(with-layout)/p/[id]/page.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ClientSidePage from "./client-side-page";
44
import { headers } from "next/headers";
55
import type { Metadata, ResolvingMetadata } from "next";
66
import { Media } from "@courselit/common-models";
7+
import { notFound } from "next/navigation";
78

89
type Props = {
910
params: {
@@ -26,7 +27,13 @@ export async function generateMetadata(
2627
};
2728
}
2829

29-
const title = page.title || page.pageData?.title || page.name;
30+
if (!page) {
31+
return {
32+
title: "Page not found",
33+
};
34+
}
35+
36+
const title = page?.title || page.pageData?.title || page.name;
3037
const socialImage: Media | undefined =
3138
page.socialImage ||
3239
(page.pageData?.featuredImage as Media) ||
@@ -76,6 +83,10 @@ export default async function Page({ params }: Props) {
7683
return null;
7784
}
7885

86+
if (!page) {
87+
return notFound();
88+
}
89+
7990
return (
8091
<ClientSidePage
8192
page={page}

apps/web/app/(with-contexts)/dashboard/(sidebar)/product/[id]/page.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,14 @@ export default function DashboardPage() {
193193
</DropdownMenuTrigger>
194194
<DropdownMenuContent align="end">
195195
<DropdownMenuItem asChild>
196-
<Link href={`/p/${product?.pageId}`}>
196+
<a
197+
href={`/p/${encodeURIComponent(product?.pageId!)}`}
198+
target="_blank"
199+
rel="noopener noreferrer"
200+
>
197201
<Eye className="mr-2 h-4 w-4" />
198202
{VIEW_PAGE_MENU_ITEM}
199-
</Link>
203+
</a>
200204
</DropdownMenuItem>
201205
<DropdownMenuSeparator />
202206
<DropdownMenuItem asChild>

apps/web/ui-lib/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ type FrontEndPage = Pick<
8686
export const getPage = async (
8787
backend: string,
8888
id?: string,
89-
): Promise<FrontEndPage> => {
89+
): Promise<FrontEndPage | null> => {
9090
const query = id
9191
? `
9292
query {
@@ -133,7 +133,7 @@ export const getPage = async (
133133
} catch (e: any) {
134134
console.log("getPage", e.message); // eslint-disable-line no-console
135135
}
136-
return undefined as unknown as Page;
136+
return null;
137137
};
138138

139139
export const getSiteInfo = async (

0 commit comments

Comments
 (0)