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

View File

@ -1,5 +1,6 @@
import {
User,
UserAttributes,
ReduxAction,
REGISTRATION_REQUEST_SENT,
REGISTRATION_REQUEST_SUCCEEDED,
@ -49,12 +50,19 @@ const currentUser = (state: User = initialUser, action: ReduxAction): User => {
isLoggedIn: false,
}
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 {
...state,
attributes: {
...state.attributes,
firstName: null,
},
attributes: allNullUserAttributes,
isLoading: false,
isLoggedIn: false,
}

View File

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