hide app access when selected dashboard role is admin
This commit is contained in:
parent
4e25903847
commit
d4c4c6104f
1 changed files with 46 additions and 41 deletions
|
@ -11,6 +11,7 @@ import { UserModalProps } from './types';
|
|||
|
||||
export const UserModal = ({ open, onClose, userId, setUserId }: UserModalProps) => {
|
||||
const [deleteModal, setDeleteModal] = useState(false);
|
||||
const [isAdminRoleSelected, setAdminRoleSelected] = useState(true);
|
||||
const [isPersonalModal, setPersonalModal] = useState(false);
|
||||
const {
|
||||
user,
|
||||
|
@ -63,7 +64,9 @@ export const UserModal = ({ open, onClose, userId, setUserId }: UserModalProps)
|
|||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (dashboardRole === UserRole.Admin) {
|
||||
const isAdminDashboardRoleSelected = dashboardRole === UserRole.Admin;
|
||||
setAdminRoleSelected(isAdminDashboardRoleSelected);
|
||||
if (isAdminDashboardRoleSelected) {
|
||||
fields.forEach((field, index) => update(index, { name: field.name, role: UserRole.Admin }));
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
|
@ -197,13 +200,13 @@ export const UserModal = ({ open, onClose, userId, setUserId }: UserModalProps)
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{isAdmin && (
|
||||
{isAdmin && !userModalLoading && (
|
||||
<div>
|
||||
<div className="mt-8">
|
||||
<h3 className="text-lg leading-6 font-medium text-gray-900">App Access</h3>
|
||||
</div>
|
||||
|
||||
{dashboardRole === UserRole.Admin && (
|
||||
{isAdminRoleSelected && (
|
||||
<div className="sm:col-span-6">
|
||||
<Banner
|
||||
title="Admin users automatically have admin-level access to all apps."
|
||||
|
@ -212,8 +215,9 @@ export const UserModal = ({ open, onClose, userId, setUserId }: UserModalProps)
|
|||
</div>
|
||||
)}
|
||||
|
||||
{!isAdminRoleSelected && (
|
||||
<div>
|
||||
<div className={`flow-root mt-6 ${dashboardRole === UserRole.Admin ? 'opacity-70' : ''}`}>
|
||||
<div className="flow-root mt-6">
|
||||
<ul className="-my-5 divide-y divide-gray-200">
|
||||
{fields.map((item, index) => {
|
||||
if (item.name === 'dashboard') {
|
||||
|
@ -238,7 +242,7 @@ export const UserModal = ({ open, onClose, userId, setUserId }: UserModalProps)
|
|||
key={item.id}
|
||||
control={control}
|
||||
name={`app_roles.${index}.role`}
|
||||
disabled={dashboardRole === UserRole.Admin}
|
||||
disabled={isAdminRoleSelected}
|
||||
options={[
|
||||
{ value: UserRole.NoAccess, name: 'No Access' },
|
||||
{ value: UserRole.User, name: 'User' },
|
||||
|
@ -253,6 +257,7 @@ export const UserModal = ({ open, onClose, userId, setUserId }: UserModalProps)
|
|||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue