diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f8e2f57d13..20222979d5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,7 @@ name: Unit tests on: push: - branches: [fixes/e2e-consolidation] # TODO: Remove this after merged in main + branches: [ feat/routing-forms/reporting ] # TODO: Remove this after merged in main pull_request_target: # So we can test on forks branches: - main @@ -21,7 +21,8 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} # So we can test on forks fetch-depth: 2 - - run: echo 'NODE_OPTIONS="--max_old_space_size=4096"' >> $GITHUB_ENV + # Should be an 8GB machine as per https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners + - run: echo 'NODE_OPTIONS="--max_old_space_size=6144"' >> $GITHUB_ENV - name: Use Node 16.x uses: actions/setup-node@v3 with: diff --git a/jest.config.ts b/jest.config.ts index 9123946007..5145bfd33d 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -50,6 +50,16 @@ const config: Config = { testEnvironment: "jsdom", setupFiles: ["/packages/app-store/closecomothercalendar/test/globals.ts"], }, + { + displayName: "@calcom/routing-forms", + roots: ["/packages/app-store/ee/routing-forms"], + testMatch: ["**/test/lib/**/*.(spec|test).(ts|tsx|js)"], + transform: { + "^.+\\.ts?$": "ts-jest", + }, + transformIgnorePatterns: ["/node_modules/", "^.+\\.module\\.(css|sass|scss)$"], + testEnvironment: "jsdom", + }, { displayName: "@calcom/api", roots: ["/apps/api"], diff --git a/packages/app-store/ee/routing-forms/components/RoutingNavBar.tsx b/packages/app-store/ee/routing-forms/components/RoutingNavBar.tsx index 945c535d7f..b9a83dffa2 100644 --- a/packages/app-store/ee/routing-forms/components/RoutingNavBar.tsx +++ b/packages/app-store/ee/routing-forms/components/RoutingNavBar.tsx @@ -19,6 +19,11 @@ export default function RoutingNavBar({ href: `${appUrl}/route-builder/${form?.id}`, className: "pointer-events-none opacity-30 lg:pointer-events-auto lg:opacity-100", }, + { + name: "Reporting", + href: `${appUrl}/reporting/${form?.id}`, + className: "pointer-events-none opacity-30 lg:pointer-events-auto lg:opacity-100", + }, ]; return (
diff --git a/packages/app-store/ee/routing-forms/components/SingleForm.tsx b/packages/app-store/ee/routing-forms/components/SingleForm.tsx index 83471e3a41..f2184a1af3 100644 --- a/packages/app-store/ee/routing-forms/components/SingleForm.tsx +++ b/packages/app-store/ee/routing-forms/components/SingleForm.tsx @@ -5,6 +5,12 @@ import { useForm, UseFormReturn, Controller } from "react-hook-form"; import useApp from "@calcom/lib/hooks/useApp"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; +import { + AppGetServerSidePropsContext, + AppPrisma, + AppUser, + AppSsrInit, +} from "@calcom/types/AppGetServerSideProps"; import { Icon } from "@calcom/ui"; import { Dialog, DialogContent, DialogClose, DialogFooter, DialogHeader } from "@calcom/ui/Dialog"; import { Button, ButtonGroup } from "@calcom/ui/components"; @@ -15,6 +21,7 @@ import SettingsToggle from "@calcom/ui/v2/core/SettingsToggle"; import { ShellMain } from "@calcom/ui/v2/core/Shell"; import Banner from "@calcom/ui/v2/core/banner"; +import { getSerializableForm } from "../lib/getSerializableForm"; import { processRoute } from "../lib/processRoute"; import { RoutingPages } from "../pages/route-builder/[...appPages]"; import { SerializableForm } from "../types/types"; @@ -392,3 +399,65 @@ export default function SingleFormWrapper({ form: _form, ...props }: SingleFormC } return ; } + +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 isAllowed = (await import("../lib/isAllowed")).isAllowed; + if (!(await isAllowed({ userId: user.id, formId }))) { + return { + notFound: true, + }; + } + + const form = await prisma.app_RoutingForms_Form.findUnique({ + where: { + id: formId, + }, + include: { + _count: { + select: { + responses: true, + }, + }, + }, + }); + if (!form) { + return { + notFound: true, + }; + } + + return { + props: { + trpcState: ssr.dehydrate(), + form: getSerializableForm(form), + }, + }; +}; diff --git a/packages/app-store/ee/routing-forms/components/react-awesome-query-builder/widgets.tsx b/packages/app-store/ee/routing-forms/components/react-awesome-query-builder/widgets.tsx index 24bbfaf23d..1812d05425 100644 --- a/packages/app-store/ee/routing-forms/components/react-awesome-query-builder/widgets.tsx +++ b/packages/app-store/ee/routing-forms/components/react-awesome-query-builder/widgets.tsx @@ -150,7 +150,7 @@ function SelectWidget({ ); } -function Button({ type, label, onClick, readonly }: ButtonProps) { +function Button({ config, type, label, onClick, readonly }: ButtonProps) { if (type === "delRule" || type == "delGroup") { return (