/* eslint-disable prefer-promise-reject-errors */
import { addNotification as notify } from 'reapop'
import { accountPasswordRetrieveSuccess } from 'utils/notifications'
import * as t from '../action-types'
import { createAction } from './create-action'

export default user => (dispatch, getState, { api, intl }) => {
  const endpoint = '/retrieve'
  const body = { user }

  dispatch(createAction(t.ASYNC_RETRIEVE_PASSWORD_REQUEST))
  return api.post(endpoint, body)
    .then(res => {
      if (res.status === 200 && res.data.errors) {
        // Reject request on redux-form
        return Promise.reject({ ...res.data.errors })
      } else if (res.status === 200) {
        dispatch(createAction(t.ASYNC_RETRIEVE_PASSWORD_SUCCESS, res.data))
        dispatch(notify(accountPasswordRetrieveSuccess(intl)))
        return Promise.resolve()
      }
    })
    .catch(ex => {
      dispatch(createAction(t.ASYNC_RETRIEVE_PASSWORD_FAILURE))
      return Promise.reject(ex)
    })
}

@@ -51,16 +51,122 @@
 import %7B
+ toast %7D from 'react-toastify'%0A// TO DO: remove before migration notification to react-toastify%0A//import %7B
  addNoti
@@ -859,61 +859,278 @@
     
-dispatch(notify(accountPasswordRetrieveSuccess(intl))
+// TO DO: remove before migration notification to react-toastify%0A        //dispatch(notify(accountPasswordRetrieveSuccess(intl)))%0A        toast.success(accountPasswordRetrieveSuccess(intl).message, %7B %0A          autoClose: 5000,%0A          hideProgressBar: true,%0A        %7D
 )%0A  

refactor notification in async-retrive-password