Explorar o código

Don't show user link if user mgmt. isn't available

This is applicable to the user details page link found in all the pages
containing the user details dropdown.
Sergiu Miclea %!s(int64=7) %!d(string=hai) anos
pai
achega
996d5e9bf7
Modificáronse 1 ficheiros con 11 adicións e 4 borrados
  1. 11 4
      src/components/molecules/UserDropdown/UserDropdown.jsx

+ 11 - 4
src/components/molecules/UserDropdown/UserDropdown.jsx

@@ -20,7 +20,8 @@ import styled, { css } from 'styled-components'
 
 
 import Palette from '../../styleUtils/Palette'
 import Palette from '../../styleUtils/Palette'
 import StyleProps from '../../styleUtils/StyleProps'
 import StyleProps from '../../styleUtils/StyleProps'
-
+import { navigationMenu } from '../../../config'
+import type { User } from '../../../types/User'
 import userImage from './images/user.svg'
 import userImage from './images/user.svg'
 import userWhiteImage from './images/user-white.svg'
 import userWhiteImage from './images/user-white.svg'
 
 
@@ -91,7 +92,7 @@ const Username = styled.a`
   color: ${Palette.black};
   color: ${Palette.black};
   text-decoration: none;
   text-decoration: none;
   &:hover {
   &:hover {
-    color: ${Palette.primary};
+    color: ${props => props.href ? Palette.primary : 'inherit'};
   }
   }
 `
 `
 const Email = styled.div`
 const Email = styled.div`
@@ -102,7 +103,6 @@ const Email = styled.div`
   border-bottom: 1px solid ${Palette.grayscale[3]};
   border-bottom: 1px solid ${Palette.grayscale[3]};
 `
 `
 
 
-type User = { name: string, email: string, id: string }
 type DictItem = { label: string, value: string }
 type DictItem = { label: string, value: string }
 type Props = {
 type Props = {
   onItemClick: (item: DictItem) => void,
   onItemClick: (item: DictItem) => void,
@@ -165,6 +165,13 @@ class UserDropdown extends React.Component<Props, State> {
     if (!this.props.user) {
     if (!this.props.user) {
       return null
       return null
     }
     }
+
+    let href: ?string
+    let isAdmin = this.props.user.isAdmin
+    if (isAdmin && navigationMenu.find(m => m.value === 'users' && !m.disabled && (!m.requiresAdmin || isAdmin))) {
+      href = `#/user/${this.props.user.id}`
+    }
+
     return (
     return (
       <ListHeader
       <ListHeader
         onMouseDown={() => { this.itemMouseDown = true }}
         onMouseDown={() => { this.itemMouseDown = true }}
@@ -172,7 +179,7 @@ class UserDropdown extends React.Component<Props, State> {
       >
       >
         <Username
         <Username
           data-test-id="userDropdown-username"
           data-test-id="userDropdown-username"
-          href={`#/user/${this.props.user.id}`}
+          href={href}
         >{this.props.user.name}</Username>
         >{this.props.user.name}</Username>
         <Email>{this.props.user.email}</Email>
         <Email>{this.props.user.email}</Email>
       </ListHeader>
       </ListHeader>