@@ -24,7 +24,7 @@ import {
2424 toggleChat
2525} from '../../actions.web' ;
2626import { CHAT_SIZE , ChatTabs , OPTION_GROUPCHAT , SMALL_WIDTH_THRESHOLD } from '../../constants' ;
27- import { getChatMaxSize } from '../../functions' ;
27+ import { getChatMaxSize , getFocusedTab , isChatDisabled } from '../../functions' ;
2828import { IChatProps as AbstractProps } from '../../types' ;
2929
3030import ChatHeader from './ChatHeader' ;
@@ -41,13 +41,18 @@ interface IProps extends AbstractProps {
4141 /**
4242 * The currently focused tab.
4343 */
44- _focusedTab : ChatTabs ;
44+ _focusedTab ? : ChatTabs ;
4545
4646 /**
4747 * True if the CC tab is enabled and false otherwise.
4848 */
4949 _isCCTabEnabled : boolean ;
5050
51+ /**
52+ * True if chat is disabled.
53+ */
54+ _isChatDisabled : boolean ;
55+
5156 /**
5257 * True if file sharing tab is enabled.
5358 */
@@ -217,6 +222,7 @@ const Chat = ({
217222 _isOpen,
218223 _isPollsEnabled,
219224 _isCCTabEnabled,
225+ _isChatDisabled,
220226 _isFileSharingTabEnabled,
221227 _focusedTab,
222228 _isResizing,
@@ -229,6 +235,11 @@ const Chat = ({
229235 dispatch,
230236 t
231237} : IProps ) => {
238+ // If no tabs are available, don't render the chat panel at all.
239+ if ( _isChatDisabled && ! _isPollsEnabled && ! _isCCTabEnabled && ! _isFileSharingTabEnabled ) {
240+ return null ;
241+ }
242+
232243 const { classes, cx } = useStyles ( { _isResizing, width : _width } ) ;
233244 const [ isMouseDown , setIsMouseDown ] = useState ( false ) ;
234245 const [ mousePosition , setMousePosition ] = useState < number | null > ( null ) ;
@@ -416,7 +427,7 @@ const Chat = ({
416427 return (
417428 < >
418429 { renderTabs ( ) }
419- < div
430+ { ! _isChatDisabled && ( < div
420431 aria-labelledby = { ChatTabs . CHAT }
421432 className = { cx (
422433 classes . chatPanel ,
@@ -442,7 +453,7 @@ const Chat = ({
442453 ) }
443454 < ChatInput
444455 onSend = { onSendMessage } />
445- </ div >
456+ </ div > ) }
446457 { _isPollsEnabled && (
447458 < >
448459 < div
@@ -484,17 +495,27 @@ const Chat = ({
484495 * @returns {ReactElement }
485496 */
486497 function renderTabs ( ) {
487- let tabs = [
488- {
498+ // The only way focused tab will be undefined is when no tab is enabled. Therefore this function won't be
499+ // executed because Chat component won't render anything. This should never happen but adding the check
500+ // here to make TS happy (when passing the _focusedTab in the selected prop for Tabs).
501+ if ( ! _focusedTab ) {
502+ return null ;
503+ }
504+
505+ let tabs = [ ] ;
506+
507+ // Only add chat tab if chat is not disabled.
508+ if ( ! _isChatDisabled ) {
509+ tabs . push ( {
489510 accessibilityLabel : t ( 'chat.tabs.chat' ) ,
490511 countBadge :
491512 _focusedTab !== ChatTabs . CHAT && _unreadMessagesCount > 0 ? _unreadMessagesCount : undefined ,
492513 id : ChatTabs . CHAT ,
493514 controlsId : `${ ChatTabs . CHAT } -panel` ,
494515 icon : IconMessage ,
495516 title : t ( 'chat.tabs.chat' )
496- }
497- ] ;
517+ } ) ;
518+ }
498519
499520 if ( _isPollsEnabled ) {
500521 tabs . push ( {
@@ -602,7 +623,7 @@ const Chat = ({
602623 * }}
603624 */
604625function _mapStateToProps ( state : IReduxState , _ownProps : any ) {
605- const { isOpen, focusedTab , messages, unreadMessagesCount, unreadFilesCount, width, isResizing } = state [ 'features/chat' ] ;
626+ const { isOpen, messages, unreadMessagesCount, unreadFilesCount, width, isResizing } = state [ 'features/chat' ] ;
606627 const { unreadPollsCount } = state [ 'features/polls' ] ;
607628 const _localParticipant = getLocalParticipant ( state ) ;
608629
@@ -611,8 +632,9 @@ function _mapStateToProps(state: IReduxState, _ownProps: any) {
611632 _isOpen : isOpen ,
612633 _isPollsEnabled : ! arePollsDisabled ( state ) ,
613634 _isCCTabEnabled : isCCTabEnabled ( state ) ,
635+ _isChatDisabled : isChatDisabled ( state ) ,
614636 _isFileSharingTabEnabled : isFileSharingEnabled ( state ) ,
615- _focusedTab : focusedTab ,
637+ _focusedTab : getFocusedTab ( state ) ,
616638 _messages : messages ,
617639 _unreadMessagesCount : unreadMessagesCount ,
618640 _unreadPollsCount : unreadPollsCount ,
0 commit comments