pelaporan.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. export const CHANGE_THEME = "CHANGE_THEME";
  2. export const PELAPORAN_LIST_REQUEST = "PELAPORAN_LIST_REQUEST";
  3. export const PELAPORAN_LIST_SUCCESS = "PELAPORAN_LIST_SUCCESS";
  4. export const PELAPORAN_LIST_FAIL = "PELAPORAN_LIST_FAIL";
  5. export const PELAPORAN_DETAILS_REQUEST = "PELAPORAN_DETAILS_REQUEST";
  6. export const PELAPORAN_DETAILS_SUCCESS = "PELAPORAN_DETAILS_SUCCESS";
  7. export const PELAPORAN_DETAILS_FAIL = "PELAPORAN_DETAILS_FAIL";
  8. export const PELAPORAN_CREATE_REQUEST = "PELAPORAN_DETAILS_REQUEST";
  9. export const PELAPORAN_CREATE_SUCCESS = "PELAPORAN_DETAILS_SUCCESS";
  10. export const PELAPORAN_CREATE_FAIL = "PELAPORAN_DETAILS_FAIL";
  11. export const PELAPORAN_CREATE_RESET = "PELAPORAN_CREATE_RESET";
  12. /**
  13. * Change current theme path
  14. */
  15. export const listPelaporan = () => async (dispatch) => {
  16. try {
  17. dispatch({ type: PELAPORAN_LIST_REQUEST });
  18. const res = await fetch("http://localhost:5000/pelaporan");
  19. const { data } = await res.json();
  20. dispatch({
  21. type: PELAPORAN_LIST_SUCCESS,
  22. payload: data,
  23. });
  24. } catch (error) {
  25. dispatch({
  26. type: PELAPORAN_LIST_FAIL,
  27. payload: error.response && error.response.data.message ? error.response.data.message : error.message,
  28. });
  29. }
  30. };
  31. export const listPelaporanDetails = (number, ptId) => async (dispatch) => {
  32. try {
  33. dispatch({ type: PELAPORAN_DETAILS_REQUEST });
  34. const res = await fetch(`http://localhost:5000/pelaporan?number=${number}&ptId=${ptId}`);
  35. const { data } = await res.json();
  36. dispatch({
  37. type: PELAPORAN_DETAILS_SUCCESS,
  38. payload: data,
  39. });
  40. } catch (error) {
  41. dispatch({
  42. type: PELAPORAN_DETAILS_FAIL,
  43. payload: error.response && error.response.data.message ? error.response.data.message : error.message,
  44. });
  45. }
  46. };
  47. export const createPelaporan = (pelaporanResult) => async (dispatch) => {
  48. try {
  49. dispatch({
  50. type: PELAPORAN_CREATE_REQUEST,
  51. });
  52. const res = await fetch("http://localhost:5000/pelaporan/create", {
  53. method: "POST",
  54. body: pelaporanResult,
  55. });
  56. const data = await res.json();
  57. dispatch({
  58. type: PELAPORAN_CREATE_SUCCESS,
  59. payload: data,
  60. });
  61. } catch (error) {
  62. dispatch({
  63. type: PELAPORAN_CREATE_FAIL,
  64. payload: error.response && error.response.data.message ? error.response.data.message : error.message,
  65. });
  66. }
  67. };