forked from webex/widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser-state.tsx
More file actions
107 lines (98 loc) · 3.69 KB
/
Copy pathuser-state.tsx
File metadata and controls
107 lines (98 loc) · 3.69 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
import React, {useMemo} from 'react';
import {AgentUserState, UserStateComponentsProps} from './user-state.types';
import {formatTime} from '../../utils';
import './user-state.scss';
import {SelectNext, Text} from '@momentum-ui/react-collaboration';
import {Item} from '@react-stately/collections';
import {Icon, Tooltip} from '@momentum-design/components/dist/react';
import {
getDropdownClass,
getIconStyle,
getTooltipText,
handleSelectionChange,
sortDropdownItems,
getPreviousSelectableState,
getSelectedKey,
buildDropdownItems,
} from './user-state.utils';
const UserStateComponent: React.FunctionComponent<UserStateComponentsProps> = (props) => {
const {
idleCodes,
setAgentStatus,
isSettingAgentStatus,
elapsedTime,
lastIdleStateChangeElapsedTime,
currentState,
customState,
logger,
} = props;
const previousSelectableState = useMemo(() => getPreviousSelectableState(idleCodes), [idleCodes]);
const selectedKey = getSelectedKey(customState, currentState, idleCodes);
const items = buildDropdownItems(customState, idleCodes);
const sortedItems = sortDropdownItems(items);
return (
<div className="user-state-container" data-testid="user-state-container">
<SelectNext
id="user-state-tooltip"
label=""
aria-label="user-state"
direction="bottom"
onSelectionChange={(key: string) => handleSelectionChange(key, currentState, setAgentStatus, logger)}
showBorder
selectedKey={selectedKey}
items={sortedItems}
className={`state-select ${getDropdownClass(customState, currentState, idleCodes)}`}
data-testid="state-select"
>
{(item) => {
const isRonaOrEngaged = [AgentUserState.RONA, AgentUserState.Engaged].includes(
//@ts-expect-error To be fixed in SDK - https://jira-eng-sjc12.cisco.com/jira/browse/CAI-6762
idleCodes.find((code) => code.id === currentState)?.name || ''
);
const shouldHighlight = currentState === item.id || (isRonaOrEngaged && item.id === previousSelectableState);
return (
<Item key={item.id} textValue={item.name} data-testid={`state-item-${item.name}`}>
<div
className="item-container"
data-testid={`item-container ${shouldHighlight ? `selected ${getIconStyle(item).class}` : ''}`}
>
<Icon
name={getIconStyle(item).iconName}
title=""
className={`state-icon ${getIconStyle(item).class}`}
data-testid="state-icon"
/>
<Text className={`state-name ${getIconStyle(item).class}`} tagName={'small'} data-testid="state-name">
{item.name}
</Text>
</div>
</Item>
);
}}
</SelectNext>
<Tooltip
data-testid="user-state-tooltip"
placement="bottom"
color="contrast"
delay="0, 0"
className="tooltip"
triggerID="user-state-tooltip"
>
<Text tagName="small" className="tooltip-text">
{getTooltipText(customState, currentState, idleCodes)}
</Text>
</Tooltip>
{!customState && (
<span
className={`elapsedTime ${isSettingAgentStatus ? 'elapsedTime-disabled' : ''}`}
data-testid="elapsed-time"
>
{lastIdleStateChangeElapsedTime >= 0 ? formatTime(lastIdleStateChangeElapsedTime) + ' / ' : ''}
{formatTime(elapsedTime)}
</span>
)}
<Icon className="select-arrow-icon" name="arrow-down-bold" title="" data-testid="select-arrow-icon" />
</div>
);
};
export default UserStateComponent;