All files / src/hooks/common useMasqueradeRedirect.tsx

83.33% Statements 10/12
50% Branches 4/8
100% Functions 2/2
83.33% Lines 10/12

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          520x 401x 401x 401x   401x   401x 401x     401x     401x 58x              
import React from "react";
import { useAppSelector } from "@redux/hooks";
import { selectMasqueradeMode } from "@redux/slices/app";
import { useLocation, useNavigate } from "react-router-dom";
 
const useMasqueradeRedirect = () => {
  const { name, origin } = useAppSelector(selectMasqueradeMode);
  const navigate = useNavigate();
  const { pathname } = useLocation();
 
  let redirectPath = "";
  const isEnterprisePortal =
    origin === "/acquirer/providers" && pathname.includes("/provider/");
  Iif (origin === "/acquirer/providers") {
    redirectPath = `/provider/transactions`;
  } else {
    redirectPath = `/merchant/manage-money`;
  }
 
  React.useEffect(() => {
    Iif (name && !isEnterprisePortal) {
      navigate(redirectPath);
    }
  }, []);
};
 
export default useMasqueradeRedirect;