All files / src/hooks/common useGetUserRole.ts

100% Statements 7/7
50% Branches 3/6
100% Functions 1/1
100% Lines 7/7

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        21x 444x   444x   444x   444x             444x           444x            
import useMasqueradeReducer from "../Reducers/useMasqueradeReducer";
import { selectSelectedAccount } from "@redux/slices/auth/accounts";
import { useAppSelector } from "@redux/hooks";
 
export const useGetUserRole = () => {
  const { isMasqueradeMode } = useMasqueradeReducer();
 
  const selectedAccount = useAppSelector(selectSelectedAccount);
 
  const userRole = isMasqueradeMode ? "owner" : selectedAccount?.userRole;
 
  const canManageConversations = ![
    "sales_associate",
    "customer_support",
    "sales_executive",
  ].includes(userRole || "");
 
  //this is a temporary fix until the BE will manege the permission for this
  const showSponsorCardByRole = [
    "owner",
    "sponsor",
    "admin",
    "risk_manager",
  ].includes(userRole || "");
  return {
    userRole,
    showSponsorCardByRole,
    canManageConversations
  };
};