Skip to content

Commit 51d96a6

Browse files
author
Rakib Ansary
committed
feature: add actions and reducers to fetch groups a member is a part of
1 parent 0fece44 commit 51d96a6

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

__tests__/__snapshots__/index.js.snap

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Object {
5353
"dropGroups": [Function],
5454
"getGroupsDone": [Function],
5555
"getGroupsInit": [Function],
56+
"getMemberGroups": [Function],
5657
},
5758
"looker": Object {
5859
"getLookerDone": [Function],

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
3232
"test": "npm run lint && npm run jest"
3333
},
34-
"version": "1.1.8",
34+
"version": "1000.27.14",
3535
"dependencies": {
3636
"auth0-js": "^6.8.4",
3737
"config": "^3.2.0",

src/actions/groups.js

+11
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,21 @@ function getGroupsDone(groupIds, tokenV3) {
4242
return getService(tokenV3).getGroupMap(groupIds);
4343
}
4444

45+
/**
46+
* Get groups that a member belong to
47+
* @param {*} userId the member's userId
48+
* @param {*} tokenV3 the member's token
49+
* @returns
50+
*/
51+
function getMemberGroups(userId, tokenV3) {
52+
return getService(tokenV3).getMemberGroups(userId);
53+
}
54+
4555
export default createActions({
4656
GROUPS: {
4757
DROP_GROUPS: dropGroups,
4858
GET_GROUPS_INIT: getGroupsInit,
4959
GET_GROUPS_DONE: getGroupsDone,
60+
GET_MEMBER_GROUPS: getMemberGroups,
5061
},
5162
});

src/reducers/groups.js

+7
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ function onGetGroupsDone(state, action) {
8484
return { ...state, groups, loading };
8585
}
8686

87+
88+
function onGetMemberGroups(state, action) {
89+
return { ...state, memberGroups: action.payload };
90+
}
91+
8792
/**
8893
* Creates a new Groups reducer with the specified initial state.
8994
* @param {Object} initialState Optional. Initial state.
@@ -95,9 +100,11 @@ function create(initialState) {
95100
[a.dropGroups]: onDropGroups,
96101
[a.getGroupsInit]: onGetGroupsInit,
97102
[a.getGroupsDone]: onGetGroupsDone,
103+
[a.getMemberGroups]: onGetMemberGroups,
98104
}, _.defaults(initialState ? _.clone(initialState) : {}, {
99105
groups: {},
100106
loading: {},
107+
memberGroups: [],
101108
}));
102109
}
103110

src/services/groups.js

+11
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,17 @@ class GroupService {
354354
getTokenV3() {
355355
return this.private.tokenV3;
356356
}
357+
358+
/**
359+
* Gets the corresponding user's groups information
360+
* @param {*} userId the userId
361+
* @returns
362+
*/
363+
async getMemberGroups(userId) {
364+
const url = `/groups/memberGroups/${userId}`;
365+
const res = await this.private.api.get(url);
366+
return handleApiResponse(res);
367+
}
357368
}
358369

359370
let lastInstance = null;

0 commit comments

Comments
 (0)