auth0-extensions/auth0-delegated-administration-extension

View on GitHub
client/reducers/accessLevel.js

Summary

Maintainability
A
0 mins
Test Coverage
import { fromJS } from 'immutable';

import * as constants from '../constants';
import createReducer from '../utils/createReducer';

const initialState = {
  loading: false,
  error: null,
  record: { role: 0, memberships: [], createMemberships: false }
};

export const accessLevel = createReducer(fromJS(initialState), { // eslint-disable-line import/prefer-default-export
  [constants.FETCH_ACCESS_LEVEL_PENDING]: (state) =>
    state.merge({
      loading: true,
      error: null
    }),
  [constants.FETCH_ACCESS_LEVEL_REJECTED]: (state, action) =>
    state.merge({
      loading: false,
      error: action.errorData,
      record: fromJS({ ...initialState.record, role: 2 })
    }),
  [constants.FETCH_ACCESS_LEVEL_FULFILLED]: (state, action) =>
    state.merge({
      loading: false,
      error: null,
      record: fromJS(action.payload.data)
    })
});