All files / src/components/Disputes/DisputesList/hooks useGetDisputesStats.ts

100% Statements 8/8
100% Branches 5/5
100% Functions 2/2
100% Lines 8/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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                                                                        263x 1151x 1151x 1151x 1151x 1151x     6x                     1151x          
import { useGetCurrentMerchantId } from "@hooks/common";
import { customInstance } from "@services/api";
import { isDefined } from "@utils/helpers";
import { checkPortals } from "@utils/routing";
import Cookies from "js-cookie";
import { safeParse } from "@utils/index";
import { useQuery } from "react-query";
import { QKEY_GET_DISPUTE_STATS } from "@constants/queryKeys";
 
interface DisputeStats {
  chargebackVolume: number;
  disputeVolume: number;
  chargebackVolumeRatio: number;
  disputeVolumeRatio: number;
  chargebackCount: number;
  chargebackCountRatio: number;
  disputeCountRatio: number;
  unsettledCount: number;
  friendlyCount: number;
  friendlyRate: number;
  fraudCount: number;
  fraudRate: number;
  winCount: number;
  winRate: number;
  disputeCount: number;
  openCount: number;
  closedCount: number;
  underReviewCount: number;
  preChargebackRefundCount: number;
  preChargebackRefundCountRatio: number;
  winCountRatio: number;
  lostCount: number;
  lostCountRatio: number;
  disputeAmount: number;
}
 
export const useGetDisputesStats = () => {
  const user = Cookies.get("user");
  const parsedUser = user ? safeParse(user) : null;
  const { merchantId } = useGetCurrentMerchantId();
  const { isAcquirerPortal } = checkPortals();
  const { data, isLoading } = useQuery<DisputeStats>({
    queryKey: QKEY_GET_DISPUTE_STATS,
    queryFn: async () => {
      return await customInstance({
        url: `/disputes/stats`,
        method: "GET",
      });
    },
    enabled:
      isDefined(merchantId) &&
      isAcquirerPortal &&
      parsedUser?.role === "acquirer",
  });
 
  return {
    data,
    isLoading,
  };
};