import { useMutation } from 'react-query';

import useSnackbar from '@material-hu/components/design-system/Snackbar';

import { queryClient } from 'src/config/react-query';
import { useLokaliseTranslation } from 'src/utils/i18n';

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

export const useCreateArticle = () => {
  const { t } = useLokaliseTranslation('libraries');
  const { enqueueSnackbar } = useSnackbar();

  return useMutation({
    mutationFn: createArticle,
    onSuccess: () => {
      enqueueSnackbar({
        title: t('article.save.success'),
        variant: 'success',
      });
      queryClient.invalidateQueries(librariesKeys.article.all());
    },
  });
};
