chore: /availability - Remove Pages Router / Render App Router (#16517)
* /availability: Remove Pages Router / Render App Router * comment out server side fetching * fix * refactor for safer code * add to config.matcher
This commit is contained in:
@@ -361,7 +361,6 @@ APP_ROUTER_GETTING_STARTED_STEP_ENABLED=0
|
||||
APP_ROUTER_APPS_ENABLED=0
|
||||
APP_ROUTER_TEAM_ENABLED=0
|
||||
APP_ROUTER_TEAMS_ENABLED=0
|
||||
APP_ROUTER_AVAILABILITY_ENABLED=0
|
||||
APP_ROUTER_AUTH_FORGOT_PASSWORD_ENABLED=0
|
||||
APP_ROUTER_AUTH_LOGIN_ENABLED=0
|
||||
APP_ROUTER_AUTH_LOGOUT_ENABLED=0
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 });
|
||||
@@ -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 });
|
||||
@@ -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 });
|
||||
@@ -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 });
|
||||
@@ -193,6 +193,7 @@ export const config = {
|
||||
"/teams",
|
||||
"/future/teams/",
|
||||
"/settings/:path*",
|
||||
"/availability/:path*",
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -1,9 +0,0 @@
|
||||
import PageWrapper from "@components/PageWrapper";
|
||||
|
||||
import _AvailabilityPage from "~/availability/availability-view";
|
||||
|
||||
const AvailabilityPage = () => <_AvailabilityPage />;
|
||||
|
||||
AvailabilityPage.PageWrapper = PageWrapper;
|
||||
|
||||
export default AvailabilityPage;
|
||||
@@ -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;
|
||||
@@ -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_EVENT_TYPES_ENABLED" app/future/event-types
|
||||
checkRoute "$APP_ROUTER_AVAILABILITY_ENABLED" app/future/availability
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user