Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/state/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { toastr } from 'react-redux-toastr';

import { firebaseError, FIREBASE_RESPONSE } from 'utils';
import firebase from 'firebase.js';
import { clearUsersData } from './users';
import { clearUsersDataLogout } from './users';

export const AUTH_SIGN_IN_INIT = createAction('AUTH_SIGN_IN_INIT');
export const AUTH_SIGN_IN_FAIL = createAction('AUTH_SIGN_IN_FAIL');
Expand Down Expand Up @@ -65,7 +65,7 @@ export const logout = () => {
return async dispatch => {
dispatch(AUTH_LOGOUT_INIT());

dispatch(clearUsersData());
dispatch(clearUsersDataLogout());
await firebase.auth().signOut();

dispatch(AUTH_LOGOUT_SUCCESS());
Expand Down
8 changes: 8 additions & 0 deletions src/state/actions/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const USERS_MODIFY_USER_FAIL = createAction('USERS_MODIFY_USER_FAIL');

export const USERS_CLEAN_UP = createAction('USERS_CLEAN_UP');

export const USERS_CLEAR_DATA_LOGOUT = createAction('USERS_CLEAR_DATA_LOGOUT');

export const fetchUsers = () => {
return async (dispatch, getState) => {
dispatch(checkUserData());
Expand Down Expand Up @@ -121,6 +123,12 @@ export const clearUsersData = () => {
};
};

export const clearUsersDataLogout = () => {
return dispatch => {
dispatch(USERS_CLEAR_DATA_LOGOUT());
};
};

const uploadLogo = (uid, file) => {
const storageRef = firebase.storage().ref();

Expand Down
6 changes: 5 additions & 1 deletion src/state/reducers/users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
USERS_MODIFY_USER_INIT,
USERS_MODIFY_USER_SUCCESS,
USERS_MODIFY_USER_FAIL,
USERS_CLEAN_UP
USERS_CLEAN_UP,
USERS_CLEAR_DATA_LOGOUT
} from 'state/actions/users';

const initialState = {
Expand Down Expand Up @@ -112,6 +113,9 @@ export const usersReducer = createReducer(
error: null,
success: false,
deleted: false
}),
[USERS_CLEAR_DATA_LOGOUT]: () => ({
...initialState
})
},
initialState
Expand Down
29 changes: 26 additions & 3 deletions src/state/reducers/users/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
USERS_MODIFY_USER_INIT,
USERS_MODIFY_USER_SUCCESS,
USERS_MODIFY_USER_FAIL,
USERS_CLEAN_UP
USERS_CLEAN_UP,
USERS_CLEAR_DATA_LOGOUT
} from 'state/actions/users';

import { usersReducer } from '.';
Expand Down Expand Up @@ -90,8 +91,30 @@ describe('Establishments reducer', () => {
});
});

it('should reset the state to the initial state when USERS_CLEAR_DATA action is fired', () => {
reducerTest(initialState, USERS_CLEAR_DATA(), initialState);
it('should reset the state to the initial state when USERS_CLEAR_DATA_LOGOUT action is fired', () => {
reducerTest(initialState, USERS_CLEAR_DATA_LOGOUT(), initialState);
});

it('should reset the state to the initial state while maintaining the data when USERS_CLEAR_DATA action is fired', () => {
const userData = [
{
name: 'Test name',
email: 'Test email',
location: 'Test location',
createdAt: '11/20/2020'
}
];

reducerTest(
{
...initialState,
data: userData,
loading: true,
error: null
},
USERS_CLEAR_DATA(),
{ ...initialState, data: userData }
);
});

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