<commit_before>import {
  CHANGE_PHONE_NUMBER,
  MOBILE_AUTHENTICATION_START,
  MOBILE_AUTHENTICATION_START_SUCCESS,
  MOBILE_AUTHENTICATION_START_ERROR,
  MOBILE_AUTHENTICATION_SUCCESS,
  MOBILE_AUTHENTICATION_ERROR,
  MOBILE_AUTHENTICATION_CANCEL,
  ID_CARD_AUTHENTICATION_START,
  ID_CARD_AUTHENTICATION_SUCCESS,
  ID_CARD_AUTHENTICATION_ERROR,
  GET_USER_START,
  GET_USER_SUCCESS,
  GET_USER_ERROR,
  LOG_OUT,
} from './constants';

const TOKEN_STORAGE_KEY = 'token';

// get saved token if it's there
const token = (window.localStorage && localStorage.getItem(TOKEN_STORAGE_KEY)) || null;

const defaultState = {
  phoneNumber: '',
  controlCode: null,
  loadingAuthentication: false,
  token,
  loggedInWithMobileId: false,
  error: null,
  user: null,
  loadingUser: false,
  userError: null,
};

export default function loginReducer(state = defaultState, action) {
  switch (action.type) {
    case CHANGE_PHONE_NUMBER:
      return { ...state, phoneNumber: action.phoneNumber };

    case MOBILE_AUTHENTICATION_START:
      return { ...state, loadingAuthentication: true, error: null };
    case MOBILE_AUTHENTICATION_START_SUCCESS:
      return { ...state, loadingAuthentication: false, controlCode: action.controlCode, error: null };
    case MOBILE_AUTHENTICATION_START_ERROR:
      return { ...state, loadingAuthentication: false, error: action.error };

    case MOBILE_AUTHENTICATION_SUCCESS:
      if (window.localStorage) {
        localStorage.setItem(TOKEN_STORAGE_KEY, action.token);
      }
      return { // reset all state so page is clean when entered again.
        ...state,
        token: action.token,<commit_msg>Fixed long line<commit_after>import {
  CHANGE_PHONE_NUMBER,
  MOBILE_AUTHENTICATION_START,
  MOBILE_AUTHENTICATION_START_SUCCESS,
  MOBILE_AUTHENTICATION_START_ERROR,
  MOBILE_AUTHENTICATION_SUCCESS,
  MOBILE_AUTHENTICATION_ERROR,
  MOBILE_AUTHENTICATION_CANCEL,
  ID_CARD_AUTHENTICATION_START,
  ID_CARD_AUTHENTICATION_SUCCESS,
  ID_CARD_AUTHENTICATION_ERROR,
  GET_USER_START,
  GET_USER_SUCCESS,
  GET_USER_ERROR,
  LOG_OUT,
} from './constants';

const TOKEN_STORAGE_KEY = 'token';

// get saved token if it's there
const token = (window.localStorage && localStorage.getItem(TOKEN_STORAGE_KEY)) || null;

const defaultState = {
  phoneNumber: '',
  controlCode: null,
  loadingAuthentication: false,
  token,
  loggedInWithMobileId: false,
  error: null,
  user: null,
  loadingUser: false,
  userError: null,
};

export default function loginReducer(state = defaultState, action) {
  switch (action.type) {
    case CHANGE_PHONE_NUMBER:
      return { ...state, phoneNumber: action.phoneNumber };

    case MOBILE_AUTHENTICATION_START:
      return { ...state, loadingAuthentication: true, error: null };
    case MOBILE_AUTHENTICATION_START_SUCCESS:
      return {
        ...state,
        loadingAuthentication: false,
        controlCode: action.controlCode,
        error: null,
      };
    case MOBILE_AUTHENTICATION_START_ERROR:
      return { ...state, loadingAuthentication: false, error: action.error };

    case MOBILE_AUTHENTICATION_SUCCESS:
      if (window.localStorage) {
        localStorage.setItem(TOKEN_STORAGE_KEY, action.token);
      }
      return { // reset all state so page is clean when entered again.
        ...state,
        token: action.token,
{'fraction_non_alphanumeric': 0.0875187969924812, 'fraction_numerical': 0.0, 'mean_word_length': 4.093415007656968, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3058852', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1065, 'n_words': 219}