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

72.72% Statements 8/11
33.33% Branches 3/9
66.66% Functions 2/3
72.72% Lines 8/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 42 43                        2x           100x 100x     28x 28x 28x   28x   28x                            
import { useGetCurrentMerchantId } from "@hooks/common";
import { ROWS_PER_PAGE } from "@hooks/common/usePagination";
import { customInstance } from "@services/api";
import { useQuery } from "react-query";
 
type Props = {
  queryKey: string;
  page: number;
  searchQuery: string;
  sorting: string;
};
 
export const useGetMerchantsApiKeys = ({
  page,
  searchQuery,
  queryKey,
  sorting,
}: Props) => {
  const { merchantId } = useGetCurrentMerchantId();
  return useQuery({
    queryKey: [queryKey, merchantId, page, sorting, searchQuery],
    queryFn: async () => {
      const pageQuery = page ? `&page=${page}` : "";
      const search = searchQuery ? `&q="${searchQuery}"` : "";
      const sortingQuery = sorting || "-createdAt";
 
      const url = `/merchants/${merchantId}/api-keys?sort=${sortingQuery}${pageQuery}${search}&max=${ROWS_PER_PAGE}`;
 
      return await customInstance({
        url: url,
      });
    },
    retry: 1,
  });
};
 
export function shortenString(input: string, lengthToShow = 16): string {
  if (input.length <= lengthToShow) {
    return input;
  }
  return "..." + input.slice(-lengthToShow);
}