%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/emergentqj/actioncivile/pre-auth/.4cc3a2e1590a4463a5f392ddcc26929e/static/js/sagas/
Upload File :
Create Path :
Current File : /home/emergentqj/actioncivile/pre-auth/.4cc3a2e1590a4463a5f392ddcc26929e/static/js/sagas/getUser.js

import { put, call, takeEvery } from "redux-saga/effects";
import configFunc from "config/config";
import { getTranslations } from "utils";
import { getDataAction } from "common/actions";
import LIST_ACTIONS from "../constants/action_types";

// const cookieIsSecure = getEnvConstant() !== "develop";

const config = configFunc();

export function* runGetUser() {
  const getUserUrl = `${config.apiUrl}login/currentLoginSilent`;

  try {
    const payload = yield call(getDataAction(getUserUrl, null, true));

    yield put({
      type: LIST_ACTIONS.GET_USER_SUCCESS,
      payload,
    });

    const [userLanguage, userCountryCode] = payload.data.login.siteLanguage
      && payload.data.login.siteLanguage.split("_");
    const translations = getTranslations(userCountryCode);

    if (userCountryCode && userLanguage) {
      yield put({
        type: LIST_ACTIONS.SET_COUNTRY,
        payload: userCountryCode,
      });
      yield put({
        type: LIST_ACTIONS.SET_LANGUAGE,
        data: {
          translations,
        },
      });
    }
    const { properties } = payload.data.login;
    if (properties?.newMigratedUser) {
      yield put({
        type: LIST_ACTIONS.GET_MIGRATED_USER_DATA,
        migrationReferenceId: properties?.migrationReferenceId,
      });
    }
  } catch (e) {
    yield put({
      type: LIST_ACTIONS.GET_USER_ERROR,
      e,
    });
  }
}

export default function* getUser(dispatch) {
  yield takeEvery(LIST_ACTIONS.GET_USER_REQUEST, runGetUser, dispatch);
}

Zerion Mini Shell 1.0