Migrate actions,reducers and action types to TS #15
This commit is contained in:
78
app/reducers/users/userReducer.ts
Normal file
78
app/reducers/users/userReducer.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
// - Import action types
|
||||
import {UserActionType} from 'constants/userActionType'
|
||||
|
||||
// - Import domain
|
||||
import { User,Profile } from "domain/users";
|
||||
|
||||
import { UserState } from "./UserState";
|
||||
import { IUserAction } from "./IUserAction";
|
||||
|
||||
/**
|
||||
* User reducer
|
||||
*/
|
||||
export var userReducer = (state: UserState = new UserState(), action: IUserAction) => {
|
||||
const { payload } = action
|
||||
switch (action.type) {
|
||||
case UserActionType.USER_INFO:
|
||||
return {
|
||||
...state,
|
||||
info: {
|
||||
...state.info,
|
||||
[payload.uid]: {
|
||||
...payload.info
|
||||
}
|
||||
}
|
||||
}
|
||||
case UserActionType.ADD_USER_INFO:
|
||||
return {
|
||||
...state,
|
||||
info: {
|
||||
...state.info,
|
||||
[payload.uid]: {
|
||||
...payload.info
|
||||
}
|
||||
},
|
||||
loaded: true
|
||||
}
|
||||
case UserActionType.ADD_PEOPLE_INFO:
|
||||
return {
|
||||
...state,
|
||||
info: {
|
||||
...state.info,
|
||||
...payload
|
||||
}
|
||||
}
|
||||
|
||||
case UserActionType.UPDATE_USER_INFO:
|
||||
return {
|
||||
...state,
|
||||
info: {
|
||||
...state.info,
|
||||
[payload.uid]: {
|
||||
...state.info![payload.uid],
|
||||
...payload.info
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
case UserActionType.CLEAR_ALL_DATA_USER:
|
||||
return new UserState();
|
||||
|
||||
case UserActionType.CLOSE_EDIT_PROFILE:
|
||||
return {
|
||||
...state,
|
||||
openEditProfile: false
|
||||
}
|
||||
|
||||
case UserActionType.OPEN_EDIT_PROFILE:
|
||||
return {
|
||||
...state,
|
||||
openEditProfile: true
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user