<commit_before>/* eslint-disable prefer-promise-reject-errors */
import downloadjs from 'downloadjs'
import { toast } from 'react-toastify'
// TO DO: remove before migration notification to react-toastify
//import { addNotification as notify, removeNotification as dismiss } from 'reapop'
import * as notifications from 'utils/notifications'

const asyncDownloadActivistActions = ({ id, name, ...community }) => (dispatch, getState, { api, intl }) => {
  const { auth: { credentials } } = getState()

  const filename = `[Relatório][Ações dos Ativistas] ${name}.csv`
  // const notificationId = Math.random()
  const notifySuccess = () => {
    toast.success(notifications.reportDownloadSuccess(intl, { filename }).message, { 
      autoClose: 5000,
      hideProgressBar: true,
    })
    // TO DO: remove before migration notification to react-toastify
    // dispatch(notify(notifications.reportDownloadSuccess(intl, { filename })))
    // dispatch(dismiss(notificationId))
  }
  const notifyError = () => {
    toast.error(notifications.reportDownloadError(intl, { filename }).message, { 
      autoClose: 5000,
      hideProgressBar: true,
    })
    // TO DO: remove before migration notification to react-toastify
    // dispatch(notify(notifications.reportDownloadError(intl, { filename })))
    // dispatch(dismiss(notificationId))
  }

    // TO DO: remove before migration notification to react-toastify
  // const warningOptions = { filename, notificationId }
  // dispatch(notify(notifications.reportDownloadInProgressWarning(intl, warningOptions)))

  return api
    .get(`/communities/${id}/activist_actions.csv`, { headers: credentials })
    .then(({ status, data }) => {
      if (status === 400 && data.errors) {
        notifyError()
        return Promise.reject({ ...data.errors })<commit_msg>feat(admin): refactor notification in async-download-activist-action<commit_after>/* eslint-disable prefer-promise-reject-errors */
import downloadjs from 'downloadjs'
import { toast } from 'react-toastify'
// TO DO: remove before migration notification to react-toastify
//import { addNotification as notify, removeNotification as dismiss } from 'reapop'
import * as notifications from 'utils/notifications'

const asyncDownloadActivistActions = ({ id, name, ...community }) => (dispatch, getState, { api, intl }) => {
  const { auth: { credentials } } = getState()

  const filename = `[Relatório][Ações dos Ativistas] ${name}.csv`
  // const notificationId = Math.random()
  const notifySuccess = () => {
    toast.success(notifications.reportDownloadSuccess(intl, { filename }).message, { 
      autoClose: 5000,
      hideProgressBar: true,
    })
    // TO DO: remove before migration notification to react-toastify
    // dispatch(notify(notifications.reportDownloadSuccess(intl, { filename })))
    // dispatch(dismiss(notificationId))
  }
  const notifyError = () => {
    toast.error(notifications.reportDownloadError(intl, { filename }).message, { 
      autoClose: 5000,
      hideProgressBar: true,
    })
    // TO DO: remove before migration notification to react-toastify
    // dispatch(notify(notifications.reportDownloadError(intl, { filename })))
    // dispatch(dismiss(notificationId))
  }

  // TO DO: remove before migration notification to react-toastify
  // const warningOptions = { filename, notificationId }
  // dispatch(notify(notifications.reportDownloadInProgressWarning(intl, warningOptions)))

  return api
    .get(`/communities/${id}/activist_actions.csv`, { headers: credentials })
    .then(({ status, data }) => {
      if (status === 400 && data.errors) {
        notifyError()
        return Promise.reject({ ...data.errors })
{'fraction_non_alphanumeric': 0.13087157208797176, 'fraction_numerical': 0.005973391257127342, 'mean_word_length': 3.885941644562334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6545124', 'n_tokens_mistral': 1034, 'n_tokens_neox': 999, 'n_words': 254}