Make SIGNOUT_REQUEST_SUCCEEDED null all user attributes

This commit is contained in:
Kyle Corbelli 2017-09-15 19:53:13 -07:00
parent 319c98bcc9
commit 996c004f74
3 changed files with 17 additions and 5 deletions

View File

@ -42,6 +42,7 @@ describe('currentUser', () => {
const loggedInUser: User = { const loggedInUser: User = {
attributes: { attributes: {
firstName: 'Snowball', firstName: 'Snowball',
imageUrl: 'http://some.url',
}, },
isLoading: false, isLoading: false,
isLoggedIn: true, isLoggedIn: true,
@ -169,6 +170,7 @@ describe('currentUser', () => {
const expectedNewState: User = { const expectedNewState: User = {
attributes: { attributes: {
firstName: null, firstName: null,
imageUrl: null,
}, },
isLoading: false, isLoading: false,
isLoggedIn: false, isLoggedIn: false,

View File

@ -1,5 +1,6 @@
import { import {
User, User,
UserAttributes,
ReduxAction, ReduxAction,
REGISTRATION_REQUEST_SENT, REGISTRATION_REQUEST_SENT,
REGISTRATION_REQUEST_SUCCEEDED, REGISTRATION_REQUEST_SUCCEEDED,
@ -49,12 +50,19 @@ const currentUser = (state: User = initialUser, action: ReduxAction): User => {
isLoggedIn: false, isLoggedIn: false,
} }
case SIGNOUT_REQUEST_SUCCEEDED: case SIGNOUT_REQUEST_SUCCEEDED:
const userAttributeKeys: string[] = Object.keys(state.attributes)
const allNullUserAttributes: UserAttributes = userAttributeKeys.reduce(
(accumulatedNullUserAttributes: UserAttributes, curentUserAttributeKey: string): UserAttributes => {
return {
...accumulatedNullUserAttributes,
[curentUserAttributeKey]: null,
}
},
{},
)
return { return {
...state, ...state,
attributes: { attributes: allNullUserAttributes,
...state.attributes,
firstName: null,
},
isLoading: false, isLoading: false,
isLoggedIn: false, isLoggedIn: false,
} }

View File

@ -3,7 +3,9 @@ import {
Store, Store,
} from 'redux' } from 'redux'
export interface UserAttributes {} export interface UserAttributes {
[key: string]: string | number | null
}
export interface User { export interface User {
readonly isLoggedIn: boolean readonly isLoggedIn: boolean