* wip * fix * fix * refactor * rename to routingServerSidePropsConfig * refactor * refactor * add routing-link to useIsBookingPage hook * remove Head component * fix * redirect user to apps/routing-forms/forms if user goes to apps/routing-forms * refactor * remove log * remove client component not needed * clean up code * remove unneeded metadata * clean up further * clean up further 2 * fix type check * routing-link does not need shell * Fix title for Routing Form public link and also remove any * Remove ; in HTML * Remove unnecessary page reload --------- Co-authored-by: Hariom Balhara <hariombalhara@gmgmail.com>
95 lines
2.3 KiB
TypeScript
95 lines
2.3 KiB
TypeScript
import { orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains";
|
|
import { isAuthorizedToViewFormOnOrgDomain } from "@calcom/features/routing-forms/lib/isAuthorizedToViewForm";
|
|
import type { AppGetServerSidePropsContext, AppPrisma } from "@calcom/types/AppGetServerSideProps";
|
|
|
|
import { enrichFormWithMigrationData } from "../../enrichFormWithMigrationData";
|
|
import { getSerializableForm } from "../../lib/getSerializableForm";
|
|
|
|
export const getServerSideProps = async function getServerSideProps(
|
|
context: AppGetServerSidePropsContext,
|
|
prisma: AppPrisma
|
|
) {
|
|
const { params } = context;
|
|
if (!params) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
const appPages = params.pages.slice(1);
|
|
const formId = appPages[0];
|
|
if (!formId || appPages.length > 2) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
const { currentOrgDomain } = orgDomainConfig(context.req);
|
|
|
|
const isEmbed = appPages[1] === "embed";
|
|
|
|
const form = await prisma.app_RoutingForms_Form.findFirst({
|
|
where: {
|
|
id: formId,
|
|
},
|
|
include: {
|
|
user: {
|
|
select: {
|
|
id: true,
|
|
movedToProfileId: true,
|
|
organization: {
|
|
select: {
|
|
slug: true,
|
|
},
|
|
},
|
|
username: true,
|
|
theme: true,
|
|
brandColor: true,
|
|
darkBrandColor: true,
|
|
metadata: true,
|
|
},
|
|
},
|
|
team: {
|
|
select: {
|
|
slug: true,
|
|
parent: {
|
|
select: { slug: true },
|
|
},
|
|
parentId: true,
|
|
metadata: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!form || form.disabled) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
|
|
const { UserRepository } = await import("@calcom/lib/server/repository/user");
|
|
const formWithUserProfile = {
|
|
...form,
|
|
user: await UserRepository.enrichUserWithItsProfile({ user: form.user }),
|
|
};
|
|
|
|
if (
|
|
!isAuthorizedToViewFormOnOrgDomain({ user: formWithUserProfile.user, currentOrgDomain, team: form.team })
|
|
) {
|
|
return {
|
|
notFound: true,
|
|
};
|
|
}
|
|
return {
|
|
props: {
|
|
isEmbed,
|
|
themeBasis: form.user.username,
|
|
profile: {
|
|
theme: form.user.theme,
|
|
brandColor: form.user.brandColor,
|
|
darkBrandColor: form.user.darkBrandColor,
|
|
},
|
|
form: await getSerializableForm({ form: enrichFormWithMigrationData(formWithUserProfile) }),
|
|
},
|
|
};
|
|
};
|