perf: Remove ssrInit completely (#20439)
* remove ssrInit completely * remove instances of dehydratedState * fix * refactor * fix type checks * fix linting * Refactor * Refactor * remove log
This commit is contained in:
1 parent
b5b4134b75
commit
75c79f76c8
30 files changed
+70
-209
No files matched your search
@@ -29,7 +29,7 @@ const getData = withAppDirSsr<ClientPageProps>(getServerSideProps);
|
|||||||
const ServerPage = async ({ params, searchParams }: ServerPageProps) => {
|
const ServerPage = async ({ params, searchParams }: ServerPageProps) => {
|
||||||
const context = buildLegacyCtx(await headers(), await cookies(), await params, await searchParams);
|
const context = buildLegacyCtx(await headers(), await cookies(), await params, await searchParams);
|
||||||
|
|
||||||
const { dehydratedState, ...props } = await getData(context);
|
const props = await getData(context);
|
||||||
return <SetupView {...props} />;
|
return <SetupView {...props} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,5 @@ export const withAppDirSsr =
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...props,
|
...props,
|
||||||
// includes dehydratedState required for future page trpcPropvider
|
|
||||||
...("trpcState" in props && {
|
|
||||||
dehydratedState: props.trpcState,
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -42,9 +42,6 @@ const withEmbedSsrAppDir =
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...ssrResponse.props,
|
...ssrResponse.props,
|
||||||
...("trpcState" in ssrResponse.props && {
|
|
||||||
dehydratedState: ssrResponse.props.trpcState,
|
|
||||||
}),
|
|
||||||
isEmbed: true,
|
isEmbed: true,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { cookies, headers } from "next/headers";
|
||||||
|
|
||||||
|
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||||
|
import { createContext } from "@calcom/trpc/server/createContext";
|
||||||
|
|
||||||
|
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
||||||
|
|
||||||
|
export const getTRPCContext = async () => {
|
||||||
|
const legacyReq = buildLegacyRequest(await headers(), await cookies());
|
||||||
|
return await createContext({ req: legacyReq, res: {} as any }, getServerSession);
|
||||||
|
};
|
||||||
@@ -25,7 +25,6 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
categories: Object.entries(categories).map(([name, count]) => ({ name, count })),
|
categories: Object.entries(categories).map(([name, count]) => ({ name, count })),
|
||||||
trpcState: undefined,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -42,7 +42,6 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
}),
|
}),
|
||||||
appStore,
|
appStore,
|
||||||
userAdminTeams: userAdminTeamsIds,
|
userAdminTeams: userAdminTeamsIds,
|
||||||
trpcState: undefined,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -7,8 +7,6 @@ import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
|||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
import type { AppGetServerSidePropsContext } from "@calcom/types/AppGetServerSideProps";
|
import type { AppGetServerSidePropsContext } from "@calcom/types/AppGetServerSideProps";
|
||||||
|
|
||||||
import { ssrInit } from "@server/lib/ssr";
|
|
||||||
|
|
||||||
const paramsSchema = z.object({
|
const paramsSchema = z.object({
|
||||||
pages: z.array(z.string()),
|
pages: z.array(z.string()),
|
||||||
});
|
});
|
||||||
@@ -43,7 +41,7 @@ export async function getServerSideProps(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await getServerSideProps(context as AppGetServerSidePropsContext, prisma, user, ssrInit);
|
const result = await getServerSideProps(context as AppGetServerSidePropsContext, prisma, user);
|
||||||
|
|
||||||
if (result.notFound) {
|
if (result.notFound) {
|
||||||
return { notFound: true };
|
return { notFound: true };
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { EmbedProps } from "app/WithEmbedSSR";
|
import type { EmbedProps } from "app/WithEmbedSSR";
|
||||||
|
import { getTRPCContext } from "app/_trpc/context";
|
||||||
import type { GetServerSidePropsContext } from "next";
|
import type { GetServerSidePropsContext } from "next";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
@@ -10,6 +11,8 @@ import { UserRepository } from "@calcom/lib/server/repository/user";
|
|||||||
import slugify from "@calcom/lib/slugify";
|
import slugify from "@calcom/lib/slugify";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
import { RedirectType } from "@calcom/prisma/enums";
|
import { RedirectType } from "@calcom/prisma/enums";
|
||||||
|
import { publicViewerRouter } from "@calcom/trpc/server/routers/publicViewer/_router";
|
||||||
|
import { createCallerFactory } from "@calcom/trpc/server/trpc";
|
||||||
|
|
||||||
import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";
|
import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";
|
||||||
import type { inferSSRProps } from "@lib/types/inferSSRProps";
|
import type { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||||
@@ -23,9 +26,6 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
|
|||||||
const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(context.req);
|
const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(context.req);
|
||||||
const org = isValidOrgDomain ? currentOrgDomain : null;
|
const org = isValidOrgDomain ? currentOrgDomain : null;
|
||||||
|
|
||||||
const { ssrInit } = await import("@server/lib/ssr");
|
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
|
|
||||||
const hashedLink = await prisma.hashedLink.findUnique({
|
const hashedLink = await prisma.hashedLink.findUnique({
|
||||||
where: {
|
where: {
|
||||||
link,
|
link,
|
||||||
@@ -115,7 +115,10 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
|
|||||||
|
|
||||||
// We use this to both prefetch the query on the server,
|
// 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.
|
// 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({
|
const trpcContext = await getTRPCContext();
|
||||||
|
const createCaller = createCallerFactory(publicViewerRouter);
|
||||||
|
const caller = createCaller(trpcContext);
|
||||||
|
const eventData = await caller.event({
|
||||||
username: name,
|
username: name,
|
||||||
eventSlug: slug,
|
eventSlug: slug,
|
||||||
isTeamEvent,
|
isTeamEvent,
|
||||||
@@ -140,7 +143,6 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
|
|||||||
booking,
|
booking,
|
||||||
user: name,
|
user: name,
|
||||||
slug,
|
slug,
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
isBrandingHidden: hideBranding,
|
isBrandingHidden: hideBranding,
|
||||||
// Sending the team event from the server, because this template file
|
// Sending the team event from the server, because this template file
|
||||||
// is reused for both team and user events.
|
// is reused for both team and user events.
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
|
import { getTRPCContext } from "app/_trpc/context";
|
||||||
import type { GetServerSidePropsContext } from "next";
|
import type { GetServerSidePropsContext } from "next";
|
||||||
|
|
||||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||||
import logger from "@calcom/lib/logger";
|
import logger from "@calcom/lib/logger";
|
||||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||||
|
import { eventTypesRouter } from "@calcom/trpc/server/routers/viewer/eventTypes/_router";
|
||||||
|
import { createCallerFactory } from "@calcom/trpc/server/trpc";
|
||||||
|
|
||||||
import { asStringOrThrow } from "@lib/asStringOrNull";
|
import { asStringOrThrow } from "@lib/asStringOrNull";
|
||||||
import type { inferSSRProps } from "@lib/types/inferSSRProps";
|
import type { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||||
|
|
||||||
import { ssrInit } from "@server/lib/ssr";
|
|
||||||
|
|
||||||
export type PageProps = inferSSRProps<typeof getServerSideProps>;
|
export type PageProps = inferSSRProps<typeof getServerSideProps>;
|
||||||
|
|
||||||
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
||||||
@@ -17,7 +18,6 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
const session = await getServerSession({ req });
|
const session = await getServerSession({ req });
|
||||||
|
|
||||||
const typeParam = parseInt(asStringOrThrow(query.type));
|
const typeParam = parseInt(asStringOrThrow(query.type));
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
|
|
||||||
if (Number.isNaN(typeParam)) {
|
if (Number.isNaN(typeParam)) {
|
||||||
const notFound = {
|
const notFound = {
|
||||||
@@ -37,9 +37,11 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
return redirect;
|
return redirect;
|
||||||
}
|
}
|
||||||
const getEventTypeById = async (eventTypeId: number) => {
|
const getEventTypeById = async (eventTypeId: number) => {
|
||||||
await ssr.viewer.eventTypes.get.prefetch({ id: eventTypeId });
|
const trpcContext = await getTRPCContext();
|
||||||
|
const createCaller = createCallerFactory(eventTypesRouter);
|
||||||
|
const caller = createCaller(trpcContext);
|
||||||
try {
|
try {
|
||||||
const { eventType } = await ssr.viewer.eventTypes.get.fetch({ id: eventTypeId });
|
const { eventType } = await caller.get({ id: eventTypeId });
|
||||||
return eventType;
|
return eventType;
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
logger.error(safeStringify(e));
|
logger.error(safeStringify(e));
|
||||||
@@ -61,7 +63,6 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
props: {
|
props: {
|
||||||
eventType,
|
eventType,
|
||||||
type: typeParam,
|
type: typeParam,
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
import type { GetServerSidePropsContext } from "next";
|
import type { GetServerSidePropsContext } from "next";
|
||||||
|
|
||||||
import { getLocale } from "@calcom/features/auth/lib/getLocale";
|
|
||||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||||
import { UserRepository } from "@calcom/lib/server/repository/user";
|
import { UserRepository } from "@calcom/lib/server/repository/user";
|
||||||
|
|
||||||
import { ssrInit } from "@server/lib/ssr";
|
|
||||||
|
|
||||||
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
||||||
const { req } = context;
|
const { req } = context;
|
||||||
|
|
||||||
@@ -15,10 +12,6 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
return { redirect: { permanent: false, destination: "/auth/login" } };
|
return { redirect: { permanent: false, destination: "/auth/login" } };
|
||||||
}
|
}
|
||||||
|
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
|
|
||||||
await ssr.viewer.me.get.prefetch();
|
|
||||||
|
|
||||||
const user = await UserRepository.findUserTeams({
|
const user = await UserRepository.findUserTeams({
|
||||||
id: session.user.id,
|
id: session.user.id,
|
||||||
});
|
});
|
||||||
@@ -27,10 +20,8 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
throw new Error("User from session not found");
|
throw new Error("User from session not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
const locale = await getLocale(context.req);
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
hasPendingInvites: user.teams.find((team) => team.accepted === false) ?? false,
|
hasPendingInvites: user.teams.find((team) => team.accepted === false) ?? false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { getTRPCContext } from "app/_trpc/context";
|
||||||
import type { GetServerSidePropsContext } from "next";
|
import type { GetServerSidePropsContext } from "next";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
@@ -6,6 +7,8 @@ import { getSlugOrRequestedSlug } from "@calcom/features/ee/organizations/lib/or
|
|||||||
import { orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains";
|
import { orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains";
|
||||||
import slugify from "@calcom/lib/slugify";
|
import slugify from "@calcom/lib/slugify";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
|
import { publicViewerRouter } from "@calcom/trpc/server/routers/publicViewer/_router";
|
||||||
|
import { createCallerFactory } from "@calcom/trpc/server/trpc";
|
||||||
|
|
||||||
const paramsSchema = z.object({
|
const paramsSchema = z.object({
|
||||||
type: z.string().transform((s) => slugify(s)),
|
type: z.string().transform((s) => slugify(s)),
|
||||||
@@ -36,10 +39,10 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
const org = isValidOrgDomain ? currentOrgDomain : null;
|
const org = isValidOrgDomain ? currentOrgDomain : null;
|
||||||
|
const trpcContext = await getTRPCContext();
|
||||||
const { ssrInit } = await import("@server/lib/ssr");
|
const createCaller = createCallerFactory(publicViewerRouter);
|
||||||
const ssr = await ssrInit(context);
|
const caller = createCaller(trpcContext);
|
||||||
const eventData = await ssr.viewer.public.event.fetch({
|
const eventData = await caller.event({
|
||||||
username: teamSlug,
|
username: teamSlug,
|
||||||
eventSlug: meetingSlug,
|
eventSlug: meetingSlug,
|
||||||
isTeamEvent: true,
|
isTeamEvent: true,
|
||||||
@@ -67,7 +70,6 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
user: teamSlug,
|
user: teamSlug,
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
slug: meetingSlug,
|
slug: meetingSlug,
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
isBrandingHidden: team?.hideBranding,
|
isBrandingHidden: team?.hideBranding,
|
||||||
themeBasis: null,
|
themeBasis: null,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import slugify from "@calcom/lib/slugify";
|
|||||||
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
||||||
|
|
||||||
import { IS_GOOGLE_LOGIN_ENABLED } from "@server/lib/constants";
|
import { IS_GOOGLE_LOGIN_ENABLED } from "@server/lib/constants";
|
||||||
import { ssrInit } from "@server/lib/ssr";
|
|
||||||
|
|
||||||
const checkValidEmail = (email: string) => emailSchema.safeParse(email).success;
|
const checkValidEmail = (email: string) => emailSchema.safeParse(email).success;
|
||||||
|
|
||||||
@@ -26,7 +25,7 @@ const querySchema = z.object({
|
|||||||
export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
|
export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
|
||||||
const prisma = await import("@calcom/prisma").then((mod) => mod.default);
|
const prisma = await import("@calcom/prisma").then((mod) => mod.default);
|
||||||
const emailVerificationEnabled = await getFeatureFlag(prisma, "email-verification");
|
const emailVerificationEnabled = await getFeatureFlag(prisma, "email-verification");
|
||||||
await ssrInit(ctx);
|
|
||||||
const signupDisabled = await getFeatureFlag(prisma, "disable-signup");
|
const signupDisabled = await getFeatureFlag(prisma, "disable-signup");
|
||||||
|
|
||||||
const token = z.string().optional().parse(ctx.query.token);
|
const token = z.string().optional().parse(ctx.query.token);
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
|||||||
|
|
||||||
import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";
|
import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";
|
||||||
|
|
||||||
import { ssrInit } from "@server/lib/ssr";
|
|
||||||
|
|
||||||
const paramsSchema = z.object({
|
const paramsSchema = z.object({
|
||||||
type: z.string().transform((s) => slugify(s)),
|
type: z.string().transform((s) => slugify(s)),
|
||||||
slug: z.string().transform((s) => slugify(s)),
|
slug: z.string().transform((s) => slugify(s)),
|
||||||
@@ -59,7 +57,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
const name = team.parent?.name ?? team.name ?? null;
|
const name = team.parent?.name ?? team.name ?? null;
|
||||||
|
|
||||||
const booking = rescheduleUid ? await getBookingForReschedule(`${rescheduleUid}`, session?.user?.id) : null;
|
const booking = rescheduleUid ? await getBookingForReschedule(`${rescheduleUid}`, session?.user?.id) : null;
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
const fromRedirectOfNonOrgLink = context.query.orgRedirection === "true";
|
const fromRedirectOfNonOrgLink = context.query.orgRedirection === "true";
|
||||||
const isUnpublished = team.parent ? !team.parent.slug : !team.slug;
|
const isUnpublished = team.parent ? !team.parent.slug : !team.slug;
|
||||||
|
|
||||||
@@ -125,7 +123,6 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
user: teamSlug,
|
user: teamSlug,
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
slug: meetingSlug,
|
slug: meetingSlug,
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
isBrandingHidden: team?.hideBranding,
|
isBrandingHidden: team?.hideBranding,
|
||||||
isInstantMeeting: eventData && queryIsInstantMeeting ? true : false,
|
isInstantMeeting: eventData && queryIsInstantMeeting ? true : false,
|
||||||
themeBasis: null,
|
themeBasis: null,
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
|||||||
|
|
||||||
import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";
|
import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";
|
||||||
|
|
||||||
import { ssrInit } from "@server/lib/ssr";
|
|
||||||
|
|
||||||
const log = logger.getSubLogger({ prefix: ["team/[slug]"] });
|
const log = logger.getSubLogger({ prefix: ["team/[slug]"] });
|
||||||
|
|
||||||
function getOrgProfileRedirectToVerifiedDomain(
|
function getOrgProfileRedirectToVerifiedDomain(
|
||||||
@@ -103,7 +101,6 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
const metadata = teamMetadataSchema.parse(team?.metadata ?? {});
|
const metadata = teamMetadataSchema.parse(team?.metadata ?? {});
|
||||||
|
|
||||||
// Taking care of sub-teams and orgs
|
// Taking care of sub-teams and orgs
|
||||||
@@ -149,7 +146,6 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
parent: teamParent,
|
parent: teamParent,
|
||||||
createdAt: null,
|
createdAt: null,
|
||||||
},
|
},
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
}
|
}
|
||||||
@@ -215,7 +211,6 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
props: {
|
props: {
|
||||||
considerUnpublished: true,
|
considerUnpublished: true,
|
||||||
team: { ...serializableTeam },
|
team: { ...serializableTeam },
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
}
|
}
|
||||||
@@ -230,7 +225,6 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
children: isTeamOrParentOrgPrivate ? [] : team.children,
|
children: isTeamOrParentOrgPrivate ? [] : team.children,
|
||||||
},
|
},
|
||||||
themeBasis: serializableTeam.slug,
|
themeBasis: serializableTeam.slug,
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
markdownStrippedBio,
|
markdownStrippedBio,
|
||||||
isValidOrgDomain,
|
isValidOrgDomain,
|
||||||
currentOrgDomain,
|
currentOrgDomain,
|
||||||
|
|||||||
@@ -15,15 +15,11 @@ import { OrganizationRepository } from "@calcom/lib/server/repository/organizati
|
|||||||
import { UserRepository } from "@calcom/lib/server/repository/user";
|
import { UserRepository } from "@calcom/lib/server/repository/user";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
|
|
||||||
import { ssrInit } from "@server/lib/ssr";
|
|
||||||
|
|
||||||
const md = new MarkdownIt("default", { html: true, breaks: true, linkify: true });
|
const md = new MarkdownIt("default", { html: true, breaks: true, linkify: true });
|
||||||
|
|
||||||
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||||
const { req } = context;
|
const { req } = context;
|
||||||
|
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
|
|
||||||
const booking = await BookingRepository.findBookingForMeetingPage({
|
const booking = await BookingRepository.findBookingForMeetingPage({
|
||||||
bookingUid: context.query.uid as string,
|
bookingUid: context.query.uid as string,
|
||||||
});
|
});
|
||||||
@@ -153,7 +149,6 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
|||||||
},
|
},
|
||||||
hasTeamPlan: !!hasTeamPlan,
|
hasTeamPlan: !!hasTeamPlan,
|
||||||
calVideoLogo,
|
calVideoLogo,
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { getTRPCContext } from "app/_trpc/context";
|
||||||
import type { GetServerSidePropsContext } from "next";
|
import type { GetServerSidePropsContext } from "next";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
@@ -11,11 +12,11 @@ import { maybeGetBookingUidFromSeat } from "@calcom/lib/server/maybeGetBookingUi
|
|||||||
import { BookingRepository } from "@calcom/lib/server/repository/booking";
|
import { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
import { customInputSchema, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
import { customInputSchema, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||||
|
import { meRouter } from "@calcom/trpc/server/routers/viewer/me/_router";
|
||||||
|
import { createCallerFactory } from "@calcom/trpc/server/trpc";
|
||||||
|
|
||||||
import type { inferSSRProps } from "@lib/types/inferSSRProps";
|
import type { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||||
|
|
||||||
import { ssrInit } from "@server/lib/ssr";
|
|
||||||
|
|
||||||
const stringToBoolean = z
|
const stringToBoolean = z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
@@ -45,13 +46,15 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
|||||||
"@lib/booking"
|
"@lib/booking"
|
||||||
);
|
);
|
||||||
|
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
const session = await getServerSession({ req: context.req });
|
const session = await getServerSession({ req: context.req });
|
||||||
let tz: string | null = null;
|
let tz: string | null = null;
|
||||||
let userTimeFormat: number | null = null;
|
let userTimeFormat: number | null = null;
|
||||||
let requiresLoginToUpdate = false;
|
let requiresLoginToUpdate = false;
|
||||||
if (session) {
|
if (session) {
|
||||||
const user = await ssr.viewer.me.get.fetch();
|
const trpcContext = await getTRPCContext();
|
||||||
|
const createCaller = createCallerFactory(meRouter);
|
||||||
|
const caller = createCaller(trpcContext);
|
||||||
|
const user = await caller.get();
|
||||||
tz = user.timeZone;
|
tz = user.timeZone;
|
||||||
userTimeFormat = user.timeFormat;
|
userTimeFormat = user.timeFormat;
|
||||||
}
|
}
|
||||||
@@ -218,7 +221,6 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
|||||||
profile,
|
profile,
|
||||||
eventType,
|
eventType,
|
||||||
recurringBookings: await getRecurringBookings(bookingInfo.recurringEventId),
|
recurringBookings: await getRecurringBookings(bookingInfo.recurringEventId),
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
dynamicEventName: bookingInfo?.eventType?.eventName || "",
|
dynamicEventName: bookingInfo?.eventType?.eventName || "",
|
||||||
bookingInfo,
|
bookingInfo,
|
||||||
paymentStatus: payment,
|
paymentStatus: payment,
|
||||||
|
|||||||
@@ -12,10 +12,6 @@ vi.mock("@calcom/lib/constants", async () => {
|
|||||||
|
|
||||||
function mockedUserPageComponentProps(props: Partial<React.ComponentProps<typeof UserPage>>) {
|
function mockedUserPageComponentProps(props: Partial<React.ComponentProps<typeof UserPage>>) {
|
||||||
return {
|
return {
|
||||||
trpcState: {
|
|
||||||
mutations: [],
|
|
||||||
queries: [],
|
|
||||||
},
|
|
||||||
themeBasis: "dark",
|
themeBasis: "dark",
|
||||||
safeBio: "My Bio",
|
safeBio: "My Bio",
|
||||||
profile: {
|
profile: {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { DehydratedState } from "@tanstack/react-query";
|
import { getTRPCContext } from "app/_trpc/context";
|
||||||
import { type GetServerSidePropsContext } from "next";
|
import { type GetServerSidePropsContext } from "next";
|
||||||
import type { Session } from "next-auth";
|
import type { Session } from "next-auth";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
@@ -13,6 +13,8 @@ import { UserRepository } from "@calcom/lib/server/repository/user";
|
|||||||
import slugify from "@calcom/lib/slugify";
|
import slugify from "@calcom/lib/slugify";
|
||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
import { RedirectType } from "@calcom/prisma/client";
|
import { RedirectType } from "@calcom/prisma/client";
|
||||||
|
import { publicViewerRouter } from "@calcom/trpc/server/routers/publicViewer/_router";
|
||||||
|
import { createCallerFactory } from "@calcom/trpc/server/trpc";
|
||||||
|
|
||||||
import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";
|
import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";
|
||||||
|
|
||||||
@@ -40,7 +42,6 @@ type Props = {
|
|||||||
bookingUid: string | null;
|
bookingUid: string | null;
|
||||||
user: string;
|
user: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
trpcState: DehydratedState;
|
|
||||||
isBrandingHidden: boolean;
|
isBrandingHidden: boolean;
|
||||||
isSEOIndexable: boolean | null;
|
isSEOIndexable: boolean | null;
|
||||||
themeBasis: null | string;
|
themeBasis: null | string;
|
||||||
@@ -103,8 +104,6 @@ async function getDynamicGroupPageProps(context: GetServerSidePropsContext) {
|
|||||||
const { user: usernames, type: slug } = paramsSchema.parse(context.params);
|
const { user: usernames, type: slug } = paramsSchema.parse(context.params);
|
||||||
const { rescheduleUid, bookingUid } = context.query;
|
const { rescheduleUid, bookingUid } = context.query;
|
||||||
|
|
||||||
const { ssrInit } = await import("@server/lib/ssr");
|
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(context.req, context.params?.orgSlug);
|
const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(context.req, context.params?.orgSlug);
|
||||||
const org = isValidOrgDomain ? currentOrgDomain : null;
|
const org = isValidOrgDomain ? currentOrgDomain : null;
|
||||||
if (!org) {
|
if (!org) {
|
||||||
@@ -135,7 +134,10 @@ async function getDynamicGroupPageProps(context: GetServerSidePropsContext) {
|
|||||||
|
|
||||||
// We use this to both prefetch the query on the server,
|
// 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.
|
// 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({
|
const trpcContext = await getTRPCContext();
|
||||||
|
const createCaller = createCallerFactory(publicViewerRouter);
|
||||||
|
const caller = createCaller(trpcContext);
|
||||||
|
const eventData = await caller.event({
|
||||||
username: usernames.join("+"),
|
username: usernames.join("+"),
|
||||||
eventSlug: slug,
|
eventSlug: slug,
|
||||||
org,
|
org,
|
||||||
@@ -171,7 +173,6 @@ async function getDynamicGroupPageProps(context: GetServerSidePropsContext) {
|
|||||||
},
|
},
|
||||||
user: usernames.join("+"),
|
user: usernames.join("+"),
|
||||||
slug,
|
slug,
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
isBrandingHidden: false,
|
isBrandingHidden: false,
|
||||||
isSEOIndexable: true,
|
isSEOIndexable: true,
|
||||||
themeBasis: null,
|
themeBasis: null,
|
||||||
@@ -215,8 +216,6 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { ssrInit } = await import("@server/lib/ssr");
|
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
const [user] = await UserRepository.findUsersByUsername({
|
const [user] = await UserRepository.findUsersByUsername({
|
||||||
usernameList: [username],
|
usernameList: [username],
|
||||||
orgSlug: isValidOrgDomain ? currentOrgDomain : null,
|
orgSlug: isValidOrgDomain ? currentOrgDomain : null,
|
||||||
@@ -231,7 +230,10 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
|
|||||||
const org = isValidOrgDomain ? currentOrgDomain : null;
|
const org = isValidOrgDomain ? currentOrgDomain : null;
|
||||||
// We use this to both prefetch the query on the server,
|
// We use this to both prefetch the query on the server,
|
||||||
// as well as to check if the event exist, so we can show a 404 otherwise.
|
// as well as to check if the event exist, so we can show a 404 otherwise.
|
||||||
const eventData = await ssr.viewer.public.event.fetch({
|
const trpcContext = await getTRPCContext();
|
||||||
|
const createCaller = createCallerFactory(publicViewerRouter);
|
||||||
|
const caller = createCaller(trpcContext);
|
||||||
|
const eventData = await caller.event({
|
||||||
username,
|
username,
|
||||||
eventSlug: slug,
|
eventSlug: slug,
|
||||||
org,
|
org,
|
||||||
@@ -270,7 +272,6 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
|
|||||||
},
|
},
|
||||||
user: username,
|
user: username,
|
||||||
slug,
|
slug,
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
isBrandingHidden: user?.hideBranding,
|
isBrandingHidden: user?.hideBranding,
|
||||||
isSEOIndexable: allowSEOIndexing,
|
isSEOIndexable: allowSEOIndexing,
|
||||||
themeBasis: username,
|
themeBasis: username,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import type { DehydratedState } from "@tanstack/react-query";
|
|
||||||
import type { EmbedProps } from "app/WithEmbedSSR";
|
import type { EmbedProps } from "app/WithEmbedSSR";
|
||||||
import type { GetServerSideProps } from "next";
|
import type { GetServerSideProps } from "next";
|
||||||
import { encode } from "querystring";
|
import { encode } from "querystring";
|
||||||
@@ -20,11 +19,8 @@ import type { UserProfile } from "@calcom/types/UserProfile";
|
|||||||
|
|
||||||
import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";
|
import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";
|
||||||
|
|
||||||
import { ssrInit } from "@server/lib/ssr";
|
|
||||||
|
|
||||||
const log = logger.getSubLogger({ prefix: ["[[pages/[user]]]"] });
|
const log = logger.getSubLogger({ prefix: ["[[pages/[user]]]"] });
|
||||||
type UserPageProps = {
|
type UserPageProps = {
|
||||||
trpcState: DehydratedState;
|
|
||||||
profile: {
|
profile: {
|
||||||
name: string;
|
name: string;
|
||||||
image: string;
|
image: string;
|
||||||
@@ -74,7 +70,6 @@ type UserPageProps = {
|
|||||||
} & EmbedProps;
|
} & EmbedProps;
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps<UserPageProps> = async (context) => {
|
export const getServerSideProps: GetServerSideProps<UserPageProps> = async (context) => {
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(context.req, context.params?.orgSlug);
|
const { currentOrgDomain, isValidOrgDomain } = orgDomainConfig(context.req, context.params?.orgSlug);
|
||||||
|
|
||||||
const usernameList = getUsernameList(context.query.user as string);
|
const usernameList = getUsernameList(context.query.user as string);
|
||||||
@@ -197,7 +192,6 @@ export const getServerSideProps: GetServerSideProps<UserPageProps> = async (cont
|
|||||||
profile,
|
profile,
|
||||||
// Dynamic group has no theme preference right now. It uses system theme.
|
// Dynamic group has no theme preference right now. It uses system theme.
|
||||||
themeBasis: user.username,
|
themeBasis: user.username,
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
markdownStrippedBio,
|
markdownStrippedBio,
|
||||||
isOrgSEOIndexable: org?.organizationSettings?.allowSEOIndexing ?? false,
|
isOrgSEOIndexable: org?.organizationSettings?.allowSEOIndexing ?? false,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,13 +9,11 @@ import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl";
|
|||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
|
|
||||||
import { IS_GOOGLE_LOGIN_ENABLED } from "@server/lib/constants";
|
import { IS_GOOGLE_LOGIN_ENABLED } from "@server/lib/constants";
|
||||||
import { ssrInit } from "@server/lib/ssr";
|
|
||||||
|
|
||||||
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||||
const { req, query } = context;
|
const { req, query } = context;
|
||||||
|
|
||||||
const session = await getServerSession({ req });
|
const session = await getServerSession({ req });
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
|
|
||||||
const verifyJwt = (jwt: string) => {
|
const verifyJwt = (jwt: string) => {
|
||||||
const secret = new TextEncoder().encode(process.env.CALENDSO_ENCRYPTION_KEY);
|
const secret = new TextEncoder().encode(process.env.CALENDSO_ENCRYPTION_KEY);
|
||||||
@@ -91,7 +89,6 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
|||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
csrfToken: await getCsrfToken(context),
|
csrfToken: await getCsrfToken(context),
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
isGoogleLoginEnabled: IS_GOOGLE_LOGIN_ENABLED,
|
isGoogleLoginEnabled: IS_GOOGLE_LOGIN_ENABLED,
|
||||||
isSAMLLoginEnabled,
|
isSAMLLoginEnabled,
|
||||||
samlTenantID,
|
samlTenantID,
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ import prisma from "@calcom/prisma";
|
|||||||
|
|
||||||
import { asStringOrNull } from "@lib/asStringOrNull";
|
import { asStringOrNull } from "@lib/asStringOrNull";
|
||||||
|
|
||||||
import { ssrInit } from "@server/lib/ssr";
|
|
||||||
|
|
||||||
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
||||||
// get query params and typecast them to string
|
// get query params and typecast them to string
|
||||||
// (would be even better to assert them instead of typecasting)
|
// (would be even better to assert them instead of typecasting)
|
||||||
@@ -28,7 +26,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
const { req } = context;
|
const { req } = context;
|
||||||
|
|
||||||
const session = await getServerSession({ req });
|
const session = await getServerSession({ req });
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
const { currentOrgDomain } = orgDomainConfig(context.req);
|
const { currentOrgDomain } = orgDomainConfig(context.req);
|
||||||
|
|
||||||
if (session) {
|
if (session) {
|
||||||
@@ -93,7 +91,6 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
provider: providerParam,
|
provider: providerParam,
|
||||||
isSAMLLoginEnabled,
|
isSAMLLoginEnabled,
|
||||||
hostedCal,
|
hostedCal,
|
||||||
|
|||||||
@@ -5,12 +5,9 @@ import { getDeploymentKey } from "@calcom/features/ee/deployment/lib/getDeployme
|
|||||||
import prisma from "@calcom/prisma";
|
import prisma from "@calcom/prisma";
|
||||||
import { UserPermissionRole } from "@calcom/prisma/enums";
|
import { UserPermissionRole } from "@calcom/prisma/enums";
|
||||||
|
|
||||||
import { ssrInit } from "@server/lib/ssr";
|
|
||||||
|
|
||||||
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||||
const { req } = context;
|
const { req } = context;
|
||||||
|
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
const userCount = await prisma.user.count();
|
const userCount = await prisma.user.count();
|
||||||
|
|
||||||
const session = await getServerSession({ req });
|
const session = await getServerSession({ req });
|
||||||
@@ -45,7 +42,6 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
isFreeLicense,
|
isFreeLicense,
|
||||||
userCount,
|
userCount,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
import type { GetServerSidePropsContext } from "next";
|
|
||||||
import superjson from "superjson";
|
|
||||||
|
|
||||||
import { forms } from "@calcom/app-store/routing-forms/trpc/procedures/forms";
|
|
||||||
import { getLocale } from "@calcom/features/auth/lib/getLocale";
|
|
||||||
import { map } from "@calcom/features/flags/server/procedures/map";
|
|
||||||
import { createContext } from "@calcom/trpc/server/createContext";
|
|
||||||
import { teamsAndUserProfilesQuery } from "@calcom/trpc/server/routers/loggedInViewer/procedures/teamsAndUserProfilesQuery";
|
|
||||||
import { event } from "@calcom/trpc/server/routers/publicViewer/procedures/event";
|
|
||||||
import { session } from "@calcom/trpc/server/routers/publicViewer/procedures/session";
|
|
||||||
import { get } from "@calcom/trpc/server/routers/viewer/eventTypes/procedures/get";
|
|
||||||
import { meRouter } from "@calcom/trpc/server/routers/viewer/me/_router";
|
|
||||||
import { hasTeamPlan } from "@calcom/trpc/server/routers/viewer/teams/procedures/hasTeamPlan";
|
|
||||||
import { mergeRouters, router } from "@calcom/trpc/server/trpc";
|
|
||||||
|
|
||||||
import { createServerSideHelpers } from "@trpc/react-query/server";
|
|
||||||
|
|
||||||
// Temporary workaround for OOM issue, import only procedures that are called on the server side
|
|
||||||
const routerSlice = router({
|
|
||||||
viewer: mergeRouters(
|
|
||||||
router({
|
|
||||||
me: meRouter,
|
|
||||||
features: router({
|
|
||||||
map,
|
|
||||||
}),
|
|
||||||
public: router({
|
|
||||||
session,
|
|
||||||
event,
|
|
||||||
}),
|
|
||||||
teams: router({
|
|
||||||
hasTeamPlan,
|
|
||||||
}),
|
|
||||||
appRoutingForms: router({
|
|
||||||
forms,
|
|
||||||
}),
|
|
||||||
teamsAndUserProfilesQuery: router({
|
|
||||||
teamsAndUserProfilesQuery,
|
|
||||||
}),
|
|
||||||
eventTypes: router({
|
|
||||||
get,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize server-side rendering tRPC helpers.
|
|
||||||
* Provides a method to prefetch tRPC-queries in a `getServerSideProps`-function.
|
|
||||||
* Automatically prefetches i18n based on the passed in `context`-object to prevent i18n-flickering.
|
|
||||||
* Make sure to `return { props: { trpcState: ssr.dehydrate() } }` at the end.
|
|
||||||
*/
|
|
||||||
export async function ssrInit(context: GetServerSidePropsContext, options?: { noI18nPreload: boolean }) {
|
|
||||||
const ctx = await createContext(context);
|
|
||||||
const locale = await getLocale(context.req);
|
|
||||||
|
|
||||||
const ssr = createServerSideHelpers({
|
|
||||||
router: routerSlice,
|
|
||||||
transformer: superjson,
|
|
||||||
ctx: { ...ctx, locale },
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.allSettled([
|
|
||||||
// So feature flags are available on first render
|
|
||||||
ssr.viewer.features.map.prefetch(),
|
|
||||||
// Provides a better UX to the users who have already upgraded.
|
|
||||||
ssr.viewer.teams.hasTeamPlan.prefetch(),
|
|
||||||
ssr.viewer.public.session.prefetch(),
|
|
||||||
ssr.viewer.me.get.prefetch(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return ssr;
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,4 @@
|
|||||||
import type {
|
import type { AppGetServerSidePropsContext, AppPrisma, AppUser } from "@calcom/types/AppGetServerSideProps";
|
||||||
AppGetServerSidePropsContext,
|
|
||||||
AppPrisma,
|
|
||||||
AppSsrInit,
|
|
||||||
AppUser,
|
|
||||||
} from "@calcom/types/AppGetServerSideProps";
|
|
||||||
|
|
||||||
import { enrichFormWithMigrationData } from "../enrichFormWithMigrationData";
|
import { enrichFormWithMigrationData } from "../enrichFormWithMigrationData";
|
||||||
import { getSerializableForm } from "../lib/getSerializableForm";
|
import { getSerializableForm } from "../lib/getSerializableForm";
|
||||||
@@ -11,11 +6,8 @@ import { getSerializableForm } from "../lib/getSerializableForm";
|
|||||||
export const getServerSidePropsForSingleFormView = async function getServerSidePropsForSingleFormView(
|
export const getServerSidePropsForSingleFormView = async function getServerSidePropsForSingleFormView(
|
||||||
context: AppGetServerSidePropsContext,
|
context: AppGetServerSidePropsContext,
|
||||||
prisma: AppPrisma,
|
prisma: AppPrisma,
|
||||||
user: AppUser,
|
user: AppUser
|
||||||
ssrInit: AppSsrInit
|
|
||||||
) {
|
) {
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
import { getTeamsFiltersFromQuery } from "@calcom/features/filters/lib/getTeamsFiltersFromQuery";
|
import type { AppGetServerSidePropsContext, AppPrisma, AppUser } from "@calcom/types/AppGetServerSideProps";
|
||||||
import type {
|
|
||||||
AppGetServerSidePropsContext,
|
|
||||||
AppPrisma,
|
|
||||||
AppSsrInit,
|
|
||||||
AppUser,
|
|
||||||
} from "@calcom/types/AppGetServerSideProps";
|
|
||||||
|
|
||||||
export const getServerSideProps = async function getServerSideProps(
|
export const getServerSideProps = async function getServerSideProps(
|
||||||
context: AppGetServerSidePropsContext,
|
context: AppGetServerSidePropsContext,
|
||||||
prisma: AppPrisma,
|
prisma: AppPrisma,
|
||||||
user: AppUser,
|
user: AppUser
|
||||||
ssrInit: AppSsrInit
|
|
||||||
) {
|
) {
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
@@ -20,15 +13,7 @@ export const getServerSideProps = async function getServerSideProps(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
|
|
||||||
const filters = getTeamsFiltersFromQuery(context.query);
|
|
||||||
|
|
||||||
await ssr.viewer.appRoutingForms.forms.prefetch({
|
|
||||||
filters,
|
|
||||||
});
|
|
||||||
// Prefetch this so that New Button is immediately available
|
|
||||||
await ssr.viewer.teamsAndUserProfilesQuery.prefetch();
|
|
||||||
return {
|
return {
|
||||||
props: {},
|
props: {},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import { paymentDataSelect } from "@calcom/prisma/selects/payment";
|
|||||||
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||||
import type { inferSSRProps } from "@calcom/types/inferSSRProps";
|
import type { inferSSRProps } from "@calcom/types/inferSSRProps";
|
||||||
|
|
||||||
import { ssrInit } from "../../../../../apps/web/server/lib/ssr";
|
|
||||||
|
|
||||||
export type PaymentPageProps = inferSSRProps<typeof getServerSideProps>;
|
export type PaymentPageProps = inferSSRProps<typeof getServerSideProps>;
|
||||||
|
|
||||||
const querySchema = z.object({
|
const querySchema = z.object({
|
||||||
@@ -17,8 +15,6 @@ const querySchema = z.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
||||||
const ssr = await ssrInit(context);
|
|
||||||
|
|
||||||
const { uid } = querySchema.parse(context.query);
|
const { uid } = querySchema.parse(context.query);
|
||||||
const rawPayment = await prisma.payment.findFirst({
|
const rawPayment = await prisma.payment.findFirst({
|
||||||
where: {
|
where: {
|
||||||
@@ -79,7 +75,6 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
|||||||
metadata: EventTypeMetaDataSchema.parse(eventType.metadata),
|
metadata: EventTypeMetaDataSchema.parse(eventType.metadata),
|
||||||
},
|
},
|
||||||
booking,
|
booking,
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
payment,
|
payment,
|
||||||
clientSecret: getClientSecretFromPayment(payment),
|
clientSecret: getClientSecretFromPayment(payment),
|
||||||
profile,
|
profile,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export const useAtomsEventTypePaymentInfo = ({
|
|||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: [QUERY_KEY, uid],
|
queryKey: [QUERY_KEY, uid],
|
||||||
queryFn: () => {
|
queryFn: () => {
|
||||||
return http?.get<ApiResponse<Omit<PaymentPageProps, "trpcState">>>(pathname).then((res) => {
|
return http?.get<ApiResponse<PaymentPageProps>>(pathname).then((res) => {
|
||||||
if (res.data.status === SUCCESS_STATUS) {
|
if (res.data.status === SUCCESS_STATUS) {
|
||||||
onEventTypePaymentInfoSuccess?.();
|
onEventTypePaymentInfoSuccess?.();
|
||||||
return res.data.data;
|
return res.data.data;
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ export const PaymentForm = ({
|
|||||||
onEventTypePaymentInfoFailure,
|
onEventTypePaymentInfoFailure,
|
||||||
}: {
|
}: {
|
||||||
paymentUid: string;
|
paymentUid: string;
|
||||||
onPaymentSuccess?: (input: Omit<PaymentPageProps, "trpcState">) => void;
|
onPaymentSuccess?: (input: PaymentPageProps) => void;
|
||||||
onPaymentCancellation?: (input: Omit<PaymentPageProps, "trpcState">) => void;
|
onPaymentCancellation?: (input: PaymentPageProps) => void;
|
||||||
onEventTypePaymentInfoSuccess?: () => void;
|
onEventTypePaymentInfoSuccess?: () => void;
|
||||||
onEventTypePaymentInfoFailure?: () => void;
|
onEventTypePaymentInfoFailure?: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|||||||
|
|
||||||
const StripePaymentComponent = (
|
const StripePaymentComponent = (
|
||||||
props: Props & {
|
props: Props & {
|
||||||
onPaymentSuccess?: (input: Omit<PaymentPageProps, "trpcState">) => void;
|
onPaymentSuccess?: (input: PaymentPageProps) => void;
|
||||||
onPaymentCancellation?: (input: Omit<PaymentPageProps, "trpcState">) => void;
|
onPaymentCancellation?: (input: PaymentPageProps) => void;
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
const { t } = useLocale();
|
const { t } = useLocale();
|
||||||
@@ -82,7 +82,7 @@ const StripePaymentComponent = (
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
setState({ status: "idle" });
|
setState({ status: "idle" });
|
||||||
props.onPaymentSuccess?.(props as unknown as Omit<PaymentPageProps, "trpcState">);
|
props.onPaymentSuccess?.(props as unknown as PaymentPageProps);
|
||||||
if (props.location) {
|
if (props.location) {
|
||||||
if (props.location.includes("integration")) {
|
if (props.location.includes("integration")) {
|
||||||
params.location = t("web_conferencing_details_to_follow");
|
params.location = t("web_conferencing_details_to_follow");
|
||||||
@@ -93,7 +93,7 @@ const StripePaymentComponent = (
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
props.onPaymentCancellation?.(props as unknown as Omit<PaymentPageProps, "trpcState">);
|
props.onPaymentCancellation?.(props as unknown as PaymentPageProps);
|
||||||
}}
|
}}
|
||||||
onPaymentElementChange={() => {
|
onPaymentElementChange={() => {
|
||||||
setState({ status: "idle" });
|
setState({ status: "idle" });
|
||||||
@@ -105,8 +105,8 @@ const StripePaymentComponent = (
|
|||||||
const StripePaymentForm = (
|
const StripePaymentForm = (
|
||||||
props: Props & {
|
props: Props & {
|
||||||
uid: string;
|
uid: string;
|
||||||
onPaymentSuccess?: (input: Omit<PaymentPageProps, "trpcState">) => void;
|
onPaymentSuccess?: (input: PaymentPageProps) => void;
|
||||||
onPaymentCancellation?: (input: Omit<PaymentPageProps, "trpcState">) => void;
|
onPaymentCancellation?: (input: PaymentPageProps) => void;
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
const stripePromise = getStripe(props.payment.data.stripe_publishable_key as any);
|
const stripePromise = getStripe(props.payment.data.stripe_publishable_key as any);
|
||||||
|
|||||||
+2
-5
@@ -3,17 +3,14 @@ import type { CalendsoSessionUser } from "next-auth";
|
|||||||
|
|
||||||
import type prisma from "@calcom/prisma";
|
import type prisma from "@calcom/prisma";
|
||||||
|
|
||||||
import type { ssrInit } from "@server/lib/ssr";
|
|
||||||
|
|
||||||
export type AppUser = CalendsoSessionUser | undefined;
|
export type AppUser = CalendsoSessionUser | undefined;
|
||||||
export type AppPrisma = typeof prisma;
|
export type AppPrisma = typeof prisma;
|
||||||
export type AppGetServerSidePropsContext = GetServerSidePropsContext<{
|
export type AppGetServerSidePropsContext = GetServerSidePropsContext<{
|
||||||
pages: string[];
|
pages: string[];
|
||||||
}>;
|
}>;
|
||||||
export type AppSsrInit = ssrInit;
|
|
||||||
export type AppGetServerSideProps = (
|
export type AppGetServerSideProps = (
|
||||||
context: AppGetServerSidePropsContext,
|
context: AppGetServerSidePropsContext,
|
||||||
prisma: AppPrisma,
|
prisma: AppPrisma,
|
||||||
user: AppUser,
|
user: AppUser
|
||||||
ssrInit: AppSsrInit
|
|
||||||
) => GetServerSidePropsResult;
|
) => GetServerSidePropsResult;
|
||||||
Reference in new issue
Block a user