actionUpdateAvatar.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { call, put, select } from "redux-saga/effects";
  2. import { actionPromiseClear } from "../reducers";
  3. import { promiseWorker } from "../reducers/promiseReducer";
  4. import { actionAboutMe } from "./actionAboutMe";
  5. import { actionUploadFile } from "./actionUploadFile";
  6. import { actionUserUpsert } from "./actionUserUpsert";
  7. export const actionUpdateAvatar = (file) => ({ type: "UPDATE_AVATAR", payload: file });
  8. export function* updateAvatarWorker(action) {
  9. const file = action.payload;
  10. yield call(promiseWorker, actionUploadFile(file));
  11. const {
  12. promise: {
  13. uploadFile: {
  14. payload: { _id: fileId },
  15. status,
  16. },
  17. },
  18. auth: {
  19. payload: {
  20. sub: { _id },
  21. },
  22. },
  23. } = yield select();
  24. yield call(promiseWorker, actionUserUpsert({ avatar: { _id: fileId }, _id }));
  25. if (status === "FULFILLED") {
  26. yield put(actionAboutMe());
  27. }
  28. yield put(actionPromiseClear("uploadFile"));
  29. }