2022-09-08 15:35:31 +00:00
|
|
|
import { useSession } from "next-auth/react";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import React, { ComponentProps, useEffect } from "react";
|
2022-08-09 09:21:15 +00:00
|
|
|
|
2023-01-05 17:00:16 +00:00
|
|
|
import SettingsLayout from "@calcom/features/settings/layouts/SettingsLayout";
|
2023-01-10 15:39:29 +00:00
|
|
|
import Shell from "@calcom/features/shell/Shell";
|
|
|
|
import { ErrorBoundary } from "@calcom/ui";
|
2023-01-05 17:00:16 +00:00
|
|
|
|
2022-09-08 15:35:31 +00:00
|
|
|
import { UserPermissionRole } from ".prisma/client";
|
2022-08-09 09:21:15 +00:00
|
|
|
|
|
|
|
export default function AdminLayout({
|
|
|
|
children,
|
2023-01-31 21:45:38 +00:00
|
|
|
|
2022-08-09 09:21:15 +00:00
|
|
|
...rest
|
|
|
|
}: { children: React.ReactNode } & ComponentProps<typeof Shell>) {
|
2022-09-08 15:35:31 +00:00
|
|
|
const session = useSession();
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
// Force redirect on component level
|
|
|
|
useEffect(() => {
|
2022-11-23 21:54:17 +00:00
|
|
|
if (session.data && session.data.user.role !== UserPermissionRole.ADMIN) {
|
2022-11-25 12:36:33 +00:00
|
|
|
router.replace("/settings/my-account/profile");
|
2022-09-08 15:35:31 +00:00
|
|
|
}
|
|
|
|
}, [session, router]);
|
|
|
|
|
2023-01-31 21:45:38 +00:00
|
|
|
const isAppsPage = router.asPath.startsWith("/settings/admin/apps");
|
2022-08-09 09:21:15 +00:00
|
|
|
return (
|
|
|
|
<SettingsLayout {...rest}>
|
2022-12-07 21:47:02 +00:00
|
|
|
<div className="mx-auto flex max-w-4xl flex-row divide-y divide-gray-200">
|
2023-01-31 21:45:38 +00:00
|
|
|
<div className={isAppsPage ? "min-w-0" : "flex flex-1 [&>*]:flex-1"}>
|
2022-09-12 19:07:52 +00:00
|
|
|
<ErrorBoundary>{children}</ErrorBoundary>
|
|
|
|
</div>
|
2022-08-09 09:21:15 +00:00
|
|
|
</div>
|
|
|
|
</SettingsLayout>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getLayout = (page: React.ReactElement) => <AdminLayout>{page}</AdminLayout>;
|