soportes.js
1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { tap } from 'ramda'
import { SENATICS_URL } from '../../constants'
export const REQUEST_SOPORTES = 'REQUEST_SOPORTES'
export const requestSoportes = () => ({
type: REQUEST_SOPORTES
})
export const RECEIVE_SOPORTES = 'RECEIVE_SOPORTES'
export const receiveSoportes = (soportes) => ({
type: RECEIVE_SOPORTES,
soportes: soportes.results,
pages: soportes.meta
})
export const ERROR_SOPORTES = 'ERROR_SOPORTES'
export const errorSoportes = (error) => ({
type: ERROR_SOPORTES,
error,
})
export const fetchSoportes = (token) => (dispatch) => {
dispatch(requestSoportes())
const options = {
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${token}`
},
}
const url = `${SENATICS_URL}/soportes`
const internal = () => fetch(url, options)
.then(response => response.text())
.then(tap(text => dispatch({ type: 'TEXT_RECEIVED', text })))
.then(JSON.parse)
.then(json => dispatch(receiveSoportes(json)))
.catch(error => dispatch(errorSoportes(error)))
return internal()
}