%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/emergentqj/actioncivile/pre-auth/.f81b4c9eb38fd76cdf20462cf2027aa3/static/js/reducers/
Upload File :
Create Path :
Current File : /home/emergentqj/actioncivile/pre-auth/.f81b4c9eb38fd76cdf20462cf2027aa3/static/js/reducers/user.js

import { fromJS } from "immutable";
import { isLoggedIn, isDomEnabled } from "../utils";
import LIST_ACTIONS from "../constants/action_types";
import { getUniversalCookies } from "../utils/cookies";

import MIXPANEL_ACTIONS from "../constants/mixpanel_actions";

const mixpanel = isDomEnabled ? require("mixpanel-browser") : null;

const initialState = fromJS({
  current: {},
  pending: false,
  redirect: false,
  isLoggedIn: isLoggedIn(),
  loginError: false,
  selectedCode: null,
  corporate: false,
  errorType: null,
  editUser: false,
  userSettings: [],
  userAddress: [],
  paymentMethods: [],
  subscriptionAgreements: [],
  deactivationEnabled: false,
  selectedPackageId: null,
  parkingUsers: [],
  selectedParkingUser: null,
  historyEnabled: true,
  profileAccesses: [],
  switchedUser: null,
  cookie: null,
  profile: null,
  isDualAccount: {
    isDual: false,
    userEmail: null,
    userFullName: null,
  },
  productPackage: null,
  signInModal: false,
  signUpModal: false,
  cityModal: true,
  checkExistingUser: null,
  isLoading: false,
  unauthorized: false,
  unauthorizedReason: "",
  migrationData: {
    billingAccountId: null,
    customerId: null,
    originalMoP: null,
  },
  sepaDetails: {
    billingAccountId: null,
    firstName: null,
    lastName: null,
    billingAddress: {
      street: null,
      postalCode: null,
      city: null,
      countryCode: null,
    },
    email: null,
    iban: null,
    paymentConfigurationId: null,
  },
});

const user = (state = initialState, action = {}) => {
  const performanceCookie = document.cookie
    .split("; ")
    .find((c) => c.startsWith("userConsent") && c.includes("performance"))
    || "={}";
  const isPerformanceAllowed = JSON.parse(
    decodeURIComponent(performanceCookie.split("=").pop()),
  ).performance;
  switch (action.type) {
    // case LIST_ACTIONS.SIGNUP_PRIVATE_SUCCESS: {
    //   if (mixpanel && isPerformanceAllowed) {
    //     mixpanel.track(MIXPANEL_ACTIONS.SIGNUP_BUTTON_PRIVATE_SUCCESS, {
    //       channel: "DesktopWeb",
    //     });
    //   }
    //   return state;
    // }
    case LIST_ACTIONS.SIGNUP_PRIVATE_ERROR: {
      if (mixpanel && isPerformanceAllowed) {
        mixpanel.track(MIXPANEL_ACTIONS.SIGNUP_BUTTON_PRIVATE_ERROR, {
          channel: "DesktopWeb",
          label: action.error.status,
        });
      }
      return state;
    }
    // case LIST_ACTIONS.SIGNUP_BUSINESS_SUCCESS: {
    //   if (mixpanel && isPerformanceAllowed) {
    //     mixpanel.track(MIXPANEL_ACTIONS.SIGNUP_BUTTON_BUSINESS_SUCCESS, {
    //       channel: "DesktopWeb",
    //     });
    //   }
    //   return state;
    // }
    case LIST_ACTIONS.SIGNUP_BUSINESS_ERROR: {
      if (mixpanel && isPerformanceAllowed) {
        mixpanel.track(MIXPANEL_ACTIONS.SIGNUP_BUTTON_BUSINESS_ERROR, {
          channel: "DesktopWeb",
          label: action.error.status,
        });
      }
      return state;
    }
    case LIST_ACTIONS.GET_CHECK_EXISTING_USER_REQUEST: {
      return state.set("isLoading", true);
    }
    case LIST_ACTIONS.GET_CHECK_EXISTING_USER_SUCCESS: {
      return state
        .set("isLoading", false)
        .set("checkExistingUser", action.payload);
    }
    case LIST_ACTIONS.GET_CHECK_EXISTING_USER_RESET: {
      return state.set("isLoading", false).set("checkExistingUser", null);
    }
    case LIST_ACTIONS.GET_CHECK_EXISTING_USER_ERROR:
      return state
        .set("isLoading", false)
        .set("checkExistingUser", action.payload);
    case LIST_ACTIONS.SWITCH_USER:
      return state.set("switchedUser", action.payload.name);
    case LIST_ACTIONS.GET_ACCESSES_SUCCESS:
      return state
        .set("cookie", action.payload.data.cookie)
        .set("profile", action.payload.data.login)
        .set("profileAccesses", action.payload.data.accesses.groupedAccesses)
        .set("accesses", action.payload.data.accesses);
    case LIST_ACTIONS.SELECT_PARKING_USER:
      return state.set("selectedParkingUser", action.payload);
    case LIST_ACTIONS.GET_PARKING_USER_LIST_SUCCESS:
      return state.set("parkingUsers", action.payload.data.parkingUsers);
    case LIST_ACTIONS.SAVE_AGREEMENT_PACKAGE_SUCCESS:
      return state
        .set("deactivationEnabled", false)
        .set("selectedPackageId", null);
    case LIST_ACTIONS.SELECT_PACKAGE_ID:
      return state.set("selectedPackageId", action.payload);
    case LIST_ACTIONS.ENABLE_DEACTIVATION:
      return state.set("deactivationEnabled", true);
    case LIST_ACTIONS.GET_SUBSCRIPTION_SUCCESS:
      return state.set(
        "subscriptionAgreements",
        action.payload.subscriptionAgreements,
      );
    case LIST_ACTIONS.USER_EDIT:
      return state.set("editUser", action.payload);
    case LIST_ACTIONS.SIGNUP_REQUEST:
      return state.set("errorType", null);
    case LIST_ACTIONS.SELECT_CODE:
      return state.set("selectedCode", action.data);
    case LIST_ACTIONS.USER_AUTH_REQUEST: {
      return state.set("pending", true);
    }
    case LIST_ACTIONS.USER_AUTH_UNAUTHORIZED: {
      return state
        .set("unauthorized", action.payload.unauthorized)
        .set("unauthorizedReason", action.payload.unauthorizedReason)
        .set("pending", false);
    }
    case LIST_ACTIONS.USER_AUTH_SUCCESS: {
      if (action.payload.data.corporate) {
        return state
          .set("pending", false)
          .set("corporate", true)
          .set("signInModal", false);
      }
      if (action.payload.data.redirect) {
        return state
          .set("isLoggedIn", true)
          .set("pending", false)
          .set("redirect", action.payload.data.redirect)
          .set("corporate", false)
          .set("signInModal", false);
      }
      return state
        .set("isLoggedIn", true)
        .set("pending", false)
        .set("corporate", false)
        .set("signInModal", false);
    }
    case LIST_ACTIONS.GET_PAYMENT_METHOD_SUCCESS: {
      return state.set("paymentMethods", action.payload.data.paymentMethods);
    }
    case LIST_ACTIONS.GET_PAYMENT_METHOD_ERROR:
      return state.set("paymentMethods", action.e.status === 403 ? null : []);
    case LIST_ACTIONS.USER_AUTH_ERROR:
      return state.set("loginError", true).set("pending", false);
    case LIST_ACTIONS.GET_USER_SETTINGS_SUCCESS:
      return state
        .set("userAddress", action.payload.data.deliveryAddress)
        .set("userSettings", action.payload.data.userSettings);
    // Should be check user
    case LIST_ACTIONS.UPDATE_USER_SUCCESS:
    case LIST_ACTIONS.GET_USER_SUCCESS:
      if (action.payload.data.login) {
        return state.set("isLoggedIn", true).set("current", action.payload.data);
      }
      return state.set("isLoggedIn", false).set("current", {});
    case LIST_ACTIONS.GET_MIGRATED_USER_DATA_SUCCESS:
      return state.set("migrationData", {
        billingAccountId: action.payload.data.data.billingAccountId,
        customerId: action.payload.data.data.customerId,
        originalMoP: action.payload.data.data.originalMoP,
      });
    case LIST_ACTIONS.GET_SEPA_DETAILS_SUCCESS:
      return state.set("sepaDetails", action.payload.data);
    case LIST_ACTIONS.SET_SEPA_DETAILS:
      return state.set("sepaDetails", {
        ...state.get("sepaDetails"),
        firstName: action.payload.firstName,
        lastName: action.payload.lastName,
        billingAddress: {
          ...state.getIn(["sepaDetails", "billingAddress"]),
          street: action.payload.street,
          city: action.payload.city,
          postalCode: action.payload.postalCode,
        },
        email: action.payload.email,
      });
    case LIST_ACTIONS.GET_USER_ERROR:
      return state.set("isLoggedIn", false);
    case LIST_ACTIONS.LOGOUT_SUCCESS: {
      getUniversalCookies().remove("userId");

      // TODO: Maybe localhost only?
      getUniversalCookies().remove("epSsAuthToken");
      getUniversalCookies().remove("epSsRefreshToken");
      getUniversalCookies().remove("epSsTokenTime");

      return state
        .set("isLoggedIn", false)
        .set("paymentMethods", [])
        .set("redirect", false)
        .set("current", {})
        .set("selectedParkingUser", null)
        .set("deactivationEnabled", false)
        .set("selectedPackageId", null)
        .set("parkingUsers", [])
        .set("isDualAccount", {
          isDual: false,
          userEmail: null,
          userFullName: null,
        });
    }
    case LIST_ACTIONS.SET_IS_DUAL_ENV:
      return state.set("isDualAccount", action.payload);
    case LIST_ACTIONS.GET_PRODUCT_PACKAGE_SUCCESS:
      return state.set("productPackage", action.payload);
    default:
      return state;
  }
};

export default user;

Zerion Mini Shell 1.0