import { combineReducers } from 'redux';
import { reducer as reduxFormReducer } from 'redux-form';
import auth from './auth';
import errors from './errors';
import user from './user';
import lessons from './lessons';
import cards from './cards';
import { LOGOUT } from '../constants/auth';

const appReducer = combineReducers({
  form: reduxFormReducer,
  errors,
  auth,
  user,
  lessons,
  cards
});

function rootReducer(state, action) {
  if (action.type === LOGOUT) state = undefined;
  return appReducer(state, action);
}

export default rootReducer;
