Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

profileSaga.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { all, call, put, takeLatest, select } from "@redux-saga/core/effects";
  2. import {
  3. attemptEditProfile,
  4. attemptFetchProfile,
  5. } from "../../request/profileRequest";
  6. import {
  7. PROFILE_FETCH,
  8. PROFILE_MINE_FETCH,
  9. PROFILE_EDIT,
  10. } from "../actions/profile/profileActionConstants";
  11. import {
  12. // editMineProfile,
  13. setMineProfile,
  14. setProfile,
  15. } from "../actions/profile/profileActions";
  16. import { selectUserId } from "../selectors/loginSelectors";
  17. function* fetchProfile(payload) {
  18. try {
  19. console.log(payload);
  20. const data = yield call(attemptFetchProfile, payload.payload);
  21. console.log(data.data);
  22. if (data) yield put(setProfile(data.data));
  23. } catch (e) {
  24. console.log(e);
  25. }
  26. }
  27. function* fetchMineProfile() {
  28. try {
  29. const userId = yield select(selectUserId);
  30. if (userId) {
  31. const data = yield call(attemptFetchProfile, userId);
  32. console.log(data);
  33. if (data) yield put(setMineProfile(data.data));
  34. }
  35. } catch (e) {
  36. console.log(e);
  37. }
  38. }
  39. function* changeMineProfile(payload) {
  40. try {
  41. yield console.log(payload);
  42. let image;
  43. if (payload.payload.firmLogo.includes("data:image")) {
  44. image = payload.payload.firmLogo
  45. .replace("data:image/jpeg;base64,", "")
  46. .replace("data:image/jpg;base64,", "")
  47. .replace("data:image/png;base64,", "");
  48. } else if (payload.payload.firmLogo === "") {
  49. image = "";
  50. }
  51. const reqData = {
  52. company: {
  53. name: payload.payload.firmName,
  54. PIB: payload.payload.firmPIB,
  55. contacts: {
  56. telephone: payload.payload.firmPhone,
  57. location: payload.payload.firmLocation,
  58. web: payload.payload.firmWebsite,
  59. },
  60. },
  61. image: image,
  62. };
  63. if (payload.payload.firmLogo.includes("https")) delete reqData.image;
  64. const userId = yield select(selectUserId);
  65. const data = yield call(attemptEditProfile, userId, reqData);
  66. if (payload.payload.handleApiResponseSuccess) {
  67. yield call(payload.payload.handleApiResponseSuccess);
  68. }
  69. console.log(data);
  70. } catch (e) {
  71. console.log(e);
  72. }
  73. }
  74. export default function* profileSaga() {
  75. yield all([
  76. takeLatest(PROFILE_FETCH, fetchProfile),
  77. takeLatest(PROFILE_MINE_FETCH, fetchMineProfile),
  78. takeLatest(PROFILE_EDIT, changeMineProfile),
  79. ]);
  80. }