From d804b3947dd9b8f7de3e6d6f4a4f4a32c6cf8371 Mon Sep 17 00:00:00 2001 From: Greg Pabian <35925521+grzpab@users.noreply.github.com> Date: Fri, 26 Jan 2024 21:06:02 +0100 Subject: [PATCH] chore: [app-router-migration 36] Migrate /org/* page group (#13202) Co-authored-by: CarinaWolli Co-authored-by: Peer Richelsen Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> Co-authored-by: Pradumn Kumar Co-authored-by: zomars --- .../app/future/org/[orgSlug]/embed/page.tsx | 41 ++++++++++++++++++ apps/web/app/future/org/[orgSlug]/page.tsx | 37 ++++++++++++++++ .../org/[orgSlug]/team/[slug]/[type]/page.tsx | 43 +++++++++++++++++++ .../future/org/[orgSlug]/team/[slug]/page.tsx | 37 ++++++++++++++++ .../lib/team/[slug]/getServerSideProps.tsx | 16 ++++++- 5 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 apps/web/app/future/org/[orgSlug]/embed/page.tsx create mode 100644 apps/web/app/future/org/[orgSlug]/page.tsx create mode 100644 apps/web/app/future/org/[orgSlug]/team/[slug]/[type]/page.tsx create mode 100644 apps/web/app/future/org/[orgSlug]/team/[slug]/page.tsx diff --git a/apps/web/app/future/org/[orgSlug]/embed/page.tsx b/apps/web/app/future/org/[orgSlug]/embed/page.tsx new file mode 100644 index 0000000000..9146f8baaa --- /dev/null +++ b/apps/web/app/future/org/[orgSlug]/embed/page.tsx @@ -0,0 +1,41 @@ +import { type PageProps } from "@pages/team/[slug]"; +import EmbedPage from "@pages/team/[slug]/embed"; +import { withAppDirSsr } from "app/WithAppDirSsr"; +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"; +import { getServerSideProps } from "@lib/team/[slug]/getServerSideProps"; + +const getData = withAppDirSsr(getServerSideProps); + +export const generateMetadata = async ({ + params, + searchParams, +}: { + params: Params; + searchParams: SearchParams; +}) => { + const props = await getData( + buildLegacyCtx(headers(), cookies(), params, searchParams) as unknown as GetServerSidePropsContext + ); + const teamName = props.team.name || "Nameless Team"; + + return await _generateMetadata( + () => teamName, + () => teamName + ); +}; + +const getEmbedData = withEmbedSsrAppDir(getData); + +export default WithLayout({ + Page: EmbedPage, + getData: getEmbedData, + getLayout: null, + isBookingPage: true, +})<"P">; diff --git a/apps/web/app/future/org/[orgSlug]/page.tsx b/apps/web/app/future/org/[orgSlug]/page.tsx new file mode 100644 index 0000000000..2ac5e96d17 --- /dev/null +++ b/apps/web/app/future/org/[orgSlug]/page.tsx @@ -0,0 +1,37 @@ +import TeamPage, { type PageProps } from "@pages/team/[slug]"; +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"; +import { getServerSideProps } from "@lib/team/[slug]/getServerSideProps"; + +export const generateMetadata = async ({ + params, + searchParams, +}: { + params: Params; + searchParams: SearchParams; +}) => { + const props = await getData( + buildLegacyCtx(headers(), cookies(), params, searchParams) as unknown as GetServerSidePropsContext + ); + const teamName = props.team.name || "Nameless Team"; + + return await _generateMetadata( + () => teamName, + () => teamName + ); +}; + +const getData = withAppDirSsr(getServerSideProps); + +export default WithLayout({ + Page: TeamPage, + getData, + getLayout: null, + isBookingPage: true, +})<"P">; diff --git a/apps/web/app/future/org/[orgSlug]/team/[slug]/[type]/page.tsx b/apps/web/app/future/org/[orgSlug]/team/[slug]/[type]/page.tsx new file mode 100644 index 0000000000..9a3d0dbd10 --- /dev/null +++ b/apps/web/app/future/org/[orgSlug]/team/[slug]/[type]/page.tsx @@ -0,0 +1,43 @@ +import TypePage, { type PageProps } from "@pages/team/[slug]/[type]"; +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"; +import { getServerSideProps } from "@lib/team/[slug]/[type]/getServerSideProps"; + +export const generateMetadata = async ({ + params, + searchParams, +}: { + params: Params; + searchParams: SearchParams; +}) => { + const legacyCtx = buildLegacyCtx(headers(), cookies(), params, searchParams); + const props = await getData(legacyCtx as unknown as GetServerSidePropsContext); + const { entity, user, slug, booking } = props; + const { trpc } = await import("@calcom/trpc"); + const { data: event } = trpc.viewer.public.event.useQuery( + { username: user, eventSlug: slug, isTeamEvent: false, org: entity.orgSlug ?? null }, + { refetchOnWindowFocus: false } + ); + + const profileName = event?.profile?.name ?? ""; + const title = event?.title ?? ""; + + return await _generateMetadata( + (t) => `${booking?.uid && !!booking ? t("reschedule") : ""} ${title} | ${profileName}`, + (t) => `${booking?.uid ? t("reschedule") : ""} ${title}` + ); +}; +const getData = withAppDirSsr(getServerSideProps); + +export default WithLayout({ + Page: TypePage, + getData, + getLayout: null, + isBookingPage: true, +})<"P">; diff --git a/apps/web/app/future/org/[orgSlug]/team/[slug]/page.tsx b/apps/web/app/future/org/[orgSlug]/team/[slug]/page.tsx new file mode 100644 index 0000000000..2ac5e96d17 --- /dev/null +++ b/apps/web/app/future/org/[orgSlug]/team/[slug]/page.tsx @@ -0,0 +1,37 @@ +import TeamPage, { type PageProps } from "@pages/team/[slug]"; +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"; +import { getServerSideProps } from "@lib/team/[slug]/getServerSideProps"; + +export const generateMetadata = async ({ + params, + searchParams, +}: { + params: Params; + searchParams: SearchParams; +}) => { + const props = await getData( + buildLegacyCtx(headers(), cookies(), params, searchParams) as unknown as GetServerSidePropsContext + ); + const teamName = props.team.name || "Nameless Team"; + + return await _generateMetadata( + () => teamName, + () => teamName + ); +}; + +const getData = withAppDirSsr(getServerSideProps); + +export default WithLayout({ + Page: TeamPage, + getData, + getLayout: null, + isBookingPage: true, +})<"P">; diff --git a/apps/web/lib/team/[slug]/getServerSideProps.tsx b/apps/web/lib/team/[slug]/getServerSideProps.tsx index ccd782122c..b3670f8511 100644 --- a/apps/web/lib/team/[slug]/getServerSideProps.tsx +++ b/apps/web/lib/team/[slug]/getServerSideProps.tsx @@ -18,9 +18,21 @@ import { ssrInit } from "@server/lib/ssr"; const log = logger.getSubLogger({ prefix: ["team/[slug]"] }); +const getTheLastArrayElement = (value: ReadonlyArray | string | undefined): string | undefined => { + if (value === undefined || typeof value === "string") { + return value; + } + + return value.at(-1); +}; + export const getServerSideProps = async (context: GetServerSidePropsContext) => { - const slug = Array.isArray(context.query?.slug) ? context.query.slug.pop() : context.query.slug; - const { isValidOrgDomain, currentOrgDomain } = orgDomainConfig(context.req, context.params?.orgSlug); + const slug = getTheLastArrayElement(context.query.slug) ?? getTheLastArrayElement(context.query.orgSlug); + + const { isValidOrgDomain, currentOrgDomain } = orgDomainConfig( + context.req, + context.params?.orgSlug ?? context.query?.orgSlug + ); const isOrgContext = isValidOrgDomain && currentOrgDomain; // Provided by Rewrite from next.config.js