Skip to content

Commit

Permalink
chore: App Router Migration - Fix metadata util used in App Router an…
Browse files Browse the repository at this point in the history
…d remove duplicate code (#16346)
  • Loading branch information
hbjORbj authored and zomars committed Sep 4, 2024
1 parent fd2be02 commit fa65b4d
Show file tree
Hide file tree
Showing 32 changed files with 82 additions and 258 deletions.
21 changes: 8 additions & 13 deletions apps/web/app/future/[user]/[type]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import { withAppDirSsr } from "app/WithAppDirSsr";
import type { PageProps } from "app/_types";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import { type GetServerSidePropsContext } from "next";
import { headers, cookies } from "next/headers";

import { buildLegacyCtx } from "@lib/buildLegacyCtx";

import LegacyPage from "~/users/views/users-type-public-view";
import { getServerSideProps, type PageProps } from "~/users/views/users-type-public-view.getServerSideProps";
import {
getServerSideProps,
type PageProps as LegacyPageProps,
} from "~/users/views/users-type-public-view.getServerSideProps";

export const generateMetadata = async ({
params,
searchParams,
}: {
params: Record<string, string | string[]>;
searchParams: { [key: string]: string | string[] | undefined };
}) => {
const props = await getData(
buildLegacyCtx(headers(), cookies(), params, searchParams) as unknown as GetServerSidePropsContext
);
export const generateMetadata = async ({ params, searchParams }: PageProps) => {
const props = await getData(buildLegacyCtx(headers(), cookies(), params, searchParams));

const { eventData, booking, user, slug } = props;
const rescheduleUid = booking?.uid;
Expand All @@ -42,7 +37,7 @@ export const generateMetadata = async ({
(t) => `${rescheduleUid ? t("reschedule") : ""} ${title}`
);
};
const getData = withAppDirSsr<PageProps>(getServerSideProps);
const getData = withAppDirSsr<LegacyPageProps>(getServerSideProps);

export default WithLayout({
getData,
Expand Down
14 changes: 3 additions & 11 deletions apps/web/app/future/[user]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { withAppDirSsr } from "app/WithAppDirSsr";
import type { PageProps } from "app/_types";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import { type GetServerSidePropsContext } from "next";
import { headers, cookies } from "next/headers";

import { getLayout } from "@calcom/features/MainLayoutAppDir";
Expand All @@ -11,16 +11,8 @@ import { buildLegacyCtx } from "@lib/buildLegacyCtx";
import LegacyPage from "~/users/views/users-public-view";
import { getServerSideProps, type UserPageProps } from "~/users/views/users-public-view.getServerSideProps";

export const generateMetadata = async ({
params,
searchParams,
}: {
params: Record<string, string | string[]>;
searchParams: { [key: string]: string | string[] | undefined };
}) => {
const props = await getData(
buildLegacyCtx(headers(), cookies(), params, searchParams) as unknown as GetServerSidePropsContext
);
export const generateMetadata = async ({ params, searchParams }: PageProps) => {
const props = await getData(buildLegacyCtx(headers(), cookies(), params, searchParams));

const { profile, markdownStrippedBio } = props;
return await _generateMetadata(
Expand Down
19 changes: 4 additions & 15 deletions apps/web/app/future/apps/[slug]/[...pages]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import RoutingFormsRoutingConfig, {
} from "@calcom/app-store/routing-forms/pages/app-routing.config";
import TypeformRoutingConfig from "@calcom/app-store/typeform/pages/app-routing.config";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { APP_NAME } from "@calcom/lib/constants";
import prisma from "@calcom/prisma";
import type { AppGetServerSideProps } from "@calcom/types/AppGetServerSideProps";

Expand Down Expand Up @@ -65,21 +64,16 @@ export const generateMetadata = async ({

if (mainPage === "forms") {
return await _generateMetadata(
() => `Forms | ${APP_NAME}`,
() => `Forms`,
() => ""
);
}

const legacyContext = buildLegacyCtx(
headers(),
cookies(),
params,
searchParams
) as unknown as GetServerSidePropsContext;
const legacyContext = buildLegacyCtx(headers(), cookies(), params, searchParams);
const { form } = await getPageProps(legacyContext);

return await _generateMetadata(
() => `${form.name} | ${APP_NAME}`,
() => `${form.name}`,
() => form.description
);
};
Expand Down Expand Up @@ -182,12 +176,7 @@ export default async function Page({ params, searchParams }: PageProps) {
const h = headers();
const nonce = h.get("x-nonce") ?? undefined;

const legacyContext = buildLegacyCtx(
h,
cookies(),
params,
searchParams
) as unknown as GetServerSidePropsContext;
const legacyContext = buildLegacyCtx(h, cookies(), params, searchParams);
const props = await getPageProps(legacyContext);
return (
<PageWrapper getLayout={getLayout} requiresLicense={false} nonce={nonce} themeBasis={null} {...props}>
Expand Down
12 changes: 3 additions & 9 deletions apps/web/app/future/apps/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Page from "@pages/apps/[slug]/index";
import { Prisma } from "@prisma/client";
import { withAppDirSsg } from "app/WithAppDirSsg";
import type { PageProps } from "app/_types";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import type { InferGetStaticPropsType } from "next";
import { cookies, headers } from "next/headers";

import { APP_NAME } from "@calcom/lib/constants";
import prisma from "@calcom/prisma";

import { getStaticProps } from "@lib/apps/[slug]/getStaticProps";
Expand All @@ -15,18 +15,12 @@ import { buildLegacyCtx } from "@lib/buildLegacyCtx";
type Y = InferGetStaticPropsType<typeof getStaticProps>;
const getData = withAppDirSsg<Y>(getStaticProps);

export const generateMetadata = async ({
params,
searchParams,
}: {
params: Record<string, string | string[]>;
searchParams: { [key: string]: string | string[] | undefined };
}) => {
export const generateMetadata = async ({ params, searchParams }: PageProps) => {
const legacyContext = buildLegacyCtx(headers(), cookies(), params, searchParams);
const res = await getData(legacyContext);

return await _generateMetadata(
() => `${res?.data.name} | ${APP_NAME}`,
() => res?.data.name ?? "",
() => res?.data.description ?? ""
);
};
Expand Down
3 changes: 1 addition & 2 deletions apps/web/app/future/apps/[slug]/setup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import { WithLayout } from "app/layoutHOC";
import type { InferGetServerSidePropsType } from "next";

import { getServerSideProps } from "@calcom/app-store/_pages/setup/_getServerSideProps";
import { APP_NAME } from "@calcom/lib/constants";

export const generateMetadata = async ({ params }: { params: Record<string, string | string[]> }) => {
return await _generateMetadata(
() => `${params.slug} | ${APP_NAME}`,
() => `${params.slug}`,
() => ""
);
};
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/future/apps/categories/[category]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getStaticProps } from "@lib/apps/categories/[category]/getStaticProps";

export const generateMetadata = async () => {
return await _generateMetadata(
() => `${APP_NAME} | ${APP_NAME}`,
() => `${APP_NAME}`,
() => ""
);
};
Expand Down
4 changes: 1 addition & 3 deletions apps/web/app/future/apps/categories/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import { withAppDirSsr } from "app/WithAppDirSsr";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";

import { APP_NAME } from "@calcom/lib/constants";

import { getServerSideProps } from "@lib/apps/categories/getServerSideProps";

export const generateMetadata = async () => {
return await _generateMetadata(
() => `Categories | ${APP_NAME}`,
() => `Categories`,
() => ""
);
};
Expand Down
4 changes: 1 addition & 3 deletions apps/web/app/future/apps/installed/[category]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import { withAppDirSsr } from "app/WithAppDirSsr";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";

import { APP_NAME } from "@calcom/lib/constants";

import { getServerSideProps } from "@lib/apps/installed/[category]/getServerSideProps";

export const generateMetadata = async () => {
return await _generateMetadata(
(t) => `${t("installed_apps")} | ${APP_NAME}`,
(t) => `${t("installed_apps")}`,
(t) => t("manage_your_connected_apps")
);
};
Expand Down
4 changes: 1 addition & 3 deletions apps/web/app/future/auth/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import type { InferGetServerSidePropsType } from "next";

import { APP_NAME } from "@calcom/lib/constants";

import { getServerSideProps } from "@server/lib/auth/login/getServerSideProps";

export const generateMetadata = async () => {
return await _generateMetadata(
(t) => `${t("login")} | ${APP_NAME}`,
(t) => `${t("login")}`,
(t) => t("login")
);
};
Expand Down
3 changes: 1 addition & 2 deletions apps/web/app/future/booking/[uid]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { withAppDirSsr } from "app/WithAppDirSsr";
import type { Params, SearchParams } from "app/_types";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import { type GetServerSidePropsContext } from "next";
import { cookies, headers } from "next/headers";

import { BookingStatus } from "@calcom/prisma/enums";
Expand All @@ -20,7 +19,7 @@ export const generateMetadata = async ({
searchParams: SearchParams;
}) => {
const { bookingInfo, eventType, recurringBookings } = await getData(
buildLegacyCtx(headers(), cookies(), params, searchParams) as unknown as GetServerSidePropsContext
buildLegacyCtx(headers(), cookies(), params, searchParams)
);
const needsConfirmation = bookingInfo.status === BookingStatus.PENDING && eventType.requiresConfirmation;

Expand Down
4 changes: 1 addition & 3 deletions apps/web/app/future/event-types/[type]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import { cookies, headers } from "next/headers";

import { APP_NAME } from "@calcom/lib/constants";

import { buildLegacyCtx } from "@lib/buildLegacyCtx";

import EventTypePageWrapper from "~/event-types/views/event-types-single-view";
Expand All @@ -22,7 +20,7 @@ export const generateMetadata = async ({
const { eventType } = await getData(legacyCtx);

return await _generateMetadata(
(t) => `${eventType.title} | ${t("event_type")} | ${APP_NAME}`,
(t) => `${eventType.title} | ${t("event_type")}`,
() => ""
);
};
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/future/maintenance/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { APP_NAME } from "@calcom/lib/constants";

export const generateMetadata = async () =>
await _generateMetadata(
(t) => `${t("under_maintenance")} | ${APP_NAME}`,
(t) => `${t("under_maintenance")}`,
(t) => t("under_maintenance_description", { appName: APP_NAME })
);

Expand Down
5 changes: 1 addition & 4 deletions apps/web/app/future/org/[orgSlug]/embed/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import withEmbedSsrAppDir from "app/WithEmbedSSR";
import type { Params, SearchParams } from "app/_types";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import { type GetServerSidePropsContext } from "next";
import { cookies, headers } from "next/headers";

import { buildLegacyCtx } from "@lib/buildLegacyCtx";
Expand All @@ -20,9 +19,7 @@ export const generateMetadata = async ({
params: Params;
searchParams: SearchParams;
}) => {
const props = await getData(
buildLegacyCtx(headers(), cookies(), params, searchParams) as unknown as GetServerSidePropsContext
);
const props = await getData(buildLegacyCtx(headers(), cookies(), params, searchParams));
const teamName = props.team.name || "Nameless Team";

return await _generateMetadata(
Expand Down
5 changes: 1 addition & 4 deletions apps/web/app/future/org/[orgSlug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { withAppDirSsr } from "app/WithAppDirSsr";
import type { Params, SearchParams } from "app/_types";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import { type GetServerSidePropsContext } from "next";
import { cookies, headers } from "next/headers";

import { buildLegacyCtx } from "@lib/buildLegacyCtx";
Expand All @@ -16,9 +15,7 @@ export const generateMetadata = async ({
params: Params;
searchParams: SearchParams;
}) => {
const props = await getData(
buildLegacyCtx(headers(), cookies(), params, searchParams) as unknown as GetServerSidePropsContext
);
const props = await getData(buildLegacyCtx(headers(), cookies(), params, searchParams));
const teamName = props.team.name || "Nameless Team";

return await _generateMetadata(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { withAppDirSsr } from "app/WithAppDirSsr";
import type { Params, SearchParams } from "app/_types";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import { type GetServerSidePropsContext } from "next";
import { cookies, headers } from "next/headers";

import { buildLegacyCtx } from "@lib/buildLegacyCtx";
Expand All @@ -17,7 +16,7 @@ export const generateMetadata = async ({
searchParams: SearchParams;
}) => {
const legacyCtx = buildLegacyCtx(headers(), cookies(), params, searchParams);
const props = await getData(legacyCtx as unknown as GetServerSidePropsContext);
const props = await getData(legacyCtx);
const { eventData, user, slug, booking } = props;
const entity = eventData.entity;
const { trpc } = await import("@calcom/trpc");
Expand Down
5 changes: 1 addition & 4 deletions apps/web/app/future/org/[orgSlug]/team/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { withAppDirSsr } from "app/WithAppDirSsr";
import type { Params, SearchParams } from "app/_types";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import { type GetServerSidePropsContext } from "next";
import { cookies, headers } from "next/headers";

import { buildLegacyCtx } from "@lib/buildLegacyCtx";
Expand All @@ -16,9 +15,7 @@ export const generateMetadata = async ({
params: Params;
searchParams: SearchParams;
}) => {
const props = await getData(
buildLegacyCtx(headers(), cookies(), params, searchParams) as unknown as GetServerSidePropsContext
);
const props = await getData(buildLegacyCtx(headers(), cookies(), params, searchParams));
const teamName = props.team.name || "Nameless Team";

return await _generateMetadata(
Expand Down
3 changes: 1 addition & 2 deletions apps/web/app/future/payment/[uid]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import { WithLayout } from "app/layoutHOC";

import PaymentPage from "@calcom/features/ee/payments/components/PaymentPage";
import { getServerSideProps, type PaymentPageProps } from "@calcom/features/ee/payments/pages/payment";
import { APP_NAME } from "@calcom/lib/constants";

export const generateMetadata = async () =>
await _generateMetadata(
// the title does not contain the eventName as in the legacy page
(t) => `${t("payment")} | ${APP_NAME}`,
(t) => `${t("payment")}`,
() => ""
);

Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/future/routing-forms/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type PageProps = Readonly<{

const Page = async ({ params, searchParams }: PageProps) => {
const legacyCtx = buildLegacyCtx(headers(), cookies(), params, searchParams);
await getPageProps(legacyCtx as unknown as GetServerSidePropsContext);
await getPageProps(legacyCtx);

return null;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import LegacyPage, { WrappedAboutOrganizationPage } from "@pages/settings/organizations/[id]/about";
import LegacyPage, { LayoutWrapper } from "@pages/settings/organizations/[id]/about";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";

Expand All @@ -8,4 +8,4 @@ export const generateMetadata = async () =>
(t) => t("about_your_organization_description")
);

export default WithLayout({ Page: LegacyPage, getLayout: WrappedAboutOrganizationPage });
export default WithLayout({ Page: LegacyPage, getLayout: LayoutWrapper });
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import LegacyPage, { WrapperAddNewTeamsPage } from "@pages/settings/organizations/[id]/add-teams";
import LegacyPage, { LayoutWrapper } from "@pages/settings/organizations/[id]/add-teams";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";

Expand All @@ -8,4 +8,4 @@ export const generateMetadata = async () =>
(t) => t("create_your_teams_description")
);

export default WithLayout({ Page: LegacyPage, getLayout: WrapperAddNewTeamsPage });
export default WithLayout({ Page: LegacyPage, getLayout: LayoutWrapper });
4 changes: 2 additions & 2 deletions apps/web/app/future/settings/organizations/new/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import LegacyPage, { getServerSideProps, LayoutWrapperAppDir } from "@pages/settings/organizations/new/index";
import LegacyPage, { getServerSideProps, LayoutWrapper } from "@pages/settings/organizations/new/index";
import { withAppDirSsr } from "app/WithAppDirSsr";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
Expand All @@ -12,7 +12,7 @@ export const generateMetadata = async () =>
);

export default WithLayout({
getLayout: LayoutWrapperAppDir,
getLayout: LayoutWrapper,
Page: LegacyPage,
getData: withAppDirSsr<inferSSRProps<typeof getServerSideProps>>(getServerSideProps),
});
Loading

0 comments on commit fa65b4d

Please sign in to comment.