import { useQuery } from 'react-query';

import useGeneralError from 'src/hooks/useGeneralError';
import { acknowledgementsKeys } from 'src/pages/dashboard/acknowledgements/queries';
import { getKudosCategories } from 'src/pages/dashboard/acknowledgements/services';
import { useLokaliseTranslation } from 'src/utils/i18n';

export const useGetKudosCategories = (enabled = true) => {
  const showGeneralError = useGeneralError();
  const { t } = useLokaliseTranslation('acknowledgements');

  return useQuery({
    queryKey: acknowledgementsKeys.categories.all(),
    queryFn: getKudosCategories,
    onError: err => showGeneralError(err, t('error_get_categories')),
    select: response => response.data,
    enabled,
  });
};
