All files / src/features/Merchants/MerchantSidePanel/UnderwritingTasks/hooks useReadChallangeFiles.tsx

100% Statements 6/6
100% Branches 4/4
100% Functions 2/2
100% Lines 6/6

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          8x             117x   117x   117x   117x     33x                  
import { QKEY_CHALLENGE_FILES } from "@constants/queryKeys";
import { customInstance } from "@services/api";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
import { useQuery } from "react-query";
 
export const useReadChallengeFiles = ({
  challengeId,
  merchantId,
}: {
  challengeId: number;
  merchantId: number;
}) => {
  const { isNewApprovalFlowEnabled } = useGetFeatureFlagValues();
 
  const isTasks = isNewApprovalFlowEnabled;
 
  const filesPath = isTasks ? "/tasks" : "/underwriting-challenges";
 
  return useQuery(
    [QKEY_CHALLENGE_FILES, merchantId, challengeId],
    async ({ queryKey }) =>
      await customInstance({
        url: `/merchants/${queryKey[1]}${filesPath}/${queryKey[2]}/files`,
        method: "GET",
      }),
    {
      enabled: !!merchantId && !!challengeId,
    },
  );
};