You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1 KiB

  1. import api from '../api'
  2. export const ACCOUNT_SET_SELF = 'ACCOUNT_SET_SELF';
  3. export const ACCOUNT_FETCH = 'ACCOUNT_FETCH';
  4. export const ACCOUNT_FETCH_REQUEST = 'ACCOUNT_FETCH_REQUEST';
  5. export const ACCOUNT_FETCH_SUCCESS = 'ACCOUNT_FETCH_SUCCESS';
  6. export const ACCOUNT_FETCH_FAIL = 'ACCOUNT_FETCH_FAIL';
  7. export function setAccountSelf(account) {
  8. return {
  9. type: ACCOUNT_SET_SELF,
  10. account: account
  11. };
  12. };
  13. export function fetchAccount(id) {
  14. return (dispatch, getState) => {
  15. dispatch(fetchAccountRequest(id));
  16. api(getState).get(`/api/accounts/${id}`).then(response => {
  17. dispatch(fetchAccountSuccess(response.data));
  18. }).catch(error => {
  19. dispatch(fetchAccountFail(id, error));
  20. });
  21. };
  22. };
  23. export function fetchAccountRequest(id) {
  24. return {
  25. type: ACCOUNT_FETCH_REQUEST,
  26. id: id
  27. };
  28. };
  29. export function fetchAccountSuccess(account) {
  30. return {
  31. type: ACCOUNT_FETCH_SUCCESS,
  32. account: account
  33. };
  34. };
  35. export function fetchAccountFail(id, error) {
  36. return {
  37. type: ACCOUNT_FETCH_FAIL,
  38. id: id,
  39. error: error
  40. };
  41. };