All files / src/features/TransactionPanel/hooks useResendReceipt.tsx

45.45% Statements 5/11
100% Branches 0/0
20% Functions 1/5
45.45% Lines 5/11

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                      1x         4x 4x       4x                                 4x    
import useNiceModal from "@common/Modal/ModalFactory/hooks/useNiceModal";
import { showMessage } from "@common/Toast";
import { createReceiptInstance } from "@hooks/common/useSendReceipt";
import { useMutation } from "react-query";
 
type Props = {
  isChargebackReversal: boolean;
  transactionID: string;
  customerID: number;
};
 
export const useResendReceipt = ({
  isChargebackReversal,
  customerID,
  transactionID,
}: Props) => {
  const { onClose } = useNiceModal();
  const createReceiptMutation = useMutation((data: any) =>
    createReceiptInstance({ transactionID, customerID, data }),
  );
 
  const handleSubmit = ({ recipients }: { recipients: string[] | null }) => {
    const data = {
      recipients,
      sendToCustomer: Boolean(isChargebackReversal),
    };
 
    createReceiptMutation.mutate(data, {
      onError: async () => {
        showMessage("Error", "Sending receipt failed, please try again");
      },
      onSuccess: async () => {
        showMessage("Success", "Receipt Sent");
        onClose();
      },
    });
  };
 
  return { handleSubmit, isLoading: createReceiptMutation.isLoading };
};