chore: Refactor to remove getServerSideProps for /teams route (#19286)

* remove getServerSideProps

* refactor teams route
This commit is contained in:
Benny Joo
2025-02-13 17:46:56 +00:00
committed by GitHub
parent 37f1535e1a
commit 9f34a840d0
3 changed files with 14 additions and 40 deletions
@@ -1,13 +1,13 @@
import { ShellMainAppDir } from "app/(use-page-wrapper)/(main-nav)/ShellMainAppDir";
import { withAppDirSsr } from "app/WithAppDirSsr";
import type { PageProps as ServerPageProps } from "app/_types";
import { _generateMetadata, getTranslate } from "app/_utils";
import { cookies, headers } from "next/headers";
import { redirect } from "next/navigation";
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
import { getServerSideProps } from "@lib/teams/getServerSideProps";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
import type { PageProps as ClientPageProps } from "~/teams/teams-view";
import TeamsView, { TeamsCTA } from "~/teams/teams-view";
export const generateMetadata = async () =>
@@ -16,11 +16,15 @@ export const generateMetadata = async () =>
(t) => t("create_manage_teams_collaborative")
);
const getData = withAppDirSsr<ClientPageProps>(getServerSideProps);
const ServerPage = async ({ searchParams }: ServerPageProps) => {
const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
const token = Array.isArray(searchParams?.token) ? searchParams.token[0] : searchParams?.token;
const callbackUrl = token ? `/teams?token=${encodeURIComponent(token)}` : null;
if (!session) {
redirect(callbackUrl ? `/auth/login?callbackUrl=${callbackUrl}` : "/auth/login");
}
const ServerPage = async ({ params, searchParams }: ServerPageProps) => {
const context = buildLegacyCtx(headers(), cookies(), params, searchParams);
const props = await getData(context);
const t = await getTranslate();
return (
@@ -28,7 +32,7 @@ const ServerPage = async ({ params, searchParams }: ServerPageProps) => {
CTA={<TeamsCTA />}
heading={t("teams")}
subtitle={t("create_manage_teams_collaborative")}>
<TeamsView {...props} />
<TeamsView />
</ShellMainAppDir>
);
};
-25
View File
@@ -1,25 +0,0 @@
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 });
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() } };
};
+1 -6
View File
@@ -4,13 +4,8 @@ import { TeamsListing } from "@calcom/features/ee/teams/components";
import { WEBAPP_URL } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import type { inferSSRProps } from "@calcom/types/inferSSRProps";
import { Button } from "@calcom/ui";
import type { getServerSideProps } from "@lib/teams/getServerSideProps";
export type PageProps = inferSSRProps<typeof getServerSideProps>;
export const TeamsCTA = () => {
const { t } = useLocale();
const [user] = trpc.viewer.me.useSuspenseQuery();
@@ -26,7 +21,7 @@ export const TeamsCTA = () => {
) : null;
};
function Teams(props: PageProps) {
function Teams() {
return <TeamsListing />;
}