1
- import React , { memo , useEffect , useState } from 'react' ;
1
+ import React , { memo } from 'react' ;
2
2
import { View } from 'react-native' ;
3
+ import { useNavigation } from '@react-navigation/native' ;
4
+ import { shallowEqual } from 'react-redux' ;
3
5
4
6
import * as List from '../../../../containers/List' ;
5
7
import styles from './styles' ;
6
- import { themes } from '../../../../lib/constants' ;
7
8
import { useTheme } from '../../../../theme' ;
8
- import { IUser } from '../../../../definitions' ;
9
9
import { showConfirmationAlert } from '../../../../lib/methods/helpers/info' ;
10
10
import I18n from '../../../../i18n' ;
11
11
import { changeLivechatStatus , isOmnichannelStatusAvailable } from '../../lib' ;
12
12
import OmnichannelQueue from './OmnichannelQueue' ;
13
13
import { isOmnichannelModuleAvailable } from '../../../../lib/methods' ;
14
14
import 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' ;
15
19
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 > ( ) ;
23
27
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' ) ) ) {
33
29
return null ;
34
30
}
35
31
36
32
const toggleLivechat = async ( ) => {
37
- // if not-available, prompt to change to available
38
- if ( ! isOmnichannelStatusAvailable ( user ) ) {
33
+ if ( ! isOmnichannelStatusAvailable ( statusLivechat ) ) {
39
34
showConfirmationAlert ( {
40
35
message : I18n . t ( 'Omnichannel_enable_alert' ) ,
41
36
confirmationText : I18n . t ( 'Yes' ) ,
@@ -49,29 +44,42 @@ const OmnichannelStatus = memo(({ searching, goQueue, queueSize, user }: IOmnich
49
44
} ) ;
50
45
} else {
51
46
try {
52
- setStatus ( v => ! v ) ;
53
47
await changeLivechatStatus ( ) ;
54
48
} catch {
55
- setStatus ( v => ! v ) ;
49
+ // Do nothing
56
50
}
57
51
}
58
52
} ;
59
53
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
+
60
68
return (
61
69
< >
62
70
< List . Item
63
71
title = 'Omnichannel'
64
- color = { themes [ theme ] . fontDefault }
72
+ color = { colors . fontDefault }
65
73
onPress = { toggleLivechat }
66
- additionalAcessibilityLabel = { status }
74
+ additionalAcessibilityLabel = { statusLivechat }
67
75
right = { ( ) => (
68
76
< View style = { styles . omnichannelRightContainer } >
69
- < Switch value = { status } onValueChange = { toggleLivechat } />
77
+ < Switch value = { isOmnichannelStatusAvailable ( statusLivechat ) } onValueChange = { toggleLivechat } />
70
78
</ View >
71
79
) }
72
80
/>
73
81
< List . Separator />
74
- { status ? < OmnichannelQueue queueSize = { queueSize } onPress = { goQueue } /> : null }
82
+ { isOmnichannelStatusAvailable ( statusLivechat ) ? < OmnichannelQueue queueSize = { queueSize } onPress = { goQueue } /> : null }
75
83
</ >
76
84
) ;
77
85
} ) ;
0 commit comments