All files / src/components/Disputes/RespondToDispute/hooks useGetCaseActions.tsx

100% Statements 9/9
83.33% Branches 5/6
100% Functions 4/4
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 36 37 38 39 40 41 42 43 44 45 46        2x 10x                       2x         67x         67x     10x 10x   53x                   67x    
import { customInstance } from "@services/api";
import { useQuery } from "react-query";
import { CaseActionType } from "../types";
 
const getDisputeCaseActions = (disputeId: string, caseId: string) => {
  return customInstance({
    url: `/disputes/${disputeId}/cases/${caseId}/actions`,
    method: "GET",
  });
};
 
type Props = {
  disputeId: string;
  lastCaseId: string;
  isFilterApplied?: boolean;
};
 
export const useGetCaseActions = ({
  disputeId,
  lastCaseId,
  isFilterApplied,
}: Props) => {
  const excludedActions = [
    "pre_arbitration_accepted",
    "chargeback_accepted",
    "accepted", // Worldpay accept action — handled via the separate Accept Chargeback flow
  ];
  const { data, isLoading } = useQuery(
    ["dispute-case-actions", disputeId, lastCaseId],
    async () => {
      const caseActions = await getDisputeCaseActions(disputeId, lastCaseId);
      return isFilterApplied
        ? (caseActions?.data || []).filter(
            (action: CaseActionType) => !excludedActions.includes(action.name),
          )
        : caseActions?.data;
    },
    {
      refetchOnWindowFocus: false,
      enabled: Boolean(disputeId && lastCaseId),
    },
  );
 
  return { caseActions: data as CaseActionType[], isLoading };
};