Guest User

user_actions.js

a guest
Nov 25th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import axios from 'axios';
  2. import { FETCH_USER_INFO, FETCH_USER_IMG, FETCH_ALL_USERS } from './types';
  3.  
  4. export const fetchUserInfo = (userId) => {
  5. async (dispatch) => {
  6. const response = await axios({
  7. method: 'get',
  8. url: 'http://localhost:9000/api/v1/users/info',
  9. headers: {"id": userId}
  10. });
  11. return dispatch({
  12. type: FETCH_USER_INFO,
  13. payload: response.data })
  14. };
  15. }
  16.  
  17. export function fetchUserImg(userId) {
  18. async (dispatch) => {
  19.  
  20. const response = await axios({
  21. method: 'get',
  22. url: 'http://localhost:9000/api/v1/users/info',
  23. headers: {"id": userId}
  24. });
  25.  
  26. return dispatch({
  27. type: FETCH_USER_IMG,
  28. payload: response.data.photo })
  29. };
  30. }
  31.  
  32. export const fetchAllUsers = () => async dispatch => {
  33. const request = await axios('http://localhost:9000/api/v1/users');
  34. dispatch({ type: FETCH_ALL_USERS, payload: request });
  35. }
Add Comment
Please, Sign In to add comment