Scheduling infrastructure for absolutely everyone.
chore: [app-router-migration 13] Migrate reschedule page group (#13030)
DmytroHryshyn070ec326aa5d
diff --git a/apps/web/app/AppDirSSRHOC.tsx b/apps/web/app/AppDirSSRHOC.tsxnew file mode 100644index 00000000000..87b419ca49f--- /dev/null+++ b/apps/web/app/AppDirSSRHOC.tsx@@ -0,0 +1,17 @@+import type { GetServerSideProps, GetServerSidePropsContext } from "next";+import { notFound, redirect } from "next/navigation";++export const withAppDir =+ (getServerSideProps: GetServerSideProps) => async (context: GetServerSidePropsContext) => {+ const ssrResponse = await getServerSideProps(context);++ if ("redirect" in ssrResponse) {+ redirect(ssrResponse.redirect.destination);+ }++ if ("notFound" in ssrResponse) {+ notFound();+ }++ return ssrResponse.props;+ };diff --git a/apps/web/app/future/maintenance/page.tsx b/apps/web/app/future/maintenance/page.tsxindex 38b335ae902..4995ffb7727 100644--- a/apps/web/app/future/maintenance/page.tsx+++ b/apps/web/app/future/maintenance/page.tsx@@ -10,5 +10,4 @@ export const generateMetadata = async () =>(t) => t("under_maintenance_description", { appName: APP_NAME }));-// @ts-expect-error Page typeexport default WithLayout({ getLayout: null, Page: LegacyPage })<"P">;diff --git a/apps/web/app/future/reschedule/[uid]/embed/page.tsx b/apps/web/app/future/reschedule/[uid]/embed/page.tsxnew file mode 100644index 00000000000..52bef3e4867--- /dev/null+++ b/apps/web/app/future/reschedule/[uid]/embed/page.tsx@@ -0,0 +1,21 @@+import { getServerSideProps } from "@pages/reschedule/[uid]";+import { withAppDir } from "app/AppDirSSRHOC";+import type { Params } from "next/dist/shared/lib/router/utils/route-matcher";+import { cookies, headers } from "next/headers";++import { buildLegacyCtx } from "@lib/buildLegacyCtx";+import withEmbedSsr from "@lib/withEmbedSsr";++type PageProps = Readonly<{+ params: Params;+}>;++const Page = async ({ params }: PageProps) => {+ const legacyCtx = buildLegacyCtx(headers(), cookies(), params);+ // @ts-expect-error Argument of type '{ query: Params; params: Params; req: { headers: ReadonlyHeaders; cookies: ReadonlyRequestCookies; }; }'+ await withAppDir(withEmbedSsr(getServerSideProps))(legacyCtx);++ return null;+};++export default Page;diff --git a/apps/web/app/future/reschedule/[uid]/page.tsx b/apps/web/app/future/reschedule/[uid]/page.tsxnew file mode 100644index 00000000000..40fbf05617a--- /dev/null+++ b/apps/web/app/future/reschedule/[uid]/page.tsx@@ -0,0 +1,30 @@+import OldPage, { getServerSideProps as _getServerSideProps } from "@pages/reschedule/[uid]";+import { withAppDir } from "app/AppDirSSRHOC";+import { _generateMetadata } from "app/_utils";+import type { Params } from "next/dist/shared/lib/router/utils/route-matcher";+import { headers, cookies } from "next/headers";++import { buildLegacyCtx } from "@lib/buildLegacyCtx";++export const generateMetadata = async () =>+ await _generateMetadata(+ () => "",+ () => ""+ );++type PageProps = Readonly<{+ params: Params;+}>;++const getData = withAppDir(_getServerSideProps);++const Page = async ({ params }: PageProps) => {+ const legacyCtx = buildLegacyCtx(headers(), cookies(), params);++ // @ts-expect-error Argument of type '{ query: Params; params: Params; req: { headers: ReadonlyHeaders; cookies: ReadonlyRequestCookies; }; }'+ await getData(legacyCtx);++ return <OldPage />;+};++export default Page;diff --git a/apps/web/app/layoutHOC.tsx b/apps/web/app/layoutHOC.tsxindex 5e41ed11840..29a2b56b7f0 100644--- a/apps/web/app/layoutHOC.tsx+++ b/apps/web/app/layoutHOC.tsx@@ -7,7 +7,7 @@ import PageWrapper from "@components/PageWrapperAppDir";type WithLayoutParams<T extends Record<string, any>> = {getLayout: ((page: React.ReactElement) => React.ReactNode) | null;- Page?: (props: T) => React.ReactElement;+ Page?: (props: T) => React.ReactElement | null;getData?: (arg: ReturnType<typeof buildLegacyCtx>) => Promise<T>;};diff --git a/apps/web/pages/reschedule/[uid].tsx b/apps/web/pages/reschedule/[uid].tsxindex efea8ceb060..8e3c8ed2c4b 100644--- a/apps/web/pages/reschedule/[uid].tsx+++ b/apps/web/pages/reschedule/[uid].tsx@@ -1,3 +1,4 @@+// page can be a server componentimport type { GetServerSidePropsContext } from "next";import { URLSearchParams } from "url";import { z } from "zod";diff --git a/apps/web/pages/reschedule/[uid]/embed.tsx b/apps/web/pages/reschedule/[uid]/embed.tsxindex 5d6b405e570..034b8ee719d 100644--- a/apps/web/pages/reschedule/[uid]/embed.tsx+++ b/apps/web/pages/reschedule/[uid]/embed.tsx@@ -1,3 +1,5 @@+"use client";+import withEmbedSsr from "@lib/withEmbedSsr";import { getServerSideProps as _getServerSideProps } from "../[uid]";