Skip to content

Commit 4eca3ce

Browse files
committed
Redux operations for getting group external attributes.
1 parent 6ddf208 commit 4eca3ce

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/redux/modules/groups.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const additionalActionTypes = {
3939
...createActionsWithPostfixes('LOCK_STUDENT_EXAM', 'recodex/groups'),
4040
...createActionsWithPostfixes('UNLOCK_STUDENT_EXAM', 'recodex/groups'),
4141
...createActionsWithPostfixes('RELOCATE', 'recodex/groups'),
42+
...createActionsWithPostfixes('GET_ATTRIBUTES', 'recodex/groups'),
4243
};
4344

4445
export const loadGroup = actions.pushResource;
@@ -164,6 +165,14 @@ export const relocateGroup = (groupId, newParentId) =>
164165
endpoint: `/groups/${groupId}/relocate/${newParentId}`,
165166
});
166167

168+
export const getGroupAttributes = groupId =>
169+
createApiAction({
170+
type: additionalActionTypes.GET_ATTRIBUTES,
171+
method: 'GET',
172+
endpoint: `/group-attributes/${groupId}`,
173+
meta: { groupId },
174+
});
175+
167176
/*
168177
* Exam-related stuff
169178
*/
@@ -323,6 +332,15 @@ const reducer = handleActions(
323332
state
324333
),
325334

335+
[additionalActionTypes.GET_ATTRIBUTES_PENDING]: (state, { meta: { groupId } }) =>
336+
state.setIn(['attributes', groupId], createRecord()),
337+
338+
[additionalActionTypes.GET_ATTRIBUTES_FULFILLED]: (state, { meta: { groupId }, payload: data }) =>
339+
state.setIn(['attributes', groupId], createRecord({ state: resourceStatus.FULFILLED, data })),
340+
341+
[additionalActionTypes.GET_ATTRIBUTES_REJECTED]: (state, { meta: { groupId }, payload: error }) =>
342+
state.setIn(['attributes', groupId], createRecord({ state: resourceStatus.FAILED, error })),
343+
326344
[additionalActionTypes.SET_EXAM_FLAG_PENDING]: (state, { meta: { groupId } }) =>
327345
state.setIn(['resources', groupId, 'pending-group-type'], true),
328346

src/redux/selectors/groups.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,5 @@ export const getGroupsAdmins = groups => {
170170
groups.forEach(group => group && group.primaryAdminsIds && group.primaryAdminsIds.forEach(id => ids.add(id)));
171171
return Array.from(ids);
172172
};
173+
174+
export const groupAttributesSelector = (state, groupId) => state.groups.getIn(['attributes', groupId], null);

0 commit comments

Comments
 (0)