reports.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import api from '../api';
  2. export const REPORT_INIT = 'REPORT_INIT';
  3. export const REPORT_CANCEL = 'REPORT_CANCEL';
  4. export const REPORT_SUBMIT_REQUEST = 'REPORT_SUBMIT_REQUEST';
  5. export const REPORT_SUBMIT_SUCCESS = 'REPORT_SUBMIT_SUCCESS';
  6. export const REPORT_SUBMIT_FAIL = 'REPORT_SUBMIT_FAIL';
  7. export const REPORT_STATUS_TOGGLE = 'REPORT_STATUS_TOGGLE';
  8. export const REPORT_COMMENT_CHANGE = 'REPORT_COMMENT_CHANGE';
  9. export function initReport(account, status) {
  10. return {
  11. type: REPORT_INIT,
  12. account,
  13. status
  14. };
  15. };
  16. export function cancelReport() {
  17. return {
  18. type: REPORT_CANCEL
  19. };
  20. };
  21. export function toggleStatusReport(statusId, checked) {
  22. return {
  23. type: REPORT_STATUS_TOGGLE,
  24. statusId,
  25. checked,
  26. };
  27. };
  28. export function submitReport() {
  29. return (dispatch, getState) => {
  30. dispatch(submitReportRequest());
  31. api(getState).post('/api/v1/reports', {
  32. account_id: getState().getIn(['reports', 'new', 'account_id']),
  33. status_ids: getState().getIn(['reports', 'new', 'status_ids']),
  34. comment: getState().getIn(['reports', 'new', 'comment'])
  35. }).then(response => dispatch(submitReportSuccess(response.data))).catch(error => dispatch(submitReportFail(error)));
  36. };
  37. };
  38. export function submitReportRequest() {
  39. return {
  40. type: REPORT_SUBMIT_REQUEST
  41. };
  42. };
  43. export function submitReportSuccess(report) {
  44. return {
  45. type: REPORT_SUBMIT_SUCCESS,
  46. report
  47. };
  48. };
  49. export function submitReportFail(error) {
  50. return {
  51. type: REPORT_SUBMIT_FAIL,
  52. error
  53. };
  54. };
  55. export function changeReportComment(comment) {
  56. return {
  57. type: REPORT_COMMENT_CHANGE,
  58. comment
  59. };
  60. };