Skip to content

Commit

Permalink
Merge pull request #19 from vijayg10/feature/change-user-role-assignm…
Browse files Browse the repository at this point in the history
…ent-api

feat: change user role assignment api
  • Loading branch information
vijayg10 authored Jan 14, 2022
2 parents b42cd85 + b26f5f0 commit 014c822
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/reporting-hub-bop-role-ui",
"version": "1.5.0",
"version": "1.5.1",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/App/UserProfile/connectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { RolesDelta, ParticipantsDelta, RoleDeletionItem, ParticipantDeletionIte
const mapStatePropsUserProfile = (state: State) => ({
userProfile: selectors.getUserProfile(state),
userProfileError: selectors.getUserProfileError(state),
userProfileRolesError: selectors.getUserProfileRolesError(state),
isUserProfileRequestPending: selectors.getIsUserProfileRequestPending(state),
showChangeRolesModal: selectors.showChangeRolesModal(state),
showParticipantsRolesModal: selectors.showParticipantsRolesModal(state),
Expand Down
25 changes: 14 additions & 11 deletions src/App/UserProfile/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,22 @@ function* updateUserRoles(action: PayloadAction<RolesDelta>) {
roleOperations: roleDelta,
},
};
try {
const userResponse = (yield call(api.userRoles.modify, requestBody)) as MakeResponse<null>;
if (userResponse.status !== 200) {
throw new Error(JSON.stringify(userResponse));
}

const userResponse = (yield call(api.userRoles.modify, requestBody)) as MakeResponse<null>;
if (userResponse.status !== 200) {
throw new Error(JSON.stringify(userResponse));
}

const assignedRolesResponse = (yield call(api.userRoles.read, {
id: action.payload.id,
})) as MakeResponse<FetchRolesResponse>;
if (assignedRolesResponse.status !== 200) {
throw new Error(JSON.stringify(assignedRolesResponse));
const assignedRolesResponse = (yield call(api.userRoles.read, {
id: action.payload.id,
})) as MakeResponse<FetchRolesResponse>;
if (assignedRolesResponse.status !== 200) {
throw new Error(JSON.stringify(assignedRolesResponse));
}
yield put(actions.setUserProfileRoles(assignedRolesResponse.data.roles));
} catch (e) {
yield put(actions.setUserProfileRolesError(e.message));
}
yield put(actions.setUserProfileRoles(assignedRolesResponse.data.roles));
}

function* updateUserParticipants(action: PayloadAction<ParticipantsDelta>) {
Expand Down
1 change: 1 addition & 0 deletions src/App/UserProfile/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { State } from 'store/types';
// user profile selectors
export const getUserProfile = (state: State) => state.userProfile.userProfile;
export const getUserProfileError = (state: State) => state.userProfile.userProfileError;
export const getUserProfileRolesError = (state: State) => state.userProfile.userProfileRolesError;
export const getIsUserProfileRequestPending = (state: State) =>
state.userProfile.isUserProfileRequestPending;

Expand Down
7 changes: 7 additions & 0 deletions src/App/UserProfile/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
export const initialState: UserProfileState = {
userProfile: null,
userProfileError: null,
userProfileRolesError: null,
isUserProfileRequestPending: true,
showChangeRolesModal: false,
showChangeParticipantsModal: false,
Expand Down Expand Up @@ -98,6 +99,12 @@ const slice = createSlice({
},
};
},
setUserProfileRolesError(state: UserProfileState, action: PayloadAction<string>) {
return {
...state,
userProfileRolesError: action.payload,
};
},
requestUserProfileParticipantsUpdate(
state: UserProfileState,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
1 change: 1 addition & 0 deletions src/App/UserProfile/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface UserProfile {
export interface UserProfileState {
userProfile: UserProfile | null;
userProfileError: string | null;
userProfileRolesError: string | null;
isUserProfileRequestPending: boolean;
showChangeRolesModal: boolean;
showChangeParticipantsModal: boolean;
Expand Down
11 changes: 11 additions & 0 deletions src/App/UserProfile/views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const participantColumns = [
function UserProfile({
userProfile,
userProfileError,
userProfileRolesError,
isUserProfileRequestPending,
showChangeRolesModal,
showParticipantsRolesModal,
Expand Down Expand Up @@ -92,6 +93,15 @@ function UserProfile({
});
});

let userProfileRolesErrorContent = null;
if (userProfileRolesError) {
userProfileRolesErrorContent = (
<MessageBox kind="danger">
Error updating the user roles: {userProfileRolesError}
</MessageBox>
);
}

content = (
<div>
<Heading size="3">{userProfile!.username}</Heading>
Expand All @@ -107,6 +117,7 @@ function UserProfile({
/>
<Table columns={roleColumns} rows={roleRows} flexible />
</div>
{userProfileRolesErrorContent}
<div className="userProfile__participants">
<Heading size="4">Participant Companies</Heading>
<Button
Expand Down

0 comments on commit 014c822

Please sign in to comment.