From d4c4c6104f6c5e6d22a11f6a7a692a1262518bb9 Mon Sep 17 00:00:00 2001 From: Davor Date: Wed, 13 Jul 2022 12:05:20 +0200 Subject: [PATCH] hide app access when selected dashboard role is admin --- src/components/UserModal/UserModal.tsx | 87 ++++++++++++++------------ 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/src/components/UserModal/UserModal.tsx b/src/components/UserModal/UserModal.tsx index aa25589..2828a29 100644 --- a/src/components/UserModal/UserModal.tsx +++ b/src/components/UserModal/UserModal.tsx @@ -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) - {isAdmin && ( + {isAdmin && !userModalLoading && (

App Access

- {dashboardRole === UserRole.Admin && ( + {isAdminRoleSelected && (
)} -
-
-
    - {fields.map((item, index) => { - if (item.name === 'dashboard') { - return null; - } + {!isAdminRoleSelected && ( +
    +
    +
      + {fields.map((item, index) => { + if (item.name === 'dashboard') { + return null; + } - return ( -
    • -
      -
      - {item.name -

      - {_.find(appAccessList, ['name', item.name!])?.label} -

      + return ( +
    • +
      +
      + {item.name +

      + {_.find(appAccessList, ['name', item.name!])?.label} +

      +
      +
      + -
      -
      -
    • - ); - })} -
    + + ); + })} +
+
-
+ )}
)}