All files / src/features/Merchants/MerchantSidePanel/MoveFunds/hooks useMoveFunds.ts

37.5% Statements 3/8
100% Branches 0/0
33.33% Functions 1/3
37.5% Lines 3/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                                        1x 12x   12x                                                                
import { customInstance } from "@services/api";
import { useMutation, useQueryClient } from "react-query";
import { MERCHANT_SIDE_PANEL_PREVIEW_API_KEYS } from "../../constants";
import {
  QKEY_GET_TRANSACTION_STATS,
  QKEY_PROCESSING_LIST,
} from "@constants/queryKeys";
import { showMessage } from "@common/Toast";
import { StatsType } from "@services/api/api.constant";
 
export enum ReserveTransferType {
  DEPOSIT = "deposit",
  RELEASE = "release",
}
 
interface MoveFundsPayload {
  amount: number;
  type: ReserveTransferType;
}
 
const useMoveFunds = (merchantId: number) => {
  const queryClient = useQueryClient();
 
  return useMutation({
    mutationFn: (data: MoveFundsPayload) =>
      customInstance({
        url: `/merchants/${merchantId}/reserve-transfers`,
        method: "POST",
        data,
      }),
    onSuccess: () => {
      showMessage(
        "Success",
        "",
        true,
        "The funds have been successfully moved between balances",
        5000,
        undefined,
        { lineClamp: 2 },
      );
      queryClient.invalidateQueries([
        MERCHANT_SIDE_PANEL_PREVIEW_API_KEYS.GET_STATS,
        merchantId,
      ]);
      queryClient.invalidateQueries(QKEY_PROCESSING_LIST);
      queryClient.invalidateQueries([
        QKEY_GET_TRANSACTION_STATS,
        merchantId,
        StatsType.BASE,
      ]);
    },
  });
};
 
export default useMoveFunds;