~cytrogen/masto-fe

ref: b9adea96953cb70e9222215a676b73b31f85c9c6 masto-fe/app/javascript/mastodon/actions/reports.js -rw-r--r-- 1.1 KiB
b9adea96 — github-actions[bot] New Crowdin Translations (automated) (#26072) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import api from '../api';

import { openModal } from './modal';

export const REPORT_SUBMIT_REQUEST = 'REPORT_SUBMIT_REQUEST';
export const REPORT_SUBMIT_SUCCESS = 'REPORT_SUBMIT_SUCCESS';
export const REPORT_SUBMIT_FAIL    = 'REPORT_SUBMIT_FAIL';

export const initReport = (account, status) => dispatch =>
  dispatch(openModal({
    modalType: 'REPORT',
    modalProps: {
      accountId: account.get('id'),
      statusId: status?.get('id'),
    },
  }));

export const submitReport = (params, onSuccess, onFail) => (dispatch, getState) => {
  dispatch(submitReportRequest());

  api(getState).post('/api/v1/reports', params).then(response => {
    dispatch(submitReportSuccess(response.data));
    if (onSuccess) onSuccess();
  }).catch(error => {
    dispatch(submitReportFail(error));
    if (onFail) onFail();
  });
};

export const submitReportRequest = () => ({
  type: REPORT_SUBMIT_REQUEST,
});

export const submitReportSuccess = report => ({
  type: REPORT_SUBMIT_SUCCESS,
  report,
});

export const submitReportFail = error => ({
  type: REPORT_SUBMIT_FAIL,
  error,
});