Skip to content

Scheduling infrastructure for absolutely everyone.

chore: [app-router-migration 13.5] Add ability to reuse legacy getServerSideProps and getStaticProps on the `/future` pages (#13184)

DmytroHryshynbd4722554d03
diff --git a/apps/web/app/WithAppDirSsg.tsx b/apps/web/app/WithAppDirSsg.tsx
new file mode 100644
index 00000000000..bce8446e3fa
--- /dev/null
+++ b/apps/web/app/WithAppDirSsg.tsx
@@ -0,0 +1,24 @@
+import type { GetStaticProps, GetStaticPropsContext } from "next";
+import { notFound, redirect } from "next/navigation";
+
+export const withAppDirSsg =
+ <T extends Record<string, any>>(getStaticProps: GetStaticProps<T>) =>
+ async (context: GetStaticPropsContext) => {
+ const ssgResponse = await getStaticProps(context);
+
+ if ("redirect" in ssgResponse) {
+ redirect(ssgResponse.redirect.destination);
+ }
+
+ if ("notFound" in ssgResponse) {
+ notFound();
+ }
+
+ const props = await Promise.resolve(ssgResponse.props);
+
+ return {
+ ...ssgResponse.props,
+ // includes dehydratedState required for future page trpcPropvider
+ ...("trpcState" in props && { dehydratedState: props.trpcState }),
+ };
+ };
diff --git a/apps/web/app/AppDirSSRHOC.tsx b/apps/web/app/WithAppDirSsr.tsx
similarity index 69%
rename from apps/web/app/AppDirSSRHOC.tsx
rename to apps/web/app/WithAppDirSsr.tsx
index c173497fa41..3df0c78f16e 100644
--- a/apps/web/app/AppDirSSRHOC.tsx
+++ b/apps/web/app/WithAppDirSsr.tsx
@@ -1,21 +1,24 @@
import type { GetServerSideProps, GetServerSidePropsContext } from "next";
import { notFound, redirect } from "next/navigation";
-export const withAppDir =
+export const withAppDirSsr =
<T extends Record<string, any>>(getServerSideProps: GetServerSideProps<T>) =>
- async (context: GetServerSidePropsContext): Promise<T> => {
+ async (context: GetServerSidePropsContext) => {
const ssrResponse = await getServerSideProps(context);
if ("redirect" in ssrResponse) {
redirect(ssrResponse.redirect.destination);
}
+
if ("notFound" in ssrResponse) {
notFound();
}
+ const props = await Promise.resolve(ssrResponse.props);
+
return {
- ...ssrResponse.props,
+ ...props,
// includes dehydratedState required for future page trpcPropvider
- ...("trpcState" in ssrResponse.props && { dehydratedState: ssrResponse.props.trpcState }),
+ ...("trpcState" in props && { dehydratedState: props.trpcState }),
};
};
diff --git a/apps/web/app/future/apps/[slug]/layout.tsx b/apps/web/app/future/apps/[slug]/layout.tsx
deleted file mode 100644
index dc2fb3468fd..00000000000
--- a/apps/web/app/future/apps/[slug]/layout.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-import { WithLayout } from "app/layoutHOC";
-
-export default WithLayout({ getLayout: null })<"L">;
diff --git a/apps/web/app/future/apps/[slug]/page.tsx b/apps/web/app/future/apps/[slug]/page.tsx
index ec1121c9495..f3795d4b934 100644
--- a/apps/web/app/future/apps/[slug]/page.tsx
+++ b/apps/web/app/future/apps/[slug]/page.tsx
@@ -1,40 +1,33 @@
-import AppPage from "@pages/apps/[slug]/index";
+import Page from "@pages/apps/[slug]/index";
import { Prisma } from "@prisma/client";
+import { withAppDirSsg } from "app/WithAppDirSsg";
import { _generateMetadata } from "app/_utils";
-import fs from "fs";
-import matter from "gray-matter";
-import { notFound } from "next/navigation";
-import path from "path";
-import { z } from "zod";
+import { WithLayout } from "app/layoutHOC";
+import type { InferGetStaticPropsType } from "next";
+import { cookies, headers } from "next/headers";
-import { getAppWithMetadata } from "@calcom/app-store/_appRegistry";
-import { getAppAssetFullPath } from "@calcom/app-store/getAppAssetFullPath";
-import { APP_NAME, IS_PRODUCTION } from "@calcom/lib/constants";
+import { APP_NAME } from "@calcom/lib/constants";
import prisma from "@calcom/prisma";
-const sourceSchema = z.object({
- content: z.string(),
- data: z.object({
- description: z.string().optional(),
- items: z
- .array(
- z.union([
- z.string(),
- z.object({
- iframe: z.object({ src: z.string() }),
- }),
- ])
- )
- .optional(),
- }),
-});
+import { getStaticProps } from "@lib/apps/[slug]/getStaticProps";
+import { buildLegacyCtx } from "@lib/buildLegacyCtx";
-export const generateMetadata = async ({ params }: { params: Record<string, string | string[]> }) => {
- const { data } = await getPageProps({ params });
+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 };
+}) => {
+ const legacyContext = buildLegacyCtx(headers(), cookies(), params, searchParams);
+ const res = await getData(legacyContext);
return await _generateMetadata(
- () => `${data.name} | ${APP_NAME}`,
- () => data.description
+ () => `${res?.data.name} | ${APP_NAME}`,
+ () => res?.data.description ?? ""
);
};
@@ -53,74 +46,6 @@ export const generateStaticParams = async () => {
return [];
};
-const getPageProps = async ({ params }: { params: Record<string, string | string[]> }) => {
- if (typeof params?.slug !== "string") {
- notFound();
- }
-
- const appMeta = await getAppWithMetadata({
- slug: params?.slug,
- });
-
- const appFromDb = await prisma.app.findUnique({
- where: { slug: params.slug.toLowerCase() },
- });
-
- const isAppAvailableInFileSystem = appMeta;
- const isAppDisabled = isAppAvailableInFileSystem && (!appFromDb || !appFromDb.enabled);
-
- if (!IS_PRODUCTION && isAppDisabled) {
- return {
- isAppDisabled: true as const,
- data: {
- ...appMeta,
- },
- };
- }
-
- if (!appFromDb || !appMeta || isAppDisabled) {
- notFound();
- }
-
- const isTemplate = appMeta.isTemplate;
- const appDirname = path.join(isTemplate ? "templates" : "", appFromDb.dirName);
- const README_PATH = path.join(process.cwd(), "..", "..", `packages/app-store/${appDirname}/DESCRIPTION.md`);
- const postFilePath = path.join(README_PATH);
- let source = "";
-
- try {
- source = fs.readFileSync(postFilePath).toString();
- source = source.replace(/{DESCRIPTION}/g, appMeta.description);
- } catch (error) {
- /* If the app doesn't have a README we fallback to the package description */
- console.log(`No DESCRIPTION.md provided for: ${appDirname}`);
- source = appMeta.description;
- }
-
- const result = matter(source);
- const { content, data } = sourceSchema.parse({ content: result.content, data: result.data });
- if (data.items) {
- data.items = data.items.map((item) => {
- if (typeof item === "string") {
- return getAppAssetFullPath(item, {
- dirName: appMeta.dirName,
- isTemplate: appMeta.isTemplate,
- });
- }
- return item;
- });
- }
- return {
- isAppDisabled: false as const,
- source: { content, data },
- data: appMeta,
- };
-};
-
-export default async function Page({ params }: { params: Record<string, string | string[]> }) {
- const pageProps = await getPageProps({ params });
-
- return <AppPage {...pageProps} />;
-}
+export default WithLayout({ getLayout: null, Page, getData });
export const dynamic = "force-static";
diff --git a/apps/web/app/future/apps/[slug]/setup/page.tsx b/apps/web/app/future/apps/[slug]/setup/page.tsx
index ce6abc75ba4..acd61513ecc 100644
--- a/apps/web/app/future/apps/[slug]/setup/page.tsx
+++ b/apps/web/app/future/apps/[slug]/setup/page.tsx
@@ -1,8 +1,8 @@
-import SetupPage from "@pages/apps/[slug]/setup";
+import Page from "@pages/apps/[slug]/setup";
+import { withAppDirSsr } from "app/WithAppDirSsr";
import { _generateMetadata } from "app/_utils";
-import type { GetServerSidePropsContext } from "next";
-import { cookies, headers } from "next/headers";
-import { notFound, redirect } from "next/navigation";
+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";
@@ -14,23 +14,8 @@ export const generateMetadata = async ({ params }: { params: Record<string, stri
);
};
-const getPageProps = async ({ params }: { params: Record<string, string | string[]> }) => {
- const req = { headers: headers(), cookies: cookies() };
+type T = InferGetServerSidePropsType<typeof getServerSideProps>;
- const result = await getServerSideProps({ params, req } as unknown as GetServerSidePropsContext);
+const getData = withAppDirSsr<T>(getServerSideProps);
- if (!result || "notFound" in result) {
- notFound();
- }
-
- if ("redirect" in result) {
- redirect(result.redirect.destination);
- }
-
- return result.props;
-};
-
-export default async function Page({ params }: { params: Record<string, string | string[]> }) {
- const pageProps = await getPageProps({ params });
- return <SetupPage {...pageProps} />;
-}
+export default WithLayout({ getLayout: null, Page, getData });
diff --git a/apps/web/app/future/apps/categories/page.tsx b/apps/web/app/future/apps/categories/page.tsx
index 0ef5547ee4d..8fcb079dbe3 100644
--- a/apps/web/app/future/apps/categories/page.tsx
+++ b/apps/web/app/future/apps/categories/page.tsx
@@ -1,13 +1,11 @@
-import LegacyPage from "@pages/apps/categories/index";
+import Page from "@pages/apps/categories/index";
+import { withAppDirSsr } from "app/WithAppDirSsr";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
-import type { GetServerSidePropsContext } from "next";
-import { getAppRegistry, getAppRegistryWithCredentials } from "@calcom/app-store/_appRegistry";
-import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { APP_NAME } from "@calcom/lib/constants";
-import { ssrInit } from "@server/lib/ssr";
+import { getServerSideProps } from "@lib/apps/categories/getServerSideProps";
export const generateMetadata = async () => {
return await _generateMetadata(
@@ -16,29 +14,4 @@ export const generateMetadata = async () => {
);
};
-const getData = async (ctx: GetServerSidePropsContext) => {
- const ssr = await ssrInit(ctx);
-
- const session = await getServerSession({ req: ctx.req });
-
- let appStore;
- if (session?.user?.id) {
- appStore = await getAppRegistryWithCredentials(session.user.id);
- } else {
- appStore = await getAppRegistry();
- }
-
- const categories = appStore.reduce((c, app) => {
- for (const category of app.categories) {
- c[category] = c[category] ? c[category] + 1 : 1;
- }
- return c;
- }, {} as Record<string, number>);
-
- return {
- categories: Object.entries(categories).map(([name, count]) => ({ name, count })),
- dehydratedState: ssr.dehydrate(),
- };
-};
-
-export default WithLayout({ getData, Page: LegacyPage, getLayout: null })<"P">;
+export default WithLayout({ getData: withAppDirSsr(getServerSideProps), Page, getLayout: null })<"P">;
diff --git a/apps/web/app/future/apps/installed/[category]/layout.tsx b/apps/web/app/future/apps/installed/[category]/layout.tsx
deleted file mode 100644
index dc2fb3468fd..00000000000
--- a/apps/web/app/future/apps/installed/[category]/layout.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-import { WithLayout } from "app/layoutHOC";
-
-export default WithLayout({ getLayout: null })<"L">;
diff --git a/apps/web/app/future/apps/installed/[category]/page.tsx b/apps/web/app/future/apps/installed/[category]/page.tsx
index 44b511f0f8b..829a6a0e40c 100644
--- a/apps/web/app/future/apps/installed/[category]/page.tsx
+++ b/apps/web/app/future/apps/installed/[category]/page.tsx
@@ -1,14 +1,11 @@
-import LegacyPage from "@pages/apps/installed/[category]";
+import Page from "@pages/apps/installed/[category]";
+import { withAppDirSsr } from "app/WithAppDirSsr";
import { _generateMetadata } from "app/_utils";
-import { notFound } from "next/navigation";
-import { z } from "zod";
+import { WithLayout } from "app/layoutHOC";
import { APP_NAME } from "@calcom/lib/constants";
-import { AppCategories } from "@calcom/prisma/enums";
-const querySchema = z.object({
- category: z.nativeEnum(AppCategories),
-});
+import { getServerSideProps } from "@lib/apps/installed/[category]/getServerSideProps";
export const generateMetadata = async () => {
return await _generateMetadata(
@@ -17,20 +14,6 @@ export const generateMetadata = async () => {
);
};
-const getPageProps = async ({ params }: { params: Record<string, string | string[]> }) => {
- const p = querySchema.safeParse(params);
+const getData = withAppDirSsr(getServerSideProps);
- if (!p.success) {
- return notFound();
- }
-
- return {
- category: p.data.category,
- };
-};
-
-export default async function Page({ params }: { params: Record<string, string | string[]> }) {
- await getPageProps({ params });
-
- return <LegacyPage />;
-}
+export default WithLayout({ getLayout: null, getData, Page });
diff --git a/apps/web/app/future/apps/page.tsx b/apps/web/app/future/apps/page.tsx
index cdccef7bdf5..4fdd8bea977 100644
--- a/apps/web/app/future/apps/page.tsx
+++ b/apps/web/app/future/apps/page.tsx
@@ -1,17 +1,12 @@
import AppsPage from "@pages/apps";
+import { withAppDirSsr } from "app/WithAppDirSsr";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
-import type { GetServerSidePropsContext } from "next";
-import { getAppRegistry, getAppRegistryWithCredentials } from "@calcom/app-store/_appRegistry";
import { getLayout } from "@calcom/features/MainLayoutAppDir";
-import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
-import type { UserAdminTeams } from "@calcom/features/ee/teams/lib/getUserAdminTeams";
-import getUserAdminTeams from "@calcom/features/ee/teams/lib/getUserAdminTeams";
import { APP_NAME } from "@calcom/lib/constants";
-import type { AppCategories } from "@calcom/prisma/enums";
-import { ssrInit } from "@server/lib/ssr";
+import { getServerSideProps } from "@lib/apps/getServerSideProps";
export const generateMetadata = async () => {
return await _generateMetadata(
@@ -20,44 +15,4 @@ export const generateMetadata = async () => {
);
};
-const getData = async (ctx: GetServerSidePropsContext) => {
- const ssr = await ssrInit(ctx);
-
- const session = await getServerSession({ req: ctx.req });
-
- let appStore, userAdminTeams: UserAdminTeams;
- if (session?.user?.id) {
- userAdminTeams = await getUserAdminTeams({ userId: session.user.id, getUserInfo: true });
- appStore = await getAppRegistryWithCredentials(session.user.id, userAdminTeams);
- } else {
- appStore = await getAppRegistry();
- userAdminTeams = [];
- }
-
- const categoryQuery = appStore.map(({ categories }) => ({
- categories: categories || [],
- }));
-
- const categories = categoryQuery.reduce((c, app) => {
- for (const category of app.categories) {
- c[category] = c[category] ? c[category] + 1 : 1;
- }
- return c;
- }, {} as Record<string, number>);
-
- return {
- categories: Object.entries(categories)
- .map(([name, count]): { name: AppCategories; count: number } => ({
- name: name as AppCategories,
- count,
- }))
- .sort(function (a, b) {
- return b.count - a.count;
- }),
- appStore,
- userAdminTeams,
- dehydratedState: ssr.dehydrate(),
- };
-};
-
-export default WithLayout({ getLayout, getData, Page: AppsPage });
+export default WithLayout({ getLayout, getData: withAppDirSsr(getServerSideProps), Page: AppsPage });
diff --git a/apps/web/app/future/d/[link]/[slug]/page.tsx b/apps/web/app/future/d/[link]/[slug]/page.tsx
index 2ac9aea60ec..4e380ce756c 100644
--- a/apps/web/app/future/d/[link]/[slug]/page.tsx
+++ b/apps/web/app/future/d/[link]/[slug]/page.tsx
@@ -1,27 +1,21 @@
-import LegacyPage, { type PageProps } from "@pages/d/[link]/[slug]";
-import { withAppDir } from "app/AppDirSSRHOC";
+import LegacyPage from "@pages/d/[link]/[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 { notFound } from "next/navigation";
-import { z } from "zod";
-
-import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
-import { getBookingForReschedule, getMultipleDurationValue } from "@calcom/features/bookings/lib/get-booking";
-import type { GetBookingType } from "@calcom/features/bookings/lib/get-booking";
-import { orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains";
-import slugify from "@calcom/lib/slugify";
-import prisma from "@calcom/prisma";
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
+import { getServerSideProps } from "@lib/d/[link]/[slug]/getServerSideProps";
-import { ssrInit } from "@server/lib/ssr";
-
-export const generateMetadata = async ({ params }: { params: Record<string, string | string[]> }) => {
- const pageProps = await getPageProps(
- buildLegacyCtx(headers(), cookies(), params) as unknown as GetServerSidePropsContext
- );
+export const generateMetadata = async ({
+ params,
+ searchParams,
+}: {
+ params: Params;
+ searchParams: SearchParams;
+}) => {
+ const pageProps = await getData(buildLegacyCtx(headers(), cookies(), params, searchParams));
const { entity, booking, user, slug, isTeamEvent } = pageProps;
const rescheduleUid = booking?.uid;
@@ -38,95 +32,5 @@ export const generateMetadata = async ({ params }: { params: Record<string, stri
);
};
-async function getPageProps(context: GetServerSidePropsContext) {
- const session = await getServerSession({ req: context.req });
- const { link, slug } = paramsSchema.parse(context.params);
- const { rescheduleUid, duration: queryDuration } = context.query;
- const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(context.req);
- const org = isValidOrgDomain ? currentOrgDomain : null;
-
- const hashedLink = await prisma.hashedLink.findUnique({
- where: {
- link,
- },
- select: {
- eventTypeId: true,
- eventType: {
- select: {
- users: {
- select: {
- username: true,
- },
- },
- team: {
- select: {
- id: true,
- },
- },
- },
- },
- },
- });
-
- const username = hashedLink?.eventType.users[0]?.username;
-
- if (!hashedLink || !username) {
- return notFound();
- }
-
- const user = await prisma.user.findFirst({
- where: {
- username,
- organization: isValidOrgDomain
- ? {
- slug: currentOrgDomain,
- }
- : null,
- },
- select: {
- away: true,
- hideBranding: true,
- },
- });
-
- if (!user) {
- return notFound();
- }
-
- let booking: GetBookingType | null = null;
- if (rescheduleUid) {
- booking = await getBookingForReschedule(`${rescheduleUid}`, session?.user?.id);
- }
-
- const isTeamEvent = !!hashedLink.eventType?.team?.id;
- const ssr = await ssrInit(context);
-
- // We use this to both prefetch the query on the server,
- // as well as to check if the event exist, so we c an show a 404 otherwise.
- const eventData = await ssr.viewer.public.event.fetch({ username, eventSlug: slug, isTeamEvent, org });
-
- if (!eventData) {
- return notFound();
- }
-
- return {
- entity: eventData.entity,
- duration: getMultipleDurationValue(eventData.metadata?.multipleDuration, queryDuration, eventData.length),
- booking,
- away: user?.away,
- user: username,
- slug,
- dehydratedState: ssr.dehydrate(),
- isBrandingHidden: user?.hideBranding,
- // Sending the team event from the server, because this template file
- // is reused for both team and user events.
- isTeamEvent,
- hashedLink: link,
- };
-}
-
-const paramsSchema = z.object({ link: z.string(), slug: z.string().transform((s) => slugify(s)) });
-
-// @ts-expect-error arg
-const getData = withAppDir<PageProps>(getPageProps);
+const getData = withAppDirSsr(getServerSideProps);
export default WithLayout({ getLayout: null, Page: LegacyPage, getData })<"P">;
diff --git a/apps/web/app/future/getting-started/[[...step]]/page.tsx b/apps/web/app/future/getting-started/[[...step]]/page.tsx
index b8ad1b6c84d..28c8d891e43 100644
--- a/apps/web/app/future/getting-started/[[...step]]/page.tsx
+++ b/apps/web/app/future/getting-started/[[...step]]/page.tsx
@@ -1,57 +1,7 @@
-import LegacyPage from "@pages/getting-started/[[...step]]";
+import Page from "@pages/getting-started/[[...step]]";
+import { withAppDirSsr } from "app/WithAppDirSsr";
import { WithLayout } from "app/layoutHOC";
-import { type GetServerSidePropsContext } from "next";
-import { redirect } from "next/navigation";
-import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
-import prisma from "@calcom/prisma";
+import { getServerSideProps } from "@lib/getting-started/[[...step]]/getServerSideProps";
-import { ssrInit } from "@server/lib/ssr";
-
-const getData = async (ctx: GetServerSidePropsContext) => {
- const session = await getServerSession({ req: ctx.req });
-
- if (!session?.user?.id) {
- return redirect("/auth/login");
- }
- const ssr = await ssrInit(ctx);
- await ssr.viewer.me.prefetch();
-
- const user = await prisma.user.findUnique({
- where: {
- id: session.user.id,
- },
- select: {
- completedOnboarding: true,
- teams: {
- select: {
- accepted: true,
- team: {
- select: {
- id: true,
- name: true,
- logo: true,
- },
- },
- },
- },
- },
- });
-
- if (!user) {
- throw new Error("User from session not found");
- }
-
- if (user.completedOnboarding) {
- redirect("/event-types");
- }
-
- return {
- dehydratedState: ssr.dehydrate(),
- hasPendingInvites: user.teams.find((team) => team.accepted === false) ?? false,
- requiresLicense: false,
- themeBasis: null,
- };
-};
-
-export default WithLayout({ getLayout: null, getData, Page: LegacyPage });
+export default WithLayout({ getLayout: null, getData: withAppDirSsr(getServerSideProps), Page });
diff --git a/apps/web/app/future/org/[orgSlug]/[user]/[type]/embed/page.tsx b/apps/web/app/future/org/[orgSlug]/[user]/[type]/embed/page.tsx
index 5df230f6325..6762375103a 100644
--- a/apps/web/app/future/org/[orgSlug]/[user]/[type]/embed/page.tsx
+++ b/apps/web/app/future/org/[orgSlug]/[user]/[type]/embed/page.tsx
@@ -1,13 +1,12 @@
import { type PageProps } from "@pages/org/[orgSlug]/[user]/[type]";
import Page from "@pages/org/[orgSlug]/[user]/[type]/embed";
-import { withAppDir } from "app/AppDirSSRHOC";
+import { withAppDirSsr } from "app/WithAppDirSsr";
import withEmbedSsrAppDir from "app/WithEmbedSSR";
import { WithLayout } from "app/layoutHOC";
import { getServerSideProps } from "@lib/org/[orgSlug]/[user]/[type]/getServerSideProps";
-const getData = withAppDir<PageProps>(getServerSideProps);
-
+const getData = withAppDirSsr<PageProps>(getServerSideProps);
const getEmbedData = withEmbedSsrAppDir(getData);
export default WithLayout({ getLayout: null, getData: getEmbedData, isBookingPage: true, Page });
diff --git a/apps/web/app/future/org/[orgSlug]/[user]/[type]/page.tsx b/apps/web/app/future/org/[orgSlug]/[user]/[type]/page.tsx
index 5355468abfc..3965d209b36 100644
--- a/apps/web/app/future/org/[orgSlug]/[user]/[type]/page.tsx
+++ b/apps/web/app/future/org/[orgSlug]/[user]/[type]/page.tsx
@@ -1,9 +1,9 @@
import Page, { type PageProps } from "@pages/org/[orgSlug]/[user]/[type]";
-import { withAppDir } from "app/AppDirSSRHOC";
+import { withAppDirSsr } from "app/WithAppDirSsr";
import { WithLayout } from "app/layoutHOC";
import { getServerSideProps } from "@lib/org/[orgSlug]/[user]/[type]/getServerSideProps";
-const getData = withAppDir<PageProps>(getServerSideProps);
+const getData = withAppDirSsr<PageProps>(getServerSideProps);
export default WithLayout({ getLayout: null, getData, isBookingPage: true, Page });
diff --git a/apps/web/app/future/org/[orgSlug]/[user]/embed/page.tsx b/apps/web/app/future/org/[orgSlug]/[user]/embed/page.tsx
index c522f02c16e..adf85d2655c 100644
--- a/apps/web/app/future/org/[orgSlug]/[user]/embed/page.tsx
+++ b/apps/web/app/future/org/[orgSlug]/[user]/embed/page.tsx
@@ -1,10 +1,11 @@
import { getServerSideProps, type PageProps } from "@pages/org/[orgSlug]/[user]";
import Page from "@pages/org/[orgSlug]/[user]/embed";
-import { withAppDir } from "app/AppDirSSRHOC";
+import { withAppDirSsr } from "app/WithAppDirSsr";
import withEmbedSsrAppDir from "app/WithEmbedSSR";
import { WithLayout } from "app/layoutHOC";
-const getData = withAppDir<PageProps>(getServerSideProps);
+const getData = withAppDirSsr<PageProps>(getServerSideProps);
+
const getEmbedData = withEmbedSsrAppDir(getData);
export default WithLayout({ getLayout: null, getData: getEmbedData, isBookingPage: true, Page });
diff --git a/apps/web/app/future/org/[orgSlug]/[user]/page.tsx b/apps/web/app/future/org/[orgSlug]/[user]/page.tsx
index 3acb0404dcb..c22edc214c2 100644
--- a/apps/web/app/future/org/[orgSlug]/[user]/page.tsx
+++ b/apps/web/app/future/org/[orgSlug]/[user]/page.tsx
@@ -1,7 +1,7 @@
import Page, { getServerSideProps, type PageProps } from "@pages/org/[orgSlug]/[user]";
-import { withAppDir } from "app/AppDirSSRHOC";
+import { withAppDirSsr } from "app/WithAppDirSsr";
import { WithLayout } from "app/layoutHOC";
-const getData = withAppDir<PageProps>(getServerSideProps);
+const getData = withAppDirSsr<PageProps>(getServerSideProps);
export default WithLayout({ getLayout: null, getData, isBookingPage: true, Page });
diff --git a/apps/web/app/future/reschedule/[uid]/embed/page.tsx b/apps/web/app/future/reschedule/[uid]/embed/page.tsx
index 52bef3e4867..a81eed65233 100644
--- a/apps/web/app/future/reschedule/[uid]/embed/page.tsx
+++ b/apps/web/app/future/reschedule/[uid]/embed/page.tsx
@@ -1,5 +1,6 @@
import { getServerSideProps } from "@pages/reschedule/[uid]";
-import { withAppDir } from "app/AppDirSSRHOC";
+import { withAppDirSsr } from "app/WithAppDirSsr";
+import type { SearchParams } from "app/_types";
import type { Params } from "next/dist/shared/lib/router/utils/route-matcher";
import { cookies, headers } from "next/headers";
@@ -8,12 +9,12 @@ import withEmbedSsr from "@lib/withEmbedSsr";
type PageProps = Readonly<{
params: Params;
+ searchParams: SearchParams;
}>;
-const Page = async ({ params }: PageProps) => {
- const legacyCtx = buildLegacyCtx(headers(), cookies(), params);
- // @ts-expect-error Argument of type '{ query: Params; params: Params; req: { headers: ReadonlyHeaders; cookies: ReadonlyRequestCookies; }; }'
- await withAppDir(withEmbedSsr(getServerSideProps))(legacyCtx);
+const Page = async ({ params, searchParams }: PageProps) => {
+ const legacyCtx = buildLegacyCtx(headers(), cookies(), params, searchParams);
+ await withAppDirSsr(withEmbedSsr(getServerSideProps))(legacyCtx);
return null;
};
diff --git a/apps/web/app/future/reschedule/[uid]/page.tsx b/apps/web/app/future/reschedule/[uid]/page.tsx
index 40fbf05617a..9eb26e4bce9 100644
--- a/apps/web/app/future/reschedule/[uid]/page.tsx
+++ b/apps/web/app/future/reschedule/[uid]/page.tsx
@@ -1,5 +1,6 @@
import OldPage, { getServerSideProps as _getServerSideProps } from "@pages/reschedule/[uid]";
-import { withAppDir } from "app/AppDirSSRHOC";
+import { withAppDirSsr } from "app/WithAppDirSsr";
+import type { SearchParams } from "app/_types";
import { _generateMetadata } from "app/_utils";
import type { Params } from "next/dist/shared/lib/router/utils/route-matcher";
import { headers, cookies } from "next/headers";
@@ -14,14 +15,14 @@ export const generateMetadata = async () =>
type PageProps = Readonly<{
params: Params;
+ searchParams: SearchParams;
}>;
-const getData = withAppDir(_getServerSideProps);
+const getData = withAppDirSsr(_getServerSideProps);
-const Page = async ({ params }: PageProps) => {
- const legacyCtx = buildLegacyCtx(headers(), cookies(), params);
+const Page = async ({ params, searchParams }: PageProps) => {
+ const legacyCtx = buildLegacyCtx(headers(), cookies(), params, searchParams);
- // @ts-expect-error Argument of type '{ query: Params; params: Params; req: { headers: ReadonlyHeaders; cookies: ReadonlyRequestCookies; }; }'
await getData(legacyCtx);
return <OldPage />;
diff --git a/apps/web/app/future/teams/page.tsx b/apps/web/app/future/teams/page.tsx
index 6453ac8e012..2145383bb87 100644
--- a/apps/web/app/future/teams/page.tsx
+++ b/apps/web/app/future/teams/page.tsx
@@ -1,13 +1,11 @@
-import OldPage from "@pages/teams/index";
+import Page from "@pages/teams/index";
+import { withAppDirSsr } from "app/WithAppDirSsr";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
-import type { GetServerSidePropsContext } from "next";
-import { redirect } from "next/navigation";
import { getLayout } from "@calcom/features/MainLayoutAppDir";
-import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
-import { ssrInit } from "@server/lib/ssr";
+import { getServerSideProps } from "@lib/teams/getServerSideProps";
export const generateMetadata = async () =>
await _generateMetadata(
@@ -15,23 +13,4 @@ export const generateMetadata = async () =>
(t) => t("create_manage_teams_collaborative")
);
-async function getData(context: GetServerSidePropsContext) {
- const ssr = await ssrInit(context);
-
- await ssr.viewer.me.prefetch();
-
- const session = await getServerSession({
- req: context.req,
- });
-
- if (!session) {
- const token = Array.isArray(context.query.token) ? context.query.token[0] : context.query.token;
-
- const callbackUrl = token ? `/teams?token=${encodeURIComponent(token)}` : null;
- return redirect(callbackUrl ? `/auth/login?callbackUrl=${callbackUrl}` : "/auth/login");
- }
-
- return { dehydratedState: ssr.dehydrate() };
-}
-
-export default WithLayout({ getData, getLayout, Page: OldPage })<"P">;
+export default WithLayout({ getData: withAppDirSsr(getServerSideProps), getLayout, Page })<"P">;
diff --git a/apps/web/app/future/video/[uid]/page.tsx b/apps/web/app/future/video/[uid]/page.tsx
index 7625bd01252..1d80f62af79 100644
--- a/apps/web/app/future/video/[uid]/page.tsx
+++ b/apps/web/app/future/video/[uid]/page.tsx
@@ -1,15 +1,11 @@
-import OldPage from "@pages/video/[uid]";
+import Page, { type JoinCallPageProps } from "@pages/video/[uid]";
+import { withAppDirSsr } from "app/WithAppDirSsr";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
-import MarkdownIt from "markdown-it";
-import type { GetServerSidePropsContext } from "next";
-import { redirect } from "next/navigation";
-import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { APP_NAME } from "@calcom/lib/constants";
-import prisma, { bookingMinimalSelect } from "@calcom/prisma";
-import { ssrInit } from "@server/lib/ssr";
+import { getServerSideProps } from "@lib/video/[uid]/getServerSideProps";
export const generateMetadata = async () =>
await _generateMetadata(
@@ -17,86 +13,6 @@ export const generateMetadata = async () =>
(t) => t("quick_video_meeting")
);
-const md = new MarkdownIt("default", { html: true, breaks: true, linkify: true });
+const getData = withAppDirSsr<JoinCallPageProps>(getServerSideProps);
-async function getData(context: GetServerSidePropsContext) {
- const ssr = await ssrInit(context);
-
- const booking = await prisma.booking.findUnique({
- where: {
- uid: context.query.uid as string,
- },
- select: {
- ...bookingMinimalSelect,
- uid: true,
- description: true,
- isRecorded: true,
- user: {
- select: {
- id: true,
- timeZone: true,
- name: true,
- email: true,
- organization: {
- select: {
- calVideoLogo: true,
- },
- },
- },
- },
- references: {
- select: {
- uid: true,
- type: true,
- meetingUrl: true,
- meetingPassword: true,
- },
- where: {
- type: "daily_video",
- },
- },
- },
- });
-
- if (!booking || booking.references.length === 0 || !booking.references[0].meetingUrl) {
- return redirect("/video/no-meeting-found");
- }
-
- //daily.co calls have a 60 minute exit buffer when a user enters a call when it's not available it will trigger the modals
- const now = new Date();
- const exitDate = new Date(now.getTime() - 60 * 60 * 1000);
-
- //find out if the meeting is in the past
- const isPast = booking?.endTime <= exitDate;
- if (isPast) {
- return redirect(`/video/meeting-ended/${booking?.uid}`);
- }
-
- const bookingObj = Object.assign({}, booking, {
- startTime: booking.startTime.toString(),
- endTime: booking.endTime.toString(),
- });
-
- const session = await getServerSession({ req: context.req });
-
- // set meetingPassword to null for guests
- if (session?.user.id !== bookingObj.user?.id) {
- bookingObj.references.forEach((bookRef) => {
- bookRef.meetingPassword = null;
- });
- }
-
- return {
- meetingUrl: bookingObj.references[0].meetingUrl ?? "",
- ...(typeof bookingObj.references[0].meetingPassword === "string" && {
- meetingPassword: bookingObj.references[0].meetingPassword,
- }),
- booking: {
- ...bookingObj,
- ...(bookingObj.description && { description: md.render(bookingObj.description) }),
- },
- dehydratedState: ssr.dehydrate(),
- };
-}
-
-export default WithLayout({ getData, Page: OldPage, getLayout: null })<"P">;
+export default WithLayout({ getData, Page, getLayout: null })<"P">;
diff --git a/apps/web/app/future/video/meeting-ended/[uid]/page.tsx b/apps/web/app/future/video/meeting-ended/[uid]/page.tsx
index 9c86ca58bd6..68c17447620 100644
--- a/apps/web/app/future/video/meeting-ended/[uid]/page.tsx
+++ b/apps/web/app/future/video/meeting-ended/[uid]/page.tsx
@@ -1,10 +1,9 @@
-import OldPage from "@pages/video/meeting-ended/[uid]";
+import Page from "@pages/video/meeting-ended/[uid]";
+import { withAppDirSsr } from "app/WithAppDirSsr";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
-import { type GetServerSidePropsContext } from "next";
-import { redirect } from "next/navigation";
-import prisma, { bookingMinimalSelect } from "@calcom/prisma";
+import { getServerSideProps } from "@lib/video/meeting-ended/[uid]/getServerSideProps";
export const generateMetadata = async () =>
await _generateMetadata(
@@ -12,41 +11,6 @@ export const generateMetadata = async () =>
() => "Meeting Unavailable"
);
-async function getData(context: Omit<GetServerSidePropsContext, "res" | "resolvedUrl">) {
- const booking = await prisma.booking.findUnique({
- where: {
- uid: typeof context?.params?.uid === "string" ? context.params.uid : "",
- },
- select: {
- ...bookingMinimalSelect,
- uid: true,
- user: {
- select: {
- credentials: true,
- },
- },
- references: {
- select: {
- uid: true,
- type: true,
- meetingUrl: true,
- },
- },
- },
- });
+const getData = withAppDirSsr(getServerSideProps);
- if (!booking) {
- return redirect("/video/no-meeting-found");
- }
-
- const bookingObj = Object.assign({}, booking, {
- startTime: booking.startTime.toString(),
- endTime: booking.endTime.toString(),
- });
-
- return {
- booking: bookingObj,
- };
-}
-
-export default WithLayout({ getData, Page: OldPage, getLayout: null })<"P">;
+export default WithLayout({ getData, Page, getLayout: null })<"P">;
diff --git a/apps/web/app/future/video/meeting-not-started/[uid]/page.tsx b/apps/web/app/future/video/meeting-not-started/[uid]/page.tsx
index 3d71a3859d3..ade26a9e85c 100644
--- a/apps/web/app/future/video/meeting-not-started/[uid]/page.tsx
+++ b/apps/web/app/future/video/meeting-not-started/[uid]/page.tsx
@@ -1,15 +1,12 @@
-import OldPage from "@pages/video/meeting-not-started/[uid]";
-import { type Params } from "app/_types";
+import Page from "@pages/video/meeting-not-started/[uid]";
+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 { redirect } from "next/navigation";
import prisma, { bookingMinimalSelect } from "@calcom/prisma";
-type PageProps = Readonly<{
- params: Params;
-}>;
+import { getServerSideProps } from "@lib/video/meeting-not-started/[uid]/getServerSideProps";
export const generateMetadata = async ({ params }: PageProps) => {
const booking = await prisma.booking.findUnique({
@@ -25,26 +22,6 @@ export const generateMetadata = async ({ params }: PageProps) => {
);
};
-async function getData(context: Omit<GetServerSidePropsContext, "res" | "resolvedUrl">) {
- const booking = await prisma.booking.findUnique({
- where: {
- uid: typeof context?.params?.uid === "string" ? context.params.uid : "",
- },
- select: bookingMinimalSelect,
- });
-
- if (!booking) {
- return redirect("/video/no-meeting-found");
- }
-
- const bookingObj = Object.assign({}, booking, {
- startTime: booking.startTime.toString(),
- endTime: booking.endTime.toString(),
- });
-
- return {
- booking: bookingObj,
- };
-}
+const getData = withAppDirSsr(getServerSideProps);
-export default WithLayout({ getData, Page: OldPage, getLayout: null })<"P">;
+export default WithLayout({ getData, Page, getLayout: null })<"P">;
diff --git a/apps/web/app/future/video/no-meeting-found/page.tsx b/apps/web/app/future/video/no-meeting-found/page.tsx
index 63d728e96fe..9f16119f8ba 100644
--- a/apps/web/app/future/video/no-meeting-found/page.tsx
+++ b/apps/web/app/future/video/no-meeting-found/page.tsx
@@ -1,7 +1,7 @@
import LegacyPage from "@pages/video/no-meeting-found";
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
-import { type GetServerSidePropsContext } from "next";
+import type { GetServerSidePropsContext } from "next";
import { ssrInit } from "@server/lib/ssr";
@@ -11,6 +11,7 @@ export const generateMetadata = async () =>
(t) => t("no_meeting_found")
);
+// ssr was added by Intuita, legacy page does not have it
const getData = async (context: GetServerSidePropsContext) => {
const ssr = await ssrInit(context);
diff --git a/apps/web/app/future/workflows/[workflow]/page.tsx b/apps/web/app/future/workflows/[workflow]/page.tsx
index f368cf6a8cd..6b21ce6e2a1 100644
--- a/apps/web/app/future/workflows/[workflow]/page.tsx
+++ b/apps/web/app/future/workflows/[workflow]/page.tsx
@@ -13,9 +13,15 @@ const querySchema = z.object({
workflow: z.string(),
});
-export const generateMetadata = async ({ params }: { params: Record<string, string | string[]> }) => {
+export const generateMetadata = async ({
+ params,
+ searchParams,
+}: {
+ params: Record<string, string | string[]>;
+ searchParams: { [key: string]: string | string[] | undefined };
+}) => {
const { workflow } = await getProps(
- buildLegacyCtx(headers(), cookies(), params) as unknown as GetServerSidePropsContext
+ buildLegacyCtx(headers(), cookies(), params, searchParams) as unknown as GetServerSidePropsContext
);
return await _generateMetadata(
() => workflow ?? "Untitled",
diff --git a/apps/web/app/layoutHOC.tsx b/apps/web/app/layoutHOC.tsx
index 14543014d8d..8abe969022b 100644
--- a/apps/web/app/layoutHOC.tsx
+++ b/apps/web/app/layoutHOC.tsx
@@ -9,7 +9,7 @@ import PageWrapper from "@components/PageWrapperAppDir";
type WithLayoutParams<T extends Record<string, any>> = {
getLayout: ((page: React.ReactElement) => React.ReactNode) | null;
Page?: (props: T) => React.ReactElement | null;
- getData?: (arg: GetServerSidePropsContext) => Promise<T>;
+ getData?: (arg: GetServerSidePropsContext) => Promise<T | undefined>;
isBookingPage?: boolean;
};
@@ -22,9 +22,11 @@ export function WithLayout<T extends Record<string, any>>({
return async <P extends "P" | "L">(p: P extends "P" ? PageProps : LayoutProps) => {
const h = headers();
const nonce = h.get("x-nonce") ?? undefined;
- const props = getData
- ? await getData(buildLegacyCtx(h, cookies(), p.params) as unknown as GetServerSidePropsContext)
- : ({} as T);
+ let props = {} as T;
+
+ if ("searchParams" in p && getData) {
+ props = (await getData(buildLegacyCtx(h, cookies(), p.params, p.searchParams))) ?? ({} as T);
+ }
const children = "children" in p ? p.children : null;
diff --git a/apps/web/lib/apps/[slug]/getStaticProps.tsx b/apps/web/lib/apps/[slug]/getStaticProps.tsx
new file mode 100644
index 00000000000..9113ba9c4e5
--- /dev/null
+++ b/apps/web/lib/apps/[slug]/getStaticProps.tsx
@@ -0,0 +1,94 @@
+import fs from "fs";
+import matter from "gray-matter";
+import MarkdownIt from "markdown-it";
+import type { GetStaticPropsContext } from "next";
+import path from "path";
+import { z } from "zod";
+
+import { getAppWithMetadata } from "@calcom/app-store/_appRegistry";
+import { getAppAssetFullPath } from "@calcom/app-store/getAppAssetFullPath";
+import { IS_PRODUCTION } from "@calcom/lib/constants";
+import prisma from "@calcom/prisma";
+
+const md = new MarkdownIt("default", { html: true, breaks: true });
+
+export const sourceSchema = z.object({
+ content: z.string(),
+ data: z.object({
+ description: z.string().optional(),
+ items: z
+ .array(
+ z.union([
+ z.string(),
+ z.object({
+ iframe: z.object({ src: z.string() }),
+ }),
+ ])
+ )
+ .optional(),
+ }),
+});
+
+export const getStaticProps = async (ctx: GetStaticPropsContext) => {
+ if (typeof ctx.params?.slug !== "string") return { notFound: true } as const;
+
+ const appMeta = await getAppWithMetadata({
+ slug: ctx.params?.slug,
+ });
+
+ const appFromDb = await prisma.app.findUnique({
+ where: { slug: ctx.params.slug.toLowerCase() },
+ });
+
+ const isAppAvailableInFileSystem = appMeta;
+ const isAppDisabled = isAppAvailableInFileSystem && (!appFromDb || !appFromDb.enabled);
+
+ if (!IS_PRODUCTION && isAppDisabled) {
+ return {
+ props: {
+ isAppDisabled: true as const,
+ data: {
+ ...appMeta,
+ },
+ },
+ };
+ }
+
+ if (!appFromDb || !appMeta || isAppDisabled) return { notFound: true } as const;
+
+ const isTemplate = appMeta.isTemplate;
+ const appDirname = path.join(isTemplate ? "templates" : "", appFromDb.dirName);
+ const README_PATH = path.join(process.cwd(), "..", "..", `packages/app-store/${appDirname}/DESCRIPTION.md`);
+ const postFilePath = path.join(README_PATH);
+ let source = "";
+
+ try {
+ source = fs.readFileSync(postFilePath).toString();
+ source = source.replace(/{DESCRIPTION}/g, appMeta.description);
+ } catch (error) {
+ /* If the app doesn't have a README we fallback to the package description */
+ console.log(`No DESCRIPTION.md provided for: ${appDirname}`);
+ source = appMeta.description;
+ }
+
+ const result = matter(source);
+ const { content, data } = sourceSchema.parse({ content: result.content, data: result.data });
+ if (data.items) {
+ data.items = data.items.map((item) => {
+ if (typeof item === "string") {
+ return getAppAssetFullPath(item, {
+ dirName: appMeta.dirName,
+ isTemplate: appMeta.isTemplate,
+ });
+ }
+ return item;
+ });
+ }
+ return {
+ props: {
+ isAppDisabled: false as const,
+ source: { content, data },
+ data: appMeta,
+ },
+ };
+};
diff --git a/apps/web/lib/apps/categories/[category]/getStaticProps.tsx b/apps/web/lib/apps/categories/[category]/getStaticProps.tsx
new file mode 100644
index 00000000000..7afa898b1c9
--- /dev/null
+++ b/apps/web/lib/apps/categories/[category]/getStaticProps.tsx
@@ -0,0 +1,31 @@
+import type { GetStaticPropsContext } from "next";
+
+import { getAppRegistry } from "@calcom/app-store/_appRegistry";
+import prisma from "@calcom/prisma";
+import type { AppCategories } from "@calcom/prisma/enums";
+
+export const getStaticProps = async (context: GetStaticPropsContext) => {
+ const category = context.params?.category as AppCategories;
+
+ const appQuery = await prisma.app.findMany({
+ where: {
+ categories: {
+ has: category,
+ },
+ },
+ select: {
+ slug: true,
+ },
+ });
+
+ const dbAppsSlugs = appQuery.map((category) => category.slug);
+
+ const appStore = await getAppRegistry();
+
+ const apps = appStore.filter((app) => dbAppsSlugs.includes(app.slug));
+ return {
+ props: {
+ apps,
+ },
+ };
+};
diff --git a/apps/web/lib/apps/categories/getServerSideProps.tsx b/apps/web/lib/apps/categories/getServerSideProps.tsx
new file mode 100644
index 00000000000..80f91be0015
--- /dev/null
+++ b/apps/web/lib/apps/categories/getServerSideProps.tsx
@@ -0,0 +1,35 @@
+import type { GetServerSidePropsContext } from "next";
+
+import { getAppRegistry, getAppRegistryWithCredentials } from "@calcom/app-store/_appRegistry";
+import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
+
+import { ssrInit } from "@server/lib/ssr";
+
+export const getServerSideProps = async (context: GetServerSidePropsContext) => {
+ const { req, res } = context;
+
+ const ssr = await ssrInit(context);
+
+ const session = await getServerSession({ req, res });
+
+ let appStore;
+ if (session?.user?.id) {
+ appStore = await getAppRegistryWithCredentials(session.user.id);
+ } else {
+ appStore = await getAppRegistry();
+ }
+
+ const categories = appStore.reduce((c, app) => {
+ for (const category of app.categories) {
+ c[category] = c[category] ? c[category] + 1 : 1;
+ }
+ return c;
+ }, {} as Record<string, number>);
+
+ return {
+ props: {
+ categories: Object.entries(categories).map(([name, count]) => ({ name, count })),
+ trpcState: ssr.dehydrate(),
+ },
+ };
+};
diff --git a/apps/web/lib/apps/getServerSideProps.tsx b/apps/web/lib/apps/getServerSideProps.tsx
new file mode 100644
index 00000000000..c0a3e2acc05
--- /dev/null
+++ b/apps/web/lib/apps/getServerSideProps.tsx
@@ -0,0 +1,52 @@
+import type { GetServerSidePropsContext } from "next";
+
+import { getAppRegistry, getAppRegistryWithCredentials } from "@calcom/app-store/_appRegistry";
+import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
+import getUserAdminTeams from "@calcom/features/ee/teams/lib/getUserAdminTeams";
+import type { UserAdminTeams } from "@calcom/features/ee/teams/lib/getUserAdminTeams";
+import type { AppCategories } from "@calcom/prisma/enums";
+
+import { ssrInit } from "@server/lib/ssr";
+
+export const getServerSideProps = async (context: GetServerSidePropsContext) => {
+ const { req, res } = context;
+
+ const ssr = await ssrInit(context);
+
+ const session = await getServerSession({ req, res });
+
+ let appStore, userAdminTeams: UserAdminTeams;
+ if (session?.user?.id) {
+ userAdminTeams = await getUserAdminTeams({ userId: session.user.id, getUserInfo: true });
+ appStore = await getAppRegistryWithCredentials(session.user.id, userAdminTeams);
+ } else {
+ appStore = await getAppRegistry();
+ userAdminTeams = [];
+ }
+
+ const categoryQuery = appStore.map(({ categories }) => ({
+ categories: categories || [],
+ }));
+ const categories = categoryQuery.reduce((c, app) => {
+ for (const category of app.categories) {
+ c[category] = c[category] ? c[category] + 1 : 1;
+ }
+ return c;
+ }, {} as Record<string, number>);
+
+ return {
+ props: {
+ categories: Object.entries(categories)
+ .map(([name, count]): { name: AppCategories; count: number } => ({
+ name: name as AppCategories,
+ count,
+ }))
+ .sort(function (a, b) {
+ return b.count - a.count;
+ }),
+ appStore,
+ userAdminTeams,
+ trpcState: ssr.dehydrate(),
+ },
+ };
+};
diff --git a/apps/web/lib/apps/installed/[category]/getServerSideProps.tsx b/apps/web/lib/apps/installed/[category]/getServerSideProps.tsx
new file mode 100644
index 00000000000..9be2a03ab14
--- /dev/null
+++ b/apps/web/lib/apps/installed/[category]/getServerSideProps.tsx
@@ -0,0 +1,43 @@
+import type { GetServerSidePropsContext } from "next";
+import { z } from "zod";
+
+import { AppCategories } from "@calcom/prisma/enums";
+
+export type querySchemaType = z.infer<typeof querySchema>;
+
+export const querySchema = z.object({
+ category: z.nativeEnum(AppCategories),
+});
+
+export async function getServerSideProps(ctx: GetServerSidePropsContext) {
+ // get return-to cookie and redirect if needed
+ const { cookies } = ctx.req;
+
+ const returnTo = cookies["return-to"];
+
+ if (cookies && returnTo) {
+ ctx.res.setHeader("Set-Cookie", "return-to=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT");
+ const redirect = {
+ redirect: {
+ destination: `${returnTo}`,
+ permanent: false,
+ },
+ } as const;
+
+ return redirect;
+ }
+
+ const params = querySchema.safeParse(ctx.params);
+
+ if (!params.success) {
+ const notFound = { notFound: true } as const;
+
+ return notFound;
+ }
+
+ return {
+ props: {
+ category: params.data.category,
+ },
+ };
+}
diff --git a/apps/web/lib/apps/installed/getServerSideProps.tsx b/apps/web/lib/apps/installed/getServerSideProps.tsx
new file mode 100644
index 00000000000..a43490aea51
--- /dev/null
+++ b/apps/web/lib/apps/installed/getServerSideProps.tsx
@@ -0,0 +1,3 @@
+export async function getServerSideProps() {
+ return { redirect: { permanent: false, destination: "/apps/installed/calendar" } };
+}
diff --git a/apps/web/lib/buildLegacyCtx.tsx b/apps/web/lib/buildLegacyCtx.tsx
index 2dfbf3ff2f3..3aa9372de7e 100644
--- a/apps/web/lib/buildLegacyCtx.tsx
+++ b/apps/web/lib/buildLegacyCtx.tsx
@@ -1,23 +1,53 @@
+import type { SearchParams } from "app/_types";
import { type Params } from "app/_types";
+import type { GetServerSidePropsContext } from "next";
import { type ReadonlyHeaders } from "next/dist/server/web/spec-extension/adapters/headers";
import { type ReadonlyRequestCookies } from "next/dist/server/web/spec-extension/adapters/request-cookies";
-// returns query object same as ctx.query but for app dir
-export const getQuery = (url: string, params: Params) => {
- if (!url.length) {
- return params;
- }
+const createProxifiedObject = (object: Record<string, string>) =>
+ new Proxy(object, {
+ set: () => {
+ throw new Error("You are trying to modify 'headers' or 'cookies', which is not supported in app dir");
+ },
+ });
- const { searchParams } = new URL(url);
- const searchParamsObj = Object.fromEntries(searchParams.entries());
+const buildLegacyHeaders = (headers: ReadonlyHeaders) => {
+ const headersObject = Object.fromEntries(headers.entries());
- return { ...searchParamsObj, ...params };
+ return createProxifiedObject(headersObject);
};
-export const buildLegacyCtx = (headers: ReadonlyHeaders, cookies: ReadonlyRequestCookies, params: Params) => {
- return {
- query: getQuery(headers.get("x-url") ?? "", params),
- params,
- req: { headers, cookies },
- };
+const buildLegacyCookies = (cookies: ReadonlyRequestCookies) => {
+ const cookiesObject = cookies.getAll().reduce<Record<string, string>>((acc, { name, value }) => {
+ acc[name] = value;
+ return acc;
+ }, {});
+
+ return createProxifiedObject(cookiesObject);
+};
+
+export const buildLegacyCtx = (
+ headers: ReadonlyHeaders,
+ cookies: ReadonlyRequestCookies,
+ params: Params,
+ searchParams: SearchParams
+) => {
+ return new Proxy<Record<string, any>>(
+ {
+ query: { ...searchParams, ...params },
+ params,
+ req: { headers: buildLegacyHeaders(headers), cookies: buildLegacyCookies(cookies) },
+ },
+ {
+ get(obj, prop) {
+ if (prop === "res") {
+ throw new Error(
+ "You are trying to access the 'res' property of the context, which is not supported in app dir"
+ );
+ }
+
+ return obj[prop as keyof typeof obj];
+ },
+ }
+ ) as unknown as GetServerSidePropsContext;
};
diff --git a/apps/web/lib/d/[link]/[slug]/getServerSideProps.tsx b/apps/web/lib/d/[link]/[slug]/getServerSideProps.tsx
new file mode 100644
index 00000000000..cea6dc74925
--- /dev/null
+++ b/apps/web/lib/d/[link]/[slug]/getServerSideProps.tsx
@@ -0,0 +1,121 @@
+import type { GetServerSidePropsContext } from "next";
+import { z } from "zod";
+
+import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
+import { getBookingForReschedule, getMultipleDurationValue } from "@calcom/features/bookings/lib/get-booking";
+import type { GetBookingType } from "@calcom/features/bookings/lib/get-booking";
+import { orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains";
+import slugify from "@calcom/lib/slugify";
+import prisma from "@calcom/prisma";
+
+import type { inferSSRProps } from "@lib/types/inferSSRProps";
+import type { EmbedProps } from "@lib/withEmbedSsr";
+
+export type PageProps = inferSSRProps<typeof getServerSideProps> & EmbedProps;
+
+async function getUserPageProps(context: GetServerSidePropsContext) {
+ const session = await getServerSession(context);
+ const { link, slug } = paramsSchema.parse(context.params);
+ const { rescheduleUid, duration: queryDuration } = context.query;
+ const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(context.req);
+ const org = isValidOrgDomain ? currentOrgDomain : null;
+
+ const { ssrInit } = await import("@server/lib/ssr");
+ const ssr = await ssrInit(context);
+
+ const hashedLink = await prisma.hashedLink.findUnique({
+ where: {
+ link,
+ },
+ select: {
+ eventTypeId: true,
+ eventType: {
+ select: {
+ users: {
+ select: {
+ username: true,
+ },
+ },
+ team: {
+ select: {
+ id: true,
+ },
+ },
+ },
+ },
+ },
+ });
+
+ const username = hashedLink?.eventType.users[0]?.username;
+
+ const notFound = {
+ notFound: true,
+ } as const;
+
+ if (!hashedLink || !username) {
+ return notFound;
+ }
+
+ const user = await prisma.user.findFirst({
+ where: {
+ username,
+ organization: isValidOrgDomain
+ ? {
+ slug: currentOrgDomain,
+ }
+ : null,
+ },
+ select: {
+ away: true,
+ hideBranding: true,
+ },
+ });
+
+ if (!user) {
+ return notFound;
+ }
+
+ let booking: GetBookingType | null = null;
+ if (rescheduleUid) {
+ booking = await getBookingForReschedule(`${rescheduleUid}`, session?.user?.id);
+ }
+
+ const isTeamEvent = !!hashedLink.eventType?.team?.id;
+
+ // We use this to both prefetch the query on the server,
+ // as well as to check if the event exist, so we c an show a 404 otherwise.
+ const eventData = await ssr.viewer.public.event.fetch({ username, eventSlug: slug, isTeamEvent, org });
+
+ if (!eventData) {
+ return notFound;
+ }
+
+ return {
+ props: {
+ entity: eventData.entity,
+ duration: getMultipleDurationValue(
+ eventData.metadata?.multipleDuration,
+ queryDuration,
+ eventData.length
+ ),
+ booking,
+ away: user?.away,
+ user: username,
+ slug,
+ trpcState: ssr.dehydrate(),
+ isBrandingHidden: user?.hideBranding,
+ // Sending the team event from the server, because this template file
+ // is reused for both team and user events.
+ isTeamEvent,
+ hashedLink: link,
+ },
+ };
+}
+
+const paramsSchema = z.object({ link: z.string(), slug: z.string().transform((s) => slugify(s)) });
+
+// Booker page fetches a tiny bit of data server side, to determine early
+// whether the page should show an away state or dynamic booking not allowed.
+export const getServerSideProps = async (context: GetServerSidePropsContext) => {
+ return await getUserPageProps(context);
+};
diff --git a/apps/web/lib/event-types/[type]/getServerSideProps.tsx b/apps/web/lib/event-types/[type]/getServerSideProps.tsx
new file mode 100644
index 00000000000..54e527306f3
--- /dev/null
+++ b/apps/web/lib/event-types/[type]/getServerSideProps.tsx
@@ -0,0 +1,42 @@
+import type { GetServerSidePropsContext } from "next";
+
+import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
+
+import { asStringOrThrow } from "@lib/asStringOrNull";
+import type { inferSSRProps } from "@lib/types/inferSSRProps";
+
+import { ssrInit } from "@server/lib/ssr";
+
+export type PageProps = inferSSRProps<typeof getServerSideProps>;
+
+export const getServerSideProps = async (context: GetServerSidePropsContext) => {
+ const { req, res, query } = context;
+
+ const session = await getServerSession({ req, res });
+
+ const typeParam = parseInt(asStringOrThrow(query.type));
+ const ssr = await ssrInit(context);
+
+ if (Number.isNaN(typeParam)) {
+ return {
+ notFound: true,
+ };
+ }
+
+ if (!session?.user?.id) {
+ return {
+ redirect: {
+ permanent: false,
+ destination: "/auth/login",
+ },
+ };
+ }
+
+ await ssr.viewer.eventTypes.get.prefetch({ id: typeParam });
+ return {
+ props: {
+ type: typeParam,
+ trpcState: ssr.dehydrate(),
+ },
+ };
+};
diff --git a/apps/web/lib/getting-started/[[...step]]/getServerSideProps.tsx b/apps/web/lib/getting-started/[[...step]]/getServerSideProps.tsx
new file mode 100644
index 00000000000..e6fa841c672
--- /dev/null
+++ b/apps/web/lib/getting-started/[[...step]]/getServerSideProps.tsx
@@ -0,0 +1,59 @@
+import type { GetServerSidePropsContext } from "next";
+import { serverSideTranslations } from "next-i18next/serverSideTranslations";
+
+import { getLocale } from "@calcom/features/auth/lib/getLocale";
+import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
+import prisma from "@calcom/prisma";
+
+import { ssrInit } from "@server/lib/ssr";
+
+export const getServerSideProps = async (context: GetServerSidePropsContext) => {
+ const { req, res } = context;
+
+ const session = await getServerSession({ req, res });
+
+ if (!session?.user?.id) {
+ return { redirect: { permanent: false, destination: "/auth/login" } };
+ }
+
+ const ssr = await ssrInit(context);
+
+ await ssr.viewer.me.prefetch();
+
+ const user = await prisma.user.findUnique({
+ where: {
+ id: session.user.id,
+ },
+ select: {
+ completedOnboarding: true,
+ teams: {
+ select: {
+ accepted: true,
+ team: {
+ select: {
+ id: true,
+ name: true,
+ logo: true,
+ },
+ },
+ },
+ },
+ },
+ });
+
+ if (!user) {
+ throw new Error("User from session not found");
+ }
+
+ if (user.completedOnboarding) {
+ return { redirect: { permanent: false, destination: "/event-types" } };
+ }
+ const locale = await getLocale(context.req);
+ return {
+ props: {
+ ...(await serverSideTranslations(locale, ["common"])),
+ trpcState: ssr.dehydrate(),
+ hasPendingInvites: user.teams.find((team) => team.accepted === false) ?? false,
+ },
+ };
+};
diff --git a/apps/web/lib/teams/getServerSideProps.tsx b/apps/web/lib/teams/getServerSideProps.tsx
new file mode 100644
index 00000000000..ae63a5f8118
--- /dev/null
+++ b/apps/web/lib/teams/getServerSideProps.tsx
@@ -0,0 +1,25 @@
+import type { GetServerSidePropsContext } from "next";
+
+import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
+
+import { ssrInit } from "@server/lib/ssr";
+
+export const getServerSideProps = async (context: GetServerSidePropsContext) => {
+ const ssr = await ssrInit(context);
+ await ssr.viewer.me.prefetch();
+ const session = await getServerSession({ req: context.req, res: context.res });
+ const token = Array.isArray(context.query?.token) ? context.query.token[0] : context.query?.token;
+
+ const callbackUrl = token ? `/teams?token=${encodeURIComponent(token)}` : null;
+
+ if (!session) {
+ return {
+ redirect: {
+ destination: callbackUrl ? `/auth/login?callbackUrl=${callbackUrl}` : "/auth/login",
+ permanent: false,
+ },
+ };
+ }
+
+ return { props: { trpcState: ssr.dehydrate() } };
+};
diff --git a/apps/web/lib/video/[uid]/getServerSideProps.tsx b/apps/web/lib/video/[uid]/getServerSideProps.tsx
new file mode 100644
index 00000000000..6052f58a4ca
--- /dev/null
+++ b/apps/web/lib/video/[uid]/getServerSideProps.tsx
@@ -0,0 +1,105 @@
+import MarkdownIt from "markdown-it";
+import type { GetServerSidePropsContext } from "next";
+
+import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
+import { getCalVideoReference } from "@calcom/features/get-cal-video-reference";
+import prisma, { bookingMinimalSelect } from "@calcom/prisma";
+
+import { ssrInit } from "@server/lib/ssr";
+
+const md = new MarkdownIt("default", { html: true, breaks: true, linkify: true });
+
+export async function getServerSideProps(context: GetServerSidePropsContext) {
+ const { req, res } = context;
+
+ const ssr = await ssrInit(context);
+
+ const booking = await prisma.booking.findUnique({
+ where: {
+ uid: context.query.uid as string,
+ },
+ select: {
+ ...bookingMinimalSelect,
+ uid: true,
+ description: true,
+ isRecorded: true,
+ user: {
+ select: {
+ id: true,
+ timeZone: true,
+ name: true,
+ email: true,
+ organization: {
+ select: {
+ calVideoLogo: true,
+ },
+ },
+ },
+ },
+ references: {
+ select: {
+ uid: true,
+ type: true,
+ meetingUrl: true,
+ meetingPassword: true,
+ },
+ where: {
+ type: "daily_video",
+ },
+ },
+ },
+ });
+
+ if (!booking || booking.references.length === 0 || !booking.references[0].meetingUrl) {
+ return {
+ redirect: {
+ destination: "/video/no-meeting-found",
+ permanent: false,
+ },
+ };
+ }
+
+ //daily.co calls have a 60 minute exit buffer when a user enters a call when it's not available it will trigger the modals
+ const now = new Date();
+ const exitDate = new Date(now.getTime() - 60 * 60 * 1000);
+
+ //find out if the meeting is in the past
+ const isPast = booking?.endTime <= exitDate;
+ if (isPast) {
+ return {
+ redirect: {
+ destination: `/video/meeting-ended/${booking?.uid}`,
+ permanent: false,
+ },
+ };
+ }
+
+ const bookingObj = Object.assign({}, booking, {
+ startTime: booking.startTime.toString(),
+ endTime: booking.endTime.toString(),
+ });
+
+ const session = await getServerSession({ req, res });
+
+ // set meetingPassword to null for guests
+ if (session?.user.id !== bookingObj.user?.id) {
+ bookingObj.references.forEach((bookRef) => {
+ bookRef.meetingPassword = null;
+ });
+ }
+ const videoReference = getCalVideoReference(bookingObj.references);
+
+ return {
+ props: {
+ meetingUrl: videoReference.meetingUrl ?? "",
+ ...(typeof videoReference.meetingPassword === "string" && {
+ meetingPassword: videoReference.meetingPassword,
+ }),
+ booking: {
+ ...bookingObj,
+ ...(bookingObj.description && { description: md.render(bookingObj.description) }),
+ },
+ trpcState: ssr.dehydrate(),
+ },
+ };
+}
diff --git a/apps/web/lib/video/meeting-ended/[uid]/getServerSideProps.tsx b/apps/web/lib/video/meeting-ended/[uid]/getServerSideProps.tsx
new file mode 100644
index 00000000000..2995d36bb72
--- /dev/null
+++ b/apps/web/lib/video/meeting-ended/[uid]/getServerSideProps.tsx
@@ -0,0 +1,49 @@
+import type { GetServerSidePropsContext } from "next";
+
+import prisma, { bookingMinimalSelect } from "@calcom/prisma";
+
+export async function getServerSideProps(context: GetServerSidePropsContext) {
+ const booking = await prisma.booking.findUnique({
+ where: {
+ uid: context.query.uid as string,
+ },
+ select: {
+ ...bookingMinimalSelect,
+ uid: true,
+ user: {
+ select: {
+ credentials: true,
+ },
+ },
+ references: {
+ select: {
+ uid: true,
+ type: true,
+ meetingUrl: true,
+ },
+ },
+ },
+ });
+
+ if (!booking) {
+ const redirect = {
+ redirect: {
+ destination: "/video/no-meeting-found",
+ permanent: false,
+ },
+ } as const;
+
+ return redirect;
+ }
+
+ const bookingObj = Object.assign({}, booking, {
+ startTime: booking.startTime.toString(),
+ endTime: booking.endTime.toString(),
+ });
+
+ return {
+ props: {
+ booking: bookingObj,
+ },
+ };
+}
diff --git a/apps/web/lib/video/meeting-not-started/[uid]/getServerSideProps.tsx b/apps/web/lib/video/meeting-not-started/[uid]/getServerSideProps.tsx
new file mode 100644
index 00000000000..ac2ba3d9cc7
--- /dev/null
+++ b/apps/web/lib/video/meeting-not-started/[uid]/getServerSideProps.tsx
@@ -0,0 +1,35 @@
+import type { GetServerSidePropsContext } from "next";
+
+import prisma, { bookingMinimalSelect } from "@calcom/prisma";
+
+// change the type
+export async function getServerSideProps(context: GetServerSidePropsContext) {
+ const booking = await prisma.booking.findUnique({
+ where: {
+ uid: context.query.uid as string,
+ },
+ select: bookingMinimalSelect,
+ });
+
+ if (!booking) {
+ const redirect = {
+ redirect: {
+ destination: "/video/no-meeting-found",
+ permanent: false,
+ },
+ } as const;
+
+ return redirect;
+ }
+
+ const bookingObj = Object.assign({}, booking, {
+ startTime: booking.startTime.toString(),
+ endTime: booking.endTime.toString(),
+ });
+
+ return {
+ props: {
+ booking: bookingObj,
+ },
+ };
+}
diff --git a/apps/web/pages/apps/[slug]/index.tsx b/apps/web/pages/apps/[slug]/index.tsx
index 27bd8dbdfbc..8c3cbe41250 100644
--- a/apps/web/pages/apps/[slug]/index.tsx
+++ b/apps/web/pages/apps/[slug]/index.tsx
@@ -1,19 +1,14 @@
"use client";
import { Prisma } from "@prisma/client";
-import fs from "fs";
-import matter from "gray-matter";
import MarkdownIt from "markdown-it";
-import type { GetStaticPaths, GetStaticPropsContext } from "next";
+import type { GetStaticPaths } from "next";
import Link from "next/link";
-import path from "path";
-import { z } from "zod";
-import { getAppWithMetadata } from "@calcom/app-store/_appRegistry";
-import { getAppAssetFullPath } from "@calcom/app-store/getAppAssetFullPath";
import { IS_PRODUCTION } from "@calcom/lib/constants";
import prisma from "@calcom/prisma";
+import { getStaticProps } from "@lib/apps/[slug]/getStaticProps";
import type { inferSSRProps } from "@lib/types/inferSSRProps";
import PageWrapper from "@components/PageWrapper";
@@ -21,23 +16,6 @@ import App from "@components/apps/App";
const md = new MarkdownIt("default", { html: true, breaks: true });
-const sourceSchema = z.object({
- content: z.string(),
- data: z.object({
- description: z.string().optional(),
- items: z
- .array(
- z.union([
- z.string(),
- z.object({
- iframe: z.object({ src: z.string() }),
- }),
- ])
- )
- .optional(),
- }),
-});
-
function SingleAppPage(props: inferSSRProps<typeof getStaticProps>) {
// If it's not production environment, it would be a better idea to inform that the App is disabled.
if (props.isAppDisabled) {
@@ -113,69 +91,7 @@ export const getStaticPaths: GetStaticPaths<{ slug: string }> = async () => {
};
};
-export const getStaticProps = async (ctx: GetStaticPropsContext) => {
- if (typeof ctx.params?.slug !== "string") return { notFound: true };
-
- const appMeta = await getAppWithMetadata({
- slug: ctx.params?.slug,
- });
-
- const appFromDb = await prisma.app.findUnique({
- where: { slug: ctx.params.slug.toLowerCase() },
- });
-
- const isAppAvailableInFileSystem = appMeta;
- const isAppDisabled = isAppAvailableInFileSystem && (!appFromDb || !appFromDb.enabled);
-
- if (!IS_PRODUCTION && isAppDisabled) {
- return {
- props: {
- isAppDisabled: true as const,
- data: {
- ...appMeta,
- },
- },
- };
- }
-
- if (!appFromDb || !appMeta || isAppDisabled) return { notFound: true };
-
- const isTemplate = appMeta.isTemplate;
- const appDirname = path.join(isTemplate ? "templates" : "", appFromDb.dirName);
- const README_PATH = path.join(process.cwd(), "..", "..", `packages/app-store/${appDirname}/DESCRIPTION.md`);
- const postFilePath = path.join(README_PATH);
- let source = "";
-
- try {
- source = fs.readFileSync(postFilePath).toString();
- source = source.replace(/{DESCRIPTION}/g, appMeta.description);
- } catch (error) {
- /* If the app doesn't have a README we fallback to the package description */
- console.log(`No DESCRIPTION.md provided for: ${appDirname}`);
- source = appMeta.description;
- }
-
- const result = matter(source);
- const { content, data } = sourceSchema.parse({ content: result.content, data: result.data });
- if (data.items) {
- data.items = data.items.map((item) => {
- if (typeof item === "string") {
- return getAppAssetFullPath(item, {
- dirName: appMeta.dirName,
- isTemplate: appMeta.isTemplate,
- });
- }
- return item;
- });
- }
- return {
- props: {
- isAppDisabled: false as const,
- source: { content, data },
- data: appMeta,
- },
- };
-};
+export { getStaticProps };
SingleAppPage.PageWrapper = PageWrapper;
diff --git a/apps/web/pages/apps/categories/[category].tsx b/apps/web/pages/apps/categories/[category].tsx
index 0cad97bfa10..7cbbd49e254 100644
--- a/apps/web/pages/apps/categories/[category].tsx
+++ b/apps/web/pages/apps/categories/[category].tsx
@@ -1,10 +1,9 @@
"use client";
import { Prisma } from "@prisma/client";
-import type { GetStaticPropsContext, InferGetStaticPropsType } from "next";
+import type { InferGetStaticPropsType } from "next";
import Link from "next/link";
-import { getAppRegistry } from "@calcom/app-store/_appRegistry";
import Shell from "@calcom/features/shell/Shell";
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
import { useLocale } from "@calcom/lib/hooks/useLocale";
@@ -12,6 +11,8 @@ import prisma from "@calcom/prisma";
import { AppCategories } from "@calcom/prisma/enums";
import { AppCard, SkeletonText } from "@calcom/ui";
+import { getStaticProps } from "@lib/apps/categories/[category]/getStaticProps";
+
import PageWrapper from "@components/PageWrapper";
export default function Apps({ apps }: InferGetStaticPropsType<typeof getStaticProps>) {
@@ -79,28 +80,4 @@ export const getStaticPaths = async () => {
};
};
-export const getStaticProps = async (context: GetStaticPropsContext) => {
- const category = context.params?.category as AppCategories;
-
- const appQuery = await prisma.app.findMany({
- where: {
- categories: {
- has: category,
- },
- },
- select: {
- slug: true,
- },
- });
-
- const dbAppsSlugs = appQuery.map((category) => category.slug);
-
- const appStore = await getAppRegistry();
-
- const apps = appStore.filter((app) => dbAppsSlugs.includes(app.slug));
- return {
- props: {
- apps,
- },
- };
-};
+export { getStaticProps };
diff --git a/apps/web/pages/apps/categories/index.tsx b/apps/web/pages/apps/categories/index.tsx
index 1012640fc8d..3db426927ce 100644
--- a/apps/web/pages/apps/categories/index.tsx
+++ b/apps/web/pages/apps/categories/index.tsx
@@ -1,19 +1,16 @@
"use client";
-import type { GetServerSidePropsContext } from "next";
import Link from "next/link";
-import { getAppRegistry, getAppRegistryWithCredentials } from "@calcom/app-store/_appRegistry";
-import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import Shell from "@calcom/features/shell/Shell";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import type { inferSSRProps } from "@calcom/types/inferSSRProps";
import { SkeletonText } from "@calcom/ui";
import { ArrowLeft, ArrowRight } from "@calcom/ui/components/icon";
-import PageWrapper from "@components/PageWrapper";
+import { getServerSideProps } from "@lib/apps/categories/getServerSideProps";
-import { ssrInit } from "@server/lib/ssr";
+import PageWrapper from "@components/PageWrapper";
export default function Apps({ categories }: Omit<inferSSRProps<typeof getServerSideProps>, "trpcState">) {
const { t, isLocaleReady } = useLocale();
@@ -53,31 +50,4 @@ export default function Apps({ categories }: Omit<inferSSRProps<typeof getServer
Apps.PageWrapper = PageWrapper;
-export const getServerSideProps = async (context: GetServerSidePropsContext) => {
- const { req, res } = context;
-
- const ssr = await ssrInit(context);
-
- const session = await getServerSession({ req, res });
-
- let appStore;
- if (session?.user?.id) {
- appStore = await getAppRegistryWithCredentials(session.user.id);
- } else {
- appStore = await getAppRegistry();
- }
-
- const categories = appStore.reduce((c, app) => {
- for (const category of app.categories) {
- c[category] = c[category] ? c[category] + 1 : 1;
- }
- return c;
- }, {} as Record<string, number>);
-
- return {
- props: {
- categories: Object.entries(categories).map(([name, count]) => ({ name, count })),
- trpcState: ssr.dehydrate(),
- },
- };
-};
+export { getServerSideProps };
diff --git a/apps/web/pages/apps/index.tsx b/apps/web/pages/apps/index.tsx
index 8315bdc4e3a..642f98d2620 100644
--- a/apps/web/pages/apps/index.tsx
+++ b/apps/web/pages/apps/index.tsx
@@ -1,17 +1,11 @@
"use client";
-import type { GetServerSidePropsContext } from "next";
import type { ChangeEventHandler } from "react";
import { useState } from "react";
-import { getAppRegistry, getAppRegistryWithCredentials } from "@calcom/app-store/_appRegistry";
import { getLayout } from "@calcom/features/MainLayout";
-import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
-import getUserAdminTeams from "@calcom/features/ee/teams/lib/getUserAdminTeams";
-import type { UserAdminTeams } from "@calcom/features/ee/teams/lib/getUserAdminTeams";
import { classNames } from "@calcom/lib";
import { useLocale } from "@calcom/lib/hooks/useLocale";
-import type { AppCategories } from "@calcom/prisma/enums";
import type { inferSSRProps } from "@calcom/types/inferSSRProps";
import type { HorizontalTabItemProps } from "@calcom/ui";
import {
@@ -24,11 +18,11 @@ import {
} from "@calcom/ui";
import { Search } from "@calcom/ui/components/icon";
+import { getServerSideProps } from "@lib/apps/getServerSideProps";
+
import PageWrapper from "@components/PageWrapper";
import AppsLayout from "@components/apps/layouts/AppsLayout";
-import { ssrInit } from "@server/lib/ssr";
-
const tabs: HorizontalTabItemProps[] = [
{
name: "app_store",
@@ -106,48 +100,7 @@ export default function Apps({
);
}
+export { getServerSideProps };
+
Apps.PageWrapper = PageWrapper;
Apps.getLayout = getLayout;
-
-export const getServerSideProps = async (context: GetServerSidePropsContext) => {
- const { req, res } = context;
-
- const ssr = await ssrInit(context);
-
- const session = await getServerSession({ req, res });
-
- let appStore, userAdminTeams: UserAdminTeams;
- if (session?.user?.id) {
- userAdminTeams = await getUserAdminTeams({ userId: session.user.id, getUserInfo: true });
- appStore = await getAppRegistryWithCredentials(session.user.id, userAdminTeams);
- } else {
- appStore = await getAppRegistry();
- userAdminTeams = [];
- }
-
- const categoryQuery = appStore.map(({ categories }) => ({
- categories: categories || [],
- }));
- const categories = categoryQuery.reduce((c, app) => {
- for (const category of app.categories) {
- c[category] = c[category] ? c[category] + 1 : 1;
- }
- return c;
- }, {} as Record<string, number>);
-
- return {
- props: {
- categories: Object.entries(categories)
- .map(([name, count]): { name: AppCategories; count: number } => ({
- name: name as AppCategories,
- count,
- }))
- .sort(function (a, b) {
- return b.count - a.count;
- }),
- appStore,
- userAdminTeams,
- trpcState: ssr.dehydrate(),
- },
- };
-};
diff --git a/apps/web/pages/apps/installed/[category].tsx b/apps/web/pages/apps/installed/[category].tsx
index 5a207ecc136..6f5159c1f8c 100644
--- a/apps/web/pages/apps/installed/[category].tsx
+++ b/apps/web/pages/apps/installed/[category].tsx
@@ -1,14 +1,12 @@
"use client";
import { useReducer } from "react";
-import { z } from "zod";
import DisconnectIntegrationModal from "@calcom/features/apps/components/DisconnectIntegrationModal";
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { AppCategories } from "@calcom/prisma/enums";
import { trpc } from "@calcom/trpc/react";
-import type { AppGetServerSidePropsContext } from "@calcom/types/AppGetServerSideProps";
import { Button, EmptyScreen, AppSkeletonLoader as SkeletonLoader, ShellSubHeading } from "@calcom/ui";
import type { LucideIcon } from "@calcom/ui/components/icon";
import {
@@ -24,6 +22,8 @@ import {
} from "@calcom/ui/components/icon";
import { QueryCell } from "@lib/QueryCell";
+import type { querySchemaType } from "@lib/apps/installed/[category]/getServerSideProps";
+import { getServerSideProps } from "@lib/apps/installed/[category]/getServerSideProps";
import PageWrapper from "@components/PageWrapper";
import { AppList } from "@components/apps/AppList";
@@ -111,12 +111,6 @@ const IntegrationsContainer = ({
);
};
-const querySchema = z.object({
- category: z.nativeEnum(AppCategories),
-});
-
-type querySchemaType = z.infer<typeof querySchema>;
-
type ModalState = {
isOpen: boolean;
credentialId: null | number;
@@ -173,31 +167,6 @@ export default function InstalledApps() {
);
}
-// Server side rendering
-export async function getServerSideProps(ctx: AppGetServerSidePropsContext) {
- // get return-to cookie and redirect if needed
- const { cookies } = ctx.req;
- if (cookies && cookies["return-to"]) {
- const returnTo = cookies["return-to"];
- if (returnTo) {
- ctx.res.setHeader("Set-Cookie", "return-to=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT");
- return {
- redirect: {
- destination: `${returnTo}`,
- permanent: false,
- },
- };
- }
- }
- const params = querySchema.safeParse(ctx.params);
-
- if (!params.success) return { notFound: true };
-
- return {
- props: {
- category: params.data.category,
- },
- };
-}
+export { getServerSideProps };
InstalledApps.PageWrapper = PageWrapper;
diff --git a/apps/web/pages/apps/installed/index.tsx b/apps/web/pages/apps/installed/index.tsx
index a73184d48ae..02786d55a89 100644
--- a/apps/web/pages/apps/installed/index.tsx
+++ b/apps/web/pages/apps/installed/index.tsx
@@ -1,9 +1,7 @@
+export { getServerSideProps } from "@lib/apps/installed/getServerSideProps";
+
function RedirectPage() {
return;
}
-export async function getServerSideProps() {
- return { redirect: { permanent: false, destination: "/apps/installed/calendar" } };
-}
-
export default RedirectPage;
diff --git a/apps/web/pages/d/[link]/[slug].tsx b/apps/web/pages/d/[link]/[slug].tsx
index f09fd26893e..8a52eff77d3 100644
--- a/apps/web/pages/d/[link]/[slug].tsx
+++ b/apps/web/pages/d/[link]/[slug].tsx
@@ -1,25 +1,13 @@
"use client";
-import type { GetServerSidePropsContext } from "next";
-import { z } from "zod";
-
import { Booker } from "@calcom/atoms";
-import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { getBookerWrapperClasses } from "@calcom/features/bookings/Booker/utils/getBookerWrapperClasses";
import { BookerSeo } from "@calcom/features/bookings/components/BookerSeo";
-import { getBookingForReschedule, getMultipleDurationValue } from "@calcom/features/bookings/lib/get-booking";
-import type { GetBookingType } from "@calcom/features/bookings/lib/get-booking";
-import { orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains";
-import slugify from "@calcom/lib/slugify";
-import prisma from "@calcom/prisma";
-import type { inferSSRProps } from "@lib/types/inferSSRProps";
-import type { EmbedProps } from "@lib/withEmbedSsr";
+import { getServerSideProps, type PageProps } from "@lib/d/[link]/[slug]/getServerSideProps";
import PageWrapper from "@components/PageWrapper";
-export type PageProps = Omit<inferSSRProps<typeof getServerSideProps>, "trpcState"> & EmbedProps;
-
export default function Type({
slug,
isEmbed,
@@ -56,114 +44,7 @@ export default function Type({
);
}
+export { getServerSideProps };
+
Type.PageWrapper = PageWrapper;
Type.isBookingPage = true;
-
-async function getUserPageProps(context: GetServerSidePropsContext) {
- const session = await getServerSession(context);
- const { link, slug } = paramsSchema.parse(context.params);
- const { rescheduleUid, duration: queryDuration } = context.query;
- const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(context.req);
- const org = isValidOrgDomain ? currentOrgDomain : null;
-
- const { ssrInit } = await import("@server/lib/ssr");
- const ssr = await ssrInit(context);
-
- const hashedLink = await prisma.hashedLink.findUnique({
- where: {
- link,
- },
- select: {
- eventTypeId: true,
- eventType: {
- select: {
- users: {
- select: {
- username: true,
- },
- },
- team: {
- select: {
- id: true,
- },
- },
- },
- },
- },
- });
-
- const username = hashedLink?.eventType.users[0]?.username;
-
- if (!hashedLink || !username) {
- return {
- notFound: true,
- };
- }
-
- const user = await prisma.user.findFirst({
- where: {
- username,
- organization: isValidOrgDomain
- ? {
- slug: currentOrgDomain,
- }
- : null,
- },
- select: {
- away: true,
- hideBranding: true,
- },
- });
-
- if (!user) {
- return {
- notFound: true,
- };
- }
-
- let booking: GetBookingType | null = null;
- if (rescheduleUid) {
- booking = await getBookingForReschedule(`${rescheduleUid}`, session?.user?.id);
- }
-
- const isTeamEvent = !!hashedLink.eventType?.team?.id;
-
- // We use this to both prefetch the query on the server,
- // as well as to check if the event exist, so we c an show a 404 otherwise.
- const eventData = await ssr.viewer.public.event.fetch({ username, eventSlug: slug, isTeamEvent, org });
-
- if (!eventData) {
- return {
- notFound: true,
- };
- }
-
- return {
- props: {
- entity: eventData.entity,
- duration: getMultipleDurationValue(
- eventData.metadata?.multipleDuration,
- queryDuration,
- eventData.length
- ),
- booking,
- away: user?.away,
- user: username,
- slug,
- trpcState: ssr.dehydrate(),
- isBrandingHidden: user?.hideBranding,
- // Sending the team event from the server, because this template file
- // is reused for both team and user events.
- isTeamEvent,
- hashedLink: link,
- },
- };
-}
-
-const paramsSchema = z.object({ link: z.string(), slug: z.string().transform((s) => slugify(s)) });
-
-// Booker page fetches a tiny bit of data server side, to determine early
-// whether the page should show an away state or dynamic booking not allowed.
-export const getServerSideProps = async (context: GetServerSidePropsContext) => {
- return await getUserPageProps(context);
-};
diff --git a/apps/web/pages/event-types/[type]/index.tsx b/apps/web/pages/event-types/[type]/index.tsx
index cdad0b5c1c0..4125402d8ab 100644
--- a/apps/web/pages/event-types/[type]/index.tsx
+++ b/apps/web/pages/event-types/[type]/index.tsx
@@ -2,7 +2,6 @@
import { useAutoAnimate } from "@formkit/auto-animate/react";
import { zodResolver } from "@hookform/resolvers/zod";
import { isValidPhoneNumber } from "libphonenumber-js";
-import type { GetServerSidePropsContext } from "next";
import dynamic from "next/dynamic";
import { useEffect, useMemo, useState } from "react";
import { useForm } from "react-hook-form";
@@ -12,7 +11,6 @@ import checkForMultiplePaymentApps from "@calcom/app-store/_utils/payments/check
import { getEventLocationType } from "@calcom/app-store/locations";
import { validateCustomEventName } from "@calcom/core/event";
import type { EventLocationType } from "@calcom/core/location";
-import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import type { ChildrenEventType } from "@calcom/features/eventtypes/components/ChildrenEventTypeSelect";
import { validateIntervalLimitOrder } from "@calcom/lib";
import { CAL_URL } from "@calcom/lib/constants";
@@ -34,15 +32,12 @@ import { trpc } from "@calcom/trpc/react";
import type { IntervalLimit, RecurringEvent } from "@calcom/types/Calendar";
import { Form, showToast } from "@calcom/ui";
-import { asStringOrThrow } from "@lib/asStringOrNull";
-import type { inferSSRProps } from "@lib/types/inferSSRProps";
+import { getServerSideProps, type PageProps } from "@lib/event-types/[type]/getServerSideProps";
import PageWrapper from "@components/PageWrapper";
import type { AvailabilityOption } from "@components/eventtype/EventAvailabilityTab";
import { EventTypeSingleLayout } from "@components/eventtype/EventTypeSingleLayout";
-import { ssrInit } from "@server/lib/ssr";
-
// These can't really be moved into calcom/ui due to the fact they use infered getserverside props typings;
const EventSetupTab = dynamic(() =>
import("@components/eventtype/EventSetupTab").then((mod) => mod.EventSetupTab)
@@ -669,45 +664,14 @@ const EventTypePage = (props: EventTypeSetupProps) => {
);
};
-const EventTypePageWrapper = (props: inferSSRProps<typeof getServerSideProps>) => {
+const EventTypePageWrapper = (props: PageProps) => {
const { data } = trpc.viewer.eventTypes.get.useQuery({ id: props.type });
if (!data) return null;
return <EventTypePage {...(data as EventTypeSetupProps)} />;
};
-export const getServerSideProps = async (context: GetServerSidePropsContext) => {
- const { req, res, query } = context;
-
- const session = await getServerSession({ req, res });
-
- const typeParam = parseInt(asStringOrThrow(query.type));
- const ssr = await ssrInit(context);
-
- if (Number.isNaN(typeParam)) {
- return {
- notFound: true,
- };
- }
-
- if (!session?.user?.id) {
- return {
- redirect: {
- permanent: false,
- destination: "/auth/login",
- },
- };
- }
-
- await ssr.viewer.eventTypes.get.prefetch({ id: typeParam });
- return {
- props: {
- type: typeParam,
- trpcState: ssr.dehydrate(),
- },
- };
-};
-
EventTypePageWrapper.PageWrapper = PageWrapper;
+export { getServerSideProps };
export default EventTypePageWrapper;
diff --git a/apps/web/pages/getting-started/[[...step]].tsx b/apps/web/pages/getting-started/[[...step]].tsx
index 28d5086dcd2..7cc0080fd80 100644
--- a/apps/web/pages/getting-started/[[...step]].tsx
+++ b/apps/web/pages/getting-started/[[...step]].tsx
@@ -1,19 +1,14 @@
"use client";
-import type { GetServerSidePropsContext } from "next";
-import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import Head from "next/head";
import { usePathname, useRouter } from "next/navigation";
import { Suspense } from "react";
import { z } from "zod";
-import { getLocale } from "@calcom/features/auth/lib/getLocale";
-import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { classNames } from "@calcom/lib";
import { APP_NAME } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { useParamsWithFallback } from "@calcom/lib/hooks/useParamsWithFallback";
-import prisma from "@calcom/prisma";
import { trpc } from "@calcom/trpc";
import { Button, StepCard, Steps } from "@calcom/ui";
import { Loader } from "@calcom/ui/components/icon";
@@ -25,7 +20,7 @@ import { SetupAvailability } from "@components/getting-started/steps-views/Setup
import UserProfile from "@components/getting-started/steps-views/UserProfile";
import { UserSettings } from "@components/getting-started/steps-views/UserSettings";
-import { ssrInit } from "@server/lib/ssr";
+export { getServerSideProps } from "@lib/getting-started/[[...step]]/getServerSideProps";
const INITIAL_STEP = "user-settings";
const steps = [
@@ -183,57 +178,6 @@ const OnboardingPage = () => {
);
};
-export const getServerSideProps = async (context: GetServerSidePropsContext) => {
- const { req, res } = context;
-
- const session = await getServerSession({ req, res });
-
- if (!session?.user?.id) {
- return { redirect: { permanent: false, destination: "/auth/login" } };
- }
-
- const ssr = await ssrInit(context);
-
- await ssr.viewer.me.prefetch();
-
- const user = await prisma.user.findUnique({
- where: {
- id: session.user.id,
- },
- select: {
- completedOnboarding: true,
- teams: {
- select: {
- accepted: true,
- team: {
- select: {
- id: true,
- name: true,
- logo: true,
- },
- },
- },
- },
- },
- });
-
- if (!user) {
- throw new Error("User from session not found");
- }
-
- if (user.completedOnboarding) {
- return { redirect: { permanent: false, destination: "/event-types" } };
- }
- const locale = await getLocale(context.req);
- return {
- props: {
- ...(await serverSideTranslations(locale, ["common"])),
- trpcState: ssr.dehydrate(),
- hasPendingInvites: user.teams.find((team) => team.accepted === false) ?? false,
- },
- };
-};
-
OnboardingPage.PageWrapper = PageWrapper;
export default OnboardingPage;
diff --git a/apps/web/pages/org/[orgSlug]/[user]/[type]/embed.tsx b/apps/web/pages/org/[orgSlug]/[user]/[type]/embed.tsx
index 9b0fb7a7a8b..63531e5f392 100644
--- a/apps/web/pages/org/[orgSlug]/[user]/[type]/embed.tsx
+++ b/apps/web/pages/org/[orgSlug]/[user]/[type]/embed.tsx
@@ -4,6 +4,6 @@ import withEmbedSsr from "@lib/withEmbedSsr";
import { getServerSideProps as _getServerSideProps } from "../[type]";
-export { default } from "../[type]";
+export { default, type PageProps } from "../[type]";
export const getServerSideProps = withEmbedSsr(_getServerSideProps);
diff --git a/apps/web/pages/teams/index.tsx b/apps/web/pages/teams/index.tsx
index 87a49c83ac7..38c06ff35ae 100644
--- a/apps/web/pages/teams/index.tsx
+++ b/apps/web/pages/teams/index.tsx
@@ -1,9 +1,6 @@
"use client";
-import type { GetServerSidePropsContext } from "next";
-
import { getLayout } from "@calcom/features/MainLayout";
-import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { TeamsListing } from "@calcom/features/ee/teams/components";
import { ShellMain } from "@calcom/features/shell/Shell";
import { WEBAPP_URL } from "@calcom/lib/constants";
@@ -14,7 +11,7 @@ import { Plus } from "@calcom/ui/components/icon";
import PageWrapper from "@components/PageWrapper";
-import { ssrInit } from "@server/lib/ssr";
+export { getServerSideProps } from "@lib/teams/getServerSideProps";
function Teams() {
const { t } = useLocale();
@@ -42,27 +39,6 @@ function Teams() {
);
}
-export const getServerSideProps = async (context: GetServerSidePropsContext) => {
- const ssr = await ssrInit(context);
- await ssr.viewer.me.prefetch();
- const session = await getServerSession({ req: context.req, res: context.res });
- const token = Array.isArray(context.query?.token) ? context.query.token[0] : context.query?.token;
-
- const callbackUrl = token ? `/teams?token=${encodeURIComponent(token)}` : null;
-
- if (!session) {
- return {
- redirect: {
- destination: callbackUrl ? `/auth/login?callbackUrl=${callbackUrl}` : "/auth/login",
- permanent: false,
- },
- props: {},
- };
- }
-
- return { props: { trpcState: ssr.dehydrate() } };
-};
-
Teams.requiresLicense = false;
Teams.PageWrapper = PageWrapper;
Teams.getLayout = getLayout;
diff --git a/apps/web/pages/video/[uid].tsx b/apps/web/pages/video/[uid].tsx
index ce6057f2e3b..c3da0f43337 100644
--- a/apps/web/pages/video/[uid].tsx
+++ b/apps/web/pages/video/[uid].tsx
@@ -1,29 +1,23 @@
"use client";
import DailyIframe from "@daily-co/daily-js";
-import MarkdownIt from "markdown-it";
-import type { GetServerSidePropsContext } from "next";
import Head from "next/head";
import { useState, useEffect, useRef } from "react";
import dayjs from "@calcom/dayjs";
-import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
-import { getCalVideoReference } from "@calcom/features/get-cal-video-reference";
import classNames from "@calcom/lib/classNames";
import { APP_NAME, SEO_IMG_OGIMG_VIDEO, WEBSITE_URL } from "@calcom/lib/constants";
import { formatToLocalizedDate, formatToLocalizedTime } from "@calcom/lib/date-fns";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML";
-import prisma, { bookingMinimalSelect } from "@calcom/prisma";
import type { inferSSRProps } from "@calcom/types/inferSSRProps";
import { ChevronRight } from "@calcom/ui/components/icon";
-import PageWrapper from "@components/PageWrapper";
+import type { getServerSideProps } from "@lib/video/[uid]/getServerSideProps";
-import { ssrInit } from "@server/lib/ssr";
+import PageWrapper from "@components/PageWrapper";
export type JoinCallPageProps = Omit<inferSSRProps<typeof getServerSideProps>, "trpcState">;
-const md = new MarkdownIt("default", { html: true, breaks: true, linkify: true });
export default function JoinCall(props: JoinCallPageProps) {
const { t } = useLocale();
@@ -254,98 +248,3 @@ export function VideoMeetingInfo(props: VideoMeetingInfo) {
}
JoinCall.PageWrapper = PageWrapper;
-
-export async function getServerSideProps(context: GetServerSidePropsContext) {
- const { req, res } = context;
-
- const ssr = await ssrInit(context);
-
- const booking = await prisma.booking.findUnique({
- where: {
- uid: context.query.uid as string,
- },
- select: {
- ...bookingMinimalSelect,
- uid: true,
- description: true,
- isRecorded: true,
- user: {
- select: {
- id: true,
- timeZone: true,
- name: true,
- email: true,
- organization: {
- select: {
- calVideoLogo: true,
- },
- },
- },
- },
- references: {
- select: {
- uid: true,
- type: true,
- meetingUrl: true,
- meetingPassword: true,
- },
- where: {
- type: "daily_video",
- },
- },
- },
- });
-
- if (!booking || booking.references.length === 0 || !booking.references[0].meetingUrl) {
- return {
- redirect: {
- destination: "/video/no-meeting-found",
- permanent: false,
- },
- };
- }
-
- //daily.co calls have a 60 minute exit buffer when a user enters a call when it's not available it will trigger the modals
- const now = new Date();
- const exitDate = new Date(now.getTime() - 60 * 60 * 1000);
-
- //find out if the meeting is in the past
- const isPast = booking?.endTime <= exitDate;
- if (isPast) {
- return {
- redirect: {
- destination: `/video/meeting-ended/${booking?.uid}`,
- permanent: false,
- },
- };
- }
-
- const bookingObj = Object.assign({}, booking, {
- startTime: booking.startTime.toString(),
- endTime: booking.endTime.toString(),
- });
-
- const session = await getServerSession({ req, res });
-
- // set meetingPassword to null for guests
- if (session?.user.id !== bookingObj.user?.id) {
- bookingObj.references.forEach((bookRef) => {
- bookRef.meetingPassword = null;
- });
- }
- const videoReference = getCalVideoReference(bookingObj.references);
-
- return {
- props: {
- meetingUrl: videoReference.meetingUrl ?? "",
- ...(typeof videoReference.meetingPassword === "string" && {
- meetingPassword: videoReference.meetingPassword,
- }),
- booking: {
- ...bookingObj,
- ...(bookingObj.description && { description: md.render(bookingObj.description) }),
- },
- trpcState: ssr.dehydrate(),
- },
- };
-}
diff --git a/apps/web/pages/video/meeting-ended/[uid].tsx b/apps/web/pages/video/meeting-ended/[uid].tsx
index ce13db62335..75d867e23ae 100644
--- a/apps/web/pages/video/meeting-ended/[uid].tsx
+++ b/apps/web/pages/video/meeting-ended/[uid].tsx
@@ -1,15 +1,13 @@
"use client";
-import type { NextPageContext } from "next";
-
import dayjs from "@calcom/dayjs";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { detectBrowserTimeFormat } from "@calcom/lib/timeFormat";
-import prisma, { bookingMinimalSelect } from "@calcom/prisma";
import { Button, HeadSeo } from "@calcom/ui";
import { ArrowRight, Calendar, X } from "@calcom/ui/components/icon";
import type { inferSSRProps } from "@lib/types/inferSSRProps";
+import { getServerSideProps } from "@lib/video/meeting-ended/[uid]/getServerSideProps";
import PageWrapper from "@components/PageWrapper";
@@ -66,48 +64,5 @@ export default function MeetingUnavailable(props: inferSSRProps<typeof getServer
);
}
+export { getServerSideProps };
MeetingUnavailable.PageWrapper = PageWrapper;
-
-export async function getServerSideProps(context: NextPageContext) {
- const booking = await prisma.booking.findUnique({
- where: {
- uid: context.query.uid as string,
- },
- select: {
- ...bookingMinimalSelect,
- uid: true,
- user: {
- select: {
- credentials: true,
- },
- },
- references: {
- select: {
- uid: true,
- type: true,
- meetingUrl: true,
- },
- },
- },
- });
-
- if (!booking) {
- return {
- redirect: {
- destination: "/video/no-meeting-found",
- permanent: false,
- },
- };
- }
-
- const bookingObj = Object.assign({}, booking, {
- startTime: booking.startTime.toString(),
- endTime: booking.endTime.toString(),
- });
-
- return {
- props: {
- booking: bookingObj,
- },
- };
-}
diff --git a/apps/web/pages/video/meeting-not-started/[uid].tsx b/apps/web/pages/video/meeting-not-started/[uid].tsx
index 26a2c50070d..f43724026a6 100644
--- a/apps/web/pages/video/meeting-not-started/[uid].tsx
+++ b/apps/web/pages/video/meeting-not-started/[uid].tsx
@@ -1,15 +1,14 @@
"use client";
-import type { NextPageContext } from "next";
-
import dayjs from "@calcom/dayjs";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { detectBrowserTimeFormat } from "@calcom/lib/timeFormat";
-import prisma, { bookingMinimalSelect } from "@calcom/prisma";
import type { inferSSRProps } from "@calcom/types/inferSSRProps";
import { Button, HeadSeo, EmptyScreen } from "@calcom/ui";
import { ArrowRight, Calendar, Clock } from "@calcom/ui/components/icon";
+import { getServerSideProps } from "@lib/video/meeting-not-started/[uid]/getServerSideProps";
+
import PageWrapper from "@components/PageWrapper";
export default function MeetingNotStarted(props: inferSSRProps<typeof getServerSideProps>) {
@@ -41,33 +40,6 @@ export default function MeetingNotStarted(props: inferSSRProps<typeof getServerS
);
}
-MeetingNotStarted.PageWrapper = PageWrapper;
-
-export async function getServerSideProps(context: NextPageContext) {
- const booking = await prisma.booking.findUnique({
- where: {
- uid: context.query.uid as string,
- },
- select: bookingMinimalSelect,
- });
+export { getServerSideProps };
- if (!booking) {
- return {
- redirect: {
- destination: "/video/no-meeting-found",
- permanent: false,
- },
- };
- }
-
- const bookingObj = Object.assign({}, booking, {
- startTime: booking.startTime.toString(),
- endTime: booking.endTime.toString(),
- });
-
- return {
- props: {
- booking: bookingObj,
- },
- };
-}
+MeetingNotStarted.PageWrapper = PageWrapper;
diff --git a/apps/web/playwright/organization/organization-invitation.e2e.ts b/apps/web/playwright/organization/organization-invitation.e2e.ts
index 48e97214091..970f5869953 100644
--- a/apps/web/playwright/organization/organization-invitation.e2e.ts
+++ b/apps/web/playwright/organization/organization-invitation.e2e.ts
@@ -395,11 +395,11 @@ async function signupFromEmailInviteLink({
signupPage.goto(inviteLink);
await signupPage.locator(`[data-testid="signup-usernamefield"]`).waitFor({ state: "visible" });
await expect(signupPage.locator(`[data-testid="signup-usernamefield"]`)).toBeDisabled();
- expect(await signupPage.locator(`[data-testid="signup-usernamefield"]`).inputValue()).toBe(
- expectedUsername
- );
+ // await for value. initial value is ""
+ await expect(signupPage.locator(`[data-testid="signup-usernamefield"]`)).toHaveValue(expectedUsername);
+
await expect(signupPage.locator(`[data-testid="signup-emailfield"]`)).toBeDisabled();
- expect(await signupPage.locator(`[data-testid="signup-emailfield"]`).inputValue()).toBe(expectedEmail);
+ await expect(signupPage.locator(`[data-testid="signup-emailfield"]`)).toHaveValue(expectedEmail);
await signupPage.waitForLoadState("networkidle");
// Check required fields
diff --git a/packages/app-store/alby/pages/setup/_getServerSideProps.tsx b/packages/app-store/alby/pages/setup/_getServerSideProps.tsx
index 379f04f1607..9e7e476237c 100644
--- a/packages/app-store/alby/pages/setup/_getServerSideProps.tsx
+++ b/packages/app-store/alby/pages/setup/_getServerSideProps.tsx
@@ -7,19 +7,23 @@ import { getAlbyKeys } from "../../lib/getAlbyKeys";
import type { IAlbySetupProps } from "./index";
export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
- if (typeof ctx.params?.slug !== "string") return { notFound: true } as const;
+ const notFound = { notFound: true } as const;
+
+ if (typeof ctx.params?.slug !== "string") return notFound;
const { req, res } = ctx;
const session = await getServerSession({ req, res });
if (!session?.user?.id) {
- return res.writeHead(401).end();
+ const redirect = { redirect: { permanent: false, destination: "/auth/login" } } as const;
+
+ return redirect;
}
const credentials = await prisma.credential.findFirst({
where: {
type: "alby_payment",
- userId: session.user.id,
+ userId: session?.user.id,
},
});
diff --git a/packages/app-store/make/pages/setup/_getServerSideProps.tsx b/packages/app-store/make/pages/setup/_getServerSideProps.tsx
index 1582221efd1..b597f68c38d 100644
--- a/packages/app-store/make/pages/setup/_getServerSideProps.tsx
+++ b/packages/app-store/make/pages/setup/_getServerSideProps.tsx
@@ -7,7 +7,9 @@ export interface IMakeSetupProps {
}
export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
- if (typeof ctx.params?.slug !== "string") return { notFound: true } as const;
+ const notFound = { notFound: true } as const;
+
+ if (typeof ctx.params?.slug !== "string") return notFound;
let inviteLink = "";
const appKeys = await getAppKeysFromSlug("make");
if (typeof appKeys.invite_link === "string") inviteLink = appKeys.invite_link;
diff --git a/packages/app-store/stripepayment/pages/setup/_getServerSideProps.ts b/packages/app-store/stripepayment/pages/setup/_getServerSideProps.ts
index 788563cb993..242439236ab 100644
--- a/packages/app-store/stripepayment/pages/setup/_getServerSideProps.ts
+++ b/packages/app-store/stripepayment/pages/setup/_getServerSideProps.ts
@@ -1,7 +1,8 @@
import type { GetServerSidePropsContext } from "next";
export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
- if (typeof ctx.params?.slug !== "string") return { notFound: true } as const;
+ const notFound = { notFound: true } as const;
+ if (typeof ctx.params?.slug !== "string") return notFound;
const targetUrl = "https://dashboard.stripe.com/settings/connect";
return {
redirect: {
diff --git a/packages/app-store/zapier/pages/setup/_getServerSideProps.tsx b/packages/app-store/zapier/pages/setup/_getServerSideProps.tsx
index 9231c683bd0..04bb5760365 100644
--- a/packages/app-store/zapier/pages/setup/_getServerSideProps.tsx
+++ b/packages/app-store/zapier/pages/setup/_getServerSideProps.tsx
@@ -7,7 +7,9 @@ export interface IZapierSetupProps {
}
export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
- if (typeof ctx.params?.slug !== "string") return { notFound: true } as const;
+ const notFound = { notFound: true } as const;
+
+ if (typeof ctx.params?.slug !== "string") return notFound;
let inviteLink = "";
const appKeys = await getAppKeysFromSlug("zapier");
if (typeof appKeys.invite_link === "string") inviteLink = appKeys.invite_link;
diff --git a/packages/embeds/embed-core/playwright/tests/action-based.e2e.ts b/packages/embeds/embed-core/playwright/tests/action-based.e2e.ts
index 7bf0e5fa3cc..5bc3190016c 100644
--- a/packages/embeds/embed-core/playwright/tests/action-based.e2e.ts
+++ b/packages/embeds/embed-core/playwright/tests/action-based.e2e.ts
@@ -14,6 +14,9 @@ import {
rescheduleEvent,
} from "../lib/testUtils";
+// in parallel mode sometimes handleNewBooking endpoint throws "No available users found" error, this never happens in serial mode.
+test.describe.configure({ mode: "serial" });
+
async function bookFirstFreeUserEventThroughEmbed({
addEmbedListeners,
page,