Answer the question
In order to leave comments, you need to log in
React and backend. How to display users with their rights and present a situational set of buttons?
Good evening. I am currently writing (trying) a command system. Those. we pull the api server from the frontend, attach / detach existing users from the project, and also a simple search.
Everything should look like this schematically:
Участник [имя] [кнопка удаления участника]
Участник [имя] [кнопка удаления участника]
...
[форма поиска]
Найденный пользователь [Имя] [кнопка добавления пльзователя в участники]
...
Answer the question
In order to leave comments, you need to log in
Simple conditions will suffice for you:
render() {
const { me, project, users } = this.props;
const isMeModerator = isModerator(me);
const isMeCreator = me.id === project.creator_id;
const shouldShowSearchForm = isMeModerator || isMeCreator;
return (
<div>
{shouldShowSearchForm && <Search />}
<ul>
{users.map(user => {
const isUserCreator = user.id === project.creator_id;
const shouldShowDeleteButton = (isMeModerator || isMeCreator) && !isUserCreator;
return (
<li key={user.id}>
{user.name}
{shouldShowDeleteButton && <Button>Delete</Delete>}
{isUserCreator && <CreatorLabel />}
</li>
);
}}
</ul>
</div>
);
}
<PermissionsChecker requiredPermissions={permissions}>
<SomeComponent />
</PermissionsChecker>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question