All files / src/hooks useListRegionsQuery.tsx

100% Statements 11/11
100% Branches 1/1
100% Functions 2/2
100% Lines 11/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 284x 4x 4x     14x 14x 14x     4x         4x 1x   3x             14x    
import { request } from '@procore/core-http';
import { useQuery } from '@tanstack/react-query';
import { useAddCompanyContext } from '../Context/AddCompanyContext';
import { ListRegionsResponse } from '../models/ListRegionsResponse';
 
export function useListRegionsQuery() {
  const { companyId } = useAddCompanyContext();
  const query = useQuery<ListRegionsResponse>({
    queryKey: ['regions'],
    queryFn: async () => {
      const response = await request('/rest/v1.0/internal/regions', {
        headers: {
          'Procore-Company-ID': companyId.toString(),
        },
      });
      if (response.status >= 400) {
        throw new Error('Failed to fetch regions');
      }
      return response.json();
    },
    enabled: true,
    retry: false,
    refetchOnMount: false,
  });
 
  return query;
}