* manual: app-directory-boilerplate-calcom * manual: import components directly * manual: move files to correct route groups and add metadata * manual: Change structure & Refactor to make code up to date * manual: refactors * Fix * manual: fix type of arg of getData * manual: fix type error * fix type bugs * fix * fixing the build * wip --------- Co-authored-by: Greg Pabian <[email protected]>
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import type { LayoutProps, PageProps } from "app/_types";
|
|
import { type GetServerSidePropsContext } from "next";
|
|
import { cookies, headers } from "next/headers";
|
|
|
|
import { buildLegacyCtx } from "@lib/buildLegacyCtx";
|
|
|
|
import PageWrapper from "@components/PageWrapperAppDir";
|
|
|
|
type WithLayoutParams<T extends Record<string, any>> = {
|
|
getLayout: ((page: React.ReactElement) => React.ReactNode) | null;
|
|
Page?: (props: T) => React.ReactElement | null;
|
|
getData?: (arg: GetServerSidePropsContext) => Promise<T>;
|
|
};
|
|
|
|
export function WithLayout<T extends Record<string, any>>({ getLayout, getData, Page }: WithLayoutParams<T>) {
|
|
return async <P extends "P" | "L">(p: P extends "P" ? PageProps : LayoutProps) => {
|
|
const h = headers();
|
|
const nonce = h.get("x-nonce") ?? undefined;
|
|
const props = getData
|
|
? await getData(buildLegacyCtx(h, cookies(), p.params) as unknown as GetServerSidePropsContext)
|
|
: ({} as T);
|
|
|
|
const children = "children" in p ? p.children : null;
|
|
|
|
return (
|
|
<PageWrapper getLayout={getLayout} requiresLicense={false} nonce={nonce} themeBasis={null} {...props}>
|
|
{Page ? <Page {...props} /> : children}
|
|
</PageWrapper>
|
|
);
|
|
};
|
|
}
|