Skip to content

Scheduling infrastructure for absolutely everyone.

chore: [app-router-migration 36] Migrate /org/* page group (#13202)

Greg Pabiand804b3947dd9
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 00000000000..9146f8baaa0
--- /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<PageProps>(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 00000000000..2ac5e96d171
--- /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<PageProps>(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 00000000000..9a3d0dbd101
--- /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<PageProps>(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 00000000000..2ac5e96d171
--- /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<PageProps>(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 ccd782122ca..b3670f85112 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> | 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