All files / src/hooks/common useCheckPAH.tsx

100% Statements 9/9
80% Branches 4/5
100% Functions 2/2
100% Lines 9/9

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            25x 161x 161x 161x 161x     6x                         161x   161x   161x        
import { useGetCurrentMerchantId } from "@hooks/common";
import useUserReducer from "@hooks/Reducers/useUserReducer";
import { customInstance } from "@services/api";
import { useQuery } from "react-query";
import { QKEY_CHECK_OWNER_MEMBER } from "@constants/queryKeys";
 
const useCheckPAH = (enabled = true) => {
  const { merchantId } = useGetCurrentMerchantId();
  const { userAccID } = useUserReducer();
  const queryEnabled = enabled && Boolean(merchantId);
  const { data: ownerData, isLoading } = useQuery(
    [QKEY_CHECK_OWNER_MEMBER, merchantId],
    async () => {
      return await customInstance({
        url: `/accounts/${merchantId}/members?filter=roleName:"owner"`,
        method: "GET",
      });
    },
    {
      staleTime: 10000,
      refetchOnWindowFocus: false,
      refetchOnMount: false,
      enabled: queryEnabled,
    },
  );
 
  const owner = ownerData?.data ? ownerData?.data[0] : null;
 
  const isLoggedInPAH = owner?.user?.accID === userAccID;
 
  return { owner, isLoading, isLoggedInPAH };
};
 
export default useCheckPAH;