闭社主体 forked from https://github.com/tootsuite/mastodon
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.

80 lines
1.8 KiB

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