import { useQuery } from 'react-query';

import useGeneralError from 'src/hooks/useGeneralError';
import { useLokaliseTranslation } from 'src/utils/i18n';

import { librariesKeys } from '../queries';
import { getWelcomeConfig } from '../services';

export const useLibraryWelcomeConfig = () => {
  const { t } = useLokaliseTranslation('libraries');
  const showGeneralError = useGeneralError();

  return useQuery({
    queryKey: librariesKeys.welcomeConfig(),
    queryFn: () => getWelcomeConfig(),
    select: response => response.data,
    onError: err => showGeneralError(err, t('article.error')),
  });
};
