import {combineReducers} from 'redux';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {ActionType} from 'constants';

import AuthReducer from './auth.reducer';
import SaleOrderReducer from './sale-order.reducer';

const appReducer = combineReducers({
  auth: AuthReducer,
  saleOrder: SaleOrderReducer,
});

const rootReducer = (state, action) => {
  if (action.type === ActionType.SIGN_OUT) {
    AsyncStorage.removeItem('persist:root');
    state = undefined;
  }
  return appReducer(state, action);
};

export default rootReducer;
