perf: replace getServerSessionForAppDir usages with our original getServerSession function (#18897)

This commit is contained in:
Benny Joo authored and GitHub committed 2025-01-26 21:57:02 +00:00
1 parent 828940b4d6
commit 2b79ef0836
15 files changed
+44 -36

No files matched your search

@@ -1,23 +0,0 @@
import dynamic from "next/dynamic";
import React from "react";
import { getServerSessionForAppDir } from "@calcom/feature-auth/lib/get-server-session-for-app-dir";
import SettingsLayoutAppDir from "@calcom/features/settings/appDir/SettingsLayoutAppDir";
import type { AdminLayoutProps } from "./AdminLayoutAppDirClient";
const AdminLayoutAppDirClient = dynamic(() => import("./AdminLayoutAppDirClient"), {
ssr: false,
});
type AdminLayoutAppDirProps = Omit<AdminLayoutProps, "userRole">;
export default async function AdminLayoutAppDir(props: AdminLayoutAppDirProps) {
// FIXME: Refactor me once next-auth endpoint is migrated to App Router
const session = await getServerSessionForAppDir();
const userRole = session?.user?.role;
return await SettingsLayoutAppDir({ children: <AdminLayoutAppDirClient {...props} userRole={userRole} /> });
}
export const getLayout = async (page: React.ReactElement) => await AdminLayoutAppDir({ children: page });
@@ -1,34 +0,0 @@
"use client";
import { usePathname, useRouter } from "next/navigation";
import type { ComponentProps } from "react";
import React, { useEffect } from "react";
import type Shell from "@calcom/features/shell/Shell";
import { UserPermissionRole } from "@calcom/prisma/enums";
import { ErrorBoundary } from "@calcom/ui";
export type AdminLayoutProps = {
children: React.ReactNode;
userRole: UserPermissionRole | "INACTIVE_ADMIN" | undefined;
} & ComponentProps<typeof Shell>;
export default function AdminLayoutAppDirClient({ userRole, children }: AdminLayoutProps) {
const pathname = usePathname();
const router = useRouter();
// Force redirect on component level
useEffect(() => {
if (userRole !== UserPermissionRole.ADMIN) {
router.replace("/settings/my-account/profile");
}
}, [userRole, router]);
const isAppsPage = pathname?.startsWith("/settings/admin/apps");
return (
<div className="divide-subtle bg-default mx-auto flex max-w-4xl flex-row divide-y">
<div className={isAppsPage ? "min-w-0" : "flex flex-1 [&>*]:flex-1"}>
<ErrorBoundary>{children}</ErrorBoundary>
</div>
</div>
);
}