2023-11-20 15:16:49 +00:00
|
|
|
import { FC, ReactNode } from "react";
|
|
|
|
import { observer } from "mobx-react-lite";
|
|
|
|
// hooks
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-11-27 14:11:47 +00:00
|
|
|
// components
|
|
|
|
import { InstanceAdminRestriction } from "components/instance";
|
2023-11-20 15:16:49 +00:00
|
|
|
|
|
|
|
export interface IAdminAuthWrapper {
|
|
|
|
children: ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const AdminAuthWrapper: FC<IAdminAuthWrapper> = observer(({ children }) => {
|
|
|
|
// store
|
|
|
|
const {
|
|
|
|
user: { isUserInstanceAdmin },
|
|
|
|
workspace: { workspaceSlug },
|
|
|
|
user: { currentUserSettings },
|
|
|
|
} = useMobxStore();
|
|
|
|
|
|
|
|
// 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) {
|
2023-11-27 14:11:47 +00:00
|
|
|
return <InstanceAdminRestriction redirectWorkspaceSlug={redirectWorkspaceSlug} />;
|
2023-11-20 15:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return <>{children}</>;
|
|
|
|
});
|