import { createReducer, on } from '@ngrx/store'; import { initialState } from './state'; import { authSuccess, deptSuccess, myDeptUserSuccess, deptUserSuccess, selectedDept, selectedDeptSuccess, searchDeptUser, searchDeptUserSuccess, searchDeptUserFailure, deptUserFailure, cancelSearchDeptUser, myDeptUserFailure } from './actions'; import * as AuthenticationStore from '@app/store/account/authentication'; export const reducer = createReducer( initialState, on(authSuccess, (state, action) => { return { ...state, auth: action.res }; }), on(deptSuccess, (state, action) => { return { ...state, departmentInfoList: action.departmentInfoList }; }), on(selectedDept, (state, action) => { return { ...state, selectedDepartment: action, selectedDepartmentProcessing: true }; }), on(selectedDeptSuccess, (state, action) => { return { ...state, selectedDepartmentProcessing: false }; }), on(deptUserSuccess, (state, action) => { return { ...state, departmentUserInfoList: action.userInfos }; }), on(deptUserFailure, state => { return { ...state, selectedDepartmentProcessing: false }; }), on(myDeptUserSuccess, (state, action) => { return { ...state, myDepartmentUserInfoList: action.userInfos }; }), on(myDeptUserFailure, state => { return { ...state, selectedDepartmentProcessing: false }; }), on(searchDeptUser, (state, action) => { return { ...state, isSearch: true, selectedDepartmentProcessing: true }; }), on(searchDeptUserSuccess, (state, action) => { return { ...state, searchDepartmentUserInfoList: action.userInfos, selectedDepartmentProcessing: false }; }), on(searchDeptUserFailure, (state, action) => { return { ...state, selectedDepartmentProcessing: false }; }), on(cancelSearchDeptUser, (state, action) => { return { ...state, isSearch: false, searchDepartmentUserInfoList: null }; }), on(AuthenticationStore.logoutInitialize, (state, action) => { return { ...initialState }; }) );