Skip to content

Commit

Permalink
feature: add actions and reducers to fetch groups a member is a part of
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakib Ansary committed Jul 28, 2021
1 parent 0fece44 commit 51d96a6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions __tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Object {
"dropGroups": [Function],
"getGroupsDone": [Function],
"getGroupsInit": [Function],
"getMemberGroups": [Function],
},
"looker": Object {
"getLookerDone": [Function],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
"test": "npm run lint && npm run jest"
},
"version": "1.1.8",
"version": "1000.27.14",
"dependencies": {
"auth0-js": "^6.8.4",
"config": "^3.2.0",
Expand Down
11 changes: 11 additions & 0 deletions src/actions/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,21 @@ function getGroupsDone(groupIds, tokenV3) {
return getService(tokenV3).getGroupMap(groupIds);
}

/**
* Get groups that a member belong to
* @param {*} userId the member's userId
* @param {*} tokenV3 the member's token
* @returns
*/
function getMemberGroups(userId, tokenV3) {
return getService(tokenV3).getMemberGroups(userId);
}

export default createActions({
GROUPS: {
DROP_GROUPS: dropGroups,
GET_GROUPS_INIT: getGroupsInit,
GET_GROUPS_DONE: getGroupsDone,
GET_MEMBER_GROUPS: getMemberGroups,
},
});
7 changes: 7 additions & 0 deletions src/reducers/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ function onGetGroupsDone(state, action) {
return { ...state, groups, loading };
}


function onGetMemberGroups(state, action) {
return { ...state, memberGroups: action.payload };
}

/**
* Creates a new Groups reducer with the specified initial state.
* @param {Object} initialState Optional. Initial state.
Expand All @@ -95,9 +100,11 @@ function create(initialState) {
[a.dropGroups]: onDropGroups,
[a.getGroupsInit]: onGetGroupsInit,
[a.getGroupsDone]: onGetGroupsDone,
[a.getMemberGroups]: onGetMemberGroups,
}, _.defaults(initialState ? _.clone(initialState) : {}, {
groups: {},
loading: {},
memberGroups: [],
}));
}

Expand Down
11 changes: 11 additions & 0 deletions src/services/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,17 @@ class GroupService {
getTokenV3() {
return this.private.tokenV3;
}

/**
* Gets the corresponding user's groups information
* @param {*} userId the userId
* @returns
*/
async getMemberGroups(userId) {
const url = `/groups/memberGroups/${userId}`;
const res = await this.private.api.get(url);
return handleApiResponse(res);
}
}

let lastInstance = null;
Expand Down

0 comments on commit 51d96a6

Please sign in to comment.