58 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-03-27 17:39:01 +09:00
import { createReducer, on } from '@ngrx/store';
import { initialState } from './state';
2020-05-24 13:11:32 +09:00
import { loginSuccess, logoutSuccess, infoUserSuccess } from './actions';
import { UserInfoUpdateType } from '@ucap/protocol-info';
2020-03-27 17:39:01 +09:00
export const reducer = createReducer(
initialState,
on(loginSuccess, (state, action) => {
return {
...state,
2020-04-03 10:59:44 +09:00
loginRes: action.res
2020-03-27 17:39:01 +09:00
};
}),
on(logoutSuccess, (state, action) => {
return {
...initialState
};
2020-05-24 13:11:32 +09:00
}),
on(infoUserSuccess, (state, action) => {
let loginRes = {
...state.loginRes
};
switch (action.res.type) {
case UserInfoUpdateType.Image:
loginRes = {
...loginRes
};
break;
case UserInfoUpdateType.Intro:
loginRes = {
...loginRes,
userInfo: {
...loginRes.userInfo,
intro: action.res.info
}
};
break;
case UserInfoUpdateType.TelephoneVisible:
loginRes = {
...loginRes
};
break;
default:
break;
}
return {
...state,
loginRes: {
...loginRes
}
};
2020-03-27 17:39:01 +09:00
})
);