All files / src/components/Signup/Forms/hooks useGetMerchantRiskStatus.tsx

12.5% Statements 1/8
0% Branches 0/4
0% Functions 0/4
12.5% Lines 1/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 35 36 37 38 39 40 41 42 43 44 45                    66x                                                                    
import { useQuery } from "react-query";
import { customInstance } from "@services/api";
import { TRiskLevelName } from "@common/Tag/RiskStatusChip";
 
type TRiskStatus = {
  id: number;
  label: string;
  value: TRiskLevelName;
};
 
const getRiskStatus = (category?: string) => {
  const url = category
    ? `merchant-risk-statuses?filter=category:"${category}"`
    : `merchant-risk-statuses`;
  return customInstance({
    url,
    method: "GET",
  });
};
 
export function useGetMerchantRiskStatus(category?: string) {
  const { data, isLoading } = useQuery<TRiskStatus[]>(
    ["merchant-risk-status", category],
    async () => {
      const data = await getRiskStatus(category);
 
      return (
        data?.data?.map(
          (status: any): TRiskStatus => ({
            id: status.id,
            label: status.displayName,
            value: status.name as TRiskLevelName,
          }),
        ) || []
      );
    },
    {
      refetchOnWindowFocus: false,
      enabled: category !== undefined,
    },
  );
 
  return { data, isLoading };
}