From 6fd357d78e3d24e8aae95300e63834211c8371bb Mon Sep 17 00:00:00 2001 From: Benny Joo Date: Tue, 31 Oct 2023 21:58:03 +0000 Subject: [PATCH 1/3] delete insights/layout --- .../app/future/(layout)/insights/layout.tsx | 38 ------------------- 1 file changed, 38 deletions(-) delete mode 100644 apps/web/app/future/(layout)/insights/layout.tsx diff --git a/apps/web/app/future/(layout)/insights/layout.tsx b/apps/web/app/future/(layout)/insights/layout.tsx deleted file mode 100644 index 59cde60a81d88d..00000000000000 --- a/apps/web/app/future/(layout)/insights/layout.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import { headers } from "next/headers"; -import { type ReactElement } from "react"; - -import { getFeatureFlagMap } from "@calcom/features/flags/server/utils"; - -import PageWrapper from "@components/PageWrapperAppDir"; - -type InsightsLayoutProps = { - children: ReactElement; -}; - -// If feature flag is disabled, return not found on getServerSideProps -export const getProps = async () => { - const prisma = await import("@calcom/prisma").then((mod) => mod.default); - const flags = await getFeatureFlagMap(prisma); - - if (flags.insights === false) { - return { - notFound: true, - }; - } - - return { - props: {}, - }; -}; - -export default async function InsightsLayout({ children }: InsightsLayoutProps) { - const h = headers(); - const nonce = h.get("x-nonce") ?? undefined; - const props = await getProps(); - - return ( - - {children} - - ); -} From 81ecfc94b051466a573fe087c042c03e1fc00dbf Mon Sep 17 00:00:00 2001 From: Benny Joo Date: Tue, 31 Oct 2023 22:02:47 +0000 Subject: [PATCH 2/3] rewrite WrapperWithLayout --- apps/web/app/future/(layout)/insights/page.tsx | 17 +++++++++++++++++ apps/web/app/future/(layout)/layout.tsx | 15 +++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/apps/web/app/future/(layout)/insights/page.tsx b/apps/web/app/future/(layout)/insights/page.tsx index d1a8e8f422bad7..8634e6358be9b6 100644 --- a/apps/web/app/future/(layout)/insights/page.tsx +++ b/apps/web/app/future/(layout)/insights/page.tsx @@ -1,6 +1,7 @@ import InsightsPage from "@pages/insights"; import { headers } from "next/headers"; +import { getFeatureFlagMap } from "@calcom/features/flags/server/utils"; import { constructGenericImage } from "@calcom/lib/OgImages"; import { IS_CALCOM, WEBAPP_URL, APP_NAME, SEO_IMG_OGIMG } from "@calcom/lib/constants"; import { getFixedT } from "@calcom/lib/server/getFixedT"; @@ -36,4 +37,20 @@ export const generateMetadata = async () => { }); }; +// If feature flag is disabled, return not found on getServerSideProps +export const getProps = async () => { + const prisma = await import("@calcom/prisma").then((mod) => mod.default); + const flags = await getFeatureFlagMap(prisma); + + if (flags.insights === false) { + return { + notFound: true, + }; + } + + return { + props: {}, + }; +}; + export default InsightsPage; diff --git a/apps/web/app/future/(layout)/layout.tsx b/apps/web/app/future/(layout)/layout.tsx index 7bf97ba3b72c13..6825d3633752b5 100644 --- a/apps/web/app/future/(layout)/layout.tsx +++ b/apps/web/app/future/(layout)/layout.tsx @@ -10,17 +10,20 @@ type WrapperWithLayoutProps = { children: ReactElement; }; +const handleGetProps = async (children: ReactElement) => { + const props = await import(`./${children.props.childProp.segment}/page.tsx`).then( + (mod) => mod.getProps?.() ?? null + ); + return props; +}; + export default async function WrapperWithLayout({ children }: WrapperWithLayoutProps) { const h = headers(); const nonce = h.get("x-nonce") ?? undefined; + const props = await handleGetProps(children); return ( - + {children} ); From d68295482eeea05c8cd2c0b55c3febc6306ab3c0 Mon Sep 17 00:00:00 2001 From: Benny Joo Date: Tue, 31 Oct 2023 22:25:15 +0000 Subject: [PATCH 3/3] finish --- apps/web/app/future/(layout)/insights/page.tsx | 5 ++++- apps/web/app/future/(layout)/layout.tsx | 11 +++++------ apps/web/app/future/(no-layout)/layout.tsx | 11 +++++++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/apps/web/app/future/(layout)/insights/page.tsx b/apps/web/app/future/(layout)/insights/page.tsx index 8634e6358be9b6..e8c2d63054e3b5 100644 --- a/apps/web/app/future/(layout)/insights/page.tsx +++ b/apps/web/app/future/(layout)/insights/page.tsx @@ -53,4 +53,7 @@ export const getProps = async () => { }; }; -export default InsightsPage; +export default function Insights(props: any) { + props.params.relativePath = "insights/page.tsx"; + return ; +} diff --git a/apps/web/app/future/(layout)/layout.tsx b/apps/web/app/future/(layout)/layout.tsx index 6825d3633752b5..4c9b76971cafa5 100644 --- a/apps/web/app/future/(layout)/layout.tsx +++ b/apps/web/app/future/(layout)/layout.tsx @@ -8,19 +8,18 @@ import PageWrapper from "@components/PageWrapperAppDir"; type WrapperWithLayoutProps = { children: ReactElement; + params: { [key: string]: any }; }; -const handleGetProps = async (children: ReactElement) => { - const props = await import(`./${children.props.childProp.segment}/page.tsx`).then( - (mod) => mod.getProps?.() ?? null - ); +const handleGetProps = async (relativePath: string) => { + const props = await import(`./${relativePath}`).then((mod) => mod.getProps?.() ?? null); return props; }; -export default async function WrapperWithLayout({ children }: WrapperWithLayoutProps) { +export default async function WrapperWithLayout({ children, params }: WrapperWithLayoutProps) { const h = headers(); const nonce = h.get("x-nonce") ?? undefined; - const props = await handleGetProps(children); + const props = await handleGetProps(params.relativePath); return ( diff --git a/apps/web/app/future/(no-layout)/layout.tsx b/apps/web/app/future/(no-layout)/layout.tsx index 72f8f82d0ca34a..25c745dbc947e4 100644 --- a/apps/web/app/future/(no-layout)/layout.tsx +++ b/apps/web/app/future/(no-layout)/layout.tsx @@ -6,11 +6,18 @@ import PageWrapper from "@components/PageWrapperAppDir"; type WrapperWithoutLayoutProps = { children: ReactElement; + params: { [key: string]: any }; }; -export default async function WrapperWithoutLayout({ children }: WrapperWithoutLayoutProps) { +const handleGetProps = async (relativePath: string) => { + const props = await import(`./${relativePath}`).then((mod) => mod.getProps?.() ?? null); + return props; +}; + +export default async function WrapperWithoutLayout({ children, params }: WrapperWithoutLayoutProps) { const h = headers(); const nonce = h.get("x-nonce") ?? undefined; + const props = await handleGetProps(params.relativePath); return ( + {...props}> {children} );