Last active
November 27, 2018 10:46
-
-
Save kvnam/b6cf75d95793d55919cbcff8fcd18204 to your computer and use it in GitHub Desktop.
ReactPress - User Reducer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const initialState = { | |
username: "", | |
email: "", | |
displayname: "", | |
token: "", | |
error: null, | |
isLoading: false, | |
redirectURL: "/" | |
}; | |
const userReducer = (state = initialState, action) => { | |
let updatedUser = null; | |
switch(action.type){ | |
... | |
case actionTypes.USER_SIGNIN_SUCCESS: updatedUser = { | |
...state, | |
username: action.userDets.user_nicename, | |
email: action.userDets.user_email, | |
displayname: action.userDets.user_display_name, | |
token: action.token | |
}; | |
return updatedUser; | |
case actionTypes.USER_SIGNIN_FAIL: updatedUser = { | |
...state, | |
token: "", | |
error: action.error | |
}; | |
return updatedUser; | |
case actionTypes.USER_SIGNOUT: | |
updatedUser = { | |
...state, | |
token: "", | |
username: "", | |
email: "", | |
displayname: "", | |
redirectURL: "/" | |
}; | |
return updatedUser; | |
default : return state; | |
} | |
} | |
export default userReducer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment