reports.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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({
  8. modalType: 'REPORT',
  9. modalProps: {
  10. accountId: account.get('id'),
  11. statusId: status?.get('id'),
  12. },
  13. }));
  14. export const submitReport = (params, onSuccess, onFail) => (dispatch, getState) => {
  15. dispatch(submitReportRequest());
  16. api(getState).post('/api/v1/reports', params).then(response => {
  17. dispatch(submitReportSuccess(response.data));
  18. if (onSuccess) onSuccess();
  19. }).catch(error => {
  20. dispatch(submitReportFail(error));
  21. if (onFail) onFail();
  22. });
  23. };
  24. export const submitReportRequest = () => ({
  25. type: REPORT_SUBMIT_REQUEST,
  26. });
  27. export const submitReportSuccess = report => ({
  28. type: REPORT_SUBMIT_SUCCESS,
  29. report,
  30. });
  31. export const submitReportFail = error => ({
  32. type: REPORT_SUBMIT_FAIL,
  33. error,
  34. });