diff --git a/apps/web/app/AppDirSSRHOC.tsx b/apps/web/app/AppDirSSRHOC.tsx new file mode 100644 index 0000000000..87b419ca49 --- /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.tsx index 38b335ae90..4995ffb772 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 type export 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.tsx new file mode 100644 index 0000000000..52bef3e486 --- /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.tsx new file mode 100644 index 0000000000..40fbf05617 --- /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 ; +}; + +export default Page; diff --git a/apps/web/app/layoutHOC.tsx b/apps/web/app/layoutHOC.tsx index 5e41ed1184..29a2b56b7f 100644 --- a/apps/web/app/layoutHOC.tsx +++ b/apps/web/app/layoutHOC.tsx @@ -7,7 +7,7 @@ import PageWrapper from "@components/PageWrapperAppDir"; type WithLayoutParams> = { getLayout: ((page: React.ReactElement) => React.ReactNode) | null; - Page?: (props: T) => React.ReactElement; + Page?: (props: T) => React.ReactElement | null; getData?: (arg: ReturnType) => Promise; }; diff --git a/apps/web/pages/reschedule/[uid].tsx b/apps/web/pages/reschedule/[uid].tsx index efea8ceb06..8e3c8ed2c4 100644 --- a/apps/web/pages/reschedule/[uid].tsx +++ b/apps/web/pages/reschedule/[uid].tsx @@ -1,3 +1,4 @@ +// page can be a server component import 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.tsx index 5d6b405e57..034b8ee719 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]";