| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import { all, call, put, takeLatest, select } from "@redux-saga/core/effects";
- import {
- attemptEditProfile,
- attemptFetchProfile,
- } from "../../request/profileRequest";
- import {
- PROFILE_FETCH,
- PROFILE_MINE_FETCH,
- PROFILE_EDIT,
- } from "../actions/profile/profileActionConstants";
- import {
- // editMineProfile,
- setMineProfile,
- setProfile,
- } from "../actions/profile/profileActions";
- import { selectUserId } from "../selectors/loginSelectors";
-
- function* fetchProfile(payload) {
- try {
- console.log(payload);
- const data = yield call(attemptFetchProfile, payload.payload);
- console.log(data.data);
- if (data) yield put(setProfile(data.data));
- } catch (e) {
- console.log(e);
- }
- }
-
- function* fetchMineProfile() {
- try {
- const userId = yield select(selectUserId);
- if (userId) {
- const data = yield call(attemptFetchProfile, userId);
- console.log(data);
- if (data) yield put(setMineProfile(data.data));
- }
- } catch (e) {
- console.log(e);
- }
- }
-
- function* changeMineProfile(payload) {
- try {
- yield console.log(payload);
-
- let image;
-
- if (payload.payload.firmLogo.includes("data:image")) {
- image = payload.payload.firmLogo
- .replace("data:image/jpeg;base64,", "")
- .replace("data:image/jpg;base64,", "")
- .replace("data:image/png;base64,", "");
- } else if (payload.payload.firmLogo === "") {
- image = "";
- }
-
- const reqData = {
- company: {
- name: payload.payload.firmName,
- PIB: payload.payload.firmPIB,
- contacts: {
- telephone: payload.payload.firmPhone,
- location: payload.payload.firmLocation,
- web: payload.payload.firmWebsite,
- },
- },
- image: image,
- };
-
- if (payload.payload.firmLogo.includes("https")) delete reqData.image;
-
- const userId = yield select(selectUserId);
- const data = yield call(attemptEditProfile, userId, reqData);
- if (payload.payload.handleApiResponseSuccess) {
- yield call(payload.payload.handleApiResponseSuccess);
- }
- console.log(data);
- } catch (e) {
- console.log(e);
- }
- }
-
- export default function* profileSaga() {
- yield all([
- takeLatest(PROFILE_FETCH, fetchProfile),
- takeLatest(PROFILE_MINE_FETCH, fetchMineProfile),
- takeLatest(PROFILE_EDIT, changeMineProfile),
- ]);
- }
|