Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5316 | Rev 5320 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 5316 Rev 5317
Línea 1... Línea 1...
1
import { axios } from '../../utils'
1
import { axios } from '../../utils'
-
 
2
import { addNotification } from '../notification/notification.actions'
2
import { conversationActionTypes } from './conversation.types'
3
import { conversationActionTypes } from './conversation.types'
Línea -... Línea 4...
-
 
4
 
-
 
5
export const sendMessage = (url, message) => {
-
 
6
  return (dispatch) => {
-
 
7
    const formData = new FormData()
-
 
8
    formData.append('message', emojione.toShort(message))
-
 
9
 
-
 
10
    axios.post(url, formData)
-
 
11
      .then(({ data: response }) => {
-
 
12
        if (!response.success) {
-
 
13
          dispatch(addNotification({ style: 'danger', message: 'Ha ocurrido un error' }))
-
 
14
          return
-
 
15
        }
-
 
16
 
-
 
17
        dispatch(setNewMessage(response.data))
-
 
18
      })
-
 
19
      .catch((error) => {
-
 
20
        throw Error(error.message)
-
 
21
      })
-
 
22
      .catch((err) => dispatch(addNotification({ style: 'danger', message: new Error(err).message })))
-
 
23
      .finally(() => dispatch(finishLoading()))
-
 
24
  }
-
 
25
}
-
 
26
 
-
 
27
export const getMessages = (url) => {
-
 
28
  return (dispatch) => {
-
 
29
    dispatch(startLoading())
-
 
30
    axios.get(url)
-
 
31
      .then(({ data: response }) => {
-
 
32
        if (!response.success) {
-
 
33
          dispatch(addNotification({ style: 'danger', message: 'Ha ocurrido un error' }))
-
 
34
          return
-
 
35
        }
-
 
36
        const updatedMessages = [...response.data.items].reverse()
-
 
37
 
-
 
38
        dispatch(setMessages(updatedMessages))
-
 
39
      })
-
 
40
      .catch((err) => {
-
 
41
        const errorMessage = new Error(err).message
-
 
42
        dispatch(addNotification({ style: 'danger', message: errorMessage }))
-
 
43
      })
-
 
44
      .finally(() => dispatch(finishLoading()))
-
 
45
  }
-
 
46
}
3
 
47
 
4
export const setNewMessage = (newMessage) => ({
48
export const setNewMessage = (newMessage) => ({
5
  type: conversationActionTypes.SET_NEW_MESSAGE,
49
  type: conversationActionTypes.SET_NEW_MESSAGE,
6
  payload: newMessage
50
  payload: newMessage
Línea 16... Línea 60...
16
})
60
})
Línea 17... Línea 61...
17
 
61
 
18
export const finishLoading = () => ({
62
export const finishLoading = () => ({
19
  type: conversationActionTypes.FINISH_LOADING
63
  type: conversationActionTypes.FINISH_LOADING
20
})
-
 
21
 
-
 
22
export const getMessages = (url) => {
-
 
23
  return (dispatch) => {
-
 
24
    dispatch(startLoading)
-
 
25
    axios
-
 
26
      .get(url)
-
 
27
      .then(({ data: response }) => {
-
 
28
        if (response.success) {
-
 
29
          dispatch(setMessages(response.data))
-
 
30
        }
-
 
31
      })
-
 
32
      .catch((error) => {
-
 
33
        // dispatch(fetchFeedsFailure());
-
 
34
        throw Error(error.message)
-
 
35
      })
-
 
36
  }
-