mastodon/app/javascript/flavours/glitch/actions/reports.js
Claire ae3cd3b84c [Glitch] Fix reporting from profile
Port b7cf11d5a9 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
2022-02-23 21:46:46 +01:00

39 lines
1.0 KiB
JavaScript

import api from 'flavours/glitch/util/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('REPORT', {
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,
});