Skip to content

Commit b828b13

Browse files
committed
Solved logout not clearing data from the users redux store
1 parent c31c09f commit b828b13

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

src/state/actions/auth.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { toastr } from 'react-redux-toastr';
33

44
import { firebaseError, FIREBASE_RESPONSE } from 'utils';
55
import firebase from 'firebase.js';
6-
import { clearUsersData } from './users';
6+
import { clearUsersDataLogout } from './users';
77

88
export const AUTH_SIGN_IN_INIT = createAction('AUTH_SIGN_IN_INIT');
99
export const AUTH_SIGN_IN_FAIL = createAction('AUTH_SIGN_IN_FAIL');
@@ -65,7 +65,7 @@ export const logout = () => {
6565
return async dispatch => {
6666
dispatch(AUTH_LOGOUT_INIT());
6767

68-
dispatch(clearUsersData());
68+
dispatch(clearUsersDataLogout());
6969
await firebase.auth().signOut();
7070

7171
dispatch(AUTH_LOGOUT_SUCCESS());

src/state/actions/users.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export const USERS_MODIFY_USER_FAIL = createAction('USERS_MODIFY_USER_FAIL');
3434

3535
export const USERS_CLEAN_UP = createAction('USERS_CLEAN_UP');
3636

37+
export const USERS_CLEAR_DATA_LOGOUT = createAction('USERS_CLEAR_DATA_LOGOUT');
38+
3739
export const fetchUsers = () => {
3840
return async (dispatch, getState) => {
3941
dispatch(checkUserData());
@@ -121,6 +123,12 @@ export const clearUsersData = () => {
121123
};
122124
};
123125

126+
export const clearUsersDataLogout = () => {
127+
return dispatch => {
128+
dispatch(USERS_CLEAR_DATA_LOGOUT());
129+
};
130+
};
131+
124132
const uploadLogo = (uid, file) => {
125133
const storageRef = firebase.storage().ref();
126134

src/state/reducers/users/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
USERS_MODIFY_USER_INIT,
1515
USERS_MODIFY_USER_SUCCESS,
1616
USERS_MODIFY_USER_FAIL,
17-
USERS_CLEAN_UP
17+
USERS_CLEAN_UP,
18+
USERS_CLEAR_DATA_LOGOUT
1819
} from 'state/actions/users';
1920

2021
const initialState = {
@@ -112,6 +113,9 @@ export const usersReducer = createReducer(
112113
error: null,
113114
success: false,
114115
deleted: false
116+
}),
117+
[USERS_CLEAR_DATA_LOGOUT]: () => ({
118+
...initialState
115119
})
116120
},
117121
initialState

src/state/reducers/users/users.test.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
USERS_MODIFY_USER_INIT,
1313
USERS_MODIFY_USER_SUCCESS,
1414
USERS_MODIFY_USER_FAIL,
15-
USERS_CLEAN_UP
15+
USERS_CLEAN_UP,
16+
USERS_CLEAR_DATA_LOGOUT
1617
} from 'state/actions/users';
1718

1819
import { usersReducer } from '.';
@@ -90,8 +91,30 @@ describe('Establishments reducer', () => {
9091
});
9192
});
9293

93-
it('should reset the state to the initial state when USERS_CLEAR_DATA action is fired', () => {
94-
reducerTest(initialState, USERS_CLEAR_DATA(), initialState);
94+
it('should reset the state to the initial state when USERS_CLEAR_DATA_LOGOUT action is fired', () => {
95+
reducerTest(initialState, USERS_CLEAR_DATA_LOGOUT(), initialState);
96+
});
97+
98+
it('should reset the state to the initial state while maintaining the data when USERS_CLEAR_DATA action is fired', () => {
99+
const userData = [
100+
{
101+
name: 'Test name',
102+
email: 'Test email',
103+
location: 'Test location',
104+
createdAt: '11/20/2020'
105+
}
106+
];
107+
108+
reducerTest(
109+
{
110+
...initialState,
111+
data: userData,
112+
loading: true,
113+
error: null
114+
},
115+
USERS_CLEAR_DATA(),
116+
{ ...initialState, data: userData }
117+
);
95118
});
96119

97120
it('should set loading to true to the current state when USERS_CREATE_USER_INIT action is fired', () => {

0 commit comments

Comments
 (0)