%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/emergentqj/actioncivile/pre-auth/def/static/js/sagas/
Upload File :
Create Path :
Current File : /home/emergentqj/actioncivile/pre-auth/def/static/js/sagas/getCompanyInfo.js

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

const config = configFunc();

function* runGetCompaniesInfo(dispatch, action) {
  const postJson = {
    countryCode: action.data.countryCode,
    companyName: action.data.companyName,
  };
  const url = `${config.apiUrl}company/infoByName`;
  try {
    const payload = yield call(
      postDataAction(url, postJson, null, {
        "Content-Type": "application/json",
      }),
    );
    yield put({
      type: LIST_ACTIONS.GET_COMPANIES_INFO_SUCCESS,
      payload,
    });
  } catch (e) {
    yield put({
      type: LIST_ACTIONS.GET_COMPANIES_INFO_ERROR,
      e,
    });
  }
}

export function* getCompaniesInfo(dispatch) {
  yield takeEvery(
    LIST_ACTIONS.GET_COMPANIES_INFO_REQUEST,
    runGetCompaniesInfo,
    dispatch,
  );
}

function* runGetCompanyInfo(dispatch, action) {
  const postJson = {
    companyId: action.data.companyId,
  };
  const url = `${config.apiUrl}company/infoById`;

  try {
    const payload = yield call(
      postDataAction(url, postJson, null, {
        "Content-Type": "application/json",
      }),
    );
    yield put({
      type: LIST_ACTIONS.GET_COMPANY_INFO_SUCCESS,
      payload,
    });
  } catch (e) {
    yield put({
      type: LIST_ACTIONS.GET_COMPANY_INFO_ERROR,
      e,
    });
  }
}

export function* getCompanyInfo(dispatch) {
  yield takeEvery(
    LIST_ACTIONS.GET_COMPANY_INFO_REQUEST,
    runGetCompanyInfo,
    dispatch,
  );
}

function* runGetCompanyVatInfo(dispatch, action) {
  const postJson = {
    countrycode: action.data.countrycode,
    organizationnumber: action.data.organizationnumber,
  };
  const url = `${config.apiUrl}company/isValidOrganizationNumber`;

  try {
    const payload = yield call(
      postDataAction(url, postJson, null, {
        "Content-Type": "application/json",
      }),
    );
    yield put({
      type: LIST_ACTIONS.GET_COMPANY_VAT_INFO_SUCCESS,
      payload,
    });
  } catch (e) {
    yield put({
      type: LIST_ACTIONS.GET_COMPANY_VAT_INFO_ERROR,
      e,
    });
  }
}

export function* getCompanyVatInfo(dispatch) {
  yield takeEvery(
    LIST_ACTIONS.GET_COMPANY_VAT_INFO_REQUEST,
    runGetCompanyVatInfo,
    dispatch,
  );
}

Zerion Mini Shell 1.0