reports.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import api from '../api';
  2. import { openModal } from './modal';
  3. export const REPORT_SUBMIT_REQUEST = 'REPORT_SUBMIT_REQUEST';
  4. export const REPORT_SUBMIT_SUCCESS = 'REPORT_SUBMIT_SUCCESS';
  5. export const REPORT_SUBMIT_FAIL = 'REPORT_SUBMIT_FAIL';
  6. export const initReport = (account, status) => dispatch =>
  7. dispatch(openModal('REPORT', {
  8. accountId: account.get('id'),
  9. statusId: status?.get('id'),
  10. }));
  11. export const submitReport = (params, onSuccess, onFail) => (dispatch, getState) => {
  12. dispatch(submitReportRequest());
  13. api(getState).post('/api/v1/reports', params).then(response => {
  14. dispatch(submitReportSuccess(response.data));
  15. if (onSuccess) onSuccess();
  16. }).catch(error => {
  17. dispatch(submitReportFail(error));
  18. if (onFail) onFail();
  19. });
  20. };
  21. export const submitReportRequest = () => ({
  22. type: REPORT_SUBMIT_REQUEST,
  23. });
  24. export const submitReportSuccess = report => ({
  25. type: REPORT_SUBMIT_SUCCESS,
  26. report,
  27. });
  28. export const submitReportFail = error => ({
  29. type: REPORT_SUBMIT_FAIL,
  30. error,
  31. });