Skip to content

Commit

Permalink
Merge pull request #534 from AI4Bharat/CL-618
Browse files Browse the repository at this point in the history
fixed role editing issue
  • Loading branch information
harsh12-99 authored Jan 10, 2024
2 parents 49b1b56 + 8342be4 commit d94068c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
8 changes: 1 addition & 7 deletions src/config/profileConfigs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { availability, roles } from "../utils/utils";
import { availability } from "../utils/utils";

export const profileOptions = [
{
Expand Down Expand Up @@ -26,12 +26,6 @@ export const profileOptions = [
name: "username",
type: "textField",
},
{
title: "Role",
name: "role",
type: "select",
iterator: roles,
},
{
title: "Availability Status",
name: "availability",
Expand Down
28 changes: 24 additions & 4 deletions src/containers/UserManagement/EditProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
UpdateProfileAPI,
setSnackBar,
UpdateUserRoleAPI,
FetchUserRolesAPI,
} from "redux/actions";

const EditProfile = () => {
Expand Down Expand Up @@ -85,9 +86,15 @@ const EditProfile = () => {
(state) => state.getSupportedLanguages.translationLanguage
);
const apiStatus = useSelector((state) => state.apiStatus);
const userRoles = useSelector((state) => state.getUserRoles.data);

const getUserRolesList = () => {
const userObj = new FetchUserRolesAPI();
dispatch(APITransport(userObj));
};

useEffect(() => {
if (loggedInUserData && loggedInUserData.length) {
if (loggedInUserData && loggedInUserData.id) {
const {
organization: { organization_owner },
} = loggedInUserData;
Expand Down Expand Up @@ -133,6 +140,7 @@ const EditProfile = () => {
getUserData();
getLoggedInUserData();
getOrgList();
getUserRolesList();

const langObj = new FetchSupportedLanguagesAPI("TRANSLATION");
dispatch(APITransport(langObj));
Expand Down Expand Up @@ -334,6 +342,12 @@ const EditProfile = () => {
profileLabels.current = [...profileOptions];

profileLabels.current.push(
{
title: "Role",
name: "role",
type: "select",
iterator: userRoles,
},
{
title: "Organization",
name: "org",
Expand All @@ -353,7 +367,11 @@ const EditProfile = () => {
const { id: userId, role } = loggedInUserData;

if (userId === +id) {
if (role === "ADMIN" || userId === orgOwnerId) {
if (
role === "ADMIN" ||
userId === orgOwnerId ||
role === "PROJECT_MANAGER"
) {
if (roleIsEdited) {
updateRole();
}
Expand Down Expand Up @@ -403,7 +421,8 @@ const EditProfile = () => {

{(loggedInUserData.id === +id ||
loggedInUserData.role === "ADMIN" ||
loggedInUserData.id === orgOwnerId) && (
loggedInUserData.id === orgOwnerId ||
loggedInUserData.role === "PROJECT_MANAGER") && (
<Grid item xs={12} sm={12} md={3} lg={3} xl={3}>
<Button
variant="outlined"
Expand All @@ -422,7 +441,8 @@ const EditProfile = () => {

{(loggedInUserData.id === +id ||
loggedInUserData.role === "ADMIN" ||
loggedInUserData.id === orgOwnerId) && (
loggedInUserData.id === orgOwnerId ||
loggedInUserData.role === "PROJECT_MANAGER") && (
<Grid
container
direction="row"
Expand Down

0 comments on commit d94068c

Please sign in to comment.