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

@@ -1,97 +0,0 @@
import type { GetServerSidePropsContext } from "next";
import { getAppWithMetadata } from "@calcom/app-store/_appRegistry";
import RoutingFormsRoutingConfig from "@calcom/app-store/routing-forms/pages/app-routing.config";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import prisma from "@calcom/prisma";
import type { AppGetServerSideProps } from "@calcom/types/AppGetServerSideProps";
import type { AppProps } from "@lib/app-providers";
import { ssrInit } from "@server/lib/ssr";
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 const getServerSideProps = async (context: GetServerSidePropsContext) => {
const { req } = context;
const appName = "routing-forms";
const pages = ["forms"]; // set forms page to be the default one
const route = getRoute(pages);
if (route.notFound) {
return { notFound: true };
}
if (route.getServerSideProps) {
const session = await getServerSession({ req });
const user = session?.user;
const app = await getAppWithMetadata({ slug: appName });
if (!app) {
return {
notFound: true,
};
}
const result = await route.getServerSideProps(
context as GetServerSidePropsContext<{
slug: string;
pages: string[];
appPages: string[];
}>,
prisma,
user,
ssrInit
);
if (result.notFound) {
return { notFound: true };
}
if (result.redirect) {
return { redirect: result.redirect };
}
return {
props: {
appName,
appUrl: "/apps/routing-forms",
...result.props,
},
};
} else {
return {
props: {
appName,
},
};
}
};
+1 -5
View File
@@ -41,10 +41,6 @@ const middleware = async (req: NextRequest): Promise<NextResponse<unknown>> => {
}
}
if (url.pathname.startsWith("/apps/routing-forms/forms")) {
return NextResponse.redirect(new URL("/routing", url.origin), { headers: requestHeaders });
}
const routingFormRewriteResponse = routingForms.handleRewrite(url);
if (routingFormRewriteResponse) {
return responseWithHeaders({ url, res: routingFormRewriteResponse, req });
@@ -167,7 +163,7 @@ export const config = {
* Paths required by routingForms.handle
*/
"/apps/routing_forms/:path*",
"/apps/routing-forms/forms",
"/event-types",
"/future/event-types/",
"/apps/installed/:category/",
-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;
-15
View File
@@ -1,15 +0,0 @@
import { getServerSideProps } from "@lib/routing/getServerSideProps";
import PageWrapper from "@components/PageWrapper";
import type { PageProps } from "~/routing/pages-view";
import PagesView, { GetFormLayout as getLayout } from "~/routing/pages-view";
const Page = (props: PageProps) => <PagesView {...props} />;
Page.PageWrapper = PageWrapper;
Page.getLayout = getLayout;
export { getServerSideProps };
export default Page;
-6
View File
@@ -558,12 +558,6 @@
<path d="M4 17v2" ></path>
<path d="M5 18H3" ></path>
</symbol>
<symbol class="lucide lucide-split" viewBox="0 0 24 24" fill="inherit" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" id="split">
<path d="M16 3h5v5" ></path>
<path d="M8 3H3v5" ></path>
<path d="M12 22v-8.3a4 4 0 0 0-1.172-2.872L3 3" ></path>
<path d="m15 9 6-6" ></path>
</symbol>
<symbol class="lucide lucide-square-check" viewBox="0 0 24 24" fill="inherit" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" id="square-check">
<rect width="18" height="18" x="3" y="3" rx="2" ></rect>
<path d="m9 12 2 2 4-4" ></path>

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB