chore: migrate /apps/routing-forms/[...pages] to App Router (#18956)
* wip * fix * fix * refactor * rename to routingServerSidePropsConfig * refactor * refactor * add routing-link to useIsBookingPage hook * remove Head component * fix * redirect user to apps/routing-forms/forms if user goes to apps/routing-forms * refactor * remove log * remove client component not needed * clean up code * remove unneeded metadata * clean up further * clean up further 2 * fix type check * routing-link does not need shell * Fix title for Routing Form public link and also remove any * Remove ; in HTML * Remove unnecessary page reload --------- Co-authored-by: Hariom Balhara <[email protected]>
This commit is contained in:
1 parent
fd651133c2
commit
dc7a1c4680
24 files changed
+147
-434
No files matched your search
@@ -1,102 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import RoutingFormsRoutingConfig from "@calcom/app-store/routing-forms/pages/app-routing.config";
|
||||
import TypeformRoutingConfig from "@calcom/app-store/typeform/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
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
default: ((props: any) => JSX.Element) &
|
||||
Pick<AppProps["Component"], "isBookingPage" | "getLayout" | "PageWrapper">;
|
||||
};
|
||||
|
||||
type Found = {
|
||||
notFound: false;
|
||||
Component: AppPageType["default"];
|
||||
getServerSideProps: AppPageType["getServerSideProps"];
|
||||
};
|
||||
|
||||
type NotFound = {
|
||||
notFound: true;
|
||||
};
|
||||
|
||||
// TODO: It is a candidate for apps.*.generated.*
|
||||
const AppsRouting = {
|
||||
"routing-forms": RoutingFormsRoutingConfig,
|
||||
typeform: TypeformRoutingConfig,
|
||||
};
|
||||
|
||||
function getRoute(appName: string, pages: string[]) {
|
||||
const routingConfig = AppsRouting[appName as keyof typeof AppsRouting] as unknown as Record<
|
||||
string,
|
||||
AppPageType
|
||||
>;
|
||||
|
||||
if (!routingConfig) {
|
||||
return {
|
||||
notFound: true,
|
||||
} as NotFound;
|
||||
}
|
||||
const mainPage = pages[0];
|
||||
const appPage = routingConfig.layoutHandler || (routingConfig[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 appName = props.appName;
|
||||
const params = useParamsWithFallback();
|
||||
const pages = Array.isArray(params.pages) ? params.pages : params.pages?.split("/") ?? [];
|
||||
const route = getRoute(appName, 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.slug as string, 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 getLayout: NonNullable<(typeof AppPage)["getLayout"]> = (page) => {
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
const { slug, pages } = useParamsWithFallback();
|
||||
const route = getRoute(slug as string, pages as string[]);
|
||||
|
||||
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