Skip to content

Commit

Permalink
Fix broken community admin links in user profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
hevp committed Feb 15, 2021
1 parent c19d71a commit 7632686
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions webui/src/components/user.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ export const UserProfile = React.createClass({
);
},

createLink(communitiesList, name){
return <Link to={`/communities/${communitiesList[name.replace(new RegExp("(^com:|:[^:]*$)",'g'),"")]}/admin`}> (admin page)</Link>
createLink(communitiesMapping, name) {
return <Link to={`/communities/${communitiesMapping[name.replace(new RegExp("(^com:|:[^:]*$)",'g'),"")]}/admin`}> (admin page)</Link>
},

listRoles(roles, communitiesList){
listRoles(roles, communitiesMapping) {
return roles.map(r =>
<li key={r.get('name')}>
{r.get('description')}
{r.get('name').includes(':admin')? this.createLink(communitiesList, r.get('name')) : ""}
{r.get('name').includes(':admin')? this.createLink(communitiesMapping, r.get('name')) : ""}
</li>)
},

Expand All @@ -129,11 +129,13 @@ export const UserProfile = React.createClass({
return this.renderNoUser();
}
const roles = user.get('roles');
const communitiesListTemp = serverCache.getCommunities();
var communitiesList = communitiesListTemp.reduce(function(map, community){
map[community.get('id').replace(new RegExp("-",'g'),"")] = community.get('name');
return map;
});
const communitiesList = serverCache.getCommunities();
if (communitiesList.size) {
var communitiesMapping = communitiesList.reduce((map, community) => {
map[community.get('id').replace(new RegExp("-",'g'),"")] = community.get('name');
return map;
}, {});
}
return (
<div className="bottom-line">
<h1>User Profile</h1>
Expand All @@ -145,7 +147,7 @@ export const UserProfile = React.createClass({
<div className="row">
<h3>Roles</h3>
<p>
{roles && roles.count() && typeof(communitiesList) !== "undefined" ? this.listRoles(roles, communitiesList) : "You have no assigned roles" }
{(roles && roles.count() && communitiesMapping !== undefined) ? this.listRoles(roles, communitiesMapping) : "You have no assigned roles" }
</p>
</div>
<div className="row">
Expand Down

0 comments on commit 7632686

Please sign in to comment.