Skip to content

Commit 8046a7c

Browse files
committed
Changed users state from the redux store
1 parent c818131 commit 8046a7c

File tree

7 files changed

+30
-28
lines changed

7 files changed

+30
-28
lines changed

functions/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ node_modules/
1010
lib/
1111

1212
#Necessary config for testing
13-
env.json
13+
env.json
14+
15+
service-account-key.json

src/pages/User/User.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('<User /> rendering', () => {
88
it('should render without crashing', () => {
99
const { component } = shallowWithProviders(<User />)({
1010
users: {
11-
list: [],
11+
data: [],
1212
},
1313
});
1414

@@ -18,7 +18,7 @@ describe('<User /> rendering', () => {
1818
it('should not show the spinner when creating a user', () => {
1919
const { component } = mountWithProviders(<User />)({
2020
users: {
21-
list: [],
21+
data: [],
2222
},
2323
});
2424

@@ -28,7 +28,7 @@ describe('<User /> rendering', () => {
2828
it('should render the UserForm component when creating a user', () => {
2929
const { component } = mountWithProviders(<User />)({
3030
users: {
31-
list: [],
31+
data: [],
3232
},
3333
});
3434

src/pages/User/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const User = () => {
1616
const { success, userData, error } = useSelector(
1717
(state) => ({
1818
success: state.users.success,
19-
userData: state.users.list.find((user) => user.id === id),
19+
userData: state.users.data.find((user) => user.id === id),
2020
error: state.users.error,
2121
}),
2222
shallowEqual

src/pages/Users/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import classes from './Users.module.scss';
1414
const Users = () => {
1515
const { usersList, isAdmin, error, loading, deleted } = useSelector(
1616
(state) => ({
17-
usersList: state.users.list,
17+
usersList: state.users.data,
1818
isAdmin: state.auth.userData.isAdmin,
1919
error: state.users.error,
2020
loading: state.users.loading,

src/state/actions/users.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ export const fetchUsers = (userId = '') => {
5151
}
5252

5353
const user = { ...userData, id: userId };
54-
const users = getState().users.list;
54+
const users = getState().users.data;
5555
users.push(user);
5656

5757
return dispatch(
5858
USERS_FETCH_DATA_SUCCESS({
59-
list: users,
59+
data: users,
6060
})
6161
);
6262
}
@@ -81,7 +81,7 @@ export const fetchUsers = (userId = '') => {
8181

8282
return dispatch(
8383
USERS_FETCH_DATA_SUCCESS({
84-
list: usersData.filter((user) => user.id !== id),
84+
data: usersData.filter((user) => user.id !== id),
8585
})
8686
);
8787
};
@@ -100,7 +100,7 @@ export const deleteUser = (id) => {
100100
dispatch(USERS_DELETE_USER_INIT());
101101
const { locale } = getState().preferences;
102102
const { logoUrl } = getState()
103-
.users.list.filter((user) => user.id === id)
103+
.users.data.filter((user) => user.id === id)
104104
.pop();
105105

106106
const deleteLogoTask = logoUrl ? deleteLogo(logoUrl) : null;
@@ -236,7 +236,7 @@ export const modifyUser = ({
236236
const { locale } = getState().preferences;
237237
const { logoUrl } = isProfile
238238
? getState().auth.userData
239-
: getState().users.list.find((user) => user.id === id) ||
239+
: getState().users.data.find((user) => user.id === id) ||
240240
getState().users.user;
241241

242242
let deleteLogoTask;

src/state/reducers/users/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from 'state/actions/users';
1919

2020
const initialState = {
21-
list: [],
21+
data: [],
2222
loading: false,
2323
error: null,
2424
success: false,
@@ -33,7 +33,7 @@ export const usersReducer = createReducer(
3333
}),
3434
[USERS_FETCH_DATA_SUCCESS]: (state, payload) => ({
3535
...state,
36-
list: payload.list,
36+
data: payload.data,
3737
loading: false,
3838
error: null,
3939
}),
@@ -48,7 +48,7 @@ export const usersReducer = createReducer(
4848
}),
4949
[USERS_DELETE_USER_SUCCESS]: (state, payload) => ({
5050
...state,
51-
list: state.list.filter((elem) => elem.id !== payload.id),
51+
data: state.data.filter((elem) => elem.id !== payload.id),
5252
loading: false,
5353
error: null,
5454
deleted: true,
@@ -64,7 +64,7 @@ export const usersReducer = createReducer(
6464
}),
6565
[USERS_CREATE_USER_SUCCESS]: (state, payload) => ({
6666
...state,
67-
list: state.list.concat(payload.user),
67+
data: state.data.concat(payload.user),
6868
loading: false,
6969
error: null,
7070
success: true,
@@ -80,9 +80,9 @@ export const usersReducer = createReducer(
8080
}),
8181
[USERS_MODIFY_USER_SUCCESS]: (state, payload) => ({
8282
...state,
83-
list: !state.list
83+
data: !state.data
8484
? []
85-
: state.list.map((elem) => {
85+
: state.data.map((elem) => {
8686
if (elem.id === payload.id) {
8787
return {
8888
name: payload.user.name,

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { usersReducer } from '.';
1919

2020
describe('Establishments reducer', () => {
2121
const initialState = {
22-
list: [],
22+
data: [],
2323
loading: false,
2424
error: null,
2525
success: false,
@@ -47,7 +47,7 @@ describe('Establishments reducer', () => {
4747
});
4848
});
4949

50-
it('should set error to null, loading to false and list with the corresponding values when USERS_FETCH_DATA_SUCCESS actions is fired', () => {
50+
it('should set error to null, loading to false and data with the corresponding values when USERS_FETCH_DATA_SUCCESS actions is fired', () => {
5151
const userData = [
5252
{
5353
name: 'Test name',
@@ -57,26 +57,26 @@ describe('Establishments reducer', () => {
5757
},
5858
];
5959

60-
reducerTest(initialState, USERS_FETCH_DATA_SUCCESS({ list: userData }), {
60+
reducerTest(initialState, USERS_FETCH_DATA_SUCCESS({ data: userData }), {
6161
...initialState,
62-
list: userData,
62+
data: userData,
6363
loading: false,
6464
error: null,
6565
});
6666
});
6767

6868
it('should set error to null, loading to false and user with the corresponding values when USERS_FETCH_DATA_SUCCESS actions is fired', () => {
69-
const list = [
69+
const data = [
7070
{
7171
name: 'Test name',
7272
email: 'Test email',
7373
location: 'Test location',
7474
createdAt: '11/20/2020',
7575
},
7676
];
77-
reducerTest(initialState, USERS_FETCH_DATA_SUCCESS({ list }), {
77+
reducerTest(initialState, USERS_FETCH_DATA_SUCCESS({ data }), {
7878
...initialState,
79-
list,
79+
data,
8080
loading: false,
8181
error: null,
8282
});
@@ -93,7 +93,7 @@ describe('Establishments reducer', () => {
9393
const user = { id: 'exampleId' };
9494

9595
reducerTest(
96-
{ ...initialState, list: [user] },
96+
{ ...initialState, data: [user] },
9797
USERS_DELETE_USER_SUCCESS({ id: 'exampleId' }),
9898
{ ...initialState, error: null, loading: false, deleted: true }
9999
);
@@ -129,7 +129,7 @@ describe('Establishments reducer', () => {
129129

130130
reducerTest(initialState, USERS_CREATE_USER_SUCCESS({ user }), {
131131
...initialState,
132-
list: user,
132+
data: user,
133133
success: true,
134134
});
135135
});
@@ -170,14 +170,14 @@ describe('Establishments reducer', () => {
170170
};
171171

172172
reducerTest(
173-
{ ...initialState, list: initialUsers },
173+
{ ...initialState, data: initialUsers },
174174
USERS_MODIFY_USER_SUCCESS({
175175
user: resultUser,
176176
id: 'test id',
177177
}),
178178
{
179179
...initialState,
180-
list: [resultUser],
180+
data: [resultUser],
181181
loading: false,
182182
error: null,
183183
success: true,

0 commit comments

Comments
 (0)