%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/emergentqj/actioncivile/pre-auth/.8352c036a19b0051d0217d27d25e3f4a/static/js/reducers/
Upload File :
Create Path :
Current File : /home/emergentqj/actioncivile/pre-auth/.8352c036a19b0051d0217d27d25e3f4a/static/js/reducers/getCompanyInfo.js

import { fromJS } from "immutable";
import LIST_ACTIONS from "../constants/action_types";

const NO_COMPANY = {};

const initialState = fromJS({
  isLoading: false,
  companies: {},
  suggestionWindowIsOpen: false,
  company: {},
  fillCompanyFields: false,
  vat: {
    organizationnumber: "",
    // Presume the status to be invalid, until confirmed valid by the backend.
    // This prevents Continue button's flickering between enabled and disabled state.
    status: "organization.number.not.valid",
  },
  counter: 0,
});
const getCompanyInfo = (state = initialState, action = {}) => {
  const counter = state.get("counter") + 1;
  switch (action.type) {
    case LIST_ACTIONS.GET_COMPANIES_INFO_REQUEST:
      return state
        .set("companies", {})
        .set("isLoading", true)
        .set("suggestionWindowIsOpen", false);
    case LIST_ACTIONS.GET_COMPANIES_INFO_RESET:
      return state
        .set("companies", {})
        .set("isLoading", false)
        .set("suggestionWindowIsOpen", false);
    case LIST_ACTIONS.GET_COMPANIES_INFO_SUCCESS:
      return state
        .set("counter", counter)
        .set("companies", action.payload.data.worksites)
        .set("isLoading", false)
        .set("suggestionWindowIsOpen", true);
    case LIST_ACTIONS.GET_COMPANIES_INFO_ERROR:
      return state
        .set("counter", counter)
        .set("companies", {})
        .set("isLoading", false)
        .set("suggestionWindowIsOpen", false);

    case LIST_ACTIONS.GET_COMPANY_INFO_REQUEST:
      return state
        .set("fillCompanyFields", false)
        .set("company", NO_COMPANY)
        .set("isLoading", true)
        .set("suggestionWindowIsOpen", false);
    case LIST_ACTIONS.GET_COMPANY_INFO_RESET:
      return state
        .set("fillCompanyFields", false)
        .set("company", NO_COMPANY)
        .set("isLoading", false)
        .set("suggestionWindowIsOpen", false);
    case LIST_ACTIONS.GET_COMPANY_INFO_SUCCESS:
      return state
        .set("fillCompanyFields", true)
        .set("company", action.payload.data.worksites)
        .set("isLoading", false);
    case LIST_ACTIONS.GET_COMPANY_INFO_ERROR:
      return state
        .set("fillCompanyFields", false)
        .set("company", NO_COMPANY)
        .set("isLoading", false);

    case LIST_ACTIONS.GET_COMPANY_VAT_INFO_REQUEST:
      return state
        .set("isLoading", true);
    case LIST_ACTIONS.GET_COMPANY_VAT_INFO_RESET:
      return state
        .set("vat", {
          status: "organization.number.not.valid",
          organizationnumber: "",
        })
        .set("isLoading", false);
    case LIST_ACTIONS.GET_COMPANY_VAT_INFO_SUCCESS:
      return state
        .set("vat", {
          status: action.payload.data.userErrorKey,
          organizationnumber: action.payload.data.params.organizationnumber,
        })
        .set("isLoading", false);
    case LIST_ACTIONS.GET_COMPANY_VAT_INFO_ERROR:
      return state
        .set("vat", {
          status: null,
          organizationnumber: "",
        })
        .set("isLoading", false);
    default:
      return state;
  }
};
export default getCompanyInfo;

Zerion Mini Shell 1.0