Skip to content

Commit 9f34a84

Browse files
authored
chore: Refactor to remove getServerSideProps for /teams route (#19286)
* remove getServerSideProps * refactor teams route
1 parent 37f1535 commit 9f34a84

File tree

3 files changed

+14
-40
lines changed

3 files changed

+14
-40
lines changed

apps/web/app/(use-page-wrapper)/(main-nav)/teams/page.tsx

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { ShellMainAppDir } from "app/(use-page-wrapper)/(main-nav)/ShellMainAppDir";
2-
import { withAppDirSsr } from "app/WithAppDirSsr";
32
import type { PageProps as ServerPageProps } from "app/_types";
43
import { _generateMetadata, getTranslate } from "app/_utils";
54
import { cookies, headers } from "next/headers";
5+
import { redirect } from "next/navigation";
66

7-
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
8-
import { getServerSideProps } from "@lib/teams/getServerSideProps";
7+
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
8+
9+
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
910

10-
import type { PageProps as ClientPageProps } from "~/teams/teams-view";
1111
import TeamsView, { TeamsCTA } from "~/teams/teams-view";
1212

1313
export const generateMetadata = async () =>
@@ -16,19 +16,23 @@ export const generateMetadata = async () =>
1616
(t) => t("create_manage_teams_collaborative")
1717
);
1818

19-
const getData = withAppDirSsr<ClientPageProps>(getServerSideProps);
19+
const ServerPage = async ({ searchParams }: ServerPageProps) => {
20+
const session = await getServerSession({ req: buildLegacyRequest(headers(), cookies()) });
21+
const token = Array.isArray(searchParams?.token) ? searchParams.token[0] : searchParams?.token;
22+
const callbackUrl = token ? `/teams?token=${encodeURIComponent(token)}` : null;
23+
24+
if (!session) {
25+
redirect(callbackUrl ? `/auth/login?callbackUrl=${callbackUrl}` : "/auth/login");
26+
}
2027

21-
const ServerPage = async ({ params, searchParams }: ServerPageProps) => {
22-
const context = buildLegacyCtx(headers(), cookies(), params, searchParams);
23-
const props = await getData(context);
2428
const t = await getTranslate();
2529

2630
return (
2731
<ShellMainAppDir
2832
CTA={<TeamsCTA />}
2933
heading={t("teams")}
3034
subtitle={t("create_manage_teams_collaborative")}>
31-
<TeamsView {...props} />
35+
<TeamsView />
3236
</ShellMainAppDir>
3337
);
3438
};

apps/web/lib/teams/getServerSideProps.tsx

-25
This file was deleted.

apps/web/modules/teams/teams-view.tsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ import { TeamsListing } from "@calcom/features/ee/teams/components";
44
import { WEBAPP_URL } from "@calcom/lib/constants";
55
import { useLocale } from "@calcom/lib/hooks/useLocale";
66
import { trpc } from "@calcom/trpc/react";
7-
import type { inferSSRProps } from "@calcom/types/inferSSRProps";
87
import { Button } from "@calcom/ui";
98

10-
import type { getServerSideProps } from "@lib/teams/getServerSideProps";
11-
12-
export type PageProps = inferSSRProps<typeof getServerSideProps>;
13-
149
export const TeamsCTA = () => {
1510
const { t } = useLocale();
1611
const [user] = trpc.viewer.me.useSuspenseQuery();
@@ -26,7 +21,7 @@ export const TeamsCTA = () => {
2621
) : null;
2722
};
2823

29-
function Teams(props: PageProps) {
24+
function Teams() {
3025
return <TeamsListing />;
3126
}
3227

0 commit comments

Comments
 (0)