Scheduling infrastructure for absolutely everyone.
chore: `/availability` - Remove Pages Router / Render App Router (#16517)
Benny Joob97331aeb3e4
diff --git a/.env.example b/.env.exampleindex 616c7d2b54c..124aac0ff8c 100644--- a/.env.example+++ b/.env.example@@ -361,7 +361,6 @@ APP_ROUTER_GETTING_STARTED_STEP_ENABLED=0APP_ROUTER_APPS_ENABLED=0APP_ROUTER_TEAM_ENABLED=0APP_ROUTER_TEAMS_ENABLED=0-APP_ROUTER_AVAILABILITY_ENABLED=0APP_ROUTER_AUTH_FORGOT_PASSWORD_ENABLED=0APP_ROUTER_AUTH_LOGIN_ENABLED=0APP_ROUTER_AUTH_LOGOUT_ENABLED=0diff --git a/apps/web/abTest/middlewareFactory.ts b/apps/web/abTest/middlewareFactory.tsindex 1c92e05dd2c..e3555464bee 100644--- a/apps/web/abTest/middlewareFactory.ts+++ b/apps/web/abTest/middlewareFactory.ts@@ -25,7 +25,6 @@ const ROUTES: [URLPattern, boolean][] = [["/booking/:path*", process.env.APP_ROUTER_BOOKING_ENABLED === "1"] as const,["/team", process.env.APP_ROUTER_TEAM_ENABLED === "1"] as const,["/teams", process.env.APP_ROUTER_TEAMS_ENABLED === "1"] as const,- ["/availability", process.env.APP_ROUTER_AVAILABILITY_ENABLED === "1"] as const,].map(([pathname, enabled]) => [new URLPattern({pathname,diff --git a/apps/web/app/availability/[schedule]/page.tsx b/apps/web/app/availability/[schedule]/page.tsxnew file mode 100644index 00000000000..bdeef24588e--- /dev/null+++ b/apps/web/app/availability/[schedule]/page.tsx@@ -0,0 +1,92 @@+import type { PageProps } from "app/_types";+import { _generateMetadata } from "app/_utils";+import { WithLayout } from "app/layoutHOC";+import { notFound } from "next/navigation";+import { cache } from "react";+import { z } from "zod";++// import { getServerSessionForAppDir } from "@calcom/feature-auth/lib/get-server-session-for-app-dir";+import { ScheduleRepository } from "@calcom/lib/server/repository/schedule";++// import { TravelScheduleRepository } from "@calcom/lib/server/repository/travelSchedule";+// import { UserRepository } from "@calcom/lib/server/repository/user";+import { AvailabilitySettingsWebWrapper } from "~/availability/[schedule]/schedule-view";++const querySchema = z.object({+ schedule: z+ .string()+ .refine((val) => !isNaN(Number(val)), {+ message: "schedule must be a string that can be cast to a number",+ })+ .transform((val) => Number(val)),+});++const getSchedule = cache((id: number) => ScheduleRepository.findScheduleById({ id }));++export const generateMetadata = async ({ params, searchParams }: PageProps) => {+ const parsed = querySchema.safeParse({ ...params, ...searchParams });+ if (!parsed.success) {+ notFound();+ }++ const schedule = await getSchedule(parsed.data.schedule);++ if (!schedule) {+ notFound();+ }++ return await _generateMetadata(+ (t) => (schedule.name ? `${schedule.name} | ${t("availability")}` : t("availability")),+ () => ""+ );+};++const Page = async ({ params, searchParams }: PageProps) => {+ const parsed = querySchema.safeParse({ ...params, ...searchParams });+ if (!parsed.success) {+ notFound();+ }+ // const scheduleId = Number(params.schedule);++ // const session = await getServerSessionForAppDir();+ // const userId = session?.user?.id;+ // if (!userId) {+ // notFound();+ // }++ // let userData, schedule, travelSchedules;++ // try {+ // userData = await UserRepository.getTimeZoneAndDefaultScheduleId({+ // userId,+ // });+ // if (!userData?.timeZone || !userData?.defaultScheduleId) {+ // throw new Error("timeZone and defaultScheduleId not found");+ // }+ // } catch (e) {+ // notFound();+ // }++ // try {+ // schedule = await ScheduleRepository.findDetailedScheduleById({+ // scheduleId,+ // isManagedEventType: false,+ // userId,+ // timeZone: userData.timeZone,+ // defaultScheduleId: userData.defaultScheduleId,+ // });+ // } catch (e) {}++ // try {+ // travelSchedules = await TravelScheduleRepository.findTravelSchedulesByUserId(userId);+ // } catch (e) {}++ return (+ <AvailabilitySettingsWebWrapper++ // scheduleFetched={schedule} travelSchedules={travelSchedules}+ />+ );+};++export default WithLayout({ ServerPage: Page });diff --git a/apps/web/app/availability/page.tsx b/apps/web/app/availability/page.tsxnew file mode 100644index 00000000000..e32e6e2b26b--- /dev/null+++ b/apps/web/app/availability/page.tsx@@ -0,0 +1,39 @@+import { _generateMetadata } from "app/_utils";+import { WithLayout } from "app/layoutHOC";+import { notFound } from "next/navigation";++// import { getServerSessionForAppDir } from "@calcom/feature-auth/lib/get-server-session-for-app-dir";+// import { OrganizationRepository } from "@calcom/lib/server/repository/organization";+import AvailabilityPage from "~/availability/availability-view";++export const generateMetadata = async () => {+ return await _generateMetadata(+ (t) => t("availability"),+ (t) => t("configure_availability")+ );+};++const Page = async () => {+ // const session = await getServerSessionForAppDir();+ // const userId = session?.user?.id;+ // const orgId = session?.user?.org?.id;+ // if (!userId || !orgId) {+ // notFound();+ // }++ try {+ // const currentOrg = await OrganizationRepository.findCurrentOrg({+ // orgId,+ // userId,+ // });+ return (+ <AvailabilityPage+ // currentOrg={currentOrg}+ />+ );+ } catch {+ notFound();+ }+};++export default WithLayout({ ServerPage: Page });diff --git a/apps/web/app/future/availability/troubleshoot/page.tsx b/apps/web/app/availability/troubleshoot/page.tsxsimilarity index 100%rename from apps/web/app/future/availability/troubleshoot/page.tsxrename to apps/web/app/availability/troubleshoot/page.tsxdiff --git a/apps/web/app/future/availability/[schedule]/page.tsx b/apps/web/app/future/availability/[schedule]/page.tsxdeleted file mode 100644index 2c4fb1382e6..00000000000--- a/apps/web/app/future/availability/[schedule]/page.tsx+++ /dev/null@@ -1,72 +0,0 @@-import type { PageProps } from "app/_types";-import { _generateMetadata } from "app/_utils";-import { WithLayout } from "app/layoutHOC";-import { notFound } from "next/navigation";--import { getServerSessionForAppDir } from "@calcom/feature-auth/lib/get-server-session-for-app-dir";-import { ScheduleRepository } from "@calcom/lib/server/repository/schedule";-import { TravelScheduleRepository } from "@calcom/lib/server/repository/travelSchedule";-import { UserRepository } from "@calcom/lib/server/repository/user";--import { AvailabilitySettingsWebWrapper } from "~/availability/[schedule]/schedule-view";--export const generateMetadata = async ({ params }: PageProps) => {- const scheduleId = params?.schedule ? Number(params.schedule) : -1;- const schedule = await ScheduleRepository.findScheduleById({ id: scheduleId });-- if (!schedule) {- return await _generateMetadata(- (t) => t("availability"),- () => ""- );- }-- return await _generateMetadata(- (t) => (schedule.name ? `${schedule.name} | ${t("availability")}` : t("availability")),- () => ""- );-};--const Page = async ({ params }: PageProps) => {- if (params?.schedule) {- notFound();- }- const scheduleId = Number(params.schedule);-- const session = await getServerSessionForAppDir();- const userId = session?.user?.id;- if (!userId) {- notFound();- }-- let userData, schedule, travelSchedules;-- try {- userData = await UserRepository.getTimeZoneAndDefaultScheduleId({- userId,- });- if (!userData?.timeZone || !userData?.defaultScheduleId) {- throw new Error("timeZone and defaultScheduleId not found");- }- } catch (e) {- notFound();- }-- try {- schedule = await ScheduleRepository.findDetailedScheduleById({- scheduleId,- isManagedEventType: false,- userId,- timeZone: userData.timeZone,- defaultScheduleId: userData.defaultScheduleId,- });- } catch (e) {}-- try {- travelSchedules = await TravelScheduleRepository.findTravelSchedulesByUserId(userId);- } catch (e) {}-- return <AvailabilitySettingsWebWrapper scheduleFetched={schedule} travelSchedules={travelSchedules} />;-};--export default WithLayout({ ServerPage: Page });diff --git a/apps/web/app/future/availability/page.tsx b/apps/web/app/future/availability/page.tsxdeleted file mode 100644index 09d33577b0c..00000000000--- a/apps/web/app/future/availability/page.tsx+++ /dev/null@@ -1,36 +0,0 @@-import { _generateMetadata } from "app/_utils";-import { WithLayout } from "app/layoutHOC";-import { notFound } from "next/navigation";--import { getServerSessionForAppDir } from "@calcom/feature-auth/lib/get-server-session-for-app-dir";-import { OrganizationRepository } from "@calcom/lib/server/repository/organization";--import AvailabilityPage from "~/availability/availability-view";--export const generateMetadata = async () => {- return await _generateMetadata(- (t) => t("availability"),- (t) => t("configure_availability")- );-};--const Page = async () => {- const session = await getServerSessionForAppDir();- const userId = session?.user?.id;- const orgId = session?.user?.org?.id;- if (!userId || !orgId) {- notFound();- }-- try {- const currentOrg = await OrganizationRepository.findCurrentOrg({- orgId,- userId,- });- return <AvailabilityPage currentOrg={currentOrg} />;- } catch {- notFound();- }-};--export default WithLayout({ ServerPage: Page });diff --git a/apps/web/middleware.ts b/apps/web/middleware.tsindex 7e8c5861274..1290b8bd176 100644--- a/apps/web/middleware.ts+++ b/apps/web/middleware.ts@@ -193,6 +193,7 @@ export const config = {"/teams","/future/teams/","/settings/:path*",+ "/availability/:path*",],};diff --git a/apps/web/pages/availability/[schedule].tsx b/apps/web/pages/availability/[schedule].tsxdeleted file mode 100644index 2c95f64f5fb..00000000000--- a/apps/web/pages/availability/[schedule].tsx+++ /dev/null@@ -1,9 +0,0 @@-import PageWrapper from "@components/PageWrapper";--import { AvailabilitySettingsWebWrapper } from "~/availability/[schedule]/schedule-view";--const AvailabilitySettings = () => <AvailabilitySettingsWebWrapper />;--AvailabilitySettings.PageWrapper = PageWrapper;--export default AvailabilitySettings;diff --git a/apps/web/pages/availability/index.tsx b/apps/web/pages/availability/index.tsxdeleted file mode 100644index fd2aeffe88b..00000000000--- a/apps/web/pages/availability/index.tsx+++ /dev/null@@ -1,9 +0,0 @@-import PageWrapper from "@components/PageWrapper";--import _AvailabilityPage from "~/availability/availability-view";--const AvailabilityPage = () => <_AvailabilityPage />;--AvailabilityPage.PageWrapper = PageWrapper;--export default AvailabilityPage;diff --git a/apps/web/pages/availability/troubleshoot.tsx b/apps/web/pages/availability/troubleshoot.tsxdeleted file mode 100644index 1098bf4951e..00000000000--- a/apps/web/pages/availability/troubleshoot.tsx+++ /dev/null@@ -1,8 +0,0 @@-import PageWrapper from "@components/PageWrapper";--import Troubleshoot, { getLayout } from "~/availability/troubleshoot/troubleshoot-view";--const TroubleshooterPage = () => <Troubleshoot />;-TroubleshooterPage.getLayout = getLayout;-TroubleshooterPage.PageWrapper = PageWrapper;-export default TroubleshooterPage;diff --git a/apps/web/scripts/vercel-app-router-deploy.sh b/apps/web/scripts/vercel-app-router-deploy.shindex 86b6eb1c44e..591c0b3c3c4 100755--- a/apps/web/scripts/vercel-app-router-deploy.sh+++ b/apps/web/scripts/vercel-app-router-deploy.sh@@ -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 errorscheckRoute "$APP_ROUTER_EVENT_TYPES_ENABLED" app/future/event-types-checkRoute "$APP_ROUTER_AVAILABILITY_ENABLED" app/future/availabilitycheckRoute "$APP_ROUTER_APPS_INSTALLED_CATEGORY_ENABLED" app/future/apps/installedcheckRoute "$APP_ROUTER_APPS_SLUG_ENABLED" app/future/apps/\[slug\]checkRoute "$APP_ROUTER_APPS_SLUG_SETUP_ENABLED" app/future/apps/\[slug\]/setupdiff --git a/packages/core/EventManager.ts b/packages/core/EventManager.tsindex 0c2a49ea119..4f900c2c70a 100644--- a/packages/core/EventManager.ts+++ b/packages/core/EventManager.ts@@ -980,7 +980,7 @@ export default class EventManager {const createdEvent = await crm.createEvent(event, currentAppOption).catch((error) => {success = false;// We don't know the type of the error here, so for an Error instance we can read message but otherwise we stringify the error- let errorMsg = error instanceof Error ? error.message : JSON.stringify(error);+ const errorMsg = error instanceof Error ? error.message : JSON.stringify(error);log.warn(`Error creating crm event for ${credential.type}`, errorMsg);});diff --git a/turbo.json b/turbo.jsonindex 1e9fa18fe67..2eb54ef949c 100644--- a/turbo.json+++ b/turbo.json@@ -251,7 +251,6 @@"APP_ROUTER_AUTH_OAUTH2_ENABLED","APP_ROUTER_TEAM_ENABLED","APP_ROUTER_TEAMS_ENABLED",- "APP_ROUTER_AVAILABILITY_ENABLED","APP_USER_NAME","BASECAMP3_CLIENT_ID","BASECAMP3_CLIENT_SECRET",