redux-saga/effects#put JavaScript Examples

The following examples show how to use redux-saga/effects#put. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: sagas.js    From fhir-app-starter with MIT License 6 votes vote down vote up
function* loadPatientInfo() {
  try {
    const client = yield call(connect);
    const patient = yield call(client.patient.read);
    yield put(loadPatientInfoActionSuccess(patient));
  } catch (e) {
    yield put(loadPatientInfoActionError(e));
  }
}
Example #2
Source File: AuthSagas.js    From Alfredo-Mobile with MIT License 6 votes vote down vote up
export function * doLogin(api, action) {
  const { data } = action
  const response = yield call(api.authLogin, data)

  if(response.ok) {
    api.api.setHeaders({
      "X-AUTH-TOKEN": `Bearer ${response.data.data.token}`
    })

    yield all([
      yield put(AuthActions.doLoginSuccess(response.data.data)),
      yield put(SessionsActions.saveSession(response.data.data)),
      yield put(SessionsActions.getProfileRequest())
    ])

    Toast.show("Login Successfully!", Toast.SHORT)

    if (data.event === null) {
      NavigationServices.goBack()
    } else {
      NavigationServices.goBack()
      data.event()
    }
  } else {
    yield put(AuthActions.doLoginFailure(response))
    Toast.show(response?.data?.data?.message ?? "Internal Server Error", Toast.SHORT)
  }
}
Example #3
Source File: assignments.js    From agenda with MIT License 6 votes vote down vote up
export function* submitAssignmentData() {
    const assignment = yield select(state => state.assignments.assignment);
    const result = yield call(AssignmentsService.submitAssignment, assignment);
    if (result.success) {
        yield put(
            submitAssignmentDataSucceded()
        );
    }
}
Example #4
Source File: saga.js    From QiskitFlow with Apache License 2.0 6 votes vote down vote up
export function* getRuns() {
  const parameters = yield select(makeSelectExperimentRunsListFilter());
  const page = yield select(makeSelectExperimentRunsListPage());
  const experimentId = yield select(makeSelectExperimentRunsListExperimentId());
  const offset = 10 * (page - 1);
  const limit = 10;
  const requestUrl = `${getBaseUrl()}/api/v1/core/runs/?experiment=${experimentId}&offset=${offset}&limit=${limit}`;
  const token = localStorage.getItem('token');

  try {
    const response = yield call(request, requestUrl, {
      headers: {
        'Content-Type': 'application/json',
        Authorization: `Bearer ${token}`,
      },
    });
    yield put(updateRunsAction({ ...response, page }));
  } catch (err) {
    if (err.response.status === 401) {
      yield put(logoutAction());
    } else {
      yield put(repoLoadingError(err));
    }
  }
}
Example #5
Source File: sagas.js    From amazon-next with MIT License 6 votes vote down vote up
export function* cart({ payload }) {
    const { product } = payload;

    const products = yield select(state => state.cart.products);
    const productExists = products.find(
        cartProduct => cartProduct.id === payload.product.id
    );

    if (product && !productExists) {
        return yield put(addToCartSuccess(product));
    }
    return yield put(addToCartFailure());
}
Example #6
Source File: appstate.js    From haven with MIT License 6 votes vote down vote up
function* triggerRate() {
  const lastPrompt = yield select(getLastReviewPrompt);
  const appInstalled = yield select(getAppInstalled);
  if (lastPrompt) {
    if (moment().diff(moment(lastPrompt), 'months') >= 4) {
      yield call(rateApp);
      yield put({ type: actions.updateLastReviewPrompt });
    }
  } else {
    if (moment().diff(moment(appInstalled), 'days') >= 1) {
      yield call(rateApp);
      yield put({ type: actions.updateLastReviewPrompt });
    }
  }
}