import { LOGIN_SUCCESS } from '../actions/authenticationActions' ; import { REGISTER_SUCCESS } from '../actions/registerAction' ; import { FETCH_SETTINGS_FAIL , FETCH_SETTINGS_SUCCESS , } from '../actions/settingsAction' ; import { UserData } from '../dataObjects/user' ; import { ActionTypes } from '../actions/actionTypes' ; export interface AuthStatusState { userId ? : number ; accountName ? : string ; address ? : string ; numSellItems ? : number ; checked : boolean ; } const initialState = { checked : false , } ; const authStatus = ( state = initialState , action ) : AuthStatusState => { switch ( action . type ) { case LOGIN_SUCCESS : case REGISTER_SUCCESS : { return { ... state , ... action . payload , } ; } case FETCH_SETTINGS_SUCCESS : { const user = action . payload . settings . user ; let userPayload = { } ; if ( user ) { userPayload = { userId : user . id , accountName : user . accountName , address : user . address || undefined , numSellItems : user . numSellItems , } ; } return { ... state , ... userPayload , checked : true , } ; } case FETCH_SETTINGS_FAIL : { return { ... state , checked : true , } ; } default : return state ; } } ; export default authStatus ;