Revert "feat: migrate /apps/routing-forms/forms to /routing (#18001)"

This reverts commit 1de007ad21.
This commit is contained in:
Alex van Andel committed 2024-12-11 22:16:50 +00:00
1 parent 187a2c576e
commit 9c127cbfc2
10 files changed
+7 -223

No files matched your search

-88
View File
@@ -1,88 +0,0 @@
"use client";
import RoutingFormsRoutingConfig from "@calcom/app-store/routing-forms/pages/app-routing.config";
import { useParamsWithFallback } from "@calcom/lib/hooks/useParamsWithFallback";
import type { AppGetServerSideProps } from "@calcom/types/AppGetServerSideProps";
import type { inferSSRProps } from "@calcom/types/inferSSRProps";
import type { AppProps } from "@lib/app-providers";
import type { getServerSideProps } from "@lib/apps/[slug]/[...pages]/getServerSideProps";
type AppPageType = {
getServerSideProps: AppGetServerSideProps;
// A component than can accept any properties
default: ((props: unknown) => JSX.Element) &
Pick<AppProps["Component"], "isBookingPage" | "getLayout" | "PageWrapper">;
};
type Found = {
notFound: false;
Component: AppPageType["default"];
getServerSideProps: AppPageType["getServerSideProps"];
};
type NotFound = {
notFound: true;
};
function getRoute(pages: string[]) {
const mainPage = pages[0] as keyof typeof RoutingFormsRoutingConfig;
const appPage =
RoutingFormsRoutingConfig.layoutHandler || (RoutingFormsRoutingConfig[mainPage] as AppPageType);
if (!appPage) {
return {
notFound: true,
} as NotFound;
}
return { notFound: false, Component: appPage.default, ...appPage } as Found;
}
export type PageProps = inferSSRProps<typeof getServerSideProps>;
const AppPage: AppPageType["default"] = function AppPage(props: PageProps) {
const params = useParamsWithFallback();
const defaultPage = ["forms"];
const pages = Array.isArray(params.pages) ? params.pages : params.pages?.split("/") ?? defaultPage;
const route = getRoute(pages);
const componentProps = {
...props,
pages: pages.slice(1),
};
if (!route || route.notFound) {
throw new Error("Route can't be undefined");
}
return <route.Component {...componentProps} />;
};
AppPage.isBookingPage = ({ router }) => {
const route = getRoute(router.query.pages as string[]);
if (route.notFound) {
return false;
}
const isBookingPage = route.Component.isBookingPage;
if (typeof isBookingPage === "function") {
return isBookingPage({ router });
}
return !!isBookingPage;
};
export const GetFormLayout: NonNullable<(typeof AppPage)["getLayout"]> = (page) => {
const { pages: paramsPages } = useParamsWithFallback();
const defaultPage = ["forms"];
const pages = paramsPages?.length ? (paramsPages as string[]) : defaultPage;
const route = getRoute(pages);
if (route.notFound) {
return null;
}
if (!route.Component.getLayout) {
return page;
}
return route.Component.getLayout(page);
};
export default AppPage;