All files / src/features/Merchants/MerchantSidePanel/WithRepository/Challenges/hooks useChallenges.tsx

25% Statements 3/12
0% Branches 0/10
0% Functions 0/4
25% Lines 3/12

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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75                      21x                                               21x                                   21x                                          
import { customInstance } from "@services/api";
import { EDDData, TChallengeTypeName, TNotifyData } from "../types";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
import { checkPortals } from "@utils/routing";
 
type TQueryEDDChallenge = {
  merchantID: number;
  challengeID?: number;
  data?: EDDData;
};
 
export const useEDDChallenge = async ({
  merchantID,
  challengeID,
  data,
}: TQueryEDDChallenge) => {
  return await customInstance({
    url: `/merchants/${merchantID}/underwriting-challenges${
      challengeID ? `/${challengeID}` : ""
    }`,
    method: !challengeID ? "POST" : !data ? "DELETE" : "PATCH",
    data,
  });
};
 
type TUpdateChallange = {
  merchantID: number;
  challengeID?: number;
  data: {
    reason: string;
    status: "open" | "closed" | "rejected";
    type: TChallengeTypeName;
  };
};
 
export const useUpdateChallenge = async ({
  merchantID,
  challengeID,
  data,
}: TUpdateChallange) => {
  return await customInstance({
    url: `/merchants/${merchantID}/underwriting-challenges/${challengeID}/status`,
    method: "PATCH",
    data,
  });
};
 
type TNotifyMerchant = {
  merchantID: number;
  challengeID: number;
  data: TNotifyData;
};
 
export const useNotifyMerchant = () => {
  const { isNewApprovalFlowEnabled } = useGetFeatureFlagValues();
  const { isAcquirerEnterprises } = checkPortals();
 
  const isTasks = isNewApprovalFlowEnabled && !isAcquirerEnterprises;
 
  const filesPath = isTasks ? "/tasks" : "/underwriting-challenges";
 
  const postNotify = async ({
    merchantID,
    challengeID,
    data,
  }: TNotifyMerchant) =>
    customInstance({
      url: `merchants/${merchantID}${filesPath}/${challengeID}/notify`,
      method: "POST",
      data,
    });
 
  return { postNotify };
};