-
Notifications
You must be signed in to change notification settings - Fork 383
/
usergroups.js
126 lines (120 loc) · 3.54 KB
/
usergroups.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* Copyright 2016, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import {
GETGROUPS,
SEARCHUSERS,
EDITGROUP,
EDITGROUPDATA,
DELETEGROUP,
UPDATEGROUP,
SEARCHTEXTCHANGED
} from '../actions/usergroups';
import assign from 'object-assign';
function usergroups(state = {
start: 0,
limit: 12
}, action) {
switch (action.type) {
case GETGROUPS:
return assign({}, state, {
searchText: action.searchText,
status: action.status,
groups: action.status === "loading" ? state.groups : action.groups,
start: action.start,
limit: action.limit,
totalCount: action.status === "loading" ? state.totalCount : action.totalCount
});
case SEARCHTEXTCHANGED: {
return assign({}, state, {
searchText: action.text
});
}
case EDITGROUP: {
let newGroup = action.status ? {
status: action.status,
...action.group
} : action.group;
if (state.currentGroup && action.group && state.currentGroup.id === action.group.id ) {
return assign({}, state, {
currentGroup: assign({}, state.currentGroup, {
status: action.status,
...action.group
})}
);
// this to catch user loaded but window already closed
} else if (action.status === "loading" || action.status === "new" || !action.status) {
return assign({}, state, {
currentGroup: newGroup
});
}
return state;
}
case EDITGROUPDATA: {
let k = action.key;
let currentGroup = state.currentGroup;
currentGroup = assign({}, currentGroup, {[k]: action.newValue} );
return assign({}, state, {
currentGroup: assign({}, {...currentGroup, status: "modified"})
});
}
case UPDATEGROUP: {
let currentGroup = state.currentGroup;
return assign({}, state, {
currentGroup: assign({}, {
...currentGroup,
...action.group,
status: action.status,
lastError: action.error
})
});
}
case DELETEGROUP: {
if (action.status === "deleted" || action.status === "cancelled") {
return assign({}, state, {
deletingGroup: null
});
}
return assign({}, state, {
deletingGroup: {
id: action.id,
status: action.status,
error: action.error
}
});
}
case SEARCHUSERS: {
switch (action.status) {
case "loading": {
return assign({}, state, {
availableUsersError: null,
availableUsersLoading: true
});
}
case "success": {
return assign({}, state, {
availableUsersError: null,
availableUsersLoading: false,
availableUsers: action.users,
availableUsersCount: action.count
});
}
case "error": {
return assign({}, state, {
availableUsersError: action.error,
availableUsersLoading: false
});
}
default:
return state;
}
}
default:
return state;
}
}
export default usergroups;