All files / apps/maintenance/src/hooks useMaintenanceScopes.ts

100% Statements 7/7
100% Branches 2/2
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 32 33 34 35                        1x   1x         4x   4x           4x         4x    
import { API_ENDPOINTS } from '@repo/constants/endpoints';
 
import { useApiDataQuery } from '@repo/hooks';
 
import { OptionBase } from '@repo/types/form';
 
import { useMaintenanceRuntime } from '@/screens/Maintenance/runtime';
 
interface MaintenanceScope {
  id: string;
}
 
const EMPTY_SCOPES: MaintenanceScope[] = [];
 
export const useMaintenanceScopes = () => {
  const {
    meta: {
      api: { mainHttp },
    },
  } = useMaintenanceRuntime();
 
  const { data, isLoading, isError } = useApiDataQuery<MaintenanceScope[]>({
    queryKey: ['maintenance-scopes'],
    endpoint: API_ENDPOINTS.MAINTENANCE_SCOPES,
    httpClient: mainHttp,
  });
 
  const scopes: OptionBase[] = (data ?? EMPTY_SCOPES).map(scope => ({
    label: scope.id,
    value: scope.id,
  }));
 
  return { scopes, isLoading, isError };
};