@@ -3,11 +3,11 @@ import {ButtonPill, ListItemBase, ListItemBaseSection, Text} from '@momentum-ui/
33import { Avatar , Brandvisual , Tooltip } from '@momentum-design/components/dist/react' ;
44import { PressEvent } from '@react-types/shared' ;
55import TaskTimer from '../TaskTimer' ;
6- import { getMediaTypeInfo } from '../../../utils' ;
76import type { MEDIA_CHANNEL as MediaChannelType } from '../task.types' ;
7+ import { extractTaskComponentData , getTaskListItemClasses } from './task.utils' ;
88import './styles.scss' ;
99
10- interface TaskProps {
10+ export interface TaskProps {
1111 interactionId ?: string ;
1212 title ?: string ;
1313 state ?: string ;
@@ -46,50 +46,44 @@ const Task: React.FC<TaskProps> = ({
4646 mediaType,
4747 mediaChannel,
4848} ) => {
49- const capitalizeFirstWord = ( str : string ) => {
50- return str . replace ( / ^ \s * ( \w ) / , ( match , firstLetter ) => firstLetter . toUpperCase ( ) ) ;
51- } ;
52- const currentMediaType = getMediaTypeInfo ( mediaType , mediaChannel ) ;
53- const isNonVoiceMedia = currentMediaType . labelName !== 'Call' ;
54- // Create unique IDs for tooltip trigger and tooltip
55- const tooltipTriggerId = `tooltip-trigger-${ interactionId } ` ;
56- const tooltipId = `tooltip-${ interactionId } ` ;
57- // Helper function to get the correct CSS class
58- const getTitleClassName = ( ) => {
59- if ( isNonVoiceMedia && isIncomingTask ) {
60- return 'incoming-digital-task-title' ;
61- }
62- if ( isNonVoiceMedia && ! isIncomingTask ) {
63- return 'task-digital-title' ;
64- }
65- return 'task-title' ;
66- } ;
49+ // Extract all computed data using the utility function
50+ const taskData = extractTaskComponentData ( {
51+ mediaType,
52+ mediaChannel,
53+ isIncomingTask,
54+ interactionId,
55+ state,
56+ queue,
57+ ronaTimeout,
58+ startTimeStamp,
59+ } ) ;
60+
6761 const renderTitle = ( ) => {
6862 if ( ! title ) return null ;
6963
7064 const textComponent = (
7165 < Text
7266 tagName = "span"
7367 type = { selected ? 'body-large-bold' : 'body-large-medium' }
74- className = { getTitleClassName ( ) }
75- id = { isNonVoiceMedia ? tooltipTriggerId : undefined }
68+ className = { taskData . titleClassName }
69+ id = { taskData . isNonVoiceMedia ? taskData . tooltipTriggerId : undefined }
7670 >
7771 { title }
7872 </ Text >
7973 ) ;
8074
81- if ( isNonVoiceMedia ) {
75+ if ( taskData . isNonVoiceMedia ) {
8276 return (
8377 < >
8478 { textComponent }
8579 < Tooltip
8680 color = "contrast"
8781 delay = "0,0"
88- id = { tooltipId }
82+ id = { taskData . tooltipId }
8983 placement = "top-start"
9084 offset = { 4 }
9185 tooltip-type = "description"
92- triggerID = { tooltipTriggerId }
86+ triggerID = { taskData . tooltipTriggerId }
9387 className = "task-tooltip"
9488 >
9589 { title }
@@ -103,48 +97,66 @@ const Task: React.FC<TaskProps> = ({
10397
10498 return (
10599 < ListItemBase
106- className = { `task-list-item ${ selected ? 'task-list-item--selected' : '' } ${ styles } ` }
100+ className = { getTaskListItemClasses ( selected , styles ) }
107101 onPress = { onTaskSelect ? onTaskSelect : undefined }
108102 id = { interactionId }
109103 >
110104 < ListItemBaseSection position = "start" >
111- { currentMediaType . isBrandVisual ? (
105+ { taskData . currentMediaType . isBrandVisual ? (
112106 < div className = "brand-visual-background" >
113- < Brandvisual name = { currentMediaType . iconName } className = { currentMediaType . className } />
107+ < Brandvisual name = { taskData . currentMediaType . iconName } className = { taskData . currentMediaType . className } />
114108 </ div >
115109 ) : (
116- < Avatar icon-name = { currentMediaType . iconName } className = { currentMediaType . className } />
110+ < Avatar icon-name = { taskData . currentMediaType . iconName } className = { taskData . currentMediaType . className } />
117111 ) }
118112 </ ListItemBaseSection >
119113
120114 < ListItemBaseSection position = "fill" >
121115 < section className = "task-details" >
122116 { renderTitle ( ) }
123- { state && ! isIncomingTask && (
124- < Text tagName = "span" type = "body-midsize-regular" className = "task-text" >
125- { capitalizeFirstWord ( state ) }
117+ { taskData . shouldShowState && (
118+ < Text
119+ tagName = "span"
120+ type = "body-midsize-regular"
121+ className = "task-text"
122+ data-testid = { `${ interactionId } -state` }
123+ >
124+ { taskData . capitalizedState }
126125 </ Text >
127126 ) }
128127
129- { queue && isIncomingTask && (
130- < Text tagName = "span" type = "body-midsize-regular" className = "task-text" >
131- { capitalizeFirstWord ( queue ) }
128+ { taskData . shouldShowQueue && (
129+ < Text
130+ tagName = "span"
131+ type = "body-midsize-regular"
132+ className = "task-text"
133+ data-testid = { `${ interactionId } -queue` }
134+ >
135+ { taskData . capitalizedQueue }
132136 </ Text >
133137 ) }
134138
135139 { /* Handle Time should render if it's an incoming call without ronaTimeout OR if it's not an incoming call */ }
136- { ( isIncomingTask && ! ronaTimeout ) || ! isIncomingTask
137- ? startTimeStamp && (
138- < Text tagName = "span" type = "body-midsize-regular" className = "task-text" >
139- Handle Time: { ' ' }
140- < TaskTimer startTimeStamp = { startTimeStamp } />
141- </ Text >
142- )
143- : null }
140+ { taskData . shouldShowHandleTime && (
141+ < Text
142+ tagName = "span"
143+ type = "body-midsize-regular"
144+ className = "task-text"
145+ data-testid = { `${ interactionId } -handle-time` }
146+ >
147+ Handle Time: { ' ' }
148+ < TaskTimer startTimeStamp = { startTimeStamp } />
149+ </ Text >
150+ ) }
144151
145152 { /* Time Left should render if it's an incoming call with ronaTimeout */ }
146- { isIncomingTask && ronaTimeout && (
147- < Text tagName = "span" type = "body-midsize-regular" className = "task-text" >
153+ { taskData . shouldShowTimeLeft && (
154+ < Text
155+ tagName = "span"
156+ type = "body-midsize-regular"
157+ className = "task-text"
158+ data-testid = { `${ interactionId } -time-left` }
159+ >
148160 Time Left: { ' ' }
149161 < TaskTimer countdown = { true } ronaTimeout = { ronaTimeout } />
150162 </ Text >
0 commit comments