Guest User

Untitled

a guest
Jan 12th, 2017
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import {USER_LIST_URL} from './../app/apiRoutes';
  2. import cookie from 'react-cookie';
  3. import axios from 'axios';
  4.  
  5. export const SET_USERNAME = 'SET_USERNAME';
  6. export const SET_PASSWORD = 'SET_PASSWORD';
  7. export const LOAD_USERS_SUCCESS = 'LOAD_USERS_SUCCESS';
  8. export const LOAD_USERS_ERROR = 'LOAD_USERS_SUCCESS';
  9.  
  10. export function setUsername(username) {
  11. return { type: SET_USERNAME, username };
  12. }
  13.  
  14. export function setPassword(password) {
  15. return { type: SET_PASSWORD, password };
  16. }
  17.  
  18. export function receiveError() {
  19. return {type: LOAD_USERS_ERROR};
  20. }
  21.  
  22. export function receiveSuccess(users) {
  23. console.log('Run method in action users;')
  24. return {type: LOAD_USERS_SUCCESS, users};
  25. }
  26.  
  27. export function loadUsers() {
  28. return dispatch => {
  29. return axios({
  30. url: USER_LIST_URL,
  31. timeout: 20000,
  32. method: 'get',
  33. responseType: 'json',
  34. headers: {
  35. Authorization: cookie.load('Authorization')
  36. }
  37. })
  38. .then(function(response) {
  39. dispatch(receiveSuccess(response.data));
  40. })
  41. .catch(function(){
  42. });
  43. };
  44. }
Add Comment
Please, Sign In to add comment