Commit 1277bb91 authored by Shaphen Pangburn's avatar Shaphen Pangburn

[AFP-131 Shaphen Pangburn, Joe Lu]: Add user iamge url to global state

parent 1c287b9e
......@@ -2,11 +2,16 @@ import {postUser} from '../util/session-api-util'
export const SET_CURRENT_USER = "SET_CURRENT_USER"
export const LOGOUT_USER = "LOGOUT_USER"
export const SET_USER_IMAGE = "SET_USER_IMAGE"
export const setCurrentUser = (user) => {
return {type: SET_CURRENT_USER, user}
}
export const setUserImage = (image) => {
return {type: SET_USER_IMAGE, image}
}
export const logoutUser = () => {
return {type: LOGOUT_USER}
}
......@@ -17,6 +22,10 @@ export const login = (user) => dispatch => {
)
)
}
export const addUserImage = image => dispatch => {
return dispatch(setUserImage(image))
}
// export const login = () => {
// return (dispatch) => {
// return dispatch(setCurrentUser());
......
import { connect } from 'react-redux';
import Session from './session';
import {login, logOut} from '../../actions/session_actions';
import {login, logOut, addUserImage} from '../../actions/session_actions';
import { fetchUserCart, createUserCart, clearUserCart } from '../../actions/cart_actions';
const mSTP = state => ({
......@@ -9,6 +9,7 @@ const mSTP = state => ({
const mDTP = dispatch => ({
login: (userResponse) => dispatch(login(userResponse)),
addUserImage: image => dispatch(addUserImage(image)),
logOut: () => dispatch(logOut()),
getUserCart: userId => dispatch(fetchUserCart(userId)),
createCart: newCart => dispatch(createUserCart(newCart)),
......
......@@ -18,10 +18,12 @@ export default class Session extends Component {
}
loginSuccess = (response) => {
console.log(response);
const {accessToken, tokenId, googleId: userId, profileObj} = response
const {email, familyName: lastName, givenName: firstName} = profileObj
const {email, familyName: lastName, givenName: firstName, imageUrl} = profileObj
const userResponse = {idToken: tokenId, userId, email, firstName, lastName, accessToken}
this.props.login(userResponse)
this.props.addUserImage(imageUrl)
this.setState({logIn: true})
// try grabbing user cart
......@@ -56,11 +58,7 @@ export default class Session extends Component {
onSuccess={this.loginSuccess}
onFailure={this.loginFailed}
cookiePolicy={'single_host_origin'}
/> : <GoogleLogout
clientId={clientId}
buttonText="Logout"
onLogoutSuccess={this.logOutSuccess}
></GoogleLogout>
/> : ""
}
</div>
)
......
import {SET_CURRENT_USER, LOGOUT_USER} from '../actions/session_actions'
import {SET_CURRENT_USER, LOGOUT_USER, SET_USER_IMAGE} from '../actions/session_actions'
const initialState = {
currentUser: null,
userImage: null
}
const userReducer = (state = initialState, action) => {
......@@ -11,6 +12,9 @@ const userReducer = (state = initialState, action) => {
case SET_CURRENT_USER:
newState.currentUser = action.user.data;
return newState;
case SET_USER_IMAGE:
newState.userImage = action.image;
return newState;
case LOGOUT_USER:
return newState.currentUser = null;
default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment