Skip to content

Commit 5dcba47

Browse files
authored
Merge branch 'master' into feature/migrate-functions-ts
2 parents 3592cea + 590ece8 commit 5dcba47

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { toastr } from 'react-redux-toastr';
33

44
import { firebaseError } from 'utils';
55
import firebase from 'firebase.js';
6-
import { checkUserData } from './auth';
6+
import { checkUserData, AUTH_UPDATE_USER_DATA } from './auth';
77

88
export const USERS_FETCH_DATA_INIT = createAction('USERS_FETCH_DATA_INIT');
99
export const USERS_FETCH_DATA_SUCCESS = createAction(
@@ -33,6 +33,8 @@ export const USERS_MODIFY_USER_FAIL = createAction('USERS_MODIFY_USER_FAIL');
3333

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

36+
export const USERS_CLEAR_DATA_LOGOUT = createAction('USERS_CLEAR_DATA_LOGOUT');
37+
3638
export const fetchUsers = () => {
3739
return async (dispatch, getState) => {
3840
dispatch(checkUserData());
@@ -120,6 +122,12 @@ export const clearUsersData = () => {
120122
};
121123
};
122124

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

@@ -252,6 +260,12 @@ export const modifyUser = ({
252260
.ref(`users/${id}`)
253261
.update(userData);
254262

263+
const { uid } = firebase.auth().currentUser;
264+
265+
if (id === uid) {
266+
dispatch(AUTH_UPDATE_USER_DATA({ ...userData, id }));
267+
}
268+
255269
try {
256270
await Promise.all([deleteLogoTask, uploadLogoTask, updateUserDbTask]);
257271
} catch (error) {

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)