File tree Expand file tree Collapse file tree 4 files changed +41
-6
lines changed Expand file tree Collapse file tree 4 files changed +41
-6
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { toastr } from 'react-redux-toastr';
33
44import { firebaseError , FIREBASE_RESPONSE } from 'utils' ;
55import firebase from 'firebase.js' ;
6- import { clearUsersData } from './users' ;
6+ import { clearUsersDataLogout } from './users' ;
77
88export const AUTH_SIGN_IN_INIT = createAction ( 'AUTH_SIGN_IN_INIT' ) ;
99export 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 ( ) ) ;
Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ export const USERS_MODIFY_USER_FAIL = createAction('USERS_MODIFY_USER_FAIL');
3434
3535export const USERS_CLEAN_UP = createAction ( 'USERS_CLEAN_UP' ) ;
3636
37+ export const USERS_CLEAR_DATA_LOGOUT = createAction ( 'USERS_CLEAR_DATA_LOGOUT' ) ;
38+
3739export 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+
124132const uploadLogo = ( uid , file ) => {
125133 const storageRef = firebase . storage ( ) . ref ( ) ;
126134
Original file line number Diff line number Diff 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
2021const 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
Original file line number Diff line number Diff 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
1819import { 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' , ( ) => {
You can’t perform that action at this time.
0 commit comments