feat: migrate /apps/routing-forms/forms to /routing (#18001)
* feat: add getServerSideProps and getStaticProps * feat: add routing pages view * feat: add routing and related pages * feat: setup redirect * feat: remove routing configs in getStaticProps and getServerSideProps * feat: add redirects in next.config and middleware * feat: add split icon * feat: rename href to /routing/forms * feat: fix redirects * feat: finish routing page * feat: remove /apps/routing-forms/forms redirect in next-config * feat: revert back redirects in serverSideProps * fix: minor issues * fix: routing-form url cloning * chore: remove comments * fix: routing page link * fix: routing hover link --------- Co-authored-by: Prashant Varma <[email protected]>
This commit is contained in:
1 parent
06494a6999
commit
1de007ad21
10 files changed
+223
-7
No files matched your search
@@ -0,0 +1,88 @@
|
||||
"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;
|
||||
Reference in new issue
Block a user