@@ -4,20 +4,23 @@ import './ActiveConversationsTable.css';
44import { GuxButton , GuxTable , GuxRadialLoading } from 'genesys-spark-components-react' ;
55import { useSelector } from 'react-redux' ;
66import Card from './Card' ;
7+ import { RootState } from '../types/store' ;
8+ import { IStoredConversationState } from 'genesys-cloud-webrtc-sdk' ;
79
810
911export default function ActiveConversationsTable ( ) {
10- const conversations = useSelector (
11- ( state ) => state . conversations . activeConversations
12+ const conversationsObj = useSelector (
13+ ( state : RootState ) => state . conversations . activeConversations
1214 ) ;
15+ const conversations = Object . values ( conversationsObj ) ;
1316 const { endSession, toggleAudioMute, toggleHoldState } = useSdk ( ) ;
1417 const [ holdLabels , setHoldLabels ] = useState < Array < string | JSX . Element > > ( [ ] ) ;
1518 const [ muteLabels , setMuteLabels ] = useState < Array < string | JSX . Element > > ( [ ] ) ;
1619
1720 useEffect ( ( ) => {
1821 if ( conversations . length ) {
19- setHoldLabels ( conversations . map ( ( convo ) => convo . mostRecentCallState . held ? 'Unhold' : 'Hold' ) ) ;
20- setMuteLabels ( conversations . map ( ( convo ) => convo . mostRecentCallState . muted ? 'Unmute' : 'Mute' ) ) ;
22+ setHoldLabels ( conversations . map ( ( convo : IStoredConversationState ) => convo . mostRecentCallState ? .held ? 'Unhold' : 'Hold' ) ) ;
23+ setMuteLabels ( conversations . map ( ( convo : IStoredConversationState ) => convo . mostRecentCallState ? .muted ? 'Unmute' : 'Mute' ) ) ;
2124 }
2225 } , [ conversations ] ) ;
2326
@@ -26,8 +29,8 @@ export default function ActiveConversationsTable() {
2629 updatedHoldLabels [ index ] = < GuxRadialLoading context = 'input' screenreaderText = 'Loading...' > </ GuxRadialLoading > ;
2730 setHoldLabels ( updatedHoldLabels ) ;
2831 try {
29- await toggleHoldState ( ! conversations [ index ] . mostRecentCallState . held , conversations [ index ] . conversationId )
30- updatedHoldLabels [ index ] = conversations [ index ] . mostRecentCallState . held ? 'Unhold' : 'Hold' ;
32+ await toggleHoldState ( ! conversations [ index ] . mostRecentCallState ? .held , conversations [ index ] . conversationId )
33+ updatedHoldLabels [ index ] = conversations [ index ] . mostRecentCallState ? .held ? 'Unhold' : 'Hold' ;
3134 setHoldLabels ( updatedHoldLabels ) ;
3235 } catch ( err ) {
3336 console . error ( err ) ;
@@ -39,8 +42,8 @@ export default function ActiveConversationsTable() {
3942 updatedMuteLabels [ index ] = < GuxRadialLoading context = 'input' screenreaderText = 'Loading...' > </ GuxRadialLoading > ;
4043 setMuteLabels ( updatedMuteLabels ) ;
4144 try {
42- await toggleAudioMute ( ! conversations [ index ] . mostRecentCallState . muted , conversations [ index ] . conversationId )
43- updatedMuteLabels [ index ] = conversations [ index ] . mostRecentCallState . muted ? 'Unmute' : 'Mute' ;
45+ await toggleAudioMute ( ! conversations [ index ] . mostRecentCallState ? .muted , conversations [ index ] . conversationId )
46+ updatedMuteLabels [ index ] = conversations [ index ] . mostRecentCallState ? .muted ? 'Unmute' : 'Mute' ;
4447 setMuteLabels ( updatedMuteLabels ) ;
4548 } catch ( err ) {
4649 console . error ( err ) ;
@@ -69,14 +72,14 @@ export default function ActiveConversationsTable() {
6972 </ tr >
7073 </ thead >
7174 < tbody >
72- { conversations . map ( ( convo , index : number ) => (
75+ { conversations . map ( ( convo : IStoredConversationState , index : number ) => (
7376 < tr key = { convo . conversationId } >
7477 < td > { convo . conversationId } </ td >
75- < td > { convo . session . id } </ td >
76- < td > { convo . session . state } </ td >
77- < td > { convo . session . sessionType } </ td >
78- < td > { convo . mostRecentCallState . direction } </ td >
79- < td > { convo . session . connectionState } </ td >
78+ < td > { convo . session ? .id } </ td >
79+ < td > { convo . session ? .state } </ td >
80+ < td > { convo . session ? .sessionType } </ td >
81+ < td > { convo . mostRecentCallState ? .direction } </ td >
82+ < td > { convo . session ? .connectionState } </ td >
8083 < td > < GuxButton accent = 'secondary' onClick = { async ( ) => await toggleConversationHold ( index ) } > { holdLabels [ index ] } </ GuxButton > </ td >
8184 < td > < GuxButton accent = 'secondary' onClick = { async ( ) => await toggleConversationMute ( index ) } > { muteLabels [ index ] } </ GuxButton > </ td >
8285 < td > < GuxButton accent = 'danger' onClick = { ( ) => endSession ( convo . conversationId ) } > End</ GuxButton > </ td >
0 commit comments