All files / src/features/GiveRiskProfile/hooks useTransactionAllow.tsx

93.75% Statements 15/16
100% Branches 0/0
83.33% Functions 5/6
93.75% Lines 15/16

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                        54x 22x   22x 2x   1x     1x 1x 1x 1x 1x 1x     1x       22x 1x                             22x    
import {
  QKEY_GET_TRANSACTION_STATS,
  QKEY_LIST_RISK_PROFILE_TRANSACTIONS,
  QKEY_PROCESSING_LIST,
  QKEY_PROVIDER_PROCESSING,
  QKEY_RISK_PROFILE,
} from "@constants/queryKeys";
import NiceModal from "@ebay/nice-modal-react";
import { allowTransaction } from "@services/api/riskProfile/riskProfileActions";
import { GIVE_CONFIRMATION_POP_UP } from "modals/modal_names";
import { useMutation, useQueryClient } from "react-query";
 
export const useTransactionAllow = (merchantId: number, id: string) => {
  const queryClient = useQueryClient();
 
  const updateToAllow = useMutation({
    mutationFn: () => allowTransaction(merchantId, id),
    onSuccess: () => {
      queryClient.invalidateQueries({
        queryKey: ["get-transaction-history", id],
      });
      queryClient.invalidateQueries(QKEY_RISK_PROFILE);
      queryClient.invalidateQueries(QKEY_LIST_RISK_PROFILE_TRANSACTIONS);
      queryClient.invalidateQueries(QKEY_PROVIDER_PROCESSING);
      queryClient.invalidateQueries(QKEY_PROCESSING_LIST);
      queryClient.invalidateQueries(QKEY_GET_TRANSACTION_STATS);
      queryClient.invalidateQueries("get-all-transactions");
    },
    onError: (error) => {
      console.error("Error allowing transaction:", error);
    },
  });
 
  const handleMarkAllow = () => {
    NiceModal.show(GIVE_CONFIRMATION_POP_UP, {
      modalType: "success",
      title: "Mark Transaction as Allow",
      description: `Are you sure you want to allow this transaction? This will remove it from quarantine and capture it.`,
      customSubmitBtnText: "Yes, Allow",
      actions: {
        handleSuccess: {
          onClick: async () => {
            updateToAllow.mutate();
          },
        },
      },
    });
  };
 
  return { handleMarkAllow, updateToAllow };
};