Files
calendar/packages/app-store/routing-forms/components/getServerSidePropsSingleForm.ts
T
ab65ce73c2 feat: Support Attribute Logic fallback (#17290)
* Add fallback

* Support attribute query fallback

* Refactor

* Add tests and cleanup SingleFofrm

* small text fixes

* With fallback in picture, we dont throw error in preview now instead we capture errors and show them gracefully

* Get attribute logic preview working without saving Fixes CAL-4582

* Abstract useRoutes out

* Update e2e

* Dont define Page component again and again

---------

Co-authored-by: CarinaWolli <wollencarina@gmail.com>
2024-10-31 12:53:34 -04:00

121 lines
2.6 KiB
TypeScript

import type {
AppGetServerSidePropsContext,
AppPrisma,
AppSsrInit,
AppUser,
} from "@calcom/types/AppGetServerSideProps";
import { enrichFormWithMigrationData } from "../enrichFormWithMigrationData";
import { getSerializableForm } from "../lib/getSerializableForm";
export const getServerSidePropsForSingleFormView = async function getServerSidePropsForSingleFormView(
context: AppGetServerSidePropsContext,
prisma: AppPrisma,
user: AppUser,
ssrInit: AppSsrInit
) {
const ssr = await ssrInit(context);
if (!user) {
return {
redirect: {
permanent: false,
destination: "/auth/login",
},
};
}
const { params } = context;
if (!params) {
return {
notFound: true,
};
}
const formId = params.appPages[0];
if (!formId || params.appPages.length > 1) {
return {
notFound: true,
};
}
const isFormCreateEditAllowed = (await import("../lib/isFormCreateEditAllowed")).isFormCreateEditAllowed;
if (!(await isFormCreateEditAllowed({ userId: user.id, formId, targetTeamId: null }))) {
return {
notFound: true,
};
}
const form = await prisma.app_RoutingForms_Form.findUnique({
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,
name: true,
parent: {
select: { slug: true },
},
parentId: true,
metadata: true,
},
},
_count: {
select: {
responses: true,
},
},
},
});
if (!form) {
return {
notFound: true,
};
}
const { user: u, ...formWithoutUser } = form;
const formWithoutProfileInfo = {
...formWithoutUser,
team: form.team
? {
slug: form.team.slug,
name: form.team.name,
}
: null,
};
const { UserRepository } = await import("@calcom/lib/server/repository/user");
const formWithUserInfoProfile = {
...form,
user: await UserRepository.enrichUserWithItsProfile({ user: form.user }),
};
return {
props: {
trpcState: await ssr.dehydrate(),
form: await getSerializableForm({ form: formWithoutProfileInfo }),
enrichedWithUserProfileForm: await getSerializableForm({
form: enrichFormWithMigrationData(formWithUserInfoProfile),
}),
},
};
};