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
127 lines (118 loc) · 4.04 KB
/
Copy pathindex.tsx
File metadata and controls
127 lines (118 loc) · 4.04 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
import React from 'react';
import {ButtonPill, ListItemBase, ListItemBaseSection, Text} from '@momentum-ui/react-collaboration';
import {Avatar, Brandvisual} 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);
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">
{title && (
<Text tagName="span" type={selected ? 'body-large-bold' : 'body-large-medium'} className="task-title">
{title}
</Text>
)}
{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;