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:
Benny Joo authored and GitHub committed 2024-12-13 12:44:57 +00:00
1 parent 851d96423b
commit b97331aeb3
14 files changed
+133 -139

No files matched your search

@@ -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 });
+39
View File
@@ -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 });
@@ -0,0 +1,13 @@
import { _generateMetadata } from "app/_utils";
import { WithLayout } from "app/layoutHOC";
import Troubleshoot, { getLayout } from "~/availability/troubleshoot/troubleshoot-view";
export const generateMetadata = async () => {
return await _generateMetadata(
(t) => t("troubleshoot"),
(t) => t("troubleshoot_availability")
);
};
export default WithLayout({ getLayout, Page: Troubleshoot });