import { reducerWithInitialState } from 'typescript-fsa-reducers' import { combineReducers } from 'redux' import { IMeetingTypesState } from './interfaces' import * as actions from './actions' import { logout } from '../auth/actions' const meetingTypes = reducerWithInitialState({} as IMeetingTypesState) .case(actions.fetchCustomMeetingTypesSuccess, (state, customMeetingTypes) => ({ ...state, customMeetingTypes })) .case(actions.fetchDefaultMeetingTypeSuccess, (state, defaultMeeting) => ({ ...state, defaultMeeting })) .case(logout, () => ({} as IMeetingTypesState)) const defaultLoading = reducerWithInitialState(null) .cases([ actions.fetchDefaultMeetingTypeSuccess, ], () => false) .cases([ actions.fetchDefaultMeetingTypePending, ], () => true) const defaultLoaded = reducerWithInitialState(null) .cases([ actions.fetchDefaultMeetingTypeSuccess, ], () => true) .cases([ actions.fetchDefaultMeetingTypePending, ], () => false) const customLoading = reducerWithInitialState(null) .cases([ actions.fetchCustomMeetingTypesSuccess, ], () => false) .cases([ actions.fetchCustomMeetingTypesPending, ], () => true) const customLoaded = reducerWithInitialState(null) .cases([ actions.fetchCustomMeetingTypesSuccess, ], () => true) .cases([ actions.fetchCustomMeetingTypesPending, ], () => false) export default combineReducers({ defaultLoading, defaultLoaded, customLoading, customLoaded, meetingTypes, })