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.

83 lines
1.9 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. console.error(error);
  23. dispatch(fetchStatusFail(id, error));
  24. });
  25. };
  26. };
  27. export function fetchStatusSuccess(status, context) {
  28. return {
  29. type: STATUS_FETCH_SUCCESS,
  30. status: status,
  31. context: context
  32. };
  33. };
  34. export function fetchStatusFail(id, error) {
  35. return {
  36. type: STATUS_FETCH_FAIL,
  37. id: id,
  38. error: error
  39. };
  40. };
  41. export function deleteStatus(id) {
  42. return (dispatch, getState) => {
  43. dispatch(deleteStatusRequest(id));
  44. api(getState).delete(`/api/v1/statuses/${id}`).then(response => {
  45. dispatch(deleteStatusSuccess(id));
  46. }).catch(error => {
  47. console.error(error);
  48. dispatch(deleteStatusFail(id, error));
  49. });
  50. };
  51. };
  52. export function deleteStatusRequest(id) {
  53. return {
  54. type: STATUS_DELETE_REQUEST,
  55. id: id
  56. };
  57. };
  58. export function deleteStatusSuccess(id) {
  59. return {
  60. type: STATUS_DELETE_SUCCESS,
  61. id: id
  62. };
  63. };
  64. export function deleteStatusFail(id, error) {
  65. return {
  66. type: STATUS_DELETE_FAIL,
  67. id: id,
  68. error: error
  69. };
  70. };