plane/web/layouts/auth-layout/admin-wrapper.tsx
sriram veeraghanta 3d09a69d58
fix: eslint issues and reconfiguring (#3891)
* fix: eslint fixes

---------

Co-authored-by: gurusainath <gurusainath007@gmail.com>
2024-03-06 18:39:14 +05:30

32 lines
977 B
TypeScript

import { FC, ReactNode } from "react";
import { observer } from "mobx-react-lite";
// hooks
import { InstanceAdminRestriction } from "components/instance";
import { useApplication, useUser } from "hooks/store";
// components
export interface IAdminAuthWrapper {
children: ReactNode;
}
export const AdminAuthWrapper: FC<IAdminAuthWrapper> = observer(({ children }) => {
// store hooks
const {
router: { workspaceSlug },
} = useApplication();
const { isUserInstanceAdmin, currentUserSettings } = useUser();
// redirect url
const redirectWorkspaceSlug =
workspaceSlug ||
currentUserSettings?.workspace?.last_workspace_slug ||
currentUserSettings?.workspace?.fallback_workspace_slug ||
"";
// if user does not have admin access to the instance
if (isUserInstanceAdmin !== undefined && isUserInstanceAdmin === false) {
return <InstanceAdminRestriction redirectWorkspaceSlug={redirectWorkspaceSlug} />;
}
return <>{children}</>;
});