All files / src/features/MerchantPortal/DeveloperApi/hooks useGetDeveloperApi.tsx

100% Statements 8/8
100% Branches 2/2
100% Functions 3/3
100% Lines 8/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                    1x 1x           1x 5x   5x     1x 1x             5x    
import { useGetCurrentMerchantId } from "@hooks/common";
import { customInstance } from "@services/api";
import { useQuery } from "react-query";
import { QKEY_GET_API_KEY } from "@constants/queryKeys";
import { TApiKey } from "@components/DeveloperApi/data.types";
 
type Props = {
  apiKeyId: number;
};
 
const getApiKey = (merchantId: number, id: number) => {
  return customInstance({
    url: `/merchants/${merchantId}/api-keys/${id}`,
    method: "GET",
  });
};
 
export const useGetDeveloperApi = ({ apiKeyId }: Props) => {
  const { merchantId } = useGetCurrentMerchantId();
 
  const { data, isLoading } = useQuery(
    [QKEY_GET_API_KEY, apiKeyId, merchantId],
    async () => {
      const data = await getApiKey(merchantId, apiKeyId);
      return data as TApiKey;
    },
    {
      enabled: Boolean(merchantId && apiKeyId),
    },
  );
 
  return { data, isLoading };
};