1- import React , { memo , useEffect , useState } from 'react' ;
1+ import React , { memo } from 'react' ;
22import { View } from 'react-native' ;
3+ import { useNavigation } from '@react-navigation/native' ;
4+ import { shallowEqual } from 'react-redux' ;
35
46import * as List from '../../../../containers/List' ;
57import styles from './styles' ;
6- import { themes } from '../../../../lib/constants' ;
78import { useTheme } from '../../../../theme' ;
8- import { IUser } from '../../../../definitions' ;
99import { showConfirmationAlert } from '../../../../lib/methods/helpers/info' ;
1010import I18n from '../../../../i18n' ;
1111import { changeLivechatStatus , isOmnichannelStatusAvailable } from '../../lib' ;
1212import OmnichannelQueue from './OmnichannelQueue' ;
1313import { isOmnichannelModuleAvailable } from '../../../../lib/methods' ;
1414import Switch from '../../../../containers/Switch' ;
15+ import { useAppSelector } from '../../../../lib/hooks/useAppSelector' ;
16+ import { getUserSelector } from '../../../../selectors/login' ;
17+ import { events , logEvent } from '../../../../lib/methods/helpers/log' ;
18+ import { getInquiryQueueSelector } from '../../selectors/inquiry' ;
1519
16- interface IOmnichannelStatus {
17- searching : boolean ;
18- goQueue : ( ) => void ;
19- queueSize : number ;
20- inquiryEnabled : boolean ;
21- user : IUser ;
22- }
20+ const OmnichannelStatus = memo ( ( ) => {
21+ const { colors } = useTheme ( ) ;
22+ const { roles , statusLivechat } = useAppSelector ( state => getUserSelector ( state ) , shallowEqual ) ;
23+ const inquiryEnabled = useAppSelector ( state => state . inquiry . enabled ) ;
24+ const queueSize = useAppSelector ( state => getInquiryQueueSelector ( state ) . length ) ;
25+ const isMasterDetail = useAppSelector ( state => state . app . isMasterDetail ) ;
26+ const navigation = useNavigation < any > ( ) ;
2327
24- const OmnichannelStatus = memo ( ( { searching, goQueue, queueSize, user } : IOmnichannelStatus ) => {
25- const { theme } = useTheme ( ) ;
26- const [ status , setStatus ] = useState ( isOmnichannelStatusAvailable ( user ) ) ;
27-
28- useEffect ( ( ) => {
29- setStatus ( isOmnichannelStatusAvailable ( user ) ) ;
30- } , [ user . statusLivechat ] ) ;
31-
32- if ( searching || ! ( isOmnichannelModuleAvailable ( ) && user ?. roles ?. includes ( 'livechat-agent' ) ) ) {
28+ if ( ! ( isOmnichannelModuleAvailable ( ) && roles ?. includes ( 'livechat-agent' ) ) ) {
3329 return null ;
3430 }
3531
3632 const toggleLivechat = async ( ) => {
37- // if not-available, prompt to change to available
38- if ( ! isOmnichannelStatusAvailable ( user ) ) {
33+ if ( ! isOmnichannelStatusAvailable ( statusLivechat ) ) {
3934 showConfirmationAlert ( {
4035 message : I18n . t ( 'Omnichannel_enable_alert' ) ,
4136 confirmationText : I18n . t ( 'Yes' ) ,
@@ -49,29 +44,42 @@ const OmnichannelStatus = memo(({ searching, goQueue, queueSize, user }: IOmnich
4944 } ) ;
5045 } else {
5146 try {
52- setStatus ( v => ! v ) ;
5347 await changeLivechatStatus ( ) ;
5448 } catch {
55- setStatus ( v => ! v ) ;
49+ // Do nothing
5650 }
5751 }
5852 } ;
5953
54+ const goQueue = ( ) => {
55+ logEvent ( events . RL_GO_QUEUE ) ;
56+
57+ if ( ! inquiryEnabled ) {
58+ return ;
59+ }
60+
61+ if ( isMasterDetail ) {
62+ navigation . navigate ( 'ModalStackNavigator' , { screen : 'QueueListView' } ) ;
63+ } else {
64+ navigation . navigate ( 'QueueListView' ) ;
65+ }
66+ } ;
67+
6068 return (
6169 < >
6270 < List . Item
6371 title = 'Omnichannel'
64- color = { themes [ theme ] . fontDefault }
72+ color = { colors . fontDefault }
6573 onPress = { toggleLivechat }
66- additionalAcessibilityLabel = { status }
74+ additionalAcessibilityLabel = { statusLivechat }
6775 right = { ( ) => (
6876 < View style = { styles . omnichannelRightContainer } >
69- < Switch value = { status } onValueChange = { toggleLivechat } />
77+ < Switch value = { isOmnichannelStatusAvailable ( statusLivechat ) } onValueChange = { toggleLivechat } />
7078 </ View >
7179 ) }
7280 />
7381 < List . Separator />
74- { status ? < OmnichannelQueue queueSize = { queueSize } onPress = { goQueue } /> : null }
82+ { isOmnichannelStatusAvailable ( statusLivechat ) ? < OmnichannelQueue queueSize = { queueSize } onPress = { goQueue } /> : null }
7583 </ >
7684 ) ;
7785} ) ;
0 commit comments