Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INT-2095 Ensure initial props needed for each page are passed to PageWrapper #76

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions apps/web/app/future/(layout)/insights/layout.tsx

This file was deleted.

22 changes: 21 additions & 1 deletion apps/web/app/future/(layout)/insights/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import InsightsPage from "@pages/insights";
import { headers } from "next/headers";

import { getFeatureFlagMap } from "@calcom/features/flags/server/utils";
import { constructGenericImage } from "@calcom/lib/OgImages";
import { IS_CALCOM, WEBAPP_URL, APP_NAME, SEO_IMG_OGIMG } from "@calcom/lib/constants";
import { getFixedT } from "@calcom/lib/server/getFixedT";
Expand Down Expand Up @@ -36,4 +37,23 @@ export const generateMetadata = async () => {
});
};

export default InsightsPage;
// If feature flag is disabled, return not found on getServerSideProps
export const getProps = async () => {
const prisma = await import("@calcom/prisma").then((mod) => mod.default);
const flags = await getFeatureFlagMap(prisma);

if (flags.insights === false) {
return {
notFound: true,
};
}

return {
props: {},
};
};

export default function Insights(props: any) {
props.params.relativePath = "insights/page.tsx";
return <InsightsPage />;
}
16 changes: 9 additions & 7 deletions apps/web/app/future/(layout)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ import PageWrapper from "@components/PageWrapperAppDir";

type WrapperWithLayoutProps = {
children: ReactElement;
params: { [key: string]: any };
};

export default async function WrapperWithLayout({ children }: WrapperWithLayoutProps) {
const handleGetProps = async (relativePath: string) => {
const props = await import(`./${relativePath}`).then((mod) => mod.getProps?.() ?? null);
return props;
};

export default async function WrapperWithLayout({ children, params }: WrapperWithLayoutProps) {
const h = headers();
const nonce = h.get("x-nonce") ?? undefined;
const props = await handleGetProps(params.relativePath);

return (
<PageWrapper
getLayout={getLayout}
requiresLicense={false}
nonce={nonce}
themeBasis={null}
{...children.props}>
<PageWrapper getLayout={getLayout} requiresLicense={false} nonce={nonce} themeBasis={null} {...props}>
{children}
</PageWrapper>
);
Expand Down
11 changes: 9 additions & 2 deletions apps/web/app/future/(no-layout)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@ import PageWrapper from "@components/PageWrapperAppDir";

type WrapperWithoutLayoutProps = {
children: ReactElement;
params: { [key: string]: any };
};

export default async function WrapperWithoutLayout({ children }: WrapperWithoutLayoutProps) {
const handleGetProps = async (relativePath: string) => {
const props = await import(`./${relativePath}`).then((mod) => mod.getProps?.() ?? null);
return props;
};

export default async function WrapperWithoutLayout({ children, params }: WrapperWithoutLayoutProps) {
const h = headers();
const nonce = h.get("x-nonce") ?? undefined;
const props = await handleGetProps(params.relativePath);

return (
<PageWrapper
getLayout={(page) => page}
requiresLicense={false}
nonce={nonce}
themeBasis={null}
{...children.props}>
{...props}>
{children}
</PageWrapper>
);
Expand Down
Loading