-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathcampaign-task-popover.tsx
More file actions
105 lines (97 loc) · 3.97 KB
/
Copy pathcampaign-task-popover.tsx
File metadata and controls
105 lines (97 loc) · 3.97 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
import React, {useRef} from 'react';
import {Popover} from '@momentum-design/components/dist/react';
import CampaignTaskListItem from '../CampaignTaskListItem/campaign-task-list-item';
import GlobalVariablesPanel from '../../GlobalVariablesPanel/global-variables-panel';
import {CampaignTaskPopoverProps, CallAssociatedDataMap, getCallerIdentifier} from '../../task.types';
import {getAgentViewableGlobalVariables} from '../../Task/task.utils';
import {getCampaignCpd} from '../../TaskList/task-list.utils';
import './campaign-task-popover.style.scss';
const POPOVER_WIDTH = '440px';
const POPOVER_DELAY = '200,100';
const CampaignTaskPopover: React.FC<CampaignTaskPopoverProps> = ({
task,
logger,
triggerId,
isAcceptClicked,
isAccepted,
isAcceptDisabled,
isSkipDisabled,
isRemoveDisabled,
onAccept,
onSkip,
onRemove,
onTimeout,
handleTimestamp,
}) => {
const cpd = task.data.interaction.callProcessingDetails;
const campaignCpd = getCampaignCpd(cpd as unknown as Record<string, unknown>);
const timeoutTimestamp = campaignCpd.campaignPreviewOfferTimeout;
const callAssociatedDetails = task.data.interaction.callAssociatedDetails;
const ani = callAssociatedDetails?.ani ?? '';
const dn = callAssociatedDetails?.dn ?? '';
const customerName = callAssociatedDetails?.customerName;
const outboundType = task.data.interaction.outboundType;
const title = customerName || getCallerIdentifier(ani, dn, outboundType);
const phoneNumber = getCallerIdentifier(ani, dn, outboundType);
const callAssociatedData = (task.data.interaction as unknown as {callAssociatedData?: CallAssociatedDataMap})
.callAssociatedData;
const latestGlobalVariables = getAgentViewableGlobalVariables(callAssociatedData);
// Persist and accumulate global variables across task updates.
// Each websocket event may only carry a subset of the full
// callAssociatedData, so we merge new variables into the ref by name
// instead of replacing the whole array.
// Reset when the interaction changes so stale CAD from a previous
// contact is never shown on the next preview.
const interactionId = task.data.interactionId;
const globalVariablesRef = useRef(latestGlobalVariables);
const prevInteractionIdRef = useRef(interactionId);
if (prevInteractionIdRef.current !== interactionId) {
prevInteractionIdRef.current = interactionId;
globalVariablesRef.current = latestGlobalVariables;
} else if (latestGlobalVariables.length > 0) {
const existingMap = new Map(globalVariablesRef.current.map((v) => [v.name, v]));
latestGlobalVariables.forEach((v) => existingMap.set(v.name, v));
globalVariablesRef.current = Array.from(existingMap.values());
}
const globalVariables = globalVariablesRef.current;
return (
<Popover
triggerID={triggerId}
trigger="mouseenter"
placement="right"
interactive
delay={POPOVER_DELAY}
className="campaign-task-popover"
style={{['--mdc-popover-width' as string]: POPOVER_WIDTH}}
data-testid="campaign-task-popover"
>
<div className="campaign-task-popover__content">
<CampaignTaskListItem
title={title}
phoneNumber={phoneNumber}
customerName={customerName}
timeoutTimestamp={timeoutTimestamp}
isAcceptClicked={isAcceptClicked}
isAccepted={isAccepted}
isAcceptDisabled={isAcceptDisabled}
isSkipDisabled={isSkipDisabled}
isRemoveDisabled={isRemoveDisabled}
onAccept={onAccept}
onSkip={onSkip}
onRemove={onRemove}
onTimeout={onTimeout}
handleTimestamp={handleTimestamp}
logger={logger}
className="campaign-task-popover__list-item"
testIdPrefix="campaign-popover"
/>
<GlobalVariablesPanel
variables={globalVariables}
layout="two-column"
panelBackground="var(--mds-color-theme-background-primary-hover)"
/>
</div>
</Popover>
);
};
export default CampaignTaskPopover;