From 61b8785569d37ed2cf1911f6c728e4b569ed462d Mon Sep 17 00:00:00 2001 From: Benny Joo Date: Tue, 28 Nov 2023 15:01:36 +0000 Subject: [PATCH] manual: refactor and add metadata title/description --- .../insights/page.tsx | 31 +++++---- apps/web/pages/insights/index.tsx | 68 ++++++------------- 2 files changed, 38 insertions(+), 61 deletions(-) diff --git a/apps/web/app/future/(individual-page-wrapper)/insights/page.tsx b/apps/web/app/future/(individual-page-wrapper)/insights/page.tsx index 27b512d6862117..99de09c3eac698 100644 --- a/apps/web/app/future/(individual-page-wrapper)/insights/page.tsx +++ b/apps/web/app/future/(individual-page-wrapper)/insights/page.tsx @@ -1,34 +1,39 @@ import OldPage from "@pages/insights/index"; import { _generateMetadata } from "app/_utils"; -import type { Params } from "next/dist/shared/lib/router/utils/route-matcher"; -import { headers, cookies } from "next/headers"; +import { headers } from "next/headers"; +import { notFound } from "next/navigation"; import { getLayout } from "@calcom/features/MainLayoutAppDir"; - -import { buildLegacyCtx } from "@lib/buildLegacyCtx"; +import { getFeatureFlagMap } from "@calcom/features/flags/server/utils"; import PageWrapper from "@components/PageWrapperAppDir"; export const generateMetadata = async () => await _generateMetadata( - () => "", - () => "" + () => "Insights", + (t) => t("insights_subtitle") ); -type PageProps = Readonly<{ - params: Params; -}>; +async function getData() { + const prisma = await import("@calcom/prisma").then((mod) => mod.default); + const flags = await getFeatureFlagMap(prisma); + + if (flags.insights === false) { + return notFound(); + } + + return {}; +} -const Page = async ({ params }: PageProps) => { +const Page = async () => { const h = headers(); const nonce = h.get("x-nonce") ?? undefined; - const legacyCtx = buildLegacyCtx(params, headers(), cookies()); - const props = await getData(legacyCtx); + await getData(); return ( - + ); }; diff --git a/apps/web/pages/insights/index.tsx b/apps/web/pages/insights/index.tsx index 92f26af5750eaa..35a6fa2cca2e23 100644 --- a/apps/web/pages/insights/index.tsx +++ b/apps/web/pages/insights/index.tsx @@ -1,8 +1,5 @@ "use client"; -import type { GetServerSidePropsContext } from "next"; -import { headers, cookies } from "next/headers"; - import { getLayout } from "@calcom/features/MainLayout"; import { getFeatureFlagMap } from "@calcom/features/flags/server/utils"; import { @@ -25,51 +22,7 @@ import { RefreshCcw, UserPlus, Users } from "@calcom/ui/components/icon"; import PageWrapper from "@components/PageWrapper"; -import { buildLegacyCtx } from "../../lib/buildLegacyCtx"; - -type Params = { - [key: string]: string | string[] | undefined; -}; - -type PageProps = { - params: Params; -}; - -InsightsPage.PageWrapper = PageWrapper; -InsightsPage.getLayout = getLayout; - -// If feature flag is disabled, return not found on getServerSideProps -export const getServerSideProps = 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: {}, - }; -}; - -async function getData(props: GetServerSidePropsContext) { - const prisma = await import("@calcom/prisma").then((mod) => mod.default); - const flags = await getFeatureFlagMap(prisma); - - if (flags.insights === false) { - return { - notFound: true, - }; - } - - return {}; -} - -export default async function InsightsPage({ params }: PageProps) { - const legacyCtx = buildLegacyCtx(params, headers(), cookies()); - await getData(legacyCtx); +export default function InsightsPage() { const { t } = useLocale(); const { data: user } = trpc.viewer.me.useQuery(); @@ -149,3 +102,22 @@ export default async function InsightsPage({ params }: PageProps) { ); } + +InsightsPage.PageWrapper = PageWrapper; +InsightsPage.getLayout = getLayout; + +// If feature flag is disabled, return not found on getServerSideProps +export const getServerSideProps = 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: {}, + }; +};