From 9ae3a0eabafa330924ffb522bc5f3ff3d918ca2c Mon Sep 17 00:00:00 2001 From: Leo Giovanetti Date: Mon, 19 Sep 2022 12:03:50 +0200 Subject: [PATCH] Fixing installed app navigation (#4595) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../pages/v2/apps/installed/[category].tsx | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/apps/web/pages/v2/apps/installed/[category].tsx b/apps/web/pages/v2/apps/installed/[category].tsx index cca605e990..a9c85eff34 100644 --- a/apps/web/pages/v2/apps/installed/[category].tsx +++ b/apps/web/pages/v2/apps/installed/[category].tsx @@ -1,4 +1,4 @@ -import { useRouter } from "next/router"; +import { GetStaticPaths, GetStaticProps, InferGetStaticPropsType } from "next"; import z from "zod"; import { InstallAppButton } from "@calcom/app-store/components"; @@ -177,12 +177,8 @@ const querySchema = z.object({ category: z.nativeEnum(InstalledAppVariants), }); -export default function InstalledApps() { +export default function InstalledApps({ category }: InferGetStaticPropsType) { const { t } = useLocale(); - const router = useRouter(); - const { category } = router.isReady - ? querySchema.parse(router.query) - : { category: InstalledAppVariants.calendar as const }; return ( @@ -202,3 +198,25 @@ export default function InstalledApps() { ); } + +export const getStaticProps: GetStaticProps = (ctx) => { + const params = querySchema.safeParse(ctx.params); + + if (!params.success) return { notFound: true }; + + return { + props: { + category: params.data.category, + }, + }; +}; + +export const getStaticPaths: GetStaticPaths = () => { + return { + paths: Object.values(InstalledAppVariants).map((category) => ({ + params: { category }, + locale: "en", + })), + fallback: "blocking", + }; +};