8000 chore: migrate `/apps/[slug]` page (#18848) · calcom/cal.com@beb542e · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
chore: migrate /apps/[slug] page (#18848)
Browse files Browse the repository at this point in the history
* migrate apps/[slug] page

* remove future/apps/[slug]
  • Loading branch information
hbjORbj authored Jan 24, 2025
1 parent 84df8dc commit beb542e
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 117 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ E2E_TEST_OIDC_USER_PASSWORD=
# redirected from the legacy to the future pages
AB_TEST_BUCKET_PROBABILITY=50
APP_ROUTER_APPS_INSTALLED_CATEGORY_ENABLED=0
APP_ROUTER_APPS_SLUG_ENABLED=0
APP_ROUTER_APPS_SLUG_SETUP_ENABLED=0
# whether we redirect to the future/apps/categories from /apps/categories or not
APP_ROUTER_APPS_CATEGORIES_ENABLED=0
Expand Down
1 change: 0 additions & 1 deletion apps/web/abTest/middlewareFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { FUTURE_ROUTES_ENABLED_COOKIE_NAME, FUTURE_ROUTES_OVERRIDE_COOKIE_NAME }

const ROUTES: [URLPattern, boolean][] = [
["/apps/installed/:category", process.env.APP_ROUTER_APPS_INSTALLED_CATEGORY_ENABLED === "1"] as const,
["/apps/:slug", process.env.APP_ROUTER_APPS_SLUG_ENABLED === "1"] as const,
["/apps/:slug/setup", process.env.APP_ROUTER_APPS_SLUG_SETUP_ENABLED === "1"] as const,
["/apps/categories", process.env.APP_ROUTER_APPS_CATEGORIES_ENABLED === "1"] as const,
["/apps/categories/:category", process.env.APP_ROUTER_APPS_CATEGORIES_CATEGORY_ENABLED === "1"] as const,
Expand Down
51 changes: 51 additions & 0 deletions apps/web/app/(use-page-wrapper)/apps/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { PageProps as _PageProps } from "app/_types";
import { generateAppMetadata } from "app/_utils";
import { notFound } from "next/navigation";
import { z } from "zod";

import { getStaticProps } from "@lib/apps/[slug]/getStaticProps";

import AppView from "~/apps/[slug]/slug-view";

const paramsSchema = z.object({
slug: z.string(),
});

export const generateMetadata = async ({ params }: _PageProps) => {
const p = paramsSchema.safeParse(params);

if (!p.success) {
return notFound();
}

const props = await getStaticProps(p.data.slug);

if (!props) {
notFound();
}
const { name, logo, description } = props.data;

return await generateAppMetadata(
{ slug: logo, name, description },
() => name,
() => description
);
};

async function Page({ params }: _PageProps) {
const p = paramsSchema.safeParse(params);

if (!p.success) {
return notFound();
}

const props = await getStaticProps(p.data.slug);

if (!props) {
notFound();
}

return <AppView {...props} />;
}

export default Page;
24 changes: 22 additions & 2 deletions apps/web/app/_utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import i18next from "i18next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import { headers } from "next/headers";

import type { MeetingImageProps } from "@calcom/lib/OgImages";
import { constructGenericImage, constructMeetingImage } from "@calcom/lib/OgImages";
import type { AppImageProps, MeetingImageProps } from "@calcom/lib/OgImages";
import { constructAppImage, constructGenericImage, constructMeetingImage } from "@calcom/lib/OgImages";
import { IS_CALCOM, WEBAPP_URL, APP_NAME, SEO_IMG_OGIMG, CAL_URL } from "@calcom/lib/constants";
import { buildCanonical } from "@calcom/lib/next-seo.config";
import { truncateOnWord } from "@calcom/lib/text";
Expand Down Expand Up @@ -123,3 +123,23 @@ export const generateMeetingMetadata = async (
},
};
};

export const generateAppMetadata = async (
app: AppImageProps,
getTitle: (t: TFunction<string, undefined>) => string,
getDescription: (t: TFunction<string, undefined>) => string,
hideBranding?: boolean,
origin?: string
) => {
const metadata = await _generateMetadataWithoutImage(getTitle, getDescription, hideBranding, origin);

const image = SEO_IMG_OGIMG + constructAppImage({ ...app, description: metadata.description });

return {
...metadata,
openGraph: {
...metadata.openGraph,
images: [image],
},
};
};
45 changes: 0 additions & 45 deletions apps/web/app/future/apps/[slug]/page.tsx

This file was deleted.

30 changes: 11 additions & 19 deletions apps/web/lib/apps/[slug]/getStaticProps.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import fs from "fs";
import matter from "gray-matter";
import MarkdownIt from "markdown-it";
import type { GetStaticPropsContext } from "next";
import path from "path";
import { z } from "zod";

Expand All @@ -10,8 +8,6 @@ import { getAppAssetFullPath } from "@calcom/app-store/getAppAssetFullPath";
import { IS_PRODUCTION } from "@calcom/lib/constants";
import prisma from "@calcom/prisma";

const md = new MarkdownIt("default", { html: true, breaks: true });

export const sourceSchema = z.object({
content: z.string(),
data: z.object({
Expand All @@ -29,32 +25,30 @@ export const sourceSchema = z.object({
}),
});

export const getStaticProps = async (ctx: GetStaticPropsContext) => {
if (typeof ctx.params?.slug !== "string") return { notFound: true } as const;
export type AppDataProps = NonNullable<Awaited<ReturnType<typeof getStaticProps>>>;

export const getStaticProps = async (slug: string) => {
const appMeta = await getAppWithMetadata({
slug: ctx.params?.slug,
slug,
});

const appFromDb = await prisma.app.findUnique({
where: { slug: ctx.params.slug.toLowerCase() },
where: { slug: slug.toLowerCase() },
});

const isAppAvailableInFileSystem = appMeta;
const isAppDisabled = isAppAvailableInFileSystem && (!appFromDb || !appFromDb.enabled);

if (!IS_PRODUCTION && isAppDisabled) {
return {
props: {
isAppDisabled: true as const,
data: {
...appMeta,
},
isAppDisabled: true as const,
data: {
...appMeta,
},
};
}

if (!appFromDb || !appMeta || isAppDisabled) return { notFound: true } as const;
if (!appFromDb || !appMeta || isAppDisabled) return null;

const isTemplate = appMeta.isTemplate;
const appDirname = path.join(isTemplate ? "templates" : "", appFromDb.dirName);
Expand Down Expand Up @@ -85,10 +79,8 @@ export const getStaticProps = async (ctx: GetStaticPropsContext) => {
});
}
return {
props: {
isAppDisabled: false as const,
source: { content, data },
data: appMeta,
},
isAppDisabled: false as const,
source: { content, data },
data: appMeta,
};
};
10 changes: 2 additions & 8 deletions apps/web/modules/apps/[slug]/slug-view.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
"use client";

import MarkdownIt from "markdown-it";
import type { InferGetStaticPropsType } from "next";
import Link from "next/link";

import { IS_PRODUCTION } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML";
import { showToast } from "@calcom/ui";

import type { getStaticProps } from "@lib/apps/[slug]/getStaticProps";
import type { AppDataProps } from "@lib/apps/[slug]/getStaticProps";
import useRouterQuery from "@lib/hooks/useRouterQuery";

import App from "@components/apps/App";

const md = new MarkdownIt("default", { html: true, breaks: true });

export type PageProps = InferGetStaticPropsType<typeof getStaticProps>;

function SingleAppPage(props: PageProps) {
function SingleAppPage(props: AppDataProps) {
const { error, setQuery: setError } = useRouterQuery("error");
const { t } = useLocale();
if (error === "account_already_linked") {
Expand Down
39 changes: 0 additions & 39 deletions apps/web/pages/apps/[slug]/index.tsx

This file was deleted.

1 change: 0 additions & 1 deletion apps/web/scripts/vercel-app-router-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ checkRoute () {
# These conditionals are used to remove directories from the build that are not needed in production
# This is to reduce the size of the build and prevent OOM errors
checkRoute "$APP_ROUTER_APPS_INSTALLED_CATEGORY_ENABLED" app/future/apps/installed
checkRoute "$APP_ROUTER_APPS_SLUG_ENABLED" app/future/apps/\[slug\]
checkRoute "$APP_ROUTER_APPS_SLUG_SETUP_ENABLED" app/future/apps/\[slug\]/setup
checkRoute "$APP_ROUTER_APPS_CATEGORIES_ENABLED" app/future/apps/categories
checkRoute "$APP_ROUTER_APPS_CATEGORIES_CATEGORY_ENABLED" app/future/apps/categories/\[category\]
Expand Down
1 change: 0 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@
"APP_ROUTER_APPS_CATEGORIES_CATEGORY_ENABLED",
"APP_ROUTER_APPS_CATEGORIES_ENABLED",
"APP_ROUTER_APPS_INSTALLED_CATEGORY_ENABLED",
"APP_ROUTER_APPS_SLUG_ENABLED",
"APP_ROUTER_APPS_SLUG_SETUP_ENABLED",
"APP_ROUTER_AUTH_FORGOT_PASSWORD_ENABLED",
"APP_ROUTER_AUTH_LOGIN_ENABLED",
Expand Down

0 comments on commit beb542e

Please sign in to comment.
0