All files / src/features/Minibuilders/Conversations/hooks useGetGlobalTopic.tsx

100% Statements 5/5
66.66% Branches 4/6
100% Functions 2/2
100% Lines 5/5

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          20x         288x 288x           32x                   288x        
import { checkPortals } from "@utils/routing";
import { getGlobalTopic } from "./useConversationsModal";
import { useQuery } from "react-query";
import { TGlobalTopic } from "../types";
 
const useGetGlobalTopic = (
  name: string,
  merchantId?: number,
  enabled = true,
) => {
  const { isAcquirerPortal, isEnterprisePortal } = checkPortals();
  const { isLoading, data } = useQuery<{
    total: number;
    data: TGlobalTopic[];
  }>(
    ["topic", name],
    async () =>
      await getGlobalTopic({
        topicName: name,
        merchantId,
      }),
    {
      refetchOnMount: false,
      refetchOnWindowFocus: false,
      enabled: (isAcquirerPortal || isEnterprisePortal) && enabled,
    },
  );
  return { isLoading, topic: data?.total && data.data[0] };
};
 
export default useGetGlobalTopic;