Skip to content

Commit fafd3fb

Browse files
authored
refactor: Get rid of getServerSideProps for /getting-started pages (calcom#23003)
* refactor * fix type check
1 parent eb05d54 commit fafd3fb

3 files changed

Lines changed: 23 additions & 42 deletions

File tree

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { withAppDirSsr } from "app/WithAppDirSsr";
21
import type { PageProps as ServerPageProps } from "app/_types";
32
import { _generateMetadata } from "app/_utils";
43
import { cookies, headers } from "next/headers";
4+
import { redirect } from "next/navigation";
55

6+
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
67
import { APP_NAME } from "@calcom/lib/constants";
8+
import { UserRepository } from "@calcom/lib/server/repository/user";
9+
import prisma from "@calcom/prisma";
710

8-
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
9-
import { getServerSideProps } from "@lib/getting-started/[[...step]]/getServerSideProps";
11+
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
1012

11-
import type { PageProps as ClientPageProps } from "~/getting-started/[[...step]]/onboarding-view";
1213
import Page from "~/getting-started/[[...step]]/onboarding-view";
1314

1415
export const generateMetadata = async ({ params }: ServerPageProps) => {
@@ -23,13 +24,23 @@ export const generateMetadata = async ({ params }: ServerPageProps) => {
2324
);
2425
};
2526

26-
const getData = withAppDirSsr<ClientPageProps>(getServerSideProps);
27-
2827
const ServerPage = async ({ params, searchParams }: ServerPageProps) => {
29-
const context = buildLegacyCtx(await headers(), await cookies(), await params, await searchParams);
28+
const session = await getServerSession({ req: buildLegacyRequest(await headers(), await cookies()) });
29+
30+
if (!session?.user?.id) {
31+
return redirect("/auth/login");
32+
}
33+
34+
const userRepo = new UserRepository(prisma);
35+
const user = await userRepo.findUserTeams({
36+
id: session.user.id,
37+
});
38+
39+
if (!user) {
40+
return redirect("/auth/login");
41+
}
3042

31-
const props = await getData(context);
32-
return <Page {...props} />;
43+
return <Page hasPendingInvites={!!user.teams.find((team) => team.accepted === false)} />;
3344
};
3445

3546
export default ServerPage;

apps/web/lib/getting-started/[[...step]]/getServerSideProps.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.

apps/web/modules/getting-started/[[...step]]/onboarding-view.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import { StepCard } from "@calcom/ui/components/card";
1818
import { Steps } from "@calcom/ui/components/form";
1919
import { Icon } from "@calcom/ui/components/icon";
2020

21-
import type { getServerSideProps } from "@lib/getting-started/[[...step]]/getServerSideProps";
22-
2321
import { ConnectedCalendars } from "@components/getting-started/steps-views/ConnectCalendars";
2422
import { ConnectedVideoStep } from "@components/getting-started/steps-views/ConnectedVideoStep";
2523
import { SetupAvailability } from "@components/getting-started/steps-views/SetupAvailability";
@@ -85,7 +83,9 @@ const stepRouteSchema = z.object({
8583
from: z.string().optional(),
8684
});
8785

88-
export type PageProps = inferSSRProps<typeof getServerSideProps>;
86+
type PageProps = {
87+
hasPendingInvites: boolean;
88+
};
8989
const OnboardingPage = (props: PageProps) => {
9090
const pathname = usePathname();
9191
const params = useParamsWithFallback();

0 commit comments

Comments
 (0)