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.

81 lines
1.8 KiB

  1. import api from '../api';
  2. import axios from 'axios';
  3. export const STATUS_FETCH_REQUEST = 'STATUS_FETCH_REQUEST';
  4. export const STATUS_FETCH_SUCCESS = 'STATUS_FETCH_SUCCESS';
  5. export const STATUS_FETCH_FAIL = 'STATUS_FETCH_FAIL';
  6. export const STATUS_DELETE_REQUEST = 'STATUS_DELETE_REQUEST';
  7. export const STATUS_DELETE_SUCCESS = 'STATUS_DELETE_SUCCESS';
  8. export const STATUS_DELETE_FAIL = 'STATUS_DELETE_FAIL';
  9. export function fetchStatusRequest(id) {
  10. return {
  11. type: STATUS_FETCH_REQUEST,
  12. id: id
  13. };
  14. };
  15. export function fetchStatus(id) {
  16. return (dispatch, getState) => {
  17. const boundApi = api(getState);
  18. dispatch(fetchStatusRequest(id));
  19. axios.all([boundApi.get(`/api/v1/statuses/${id}`), boundApi.get(`/api/v1/statuses/${id}/context`)]).then(values => {
  20. dispatch(fetchStatusSuccess(values[0].data, values[1].data));
  21. }).catch(error => {
  22. dispatch(fetchStatusFail(id, error));
  23. });
  24. };
  25. };
  26. export function fetchStatusSuccess(status, context) {
  27. return {
  28. type: STATUS_FETCH_SUCCESS,
  29. status: status,
  30. context: context
  31. };
  32. };
  33. export function fetchStatusFail(id, error) {
  34. return {
  35. type: STATUS_FETCH_FAIL,
  36. id: id,
  37. error: error
  38. };
  39. };
  40. export function deleteStatus(id) {
  41. return (dispatch, getState) => {
  42. dispatch(deleteStatusRequest(id));
  43. api(getState).delete(`/api/v1/statuses/${id}`).then(response => {
  44. dispatch(deleteStatusSuccess(id));
  45. }).catch(error => {
  46. dispatch(deleteStatusFail(id, error));
  47. });
  48. };
  49. };
  50. export function deleteStatusRequest(id) {
  51. return {
  52. type: STATUS_DELETE_REQUEST,
  53. id: id
  54. };
  55. };
  56. export function deleteStatusSuccess(id) {
  57. return {
  58. type: STATUS_DELETE_SUCCESS,
  59. id: id
  60. };
  61. };
  62. export function deleteStatusFail(id, error) {
  63. return {
  64. type: STATUS_DELETE_FAIL,
  65. id: id,
  66. error: error
  67. };
  68. };