@@ -5,13 +5,15 @@ import {
55 Notification ,
66} from '@appquality/unguess-design-system' ;
77import { useTranslation } from 'react-i18next' ;
8+ import { appTheme } from 'src/app/theme' ;
89
910import { ReactComponent as EyeIconFill } from 'src/assets/icons/eye-icon-fill.svg' ;
1011import { ReactComponent as EyeIconSlash } from 'src/assets/icons/eye-icon-slash.svg' ;
1112import {
1213 useGetUsersMeQuery ,
1314 usePostPlansByPidWatchersMutation ,
1415} from 'src/features/api' ;
16+ import { useCanAccessToActiveWorkspace } from 'src/hooks/useCanAccessToActiveWorkspace' ;
1517import { useIsLastOne } from './hooks/useIsLastOne' ;
1618import { useIsWatching } from './hooks/useIsWatching' ;
1719import { useRemoveWatcher } from './hooks/useRemoveWatcher' ;
@@ -22,15 +24,26 @@ const WatchButton = ({ planId }: { planId: string }) => {
2224 const { addToast } = useToast ( ) ;
2325 const { removeWatcher } = useRemoveWatcher ( ) ;
2426 const [ addUser ] = usePostPlansByPidWatchersMutation ( ) ;
27+ const hasWorkspaceAccess = useCanAccessToActiveWorkspace ( ) ;
2528 const { data : currentUser } = useGetUsersMeQuery ( ) ;
2629 const { t } = useTranslation ( ) ;
2730
31+ const isLastWatcher = isWatching && isLastOne ;
32+
33+ const iconColor = ( ( ) => {
34+ if ( ! isWatching ) return '#fff' ;
35+ if ( isLastOne ) return appTheme . palette . grey [ 400 ] ;
36+ return undefined ;
37+ } ) ( ) ;
38+
39+ const EyeIcon = isWatching ? EyeIconSlash : EyeIconFill ;
40+
2841 if ( ! currentUser ) return null ;
2942
3043 const button = (
3144 < Button
3245 isStretched
33- disabled = { isLastOne && isWatching }
46+ disabled = { ! ! hasWorkspaceAccess !== ! ! isLastWatcher }
3447 isPrimary = { ! isWatching }
3548 onClick = { ( ) => {
3649 if ( isWatching ) {
@@ -80,23 +93,29 @@ const WatchButton = ({ planId }: { planId: string }) => {
8093 } }
8194 >
8295 < div style = { { display : 'flex' , gap : '8px' , alignItems : 'center' } } >
83- { isWatching ? < EyeIconSlash /> : < EyeIconFill color = "#fff" /> }
96+ < EyeIcon color = { iconColor } />
97+
8498 { isWatching
8599 ? t ( '__PLAN_PAGE_WATCHER_LIST_MODAL_UNFOLLOW_BUTTON' )
86100 : t ( '__PLAN_PAGE_WATCHER_LIST_MODAL_FOLLOW_BUTTON' ) }
87101 </ div >
88102 </ Button >
89103 ) ;
90104
91- if ( isLastOne && isWatching ) {
105+ // condition is true only when one value is truthy and the other is falsy, otherwise it's false
106+ if ( ! ! hasWorkspaceAccess !== ! ! isLastWatcher ) {
92107 return (
93108 < Tooltip
94109 placement = "start"
95110 type = "light"
96111 size = "medium"
97- content = { t (
98- '__PLAN_PAGE_WATCHER_LIST_MODAL_UNFOLLOW_BUTTON_DISABLED_TOOLTIP'
99- ) }
112+ content = {
113+ isLastWatcher
114+ ? t (
115+ '__PLAN_PAGE_WATCHER_LIST_MODAL_UNFOLLOW_BUTTON_DISABLED_TOOLTIP'
116+ )
117+ : t ( '__PLAN_PAGE_WATCHER_LIST_MODAL_FOLLOW_BUTTON_DISABLED_TOOLTIP' )
118+ }
100119 >
101120 { /* the following div is necessary to make Tooltip work with disabled Button */ }
102121 < div > { button } </ div >
0 commit comments