forked from calcom/cal.com
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50e4053
commit 317b43b
Showing
10 changed files
with
222 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
apps/web/app/future/(individual-page-wrapper)/apps/categories/[category]/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { headers } from "next/headers"; | ||
import { type ReactElement } from "react"; | ||
|
||
import PageWrapper from "@components/PageWrapperAppDir"; | ||
|
||
type WrapperWithLayoutProps = { | ||
children: ReactElement; | ||
}; | ||
|
||
export default async function WrapperWithLayout({ children }: WrapperWithLayoutProps) { | ||
const h = headers(); | ||
const nonce = h.get("x-nonce") ?? undefined; | ||
|
||
return ( | ||
<PageWrapper getLayout={null} requiresLicense={false} nonce={nonce} themeBasis={null}> | ||
{children} | ||
</PageWrapper> | ||
); | ||
} |
73 changes: 73 additions & 0 deletions
73
apps/web/app/future/(individual-page-wrapper)/apps/categories/[category]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import CategoryPage from "@pages/apps/categories/[category]"; | ||
import { Prisma } from "@prisma/client"; | ||
import { _generateMetadata } from "app/_utils"; | ||
import { notFound } from "next/navigation"; | ||
import z from "zod"; | ||
|
||
import { getAppRegistry } from "@calcom/app-store/_appRegistry"; | ||
import { APP_NAME } from "@calcom/lib/constants"; | ||
import prisma from "@calcom/prisma"; | ||
import { AppCategories } from "@calcom/prisma/enums"; | ||
|
||
export const generateMetadata = async () => { | ||
return await _generateMetadata( | ||
() => `${APP_NAME} | ${APP_NAME}`, | ||
() => "" | ||
); | ||
}; | ||
|
||
export const getStaticParams = async () => { | ||
const paths = Object.keys(AppCategories); | ||
|
||
try { | ||
await prisma.$queryRaw`SELECT 1`; | ||
} catch (e: unknown) { | ||
if (e instanceof Prisma.PrismaClientInitializationError) { | ||
// Database is not available at build time. Make sure we fall back to building these pages on demand | ||
return []; | ||
} else { | ||
throw e; | ||
} | ||
} | ||
|
||
return paths.map((category) => ({ category })); | ||
}; | ||
|
||
const querySchema = z.object({ | ||
category: z.nativeEnum(AppCategories), | ||
}); | ||
|
||
const getPageProps = async ({ params }: { params: Record<string, string | string[]> }) => { | ||
const p = querySchema.safeParse(params); | ||
|
||
if (!p.success) { | ||
return notFound(); | ||
} | ||
|
||
const appQuery = await prisma.app.findMany({ | ||
where: { | ||
categories: { | ||
has: p.data.category, | ||
}, | ||
}, | ||
select: { | ||
slug: true, | ||
}, | ||
}); | ||
|
||
const dbAppsSlugs = appQuery.map((category) => category.slug); | ||
|
||
const appStore = await getAppRegistry(); | ||
|
||
const apps = appStore.filter((app) => dbAppsSlugs.includes(app.slug)); | ||
return { | ||
apps, | ||
}; | ||
}; | ||
|
||
export default async function Page({ params }: { params: Record<string, string | string[]> }) { | ||
const { apps } = await getPageProps({ params }); | ||
return <CategoryPage apps={apps} />; | ||
} | ||
|
||
export const dynamic = "force-static"; |
56 changes: 56 additions & 0 deletions
56
apps/web/app/future/(individual-page-wrapper)/apps/categories/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import LegacyPage from "@pages/apps/categories/index"; | ||
import { ssrInit } from "app/_trpc/ssrInit"; | ||
import { _generateMetadata } from "app/_utils"; | ||
import { cookies, headers } from "next/headers"; | ||
|
||
import { getAppRegistry, getAppRegistryWithCredentials } from "@calcom/app-store/_appRegistry"; | ||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession"; | ||
import { APP_NAME } from "@calcom/lib/constants"; | ||
|
||
import PageWrapper from "@components/PageWrapperAppDir"; | ||
|
||
export const generateMetadata = async () => { | ||
return await _generateMetadata( | ||
() => `Categories | ${APP_NAME}`, | ||
() => "" | ||
); | ||
}; | ||
|
||
async function getPageProps() { | ||
const ssr = await ssrInit(); | ||
const req = { headers: headers(), cookies: cookies() }; | ||
|
||
// @ts-expect-error Type '{ headers: ReadonlyHeaders; cookies: ReadonlyRequestCookies; }' is not assignable to type 'NextApiRequest | IncomingMessage | ||
const session = await getServerSession({ req }); | ||
|
||
let appStore; | ||
if (session?.user?.id) { | ||
appStore = await getAppRegistryWithCredentials(session.user.id); | ||
} else { | ||
appStore = await getAppRegistry(); | ||
} | ||
|
||
const categories = appStore.reduce((c, app) => { | ||
for (const category of app.categories) { | ||
c[category] = c[category] ? c[category] + 1 : 1; | ||
} | ||
return c; | ||
}, {} as Record<string, number>); | ||
|
||
return { | ||
categories: Object.entries(categories).map(([name, count]) => ({ name, count })), | ||
dehydratedState: await ssr.dehydrate(), | ||
}; | ||
} | ||
|
||
export default async function Page() { | ||
const props = await getPageProps(); | ||
const h = headers(); | ||
const nonce = h.get("x-nonce") ?? undefined; | ||
|
||
return ( | ||
<PageWrapper getLayout={null} requiresLicense={false} nonce={nonce} themeBasis={null} {...props}> | ||
<LegacyPage {...props} /> | ||
</PageWrapper> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters