All files / src/features/Permissions/AccessControl WithAccessControl.tsx

40% Statements 4/10
25% Branches 2/8
100% Functions 1/1
37.5% Lines 3/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38                              499x         6x   6x                              
import _ from "lodash";
import { MissingPermissionContent } from "../PopUp/MissingPermissionContent";
import useAccessControl, { TUseAccessControl } from "./useAccessControl";
import {
  NotAuthorizedBanner,
  NotAuthorizedMessage,
} from "@containers/NotAuthorizedWrapper";
 
type TRenderType = "page-with-banner" | "message" | "banner";
 
interface IWithAccessControl extends TUseAccessControl {
  children: React.ReactNode;
  render?: TRenderType | (() => React.ReactNode);
}
 
const WithAccessControl = ({
  children,
  render = "message",
  ...useAccessControlProps
}: IWithAccessControl) => {
  const isAllowed = useAccessControl(useAccessControlProps);
 
  Eif (isAllowed) return <>{children}</>;
 
  if (_.isFunction(render)) return <>{render()}</>;
 
  switch (render) {
    case "page-with-banner":
      return <NotAuthorizedMessage />;
    case "banner":
      return <NotAuthorizedBanner />;
    default:
      return <MissingPermissionContent />;
  }
};
 
export default WithAccessControl;