Skip to content

Commit

Permalink
manual: refactor and add metadata title/description
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjORbj committed Nov 28, 2023
1 parent 292bf29 commit 61b8785
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 61 deletions.
31 changes: 18 additions & 13 deletions apps/web/app/future/(individual-page-wrapper)/insights/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<PageWrapper getLayout={getLayout} requiresLicense={false} nonce={nonce} themeBasis={null}>
<OldPage {...props} />
<OldPage />
</PageWrapper>
);
};
Expand Down
68 changes: 20 additions & 48 deletions apps/web/pages/insights/index.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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();

Expand Down Expand Up @@ -149,3 +102,22 @@ export default async function InsightsPage({ params }: PageProps) {
</div>
);
}

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: {},
};
};

0 comments on commit 61b8785

Please sign in to comment.