All files / src/components/Merchants/MerchantPreview/hooks useUnderwritingUpdate.ts

88.88% Statements 8/9
75% Branches 3/4
66.66% Functions 2/3
88.88% Lines 8/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        41x   6721x   6721x   6721x 1x       1x             6721x               6721x    
import { customInstance } from "@services/api";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
import { useMutation } from "react-query";
 
export const useUpdateUnderwriting = (merchantId: number) => {
  const { isMerchantStatusRefactorEnabled, isNewApprovalFlowEnabled } =
    useGetFeatureFlagValues();
 
  const urlStatusPath = isMerchantStatusRefactorEnabled ? "-status-v2" : "";
 
  const updateUnderwriting = useMutation((payload: any) => {
    const data = isNewApprovalFlowEnabled
      ? { state: payload.status, reason: payload?.reason }
      : payload;
 
    return customInstance({
      url: `/merchants/${merchantId}/underwriting${urlStatusPath}`,
      method: "PATCH",
      data,
    });
  });
 
  const updateUnderwritingData = useMutation((payload: any) => {
    return customInstance({
      url: `/merchants/${merchantId}/money-capabilities`,
      method: "PATCH",
      data: payload,
    });
  });
 
  return { updateUnderwriting, updateUnderwritingData };
};