{"size": 2242, "ext": "js", "max_stars_repo_path": "src/redux/modules/account/disableTwoFactorAuth.js", "max_stars_repo_name": "JincorTech/mypizzapie-frontend-ico-dashboard", "max_stars_repo_stars_event_min_datetime": "2018-05-30T19:29:15.000Z", "max_stars_repo_stars_event_max_datetime": "2018-08-23T02:12:19.000Z", "max_issues_repo_path": "src/redux/modules/account/disableTwoFactorAuth.js", "max_issues_repo_name": "JincorTech/mypizzapie-frontend-ico-dashboard", "max_issues_repo_issues_event_min_datetime": "2018-05-22T13:28:53.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-22T13:29:01.000Z", "max_forks_repo_path": "src/redux/modules/account/disableTwoFactorAuth.js", "max_forks_repo_name": "JincorTech/mypizzapie-frontend-ico-dashboard", "max_forks_repo_forks_event_min_datetime": "2018-05-08T20:00:55.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-22T14:36:47.000Z"}
{"max_stars_count": 2, "max_issues_count": 1, "max_forks_count": 5, "avg_line_length": 27.0120481928, "max_line_length": 108, "alphanum_fraction": 0.7136485281}
import { from } from 'seamless-immutable';
import { createReducer, createAsyncAction, createAction, createSubmitAction } from '../../../utils/actions';

export const OPEN_DISABLE_2FA_POPUP = 'account/disableTwoFactorAuth/OPEN_DISABLE_2FA_POPUP';
export const CLOSE_DISABLE_2FA_POPUP = 'account/disableTwoFactorAuth/CLOSE_DISABLE_2FA_POPUP';
export const INITIATE_DISABLE_2FA = 'account/disableTwoFactorAuth/INITIATE_DISABLE_2FA';
export const VERIFY_DISABLE_2FA = 'account/disableTwoFactorAuth/VERIFY_DISABLE_2FA';
export const RESET_STORE = 'account/disableTwoFactorAuth/RESET_STORE';

export const openDisableTwoFactorAuthPopup = createAction(OPEN_DISABLE_2FA_POPUP);
export const closeDisableTwoFactorAuthPopup = createAction(CLOSE_DISABLE_2FA_POPUP);
export const initiateDisableTwoFactorAuth = createAsyncAction(INITIATE_DISABLE_2FA);
export const verifyDisableTwoFactorAuth = createSubmitAction(VERIFY_DISABLE_2FA);
export const resetStore = createAction(RESET_STORE);

const initialState = from({
  disableTwoFactorAuthPopupOpen: false,
  spinner: false,
  verification: {
    verificationId: '',
    consumer: '',
    expiredOn: 0,
    status: 0,
    method: ''
  }
});

export default createReducer({
  [OPEN_DISABLE_2FA_POPUP]: (state) => (
    state.merge({
      disableTwoFactorAuthPopupOpen: true
    })
  ),

  [CLOSE_DISABLE_2FA_POPUP]: (state) => (
    state.merge({
      disableTwoFactorAuthPopupOpen: false
    })
  ),

  [initiateDisableTwoFactorAuth.REQUEST]: (state) => (
    state.merge({
      spinner: true
    })
  ),

  [initiateDisableTwoFactorAuth.SUCCESS]: (state, { payload }) => (
    state.merge({
      spinner: false,
      verification: payload
    })
  ),

  [initiateDisableTwoFactorAuth.FAILURE]: (state) => (
    state.merge({
      spinner: false
    })
  ),

  [verifyDisableTwoFactorAuth.REQUEST]: (state) => (
    state.merge({
      spinner: true
    })
  ),

  [verifyDisableTwoFactorAuth.SUCCESS]: (state) => (
    state.merge({
      disableTwoFactorAuthPopupOpen: false,
      spinner: false
    })
  ),

  [verifyDisableTwoFactorAuth.FAILURE]: (state) => (
    state.merge({
      spinner: false
    })
  ),

  [RESET_STORE]: (state) => (
    state.merge(initialState)
  )
}, initialState);
