import { useQuery } from 'react-query';

import useGeneralError from 'src/hooks/useGeneralError';
import { onBoardingKeys } from 'src/pages/dashboard/onboarding/queries';
import { getOnboardings } from 'src/services/onboarding';
import { useLokaliseTranslation } from 'src/utils/i18n';

export const useOnboarding = (userId: number) => {
  const showGeneralError = useGeneralError();
  const { t } = useLokaliseTranslation('onboarding');

  return useQuery(onBoardingKeys.categories(), () => getOnboardings(userId), {
    onError: err => {
      showGeneralError(err, t('error_loading_categories'));
    },
    enabled: !!userId,
  });
};

export default useOnboarding;
