forked from webex/widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall-control-consult.tsx
More file actions
154 lines (143 loc) · 4.57 KB
/
Copy pathcall-control-consult.tsx
File metadata and controls
154 lines (143 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import React, {useState} from 'react';
import {ButtonCircle, TooltipNext, Text} from '@momentum-ui/react-collaboration';
import {Avatar, Icon} from '@momentum-design/components/dist/react';
import {MUTE_CALL, UNMUTE_CALL} from '../../constants';
import TaskTimer from '../../TaskTimer';
import {CallControlConsultComponentsProps} from '../../task.types';
const CallControlConsultComponent: React.FC<CallControlConsultComponentsProps> = ({
agentName,
startTimeStamp,
onTransfer,
endConsultCall,
consultCompleted,
isAgentBeingConsulted,
isEndConsultEnabled,
logger,
muteUnmute,
isMuted,
onToggleConsultMute,
}) => {
const [isMuteDisabled, setIsMuteDisabled] = useState(false);
const timerKey = `timer-${startTimeStamp}`;
const handleTransfer = () => {
logger.info('CC-Widgets: CallControlConsult: transfer button clicked', {
module: 'call-control-consult.tsx',
method: 'handleTransfer',
});
try {
if (onTransfer) {
onTransfer();
logger.log('CC-Widgets: CallControlConsult: transfer completed', {
module: 'call-control-consult.tsx',
method: 'handleTransfer',
});
}
} catch (error) {
throw new Error('Error transferring call:', error);
}
};
const handleEndConsult = () => {
logger.info('CC-Widgets: CallControlConsult: end consult clicked', {
module: 'call-control-consult.tsx',
method: 'handleEndConsult',
});
try {
endConsultCall();
logger.log('CC-Widgets: CallControlConsult: end consult completed', {
module: 'call-control-consult.tsx',
method: 'handleEndConsult',
});
} catch (error) {
throw new Error('Error ending consult call:', error);
}
};
const handleConsultMuteToggle = () => {
setIsMuteDisabled(true);
try {
onToggleConsultMute();
} catch (error) {
logger.error('Mute toggle failed:', {
error,
module: 'call-control-consult.tsx',
method: 'handleConsultMuteToggle',
});
} finally {
// Re-enable button after operation
setTimeout(() => {
setIsMuteDisabled(false);
}, 500);
}
};
const buttons = [
{
key: 'mute',
icon: isMuted ? 'microphone-muted-bold' : 'microphone-bold',
onClick: handleConsultMuteToggle,
tooltip: isMuted ? UNMUTE_CALL : MUTE_CALL,
className: `${isMuted ? 'call-control-button-muted' : 'call-control-button'}`,
disabled: isMuteDisabled,
shouldShow: muteUnmute,
},
{
key: 'transfer',
icon: 'next-bold',
tooltip: 'Transfer Consult',
onClick: handleTransfer,
className: 'call-control-button',
disabled: !consultCompleted,
shouldShow: isAgentBeingConsulted && !!onTransfer,
},
{
key: 'cancel',
icon: 'headset-muted-bold',
tooltip: 'End Consult',
onClick: handleEndConsult,
className: 'call-control-consult-button-cancel',
shouldShow: isEndConsultEnabled || isAgentBeingConsulted,
},
];
// Filter buttons that should be shown, then map them
const visibleButtons = buttons.filter((button) => button.shouldShow);
return (
<div className="call-control-consult">
<div className="consult-header">
<Avatar iconName="handset-filled" className="task-avatar" size={32} />
<div>
<Text tagName="p" type="body-large-bold" className="consult-agent-name">
{agentName}
</Text>
<Text tagName="p" type="body-secondary" className="consult-sub-text">
{consultCompleted ? 'Consulting' : 'Consult requested'} •
<TaskTimer key={timerKey} startTimeStamp={startTimeStamp} />
</Text>
</div>
</div>
<div className="consult-buttons consult-buttons-container">
{visibleButtons.map((button) => (
<TooltipNext
key={button.key}
triggerComponent={
<ButtonCircle
className={button.className}
onPress={button.onClick}
disabled={button.disabled}
data-testid={`${button.key}-consult-btn`}
>
<Icon className={`${button.className}-icon`} name={button.icon} />
</ButtonCircle>
}
color="primary"
delay={[0, 0]}
placement="bottom-start"
type="description"
variant="small"
className="tooltip"
>
<p>{button.tooltip}</p>
</TooltipNext>
))}
</div>
</div>
);
};
export default CallControlConsultComponent;