forked from webex/widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
173 lines (161 loc) · 5.19 KB
/
Copy pathindex.tsx
File metadata and controls
173 lines (161 loc) · 5.19 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import React from 'react';
import {ButtonPill, ListItemBase, ListItemBaseSection, Text} from '@momentum-ui/react-collaboration';
import {Avatar, Brandvisual, Tooltip} from '@momentum-design/components/dist/react';
import {PressEvent} from '@react-types/shared';
import TaskTimer from '../TaskTimer';
import {getMediaTypeInfo} from '../../../utils';
import type {MEDIA_CHANNEL as MediaChannelType} from '../task.types';
import './styles.scss';
interface TaskProps {
interactionId?: string;
title?: string;
state?: string;
startTimeStamp?: number;
ronaTimeout?: number;
selected?: boolean;
isIncomingTask?: boolean;
queue?: string;
acceptTask?: (e: PressEvent) => void;
declineTask?: (e: PressEvent) => void;
onTaskSelect?: (e: PressEvent) => void;
acceptText?: string;
declineText?: string;
disableAccept?: boolean;
styles?: string;
mediaType?: MediaChannelType;
mediaChannel?: MediaChannelType;
}
const Task: React.FC<TaskProps> = ({
title,
state,
startTimeStamp,
ronaTimeout,
selected = false,
styles,
isIncomingTask = false,
queue,
acceptTask,
declineTask,
interactionId,
onTaskSelect,
acceptText,
disableAccept = false,
declineText,
mediaType,
mediaChannel,
}) => {
const capitalizeFirstWord = (str: string) => {
return str.replace(/^\s*(\w)/, (match, firstLetter) => firstLetter.toUpperCase());
};
const currentMediaType = getMediaTypeInfo(mediaType, mediaChannel);
const isNonVoiceMedia = currentMediaType.labelName !== 'Call';
// Create unique IDs for tooltip trigger and tooltip
const tooltipTriggerId = `tooltip-trigger-${interactionId}`;
const tooltipId = `tooltip-${interactionId}`;
// Helper function to get the correct CSS class
const getTitleClassName = () => {
if (isNonVoiceMedia && isIncomingTask) {
return 'incoming-digital-task-title';
}
if (isNonVoiceMedia && !isIncomingTask) {
return 'task-digital-title';
}
return 'task-title';
};
const renderTitle = () => {
if (!title) return null;
const textComponent = (
<Text
tagName="span"
type={selected ? 'body-large-bold' : 'body-large-medium'}
className={getTitleClassName()}
id={isNonVoiceMedia ? tooltipTriggerId : undefined}
>
{title}
</Text>
);
if (isNonVoiceMedia) {
return (
<>
{textComponent}
<Tooltip
color="contrast"
delay="0,0"
id={tooltipId}
placement="top-start"
offset={4}
tooltip-type="description"
triggerID={tooltipTriggerId}
className="task-tooltip"
>
{title}
</Tooltip>
</>
);
}
return textComponent;
};
return (
<ListItemBase
className={`task-list-item ${selected ? 'task-list-item--selected' : ''} ${styles}`}
onPress={onTaskSelect ? onTaskSelect : undefined}
id={interactionId}
>
<ListItemBaseSection position="start">
{currentMediaType.isBrandVisual ? (
<div className="brand-visual-background">
<Brandvisual name={currentMediaType.iconName} className={currentMediaType.className} />
</div>
) : (
<Avatar icon-name={currentMediaType.iconName} className={currentMediaType.className} />
)}
</ListItemBaseSection>
<ListItemBaseSection position="fill">
<section className="task-details">
{renderTitle()}
{state && !isIncomingTask && (
<Text tagName="span" type="body-midsize-regular" className="task-text">
{capitalizeFirstWord(state)}
</Text>
)}
{queue && isIncomingTask && (
<Text tagName="span" type="body-midsize-regular" className="task-text">
{capitalizeFirstWord(queue)}
</Text>
)}
{/* Handle Time should render if it's an incoming call without ronaTimeout OR if it's not an incoming call */}
{(isIncomingTask && !ronaTimeout) || !isIncomingTask
? startTimeStamp && (
<Text tagName="span" type="body-midsize-regular" className="task-text">
Handle Time: {' '}
<TaskTimer startTimeStamp={startTimeStamp} />
</Text>
)
: null}
{/* Time Left should render if it's an incoming call with ronaTimeout */}
{isIncomingTask && ronaTimeout && (
<Text tagName="span" type="body-midsize-regular" className="task-text">
Time Left: {' '}
<TaskTimer countdown={true} ronaTimeout={ronaTimeout} />
</Text>
)}
</section>
</ListItemBaseSection>
<ListItemBaseSection position="end">
<div className="task-button-container">
{acceptText ? (
<ButtonPill onPress={acceptTask} color="join" disabled={disableAccept}>
{acceptText}
</ButtonPill>
) : null}
{declineText ? (
<ButtonPill onPress={declineTask} color="cancel">
{declineText}
</ButtonPill>
) : null}
</div>
</ListItemBaseSection>
</ListItemBase>
);
};
export default Task;