From 9c127cbfc255fe5effe7f974eb11d7c5159aba40 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Wed, 11 Dec 2024 22:16:50 +0000 Subject: [PATCH] Revert "feat: migrate /apps/routing-forms/forms to /routing (#18001)" This reverts commit 1de007ad218b7e96ab93e300439279278d87aa6a. --- apps/web/lib/routing/getServerSideProps.ts | 97 ------------------- apps/web/middleware.ts | 6 +- apps/web/modules/routing/pages-view.tsx | 88 ----------------- apps/web/pages/routing/index.tsx | 15 --- apps/web/public/icons/sprite.svg | 6 -- .../pages/layout-handler/[...appPages].tsx | 6 +- .../playwright/tests/basic.e2e.ts | 2 +- .../features/shell/navigation/Navigation.tsx | 8 +- packages/ui/components/icon/icon-list.mjs | 1 - packages/ui/components/icon/icon-names.ts | 1 - 10 files changed, 7 insertions(+), 223 deletions(-) delete mode 100644 apps/web/lib/routing/getServerSideProps.ts delete mode 100644 apps/web/modules/routing/pages-view.tsx delete mode 100644 apps/web/pages/routing/index.tsx diff --git a/apps/web/lib/routing/getServerSideProps.ts b/apps/web/lib/routing/getServerSideProps.ts deleted file mode 100644 index 1b8021fac7..0000000000 --- a/apps/web/lib/routing/getServerSideProps.ts +++ /dev/null @@ -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; -}; - -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, - }, - }; - } -}; diff --git a/apps/web/middleware.ts b/apps/web/middleware.ts index 9d135c3418..95556aed89 100644 --- a/apps/web/middleware.ts +++ b/apps/web/middleware.ts @@ -41,10 +41,6 @@ const middleware = async (req: NextRequest): Promise> => { } } - 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/", diff --git a/apps/web/modules/routing/pages-view.tsx b/apps/web/modules/routing/pages-view.tsx deleted file mode 100644 index 6aaac609ea..0000000000 --- a/apps/web/modules/routing/pages-view.tsx +++ /dev/null @@ -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; -}; - -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; - -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 ; -}; - -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; diff --git a/apps/web/pages/routing/index.tsx b/apps/web/pages/routing/index.tsx deleted file mode 100644 index 22b65b6e5c..0000000000 --- a/apps/web/pages/routing/index.tsx +++ /dev/null @@ -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) => ; - -Page.PageWrapper = PageWrapper; -Page.getLayout = getLayout; - -export { getServerSideProps }; - -export default Page; diff --git a/apps/web/public/icons/sprite.svg b/apps/web/public/icons/sprite.svg index a9d82df2dd..949437c333 100644 --- a/apps/web/public/icons/sprite.svg +++ b/apps/web/public/icons/sprite.svg @@ -558,12 +558,6 @@ - - - - - - diff --git a/packages/app-store/routing-forms/pages/layout-handler/[...appPages].tsx b/packages/app-store/routing-forms/pages/layout-handler/[...appPages].tsx index 359f94352f..5d1058cb28 100644 --- a/packages/app-store/routing-forms/pages/layout-handler/[...appPages].tsx +++ b/packages/app-store/routing-forms/pages/layout-handler/[...appPages].tsx @@ -55,10 +55,6 @@ export async function getServerSideProps( context: GetServerSidePropsContext, ...rest: GetServerSidePropsRestArgs ) { - //add forms to be the default page, if no pages are found - //this is useful when rendering /routing as no params would be available - const defaultPage = "forms"; - const page = context.params?.pages?.[0] || defaultPage; - const component = getComponent(page); + const component = getComponent(context.params?.pages?.[0] || ""); return component.getServerSideProps?.(context, ...rest) || { props: {} }; } diff --git a/packages/app-store/routing-forms/playwright/tests/basic.e2e.ts b/packages/app-store/routing-forms/playwright/tests/basic.e2e.ts index 771c7c98b6..ce421eee54 100644 --- a/packages/app-store/routing-forms/playwright/tests/basic.e2e.ts +++ b/packages/app-store/routing-forms/playwright/tests/basic.e2e.ts @@ -84,7 +84,7 @@ test.describe("Routing Forms", () => { test("should be able to add a new form and view it", async ({ page }) => { const formId = await addForm(page); - await page.click('[href="/routing"]'); + await page.click('[href*="/forms"]'); await page.waitForSelector('[data-testid="routing-forms-list"]'); // Ensure that it's visible in forms list diff --git a/packages/features/shell/navigation/Navigation.tsx b/packages/features/shell/navigation/Navigation.tsx index cf5a21b964..000c9a15f1 100644 --- a/packages/features/shell/navigation/Navigation.tsx +++ b/packages/features/shell/navigation/Navigation.tsx @@ -87,10 +87,10 @@ const getNavigationItems = (orgBranding: OrganizationBranding): NavigationItemTy icon: "ellipsis", }, { - name: "routing", - href: "/routing", - icon: "split", - isCurrent: ({ pathname }) => pathname?.startsWith("/routing") ?? false, + name: "routing_forms", + href: "/apps/routing-forms/forms", + icon: "file-text", + isCurrent: ({ pathname }) => pathname?.startsWith("/apps/routing-forms/") ?? false, moreOnMobile: true, }, { diff --git a/packages/ui/components/icon/icon-list.mjs b/packages/ui/components/icon/icon-list.mjs index eef2e727cb..c8513f1ed7 100644 --- a/packages/ui/components/icon/icon-list.mjs +++ b/packages/ui/components/icon/icon-list.mjs @@ -114,7 +114,6 @@ export const lucideIconList = new Set([ "sliders-vertical", "smartphone", "sparkles", - "split", "square-check", "star", "sun", diff --git a/packages/ui/components/icon/icon-names.ts b/packages/ui/components/icon/icon-names.ts index 7915b661ff..a08e8f9041 100644 --- a/packages/ui/components/icon/icon-names.ts +++ b/packages/ui/components/icon/icon-names.ts @@ -115,7 +115,6 @@ export type IconName = | "sliders-vertical" | "smartphone" | "sparkles" - | "split" | "square-check" | "star" | "sun"