@defra/flood-webchat 0.0.1-beta.4 → 0.0.1-beta.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -1
- package/dist/client.js +2146 -472
- package/dist/client.js.map +1 -1
- package/dist/server.js +181 -241
- package/dist/server.js.map +1 -1
- package/main.scss +10 -6
- package/package.json +6 -2
- package/src/client/components/availability/availability.jsx +71 -54
- package/src/client/components/availability/availability.scss +15 -33
- package/src/client/components/chat/chat.jsx +233 -0
- package/src/client/components/chat/chat.scss +233 -0
- package/src/client/components/errorSummary/error-summary.jsx +34 -0
- package/src/client/components/live-region.jsx +55 -0
- package/src/client/components/message/message.jsx +20 -0
- package/src/client/components/panel/panel-footer.jsx +9 -0
- package/src/client/components/panel/panel-header.jsx +54 -14
- package/src/client/components/panel/panel.jsx +128 -71
- package/src/client/components/panel/panel.scss +63 -22
- package/src/client/components/screens/end-chat.jsx +77 -0
- package/src/client/components/screens/feedback.jsx +66 -0
- package/src/client/components/screens/pre-chat.jsx +50 -30
- package/src/client/components/screens/request-chat.jsx +177 -4
- package/src/client/components/screens/settings.jsx +97 -0
- package/src/client/components/screens/unavailable.jsx +23 -0
- package/src/client/components/skip-link.jsx +42 -0
- package/src/client/hooks/useFocusedElements.js +80 -0
- package/src/client/hooks/useTextareaAutosize.js +13 -0
- package/src/client/index.jsx +15 -1
- package/src/client/lib/agent-status-headline.js +17 -0
- package/src/client/lib/check-availability.js +1 -0
- package/src/client/lib/history.js +13 -0
- package/src/client/lib/message-notification.js +36 -0
- package/src/client/lib/transform-messages.js +34 -0
- package/src/client/scss/_objects.scss +33 -0
- package/src/client/scss/_settings.scss +101 -0
- package/src/client/scss/_tools.scss +33 -0
- package/src/client/scss/_utilities.scss +25 -0
- package/src/client/store/AppProvider.jsx +187 -0
- package/src/client/store/actions-map.js +152 -0
- package/src/client/store/constants.js +3 -0
- package/src/client/store/reducer.js +31 -0
- package/src/client/store/useApp.js +5 -0
- package/src/client/store/useChatSdk.js +37 -0
- package/src/server/index.js +15 -6
- package/src/server/lib/client.js +31 -35
- package/src/server/lib/utils.js +16 -8
- package/src/client/lib/external-stores.js +0 -4
- package/src/client/lib/external-sync-store.js +0 -42
package/dist/client.js
CHANGED
|
@@ -15,85 +15,102 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
15
15
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
16
16
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
17
17
|
/* harmony import */ var _lib_classnames__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../lib/classnames */ "./src/client/lib/classnames.js");
|
|
18
|
-
/* harmony import */ var
|
|
19
|
-
/* harmony import */ var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function Availability(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
18
|
+
/* harmony import */ var _panel_panel_jsx__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../panel/panel.jsx */ "./src/client/components/panel/panel.jsx");
|
|
19
|
+
/* harmony import */ var _skip_link_jsx__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../skip-link.jsx */ "./src/client/components/skip-link.jsx");
|
|
20
|
+
/* harmony import */ var _store_useApp__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../store/useApp */ "./src/client/store/useApp.js");
|
|
21
|
+
/* harmony import */ var _lib_history_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../lib/history.js */ "./src/client/lib/history.js");
|
|
22
|
+
/* harmony import */ var _live_region_jsx__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../live-region.jsx */ "./src/client/components/live-region.jsx");
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
function Availability() {
|
|
31
|
+
const {
|
|
32
|
+
availability,
|
|
33
|
+
isChatOpen,
|
|
34
|
+
setChatVisibility,
|
|
35
|
+
unseenCount,
|
|
36
|
+
threadId,
|
|
37
|
+
setUnseenCount,
|
|
38
|
+
setInstigatorId,
|
|
39
|
+
setLiveRegionText
|
|
40
|
+
} = (0,_store_useApp__WEBPACK_IMPORTED_MODULE_4__.useApp)();
|
|
41
|
+
const buttonRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
|
|
42
|
+
const showUnseenCount = unseenCount > 0 && !isChatOpen;
|
|
43
|
+
const onClick = e => {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
setUnseenCount(0);
|
|
46
|
+
setChatVisibility(!isChatOpen);
|
|
47
|
+
setInstigatorId(e.target.id);
|
|
48
|
+
if (!isChatOpen) {
|
|
49
|
+
(0,_lib_history_js__WEBPACK_IMPORTED_MODULE_5__.historyPushState)();
|
|
50
|
+
} else {
|
|
51
|
+
(0,_lib_history_js__WEBPACK_IMPORTED_MODULE_5__.historyReplaceState)();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const onKeyDown = event => {
|
|
44
55
|
if (event.key === ' ') {
|
|
45
56
|
event.preventDefault();
|
|
46
57
|
}
|
|
47
58
|
};
|
|
48
|
-
|
|
59
|
+
const onKeyUp = event => {
|
|
49
60
|
if (event.key === ' ') {
|
|
50
|
-
|
|
61
|
+
setUnseenCount(0);
|
|
62
|
+
setChatVisibility(!isChatOpen);
|
|
51
63
|
}
|
|
52
64
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var isBelowFold = !entry.isIntersecting && entry.boundingClientRect.top > 0;
|
|
57
|
-
setFixed(!isOpen && isBelowFold);
|
|
58
|
-
};
|
|
59
|
-
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () {
|
|
60
|
-
var _buttonRef$current;
|
|
61
|
-
var observer = new window.IntersectionObserver(intersectionCallback, {
|
|
62
|
-
rootMargin: '35px'
|
|
63
|
-
});
|
|
64
|
-
var parentElement = (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 ? void 0 : _buttonRef$current.parentElement;
|
|
65
|
-
if (parentElement) {
|
|
66
|
-
observer.observe(parentElement);
|
|
65
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
66
|
+
if (showUnseenCount) {
|
|
67
|
+
setLiveRegionText(`Floodline Webchat - ${unseenCount} new messages`);
|
|
67
68
|
}
|
|
68
|
-
return
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
return () => {
|
|
70
|
+
setLiveRegionText();
|
|
71
|
+
};
|
|
72
|
+
}, [unseenCount, isChatOpen]);
|
|
73
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
74
|
+
const onScroll = () => {
|
|
75
|
+
if (!threadId) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (availability !== 'AVAILABLE') {
|
|
79
|
+
return;
|
|
71
80
|
}
|
|
81
|
+
const rect = buttonRef.current.parentElement.getBoundingClientRect();
|
|
82
|
+
const isBelowFold = rect.top + 35 > (window.innerHeight || document.documentElement.clientHeight);
|
|
83
|
+
const isFixed = !isChatOpen && isBelowFold;
|
|
84
|
+
document.documentElement.classList.toggle('wc-u-scroll-padding', isFixed);
|
|
85
|
+
document.body.classList.toggle('wc-u-scroll-padding', isFixed);
|
|
86
|
+
buttonRef.current.classList.toggle('wc-availability--fixed', isFixed);
|
|
72
87
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
88
|
+
document.addEventListener('scroll', onScroll);
|
|
89
|
+
onScroll();
|
|
90
|
+
return () => {
|
|
91
|
+
document.removeEventListener('scroll', onScroll);
|
|
92
|
+
};
|
|
93
|
+
}, [threadId, isChatOpen, availability]);
|
|
94
|
+
switch (availability) {
|
|
79
95
|
case 'AVAILABLE':
|
|
80
96
|
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
81
|
-
className: (0,_lib_classnames__WEBPACK_IMPORTED_MODULE_1__.classnames)('wc-availability',
|
|
97
|
+
className: (0,_lib_classnames__WEBPACK_IMPORTED_MODULE_1__.classnames)('wc-availability', isChatOpen && 'wc-open'),
|
|
82
98
|
ref: buttonRef
|
|
83
99
|
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
84
100
|
className: "wc-availability__inner"
|
|
85
101
|
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
102
|
+
id: "webchat-start-chat-link",
|
|
86
103
|
className: "wc-availability__link",
|
|
87
104
|
href: "#webchat",
|
|
88
|
-
role: "button",
|
|
89
105
|
draggable: "false",
|
|
90
106
|
onClick: onClick,
|
|
91
107
|
onKeyUp: onKeyUp,
|
|
92
|
-
onKeyDown: onKeyDown
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
onKeyDown: onKeyDown,
|
|
109
|
+
role: "button",
|
|
110
|
+
"data-module": "govuk-button"
|
|
111
|
+
}, !threadId ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, "Start chat") : /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, "Show chat"), showUnseenCount ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("span", {
|
|
112
|
+
className: "wc-availability__unseen"
|
|
113
|
+
}, unseenCount) : null))), isChatOpen && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_panel_panel_jsx__WEBPACK_IMPORTED_MODULE_2__.Panel, null), showUnseenCount ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_live_region_jsx__WEBPACK_IMPORTED_MODULE_6__.LiveRegion, null) : null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_skip_link_jsx__WEBPACK_IMPORTED_MODULE_3__.SkipLink, null));
|
|
97
114
|
case 'EXISTING':
|
|
98
115
|
case 'UNAVAILABLE':
|
|
99
116
|
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
@@ -105,21 +122,422 @@ function Availability(props) {
|
|
|
105
122
|
}, "Checking availability");
|
|
106
123
|
}
|
|
107
124
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
125
|
+
|
|
126
|
+
/***/ }),
|
|
127
|
+
|
|
128
|
+
/***/ "./src/client/components/chat/chat.jsx":
|
|
129
|
+
/*!*********************************************!*\
|
|
130
|
+
!*** ./src/client/components/chat/chat.jsx ***!
|
|
131
|
+
\*********************************************/
|
|
132
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
133
|
+
|
|
134
|
+
__webpack_require__.r(__webpack_exports__);
|
|
135
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
136
|
+
/* harmony export */ Chat: () => (/* binding */ Chat)
|
|
137
|
+
/* harmony export */ });
|
|
138
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
139
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
140
|
+
/* harmony import */ var _panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../panel/panel-header.jsx */ "./src/client/components/panel/panel-header.jsx");
|
|
141
|
+
/* harmony import */ var _panel_panel_footer_jsx__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../panel/panel-footer.jsx */ "./src/client/components/panel/panel-footer.jsx");
|
|
142
|
+
/* harmony import */ var _message_message_jsx__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../message/message.jsx */ "./src/client/components/message/message.jsx");
|
|
143
|
+
/* harmony import */ var _store_useApp_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../store/useApp.js */ "./src/client/store/useApp.js");
|
|
144
|
+
/* harmony import */ var _hooks_useTextareaAutosize_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../hooks/useTextareaAutosize.js */ "./src/client/hooks/useTextareaAutosize.js");
|
|
145
|
+
/* harmony import */ var _lib_transform_messages_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../lib/transform-messages.js */ "./src/client/lib/transform-messages.js");
|
|
146
|
+
/* harmony import */ var _lib_agent_status_headline_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../lib/agent-status-headline.js */ "./src/client/lib/agent-status-headline.js");
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
function Chat({
|
|
156
|
+
onEndChatScreen,
|
|
157
|
+
onSettingsScreen
|
|
158
|
+
}) {
|
|
159
|
+
const {
|
|
160
|
+
availability,
|
|
161
|
+
thread,
|
|
162
|
+
messages,
|
|
163
|
+
agent,
|
|
164
|
+
agentStatus,
|
|
165
|
+
isAgentTyping,
|
|
166
|
+
isChatOpen,
|
|
167
|
+
settings,
|
|
168
|
+
isKeyboard,
|
|
169
|
+
setLiveRegionText
|
|
170
|
+
} = (0,_store_useApp_js__WEBPACK_IMPORTED_MODULE_4__.useApp)();
|
|
171
|
+
const [userMessage, setUserMessage] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)('');
|
|
172
|
+
const [focusVisibleWithin, setFocusVisibleWithin] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(false);
|
|
173
|
+
const messageRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
|
|
174
|
+
(0,_hooks_useTextareaAutosize_js__WEBPACK_IMPORTED_MODULE_5__.useTextareaAutosize)(messageRef.current, userMessage);
|
|
175
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
176
|
+
if (settings.scroll && messages.length !== 0) {
|
|
177
|
+
const chatBody = document.querySelector('.wc-body');
|
|
178
|
+
chatBody.scrollTop = chatBody.scrollHeight;
|
|
179
|
+
}
|
|
180
|
+
}, [messages, isAgentTyping]);
|
|
181
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
182
|
+
const label = document.querySelector('.wc-form__label');
|
|
183
|
+
if (userMessage.length === 0) {
|
|
184
|
+
label.classList.remove('govuk-visually-hidden');
|
|
185
|
+
} else {
|
|
186
|
+
label.classList.add('govuk-visually-hidden');
|
|
187
|
+
}
|
|
188
|
+
}, [userMessage]);
|
|
189
|
+
const onChange = e => {
|
|
190
|
+
setUserMessage(e.target?.value);
|
|
191
|
+
};
|
|
192
|
+
const agentName = agent?.nickname || agent?.firstName;
|
|
193
|
+
const connectionHeadlineText = (0,_lib_agent_status_headline_js__WEBPACK_IMPORTED_MODULE_7__.agentStatusHeadline)(availability, agentStatus, agentName);
|
|
194
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
195
|
+
if (connectionHeadlineText) {
|
|
196
|
+
setLiveRegionText(`Floodline Webchat - ${connectionHeadlineText}`);
|
|
197
|
+
}
|
|
198
|
+
return () => {
|
|
199
|
+
setLiveRegionText();
|
|
200
|
+
};
|
|
201
|
+
}, [connectionHeadlineText]);
|
|
202
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
203
|
+
if (isAgentTyping && isChatOpen) {
|
|
204
|
+
setLiveRegionText(`${agentName} is typing...`);
|
|
205
|
+
}
|
|
206
|
+
return () => {
|
|
207
|
+
setLiveRegionText();
|
|
208
|
+
};
|
|
209
|
+
}, [isAgentTyping, isChatOpen]);
|
|
210
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
211
|
+
const lastAgentMessage = messages[messages.length - 1];
|
|
212
|
+
if (agentStatus !== 'closed' && lastAgentMessage?.direction === 'outbound') {
|
|
213
|
+
setLiveRegionText(`${agentName} said: ${lastAgentMessage.text}`);
|
|
214
|
+
}
|
|
215
|
+
return () => {
|
|
216
|
+
setLiveRegionText();
|
|
217
|
+
};
|
|
218
|
+
}, [messages]);
|
|
219
|
+
const sendMessage = () => {
|
|
220
|
+
if (messageRef.current.value.length === 0 || agentStatus === 'closed') {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
const message = messageRef.current.value.trim();
|
|
225
|
+
thread.sendTextMessage(message);
|
|
226
|
+
setLiveRegionText(`You said: ${message}`);
|
|
227
|
+
} catch (err) {
|
|
228
|
+
console.log('[Chat Error] sendMessage', err);
|
|
229
|
+
}
|
|
230
|
+
setUserMessage('');
|
|
231
|
+
};
|
|
232
|
+
const handleSubmit = e => {
|
|
233
|
+
e.preventDefault();
|
|
234
|
+
sendMessage();
|
|
235
|
+
};
|
|
236
|
+
const saveChat = () => {
|
|
237
|
+
const transcript = (0,_lib_transform_messages_js__WEBPACK_IMPORTED_MODULE_6__.formatTranscript)(messages);
|
|
238
|
+
const saveChatLink = document.querySelector('#transcript-download');
|
|
239
|
+
saveChatLink.setAttribute('href', `data:text/plain;charset=utf-8,${transcript}`);
|
|
240
|
+
};
|
|
241
|
+
const handleKeyPress = e => {
|
|
242
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
243
|
+
switch (e.target.id) {
|
|
244
|
+
case 'text-area':
|
|
245
|
+
e.preventDefault();
|
|
246
|
+
sendMessage();
|
|
247
|
+
break;
|
|
248
|
+
case 'end-chat':
|
|
249
|
+
onEndChatScreen(e);
|
|
250
|
+
break;
|
|
251
|
+
case 'wc-settings':
|
|
252
|
+
onSettingsScreen(e);
|
|
253
|
+
break;
|
|
254
|
+
case 'transcript-download':
|
|
255
|
+
saveChat();
|
|
256
|
+
break;
|
|
257
|
+
default:
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (e.key === ' ') {
|
|
262
|
+
if (e.target.id === 'end-chat') {
|
|
263
|
+
onEndChatScreen(e);
|
|
264
|
+
}
|
|
265
|
+
if (e.target.id === 'wc-settings') {
|
|
266
|
+
onSettingsScreen(e);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__.PanelHeader, null), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
271
|
+
className: "wc-status"
|
|
272
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
273
|
+
className: "wc-status__availability"
|
|
274
|
+
}, connectionHeadlineText), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
275
|
+
id: "end-chat",
|
|
276
|
+
className: "wc-status__link",
|
|
277
|
+
href: "#",
|
|
278
|
+
"data-module": "govuk-button",
|
|
279
|
+
role: "button",
|
|
280
|
+
onClick: onEndChatScreen,
|
|
281
|
+
onKeyDown: handleKeyPress
|
|
282
|
+
}, "End chat")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
283
|
+
className: "wc-body",
|
|
284
|
+
tabIndex: "0"
|
|
285
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("ul", {
|
|
286
|
+
className: "wc-chat"
|
|
287
|
+
}, messages.length ? messages.map((msg, index) => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_message_message_jsx__WEBPACK_IMPORTED_MODULE_3__.Message, {
|
|
288
|
+
key: msg.id,
|
|
289
|
+
message: msg,
|
|
290
|
+
previousMessage: messages[index - 1]
|
|
291
|
+
})) : null, isAgentTyping ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("li", {
|
|
292
|
+
className: "wc-chat__message outbound"
|
|
293
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
294
|
+
className: "wc-chat__from"
|
|
295
|
+
}, agentName, " is typing"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
296
|
+
className: "wc-chat__text outbound"
|
|
297
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("svg", {
|
|
298
|
+
width: "28",
|
|
299
|
+
height: "16",
|
|
300
|
+
x: "0px",
|
|
301
|
+
y: "0px",
|
|
302
|
+
viewBox: "0 0 28 16"
|
|
303
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("circle", {
|
|
304
|
+
stroke: "none",
|
|
305
|
+
cx: "3",
|
|
306
|
+
cy: "8",
|
|
307
|
+
r: "3",
|
|
308
|
+
fill: "currentColor"
|
|
309
|
+
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("circle", {
|
|
310
|
+
stroke: "none",
|
|
311
|
+
cx: "14",
|
|
312
|
+
cy: "8",
|
|
313
|
+
r: "3",
|
|
314
|
+
fill: "currentColor"
|
|
315
|
+
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("circle", {
|
|
316
|
+
stroke: "none",
|
|
317
|
+
cx: "25",
|
|
318
|
+
cy: "8",
|
|
319
|
+
r: "3",
|
|
320
|
+
fill: "currentColor"
|
|
321
|
+
})))) : null)), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_panel_panel_footer_jsx__WEBPACK_IMPORTED_MODULE_2__.PanelFooter, null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("form", {
|
|
322
|
+
className: `wc-form${focusVisibleWithin ? ' wc-focus-within' : ''}`,
|
|
323
|
+
noValidate: true,
|
|
324
|
+
onSubmit: handleSubmit
|
|
325
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("label", {
|
|
326
|
+
className: "govuk-label wc-form__label",
|
|
327
|
+
htmlFor: "wc-form-textarea"
|
|
328
|
+
}, "Your message", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("span", {
|
|
329
|
+
className: "govuk-visually-hidden"
|
|
330
|
+
}, " (enter key submits)")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("textarea", {
|
|
331
|
+
ref: messageRef,
|
|
332
|
+
rows: "1",
|
|
333
|
+
"aria-required": "true",
|
|
334
|
+
className: "wc-form__textarea",
|
|
335
|
+
id: "text-area",
|
|
336
|
+
name: "message",
|
|
337
|
+
onChange: onChange,
|
|
338
|
+
onKeyDown: handleKeyPress,
|
|
339
|
+
onFocus: () => {
|
|
340
|
+
setFocusVisibleWithin(isKeyboard);
|
|
341
|
+
},
|
|
342
|
+
onBlur: () => {
|
|
343
|
+
setFocusVisibleWithin(false);
|
|
344
|
+
},
|
|
345
|
+
value: userMessage
|
|
346
|
+
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("input", {
|
|
347
|
+
type: "submit",
|
|
348
|
+
className: "wc-form__button govuk-button",
|
|
349
|
+
value: "Send",
|
|
350
|
+
"data-prevent-double-click": "true"
|
|
351
|
+
})), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
352
|
+
className: "wc-footer__settings"
|
|
353
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
354
|
+
href: "#",
|
|
355
|
+
id: "wc-settings",
|
|
356
|
+
className: "wc-footer__settings-link",
|
|
357
|
+
"data-module": "govuk-button",
|
|
358
|
+
onKeyDown: handleKeyPress,
|
|
359
|
+
onClick: onSettingsScreen
|
|
360
|
+
}, "Settings"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
361
|
+
href: "#",
|
|
362
|
+
id: "transcript-download",
|
|
363
|
+
className: "wc-footer__settings-link",
|
|
364
|
+
"data-module": "govuk-button",
|
|
365
|
+
download: "floodline-webchat-transcript.txt",
|
|
366
|
+
onKeyDown: handleKeyPress,
|
|
367
|
+
onClick: saveChat
|
|
368
|
+
}, "Save chat"))));
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/***/ }),
|
|
372
|
+
|
|
373
|
+
/***/ "./src/client/components/errorSummary/error-summary.jsx":
|
|
374
|
+
/*!**************************************************************!*\
|
|
375
|
+
!*** ./src/client/components/errorSummary/error-summary.jsx ***!
|
|
376
|
+
\**************************************************************/
|
|
377
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
378
|
+
|
|
379
|
+
__webpack_require__.r(__webpack_exports__);
|
|
380
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
381
|
+
/* harmony export */ ErrorSummary: () => (/* binding */ ErrorSummary)
|
|
382
|
+
/* harmony export */ });
|
|
383
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
384
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
385
|
+
|
|
386
|
+
const ErrorSummary = ({
|
|
387
|
+
errors
|
|
388
|
+
}) => {
|
|
389
|
+
const errs = Object.keys(errors);
|
|
390
|
+
const goToInput = e => {
|
|
391
|
+
e.preventDefault();
|
|
392
|
+
const key = e.target.getAttribute('data-key');
|
|
393
|
+
document.querySelector(`#wc-${key}`).focus();
|
|
394
|
+
};
|
|
395
|
+
if (errs.length === 0) {
|
|
396
|
+
return null;
|
|
117
397
|
}
|
|
118
|
-
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(
|
|
119
|
-
className: "
|
|
120
|
-
|
|
398
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
399
|
+
className: "govuk-error-summary govuk-!-static-margin-bottom-7",
|
|
400
|
+
"data-module": "govuk-error-summary",
|
|
401
|
+
tabIndex: "-1"
|
|
402
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
403
|
+
role: "alert"
|
|
404
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h2", {
|
|
405
|
+
id: "wc-error",
|
|
406
|
+
className: "wc-error-summary__title govuk-error-summary__title"
|
|
407
|
+
}, "There is a problem"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
408
|
+
className: "govuk-error-summary__body"
|
|
409
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("ul", {
|
|
410
|
+
className: "govuk-list govuk-error-summary__list wc-error-summary__list"
|
|
411
|
+
}, errs.map(key => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("li", {
|
|
412
|
+
key: key
|
|
413
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
414
|
+
href: "#",
|
|
415
|
+
"data-key": key,
|
|
416
|
+
onClick: goToInput
|
|
417
|
+
}, errors[key])))))));
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
/***/ }),
|
|
421
|
+
|
|
422
|
+
/***/ "./src/client/components/live-region.jsx":
|
|
423
|
+
/*!***********************************************!*\
|
|
424
|
+
!*** ./src/client/components/live-region.jsx ***!
|
|
425
|
+
\***********************************************/
|
|
426
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
427
|
+
|
|
428
|
+
__webpack_require__.r(__webpack_exports__);
|
|
429
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
430
|
+
/* harmony export */ LiveRegion: () => (/* binding */ LiveRegion)
|
|
431
|
+
/* harmony export */ });
|
|
432
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
433
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
434
|
+
/* harmony import */ var lodash_debounce__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash.debounce */ "lodash.debounce");
|
|
435
|
+
/* harmony import */ var lodash_debounce__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_debounce__WEBPACK_IMPORTED_MODULE_1__);
|
|
436
|
+
/* harmony import */ var _store_useApp__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../store/useApp */ "./src/client/store/useApp.js");
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
const DEBOUNCE_MILLISECONDS = 2000;
|
|
441
|
+
const LiveRegion = () => {
|
|
442
|
+
const {
|
|
443
|
+
agentStatus,
|
|
444
|
+
liveRegionText,
|
|
445
|
+
setLiveRegionText
|
|
446
|
+
} = (0,_store_useApp__WEBPACK_IMPORTED_MODULE_2__.useApp)();
|
|
447
|
+
const [textA, setTextA] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)();
|
|
448
|
+
const [textB, setTextB] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)();
|
|
449
|
+
const isSessionEnded = agentStatus === 'closed' || agentStatus === null;
|
|
450
|
+
const clearText = () => {
|
|
451
|
+
setTextA();
|
|
452
|
+
setTextB();
|
|
453
|
+
};
|
|
454
|
+
const setText = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(lodash_debounce__WEBPACK_IMPORTED_MODULE_1___default()(text => {
|
|
455
|
+
if (textA) {
|
|
456
|
+
setTextB(text);
|
|
457
|
+
} else {
|
|
458
|
+
setTextA(text);
|
|
459
|
+
}
|
|
460
|
+
}, DEBOUNCE_MILLISECONDS), [textA, textB]);
|
|
461
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
462
|
+
if (liveRegionText) {
|
|
463
|
+
clearText();
|
|
464
|
+
setText(liveRegionText);
|
|
465
|
+
}
|
|
466
|
+
if (isSessionEnded) {
|
|
467
|
+
clearText();
|
|
468
|
+
setLiveRegionText();
|
|
469
|
+
}
|
|
470
|
+
return () => {
|
|
471
|
+
clearText();
|
|
472
|
+
setLiveRegionText();
|
|
473
|
+
};
|
|
474
|
+
}, [liveRegionText]);
|
|
475
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
476
|
+
className: "wc-live",
|
|
477
|
+
"aria-live": "polite",
|
|
478
|
+
"aria-atomic": "true"
|
|
479
|
+
}, textA), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
480
|
+
className: "wc-live",
|
|
481
|
+
"aria-live": "polite",
|
|
482
|
+
"aria-atomic": "true"
|
|
483
|
+
}, textB));
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
/***/ }),
|
|
487
|
+
|
|
488
|
+
/***/ "./src/client/components/message/message.jsx":
|
|
489
|
+
/*!***************************************************!*\
|
|
490
|
+
!*** ./src/client/components/message/message.jsx ***!
|
|
491
|
+
\***************************************************/
|
|
492
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
493
|
+
|
|
494
|
+
__webpack_require__.r(__webpack_exports__);
|
|
495
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
496
|
+
/* harmony export */ Message: () => (/* binding */ Message)
|
|
497
|
+
/* harmony export */ });
|
|
498
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
499
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
500
|
+
/* harmony import */ var _lib_classnames__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../lib/classnames */ "./src/client/lib/classnames.js");
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
function Message({
|
|
504
|
+
message,
|
|
505
|
+
previousMessage
|
|
506
|
+
}) {
|
|
507
|
+
const outbound = message.direction === 'outbound';
|
|
508
|
+
const messageOwnerSameAsPrevious = message?.direction === previousMessage?.direction;
|
|
509
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("li", {
|
|
510
|
+
className: (0,_lib_classnames__WEBPACK_IMPORTED_MODULE_1__.classnames)('wc-chat__message', outbound ? 'outbound' : 'inbound')
|
|
511
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
512
|
+
className: "wc-chat__from"
|
|
513
|
+
}, messageOwnerSameAsPrevious ? null : /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("span", null, outbound ? message.assignee : 'You'), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("span", {
|
|
121
514
|
className: "govuk-visually-hidden"
|
|
122
|
-
}, " ",
|
|
515
|
+
}, ":")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
516
|
+
className: (0,_lib_classnames__WEBPACK_IMPORTED_MODULE_1__.classnames)('wc-chat__text', outbound ? 'outbound' : 'inbound')
|
|
517
|
+
}, message.text));
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/***/ }),
|
|
521
|
+
|
|
522
|
+
/***/ "./src/client/components/panel/panel-footer.jsx":
|
|
523
|
+
/*!******************************************************!*\
|
|
524
|
+
!*** ./src/client/components/panel/panel-footer.jsx ***!
|
|
525
|
+
\******************************************************/
|
|
526
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
527
|
+
|
|
528
|
+
__webpack_require__.r(__webpack_exports__);
|
|
529
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
530
|
+
/* harmony export */ PanelFooter: () => (/* binding */ PanelFooter)
|
|
531
|
+
/* harmony export */ });
|
|
532
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
533
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
534
|
+
|
|
535
|
+
function PanelFooter({
|
|
536
|
+
children
|
|
537
|
+
}) {
|
|
538
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
539
|
+
className: "wc-footer"
|
|
540
|
+
}, children);
|
|
123
541
|
}
|
|
124
542
|
|
|
125
543
|
/***/ }),
|
|
@@ -136,13 +554,43 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
136
554
|
/* harmony export */ });
|
|
137
555
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
138
556
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
557
|
+
/* harmony import */ var _store_useApp_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../store/useApp.js */ "./src/client/store/useApp.js");
|
|
558
|
+
/* harmony import */ var _lib_history_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../lib/history.js */ "./src/client/lib/history.js");
|
|
559
|
+
|
|
560
|
+
|
|
139
561
|
|
|
140
|
-
function PanelHeader(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
562
|
+
function PanelHeader() {
|
|
563
|
+
const {
|
|
564
|
+
thread,
|
|
565
|
+
threadId,
|
|
566
|
+
setChatVisibility,
|
|
567
|
+
setUnseenCount,
|
|
568
|
+
isMobile
|
|
569
|
+
} = (0,_store_useApp_js__WEBPACK_IMPORTED_MODULE_1__.useApp)();
|
|
570
|
+
const onClose = e => {
|
|
571
|
+
e.preventDefault();
|
|
572
|
+
setChatVisibility(false);
|
|
573
|
+
(0,_lib_history_js__WEBPACK_IMPORTED_MODULE_2__.historyReplaceState)();
|
|
574
|
+
if (threadId) {
|
|
575
|
+
thread?.lastMessageSeen();
|
|
576
|
+
setUnseenCount(0);
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
const BackButtonComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("button", {
|
|
580
|
+
className: "wc-header__back",
|
|
581
|
+
"aria-label": "Close the webchat",
|
|
582
|
+
onClick: onClose
|
|
583
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("svg", {
|
|
584
|
+
"aria-hidden": "true",
|
|
585
|
+
focusable: "false",
|
|
586
|
+
width: "20",
|
|
587
|
+
height: "20",
|
|
588
|
+
viewBox: "0 0 20 20"
|
|
589
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("path", {
|
|
590
|
+
d: "M4.828,11L12.314,18.485L10.899,19.899L1,10L10.899,0.101L12.314,1.515L4.828,9L19,9L19,11L4.828,11Z",
|
|
591
|
+
fill: "currentColor"
|
|
592
|
+
})));
|
|
593
|
+
const CloseButtonComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("button", {
|
|
146
594
|
className: "wc-header__close",
|
|
147
595
|
"aria-label": "Close the webchat",
|
|
148
596
|
onClick: onClose
|
|
@@ -156,437 +604,1663 @@ function PanelHeader(_ref) {
|
|
|
156
604
|
d: "M10,8.6L15.6,3L17,4.4L11.4,10L17,15.6L15.6,17L10,11.4L4.4,17L3,15.6L8.6,10L3,4.4L4.4,3L10,8.6Z",
|
|
157
605
|
fill: "currentColor"
|
|
158
606
|
})));
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
607
|
+
const MinimiseButtonComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("button", {
|
|
608
|
+
className: "wc-header__hide",
|
|
609
|
+
"aria-label": "Minimise the webchat",
|
|
610
|
+
onClick: onClose
|
|
611
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("svg", {
|
|
612
|
+
"aria-hidden": "true",
|
|
613
|
+
focusable: "false",
|
|
614
|
+
width: "20",
|
|
615
|
+
height: "20",
|
|
616
|
+
viewBox: "0 0 20 20"
|
|
617
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("path", {
|
|
618
|
+
d: "M10 14.4l-7-7L4.4 6l5.6 5.6L15.6 6 17 7.4l-7 7z",
|
|
619
|
+
fill: "currentColor"
|
|
620
|
+
})));
|
|
621
|
+
const isMobileAndHasHistory = isMobile && window.history.state;
|
|
622
|
+
const isMobileAndNoHistory = isMobile && !window.history.state;
|
|
623
|
+
let RightButtonComponent = CloseButtonComponent;
|
|
624
|
+
if (threadId) {
|
|
625
|
+
RightButtonComponent = MinimiseButtonComponent;
|
|
626
|
+
if (isMobileAndNoHistory) {
|
|
627
|
+
RightButtonComponent = MinimiseButtonComponent;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
if (!threadId && isMobileAndNoHistory) {
|
|
631
|
+
RightButtonComponent = CloseButtonComponent;
|
|
632
|
+
}
|
|
633
|
+
if (isMobileAndHasHistory) {
|
|
634
|
+
RightButtonComponent = null;
|
|
174
635
|
}
|
|
175
|
-
var BackButtonComponent = !isConnected && screen !== 0 ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
176
|
-
href: "#",
|
|
177
|
-
className: "wc-header__link govuk-back-link govuk-back-link--inverse",
|
|
178
|
-
onClick: onBack
|
|
179
|
-
}, "Back") : null;
|
|
180
636
|
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
181
637
|
className: "wc-header"
|
|
182
|
-
}, BackButtonComponent, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h2", {
|
|
638
|
+
}, isMobileAndHasHistory ? BackButtonComponent : null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h2", {
|
|
183
639
|
id: "wc-header-title",
|
|
184
|
-
className: "wc-header__title
|
|
185
|
-
}, "Floodline Webchat"),
|
|
640
|
+
className: "wc-header__title"
|
|
641
|
+
}, "Floodline Webchat"), RightButtonComponent);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/***/ }),
|
|
645
|
+
|
|
646
|
+
/***/ "./src/client/components/panel/panel.jsx":
|
|
647
|
+
/*!***********************************************!*\
|
|
648
|
+
!*** ./src/client/components/panel/panel.jsx ***!
|
|
649
|
+
\***********************************************/
|
|
650
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
651
|
+
|
|
652
|
+
__webpack_require__.r(__webpack_exports__);
|
|
653
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
654
|
+
/* harmony export */ Panel: () => (/* binding */ Panel)
|
|
655
|
+
/* harmony export */ });
|
|
656
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
657
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
658
|
+
/* harmony import */ var react_dom__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react-dom */ "react-dom");
|
|
659
|
+
/* harmony import */ var react_dom__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react_dom__WEBPACK_IMPORTED_MODULE_1__);
|
|
660
|
+
/* harmony import */ var _lib_classnames_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../lib/classnames.js */ "./src/client/lib/classnames.js");
|
|
661
|
+
/* harmony import */ var _screens_pre_chat_jsx__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../screens/pre-chat.jsx */ "./src/client/components/screens/pre-chat.jsx");
|
|
662
|
+
/* harmony import */ var _screens_request_chat_jsx__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../screens/request-chat.jsx */ "./src/client/components/screens/request-chat.jsx");
|
|
663
|
+
/* harmony import */ var _chat_chat_jsx__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../chat/chat.jsx */ "./src/client/components/chat/chat.jsx");
|
|
664
|
+
/* harmony import */ var _screens_unavailable_jsx__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../screens/unavailable.jsx */ "./src/client/components/screens/unavailable.jsx");
|
|
665
|
+
/* harmony import */ var _screens_end_chat_jsx__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../screens/end-chat.jsx */ "./src/client/components/screens/end-chat.jsx");
|
|
666
|
+
/* harmony import */ var _screens_settings_jsx__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../screens/settings.jsx */ "./src/client/components/screens/settings.jsx");
|
|
667
|
+
/* harmony import */ var _screens_feedback_jsx__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../screens/feedback.jsx */ "./src/client/components/screens/feedback.jsx");
|
|
668
|
+
/* harmony import */ var _live_region_jsx__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../live-region.jsx */ "./src/client/components/live-region.jsx");
|
|
669
|
+
/* harmony import */ var _store_useApp_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../store/useApp.js */ "./src/client/store/useApp.js");
|
|
670
|
+
/* harmony import */ var _store_useChatSdk_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ../../store/useChatSdk.js */ "./src/client/store/useChatSdk.js");
|
|
671
|
+
/* harmony import */ var _hooks_useFocusedElements_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ../../hooks/useFocusedElements.js */ "./src/client/hooks/useFocusedElements.js");
|
|
672
|
+
/* harmony import */ var _lib_history_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ../../lib/history.js */ "./src/client/lib/history.js");
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
function Panel() {
|
|
689
|
+
const {
|
|
690
|
+
sdk,
|
|
691
|
+
availability,
|
|
692
|
+
instigatorId,
|
|
693
|
+
thread,
|
|
694
|
+
threadId,
|
|
695
|
+
setThread,
|
|
696
|
+
setThreadId,
|
|
697
|
+
setChatVisibility,
|
|
698
|
+
setMessages,
|
|
699
|
+
setUnseenCount,
|
|
700
|
+
isMobile,
|
|
701
|
+
isKeyboard
|
|
702
|
+
} = (0,_store_useApp_js__WEBPACK_IMPORTED_MODULE_11__.useApp)();
|
|
703
|
+
const {
|
|
704
|
+
fetchThread,
|
|
705
|
+
fetchMessages
|
|
706
|
+
} = (0,_store_useChatSdk_js__WEBPACK_IMPORTED_MODULE_12__.useChatSdk)(sdk);
|
|
707
|
+
const [screen, setScreen] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(threadId ? 2 : 0);
|
|
708
|
+
(0,_hooks_useFocusedElements_js__WEBPACK_IMPORTED_MODULE_13__.useFocusedElements)(screen);
|
|
709
|
+
const onEscapeKey = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(e => {
|
|
710
|
+
if (e.key === 'Escape' || e.key === 'Esc') {
|
|
711
|
+
if (threadId) {
|
|
712
|
+
thread?.lastMessageSeen();
|
|
713
|
+
setUnseenCount(0);
|
|
714
|
+
}
|
|
715
|
+
setChatVisibility(false);
|
|
716
|
+
(0,_lib_history_js__WEBPACK_IMPORTED_MODULE_14__.historyReplaceState)();
|
|
717
|
+
}
|
|
718
|
+
}, [thread, threadId, setUnseenCount, setChatVisibility]);
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* Focus previously focused element when closing the webchat
|
|
722
|
+
*/
|
|
723
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
724
|
+
return () => {
|
|
725
|
+
document.getElementById(instigatorId)?.focus();
|
|
726
|
+
};
|
|
727
|
+
}, []);
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* We need ammend classes on the body element to handle mobile behaviour
|
|
731
|
+
*/
|
|
732
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
733
|
+
document.body.classList.remove('wc-u-hidden');
|
|
734
|
+
document.getElementsByTagName('html')[0].classList.add('wc-u-html');
|
|
735
|
+
document.body.classList.add('wc-u-body');
|
|
736
|
+
return () => {
|
|
737
|
+
document.getElementsByTagName('html')[0].classList.remove('wc-u-html');
|
|
738
|
+
document.body.classList.remove('wc-u-body');
|
|
739
|
+
};
|
|
740
|
+
}, [isMobile]);
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Initializes the eventListener for pressing the escape key
|
|
744
|
+
*/
|
|
745
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
746
|
+
document.addEventListener('keydown', onEscapeKey);
|
|
747
|
+
return () => {
|
|
748
|
+
document.removeEventListener('keydown', onEscapeKey);
|
|
749
|
+
};
|
|
750
|
+
}, [onEscapeKey, setChatVisibility]);
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* Recovers the thread if there is a threadId but no thread loaded in to state
|
|
754
|
+
*/
|
|
755
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
756
|
+
const recover = async () => {
|
|
757
|
+
try {
|
|
758
|
+
const fetchedThread = await fetchThread(threadId);
|
|
759
|
+
setThread(fetchedThread);
|
|
760
|
+
const fetchedMessages = await fetchMessages(fetchedThread, threadId);
|
|
761
|
+
setMessages(fetchedMessages);
|
|
762
|
+
} catch (err) {
|
|
763
|
+
console.log('[Chat Error] fetchThread', err);
|
|
764
|
+
setThreadId();
|
|
765
|
+
setThread();
|
|
766
|
+
setScreen(0);
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
if (threadId) {
|
|
770
|
+
if (thread) {
|
|
771
|
+
thread.lastMessageSeen();
|
|
772
|
+
setUnseenCount(0);
|
|
773
|
+
setScreen(2);
|
|
774
|
+
} else {
|
|
775
|
+
recover();
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}, [thread, threadId]);
|
|
779
|
+
const handleScreenChange = newScreen => e => {
|
|
780
|
+
e.preventDefault();
|
|
781
|
+
setScreen(newScreen);
|
|
782
|
+
};
|
|
783
|
+
const goToPreChatScreen = handleScreenChange(0);
|
|
784
|
+
const goToRequestChatScreen = handleScreenChange(1);
|
|
785
|
+
const goToChatScreen = handleScreenChange(2);
|
|
786
|
+
const goToEndChatScreen = handleScreenChange(3);
|
|
787
|
+
const goToFeedbackScreen = handleScreenChange(4);
|
|
788
|
+
const goToSettingsScreen = handleScreenChange(5);
|
|
789
|
+
let ScreenComponent;
|
|
790
|
+
switch (screen) {
|
|
791
|
+
case 0:
|
|
792
|
+
ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_screens_pre_chat_jsx__WEBPACK_IMPORTED_MODULE_3__.PreChat, {
|
|
793
|
+
onContinue: goToRequestChatScreen
|
|
794
|
+
});
|
|
795
|
+
break;
|
|
796
|
+
case 1:
|
|
797
|
+
ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_screens_request_chat_jsx__WEBPACK_IMPORTED_MODULE_4__.RequestChat, {
|
|
798
|
+
onPreChatScreen: goToPreChatScreen
|
|
799
|
+
});
|
|
800
|
+
break;
|
|
801
|
+
case 2:
|
|
802
|
+
ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_chat_chat_jsx__WEBPACK_IMPORTED_MODULE_5__.Chat, {
|
|
803
|
+
onSettingsScreen: goToSettingsScreen,
|
|
804
|
+
onEndChatScreen: goToEndChatScreen
|
|
805
|
+
});
|
|
806
|
+
break;
|
|
807
|
+
case 3:
|
|
808
|
+
ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_screens_end_chat_jsx__WEBPACK_IMPORTED_MODULE_7__.EndChat, {
|
|
809
|
+
onChatScreen: goToChatScreen,
|
|
810
|
+
onEndChatConfirm: goToFeedbackScreen
|
|
811
|
+
});
|
|
812
|
+
break;
|
|
813
|
+
case 4:
|
|
814
|
+
ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_screens_feedback_jsx__WEBPACK_IMPORTED_MODULE_9__.Feedback, {
|
|
815
|
+
onCancel: () => {
|
|
816
|
+
setChatVisibility(false);
|
|
817
|
+
(0,_lib_history_js__WEBPACK_IMPORTED_MODULE_14__.historyReplaceState)();
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
break;
|
|
821
|
+
case 5:
|
|
822
|
+
ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_screens_settings_jsx__WEBPACK_IMPORTED_MODULE_8__.Settings, {
|
|
823
|
+
onCancel: goToChatScreen
|
|
824
|
+
});
|
|
825
|
+
break;
|
|
826
|
+
default:
|
|
827
|
+
ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_screens_pre_chat_jsx__WEBPACK_IMPORTED_MODULE_3__.PreChat, {
|
|
828
|
+
onContinue: goToRequestChatScreen
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
if (availability === 'UNAVAILABLE') {
|
|
832
|
+
ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_screens_unavailable_jsx__WEBPACK_IMPORTED_MODULE_6__.Unavailable, null);
|
|
833
|
+
}
|
|
834
|
+
const Component = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
835
|
+
id: "wc-panel",
|
|
836
|
+
role: "dialog",
|
|
837
|
+
className: (0,_lib_classnames_js__WEBPACK_IMPORTED_MODULE_2__.classnames)('wc-panel', isKeyboard && 'wc-focus-visible'),
|
|
838
|
+
tabIndex: "-1",
|
|
839
|
+
"aria-modal": "true",
|
|
840
|
+
"aria-labelledby": "wc-header-title"
|
|
841
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
842
|
+
className: "wc-panel__inner"
|
|
843
|
+
}, ScreenComponent), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_live_region_jsx__WEBPACK_IMPORTED_MODULE_10__.LiveRegion, null));
|
|
844
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, /*#__PURE__*/(0,react_dom__WEBPACK_IMPORTED_MODULE_1__.createPortal)(Component, document.body));
|
|
186
845
|
}
|
|
187
846
|
|
|
188
847
|
/***/ }),
|
|
189
848
|
|
|
190
|
-
/***/ "./src/client/components/
|
|
191
|
-
|
|
192
|
-
!*** ./src/client/components/
|
|
193
|
-
|
|
849
|
+
/***/ "./src/client/components/screens/end-chat.jsx":
|
|
850
|
+
/*!****************************************************!*\
|
|
851
|
+
!*** ./src/client/components/screens/end-chat.jsx ***!
|
|
852
|
+
\****************************************************/
|
|
853
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
854
|
+
|
|
855
|
+
__webpack_require__.r(__webpack_exports__);
|
|
856
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
857
|
+
/* harmony export */ EndChat: () => (/* binding */ EndChat)
|
|
858
|
+
/* harmony export */ });
|
|
859
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
860
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
861
|
+
/* harmony import */ var _panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../panel/panel-header.jsx */ "./src/client/components/panel/panel-header.jsx");
|
|
862
|
+
/* harmony import */ var _store_useApp_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../store/useApp.js */ "./src/client/store/useApp.js");
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
function EndChat({
|
|
867
|
+
onChatScreen,
|
|
868
|
+
onEndChatConfirm
|
|
869
|
+
}) {
|
|
870
|
+
const {
|
|
871
|
+
setCustomerId,
|
|
872
|
+
setThreadId,
|
|
873
|
+
setMessages,
|
|
874
|
+
agentStatus,
|
|
875
|
+
thread,
|
|
876
|
+
threadId,
|
|
877
|
+
setUnseenCount,
|
|
878
|
+
isKeyboard
|
|
879
|
+
} = (0,_store_useApp_js__WEBPACK_IMPORTED_MODULE_2__.useApp)();
|
|
880
|
+
const confirmEndChat = async e => {
|
|
881
|
+
e.preventDefault();
|
|
882
|
+
window.localStorage.setItem('tmpThreadId', threadId);
|
|
883
|
+
setThreadId();
|
|
884
|
+
setMessages([]);
|
|
885
|
+
setCustomerId();
|
|
886
|
+
thread.lastMessageSeen();
|
|
887
|
+
setUnseenCount(0);
|
|
888
|
+
|
|
889
|
+
// End chat if still open
|
|
890
|
+
if (agentStatus !== 'closed') {
|
|
891
|
+
thread.endChat();
|
|
892
|
+
}
|
|
893
|
+
onEndChatConfirm(e);
|
|
894
|
+
};
|
|
895
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
896
|
+
if (isKeyboard) {
|
|
897
|
+
setTimeout(() => {
|
|
898
|
+
document.querySelector('#confirm-endchat').focus();
|
|
899
|
+
}, 10);
|
|
900
|
+
}
|
|
901
|
+
}, []);
|
|
902
|
+
const handleKeyPress = e => {
|
|
903
|
+
if ((e.key === 'Enter' || e.key === ' ') && e.target.id === 'confirm-endchat') {
|
|
904
|
+
confirmEndChat(e);
|
|
905
|
+
}
|
|
906
|
+
if ((e.key === 'Enter' || e.key === ' ') && e.target.id === 'resume-chat') {
|
|
907
|
+
onChatScreen(e);
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__.PanelHeader, null), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
911
|
+
className: "wc-body"
|
|
912
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
913
|
+
className: "wc-content"
|
|
914
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h3", {
|
|
915
|
+
className: "wc-heading",
|
|
916
|
+
"aria-live": "polite"
|
|
917
|
+
}, "Are you sure you want to end the chat?"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
918
|
+
className: "govuk-button-group"
|
|
919
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
920
|
+
id: "confirm-endchat",
|
|
921
|
+
href: "#endChat",
|
|
922
|
+
role: "button",
|
|
923
|
+
className: "wc-button govuk-button",
|
|
924
|
+
"data-module": "govuk-button",
|
|
925
|
+
onClick: confirmEndChat,
|
|
926
|
+
onKeyDown: handleKeyPress
|
|
927
|
+
}, "Yes, end chat"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
928
|
+
id: "resume-chat",
|
|
929
|
+
href: "#resumeChat",
|
|
930
|
+
role: "button",
|
|
931
|
+
className: "wc-link govuk-link",
|
|
932
|
+
"data-module": "govuk-button",
|
|
933
|
+
onClick: onChatScreen,
|
|
934
|
+
onKeyDown: handleKeyPress
|
|
935
|
+
}, "No, resume chat")))));
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/***/ }),
|
|
939
|
+
|
|
940
|
+
/***/ "./src/client/components/screens/feedback.jsx":
|
|
941
|
+
/*!****************************************************!*\
|
|
942
|
+
!*** ./src/client/components/screens/feedback.jsx ***!
|
|
943
|
+
\****************************************************/
|
|
944
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
945
|
+
|
|
946
|
+
__webpack_require__.r(__webpack_exports__);
|
|
947
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
948
|
+
/* harmony export */ Feedback: () => (/* binding */ Feedback)
|
|
949
|
+
/* harmony export */ });
|
|
950
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
951
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
952
|
+
/* harmony import */ var _panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../panel/panel-header.jsx */ "./src/client/components/panel/panel-header.jsx");
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
function Feedback({
|
|
956
|
+
onCancel
|
|
957
|
+
}) {
|
|
958
|
+
const feedbackSend = e => {
|
|
959
|
+
const tmpThreadId = window.localStorage.getItem('tmpThreadId');
|
|
960
|
+
window.location.href = `https://defragroup.eu.qualtrics.com/jfe/form/SV_8dgFSJcxxIfqx5Y?Id=${tmpThreadId}&Source=${window.location.href}`;
|
|
961
|
+
window.localStorage.removeItem('tmpThreadId');
|
|
962
|
+
onCancel(e);
|
|
963
|
+
};
|
|
964
|
+
const feedbackClose = async e => {
|
|
965
|
+
window.localStorage.removeItem('tmpThreadId');
|
|
966
|
+
onCancel(e);
|
|
967
|
+
};
|
|
968
|
+
const handleKeyPress = e => {
|
|
969
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
970
|
+
if (e.target.id === 'feedback-close') {
|
|
971
|
+
feedbackClose(e);
|
|
972
|
+
}
|
|
973
|
+
if (e.target.id === 'feedback-send') {
|
|
974
|
+
feedbackSend(e);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
};
|
|
978
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__.PanelHeader, null), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
979
|
+
className: "wc-body"
|
|
980
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
981
|
+
className: "wc-content"
|
|
982
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h3", {
|
|
983
|
+
id: "wc-subtitle",
|
|
984
|
+
className: "wc-heading"
|
|
985
|
+
}, "Give Feedback on Floodline webchat"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", null, "Please note we\u2019re unable to respond to feedback."), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
986
|
+
id: "feedback-send",
|
|
987
|
+
className: "govuk-link",
|
|
988
|
+
href: "#",
|
|
989
|
+
target: "_blank",
|
|
990
|
+
rel: "noreferrer",
|
|
991
|
+
onKeyDown: handleKeyPress,
|
|
992
|
+
onClick: feedbackSend
|
|
993
|
+
}, "Leave Feedback")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
994
|
+
id: "feedback-close",
|
|
995
|
+
className: "wc-link govuk-link",
|
|
996
|
+
href: "#",
|
|
997
|
+
"data-module": "govuk-button",
|
|
998
|
+
role: "button",
|
|
999
|
+
onKeyDown: handleKeyPress,
|
|
1000
|
+
onClick: feedbackClose
|
|
1001
|
+
}, "Close")))));
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
/***/ }),
|
|
1005
|
+
|
|
1006
|
+
/***/ "./src/client/components/screens/pre-chat.jsx":
|
|
1007
|
+
/*!****************************************************!*\
|
|
1008
|
+
!*** ./src/client/components/screens/pre-chat.jsx ***!
|
|
1009
|
+
\****************************************************/
|
|
1010
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1011
|
+
|
|
1012
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1013
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1014
|
+
/* harmony export */ PreChat: () => (/* binding */ PreChat)
|
|
1015
|
+
/* harmony export */ });
|
|
1016
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
1017
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
1018
|
+
/* harmony import */ var _panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../panel/panel-header.jsx */ "./src/client/components/panel/panel-header.jsx");
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
function PreChat({
|
|
1022
|
+
onContinue
|
|
1023
|
+
}) {
|
|
1024
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__.PanelHeader, null), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1025
|
+
className: "wc-body"
|
|
1026
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1027
|
+
className: "wc-content"
|
|
1028
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h3", {
|
|
1029
|
+
className: "wc-heading",
|
|
1030
|
+
"aria-live": "polite"
|
|
1031
|
+
}, "What you can use webchat for"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", null, "Webchat lets you talk directly to a Floodline adviser."), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", null, "You can use webchat to get:"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("ul", {
|
|
1032
|
+
className: "wc-list"
|
|
1033
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("li", null, "current flood warnings and alerts in your area"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("li", null, "information on the flood warning service"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("li", null, "advice on what to do before, during and after a flood")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", null, "There are other ways to\xA0", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
1034
|
+
className: "govuk-link",
|
|
1035
|
+
href: "https://www.gov.uk/sign-up-for-flood-warnings",
|
|
1036
|
+
target: "_blank",
|
|
1037
|
+
rel: "noreferrer"
|
|
1038
|
+
}, "sign up for flood warnings"), "\xA0and\xA0", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
1039
|
+
className: "govuk-link",
|
|
1040
|
+
href: "https://www.fws.environment-agency.gov.uk/app/olr/login",
|
|
1041
|
+
target: "_blank",
|
|
1042
|
+
rel: "noreferrer"
|
|
1043
|
+
}, "manage your flood warnings account"), "."), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", null, "Do not use webchat to\xA0", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
1044
|
+
className: "govuk-link",
|
|
1045
|
+
href: "https://www.gov.uk/report-flood-cause",
|
|
1046
|
+
target: "_blank",
|
|
1047
|
+
rel: "noreferrer"
|
|
1048
|
+
}, "report a flood"), "."), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("button", {
|
|
1049
|
+
className: "govuk-button wc-button govuk-!-margin-top-1",
|
|
1050
|
+
"data-module": "govuk-button",
|
|
1051
|
+
onClick: onContinue
|
|
1052
|
+
}, "Continue"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h3", {
|
|
1053
|
+
className: "wc-heading"
|
|
1054
|
+
}, "Other flood information"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", null, "Call Floodline for all other flood and flood warning information."), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("strong", null, "Floodline helpline"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("br", null), "Telephone: 0345 988 1188", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("br", null), "Textphone: 0345 602 6340", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("br", null), "Open 24 hours a day, 7 days a week", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("br", null), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
1055
|
+
className: "govuk-link",
|
|
1056
|
+
href: "https://gov.uk/call-charges",
|
|
1057
|
+
target: "_blank",
|
|
1058
|
+
rel: "noreferrer"
|
|
1059
|
+
}, "Find out more about call charges")))));
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
/***/ }),
|
|
1063
|
+
|
|
1064
|
+
/***/ "./src/client/components/screens/request-chat.jsx":
|
|
1065
|
+
/*!********************************************************!*\
|
|
1066
|
+
!*** ./src/client/components/screens/request-chat.jsx ***!
|
|
1067
|
+
\********************************************************/
|
|
1068
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1069
|
+
|
|
1070
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1071
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1072
|
+
/* harmony export */ RequestChat: () => (/* binding */ RequestChat)
|
|
1073
|
+
/* harmony export */ });
|
|
1074
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
1075
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
1076
|
+
/* harmony import */ var uuid__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! uuid */ "uuid");
|
|
1077
|
+
/* harmony import */ var uuid__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(uuid__WEBPACK_IMPORTED_MODULE_1__);
|
|
1078
|
+
/* harmony import */ var _lib_classnames_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../lib/classnames.js */ "./src/client/lib/classnames.js");
|
|
1079
|
+
/* harmony import */ var _panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../panel/panel-header.jsx */ "./src/client/components/panel/panel-header.jsx");
|
|
1080
|
+
/* harmony import */ var _store_useApp_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../store/useApp.js */ "./src/client/store/useApp.js");
|
|
1081
|
+
/* harmony import */ var _store_useChatSdk_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../store/useChatSdk.js */ "./src/client/store/useChatSdk.js");
|
|
1082
|
+
/* harmony import */ var _errorSummary_error_summary_jsx__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../errorSummary/error-summary.jsx */ "./src/client/components/errorSummary/error-summary.jsx");
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
const QUESTION_MAX_LENGTH = 500;
|
|
1091
|
+
function RequestChat({
|
|
1092
|
+
onPreChatScreen
|
|
1093
|
+
}) {
|
|
1094
|
+
const {
|
|
1095
|
+
sdk,
|
|
1096
|
+
setCustomerId,
|
|
1097
|
+
setThreadId,
|
|
1098
|
+
setThread,
|
|
1099
|
+
setLiveRegionText
|
|
1100
|
+
} = (0,_store_useApp_js__WEBPACK_IMPORTED_MODULE_4__.useApp)();
|
|
1101
|
+
const {
|
|
1102
|
+
fetchCustomerId,
|
|
1103
|
+
fetchThread
|
|
1104
|
+
} = (0,_store_useChatSdk_js__WEBPACK_IMPORTED_MODULE_5__.useChatSdk)(sdk);
|
|
1105
|
+
const [errors, setErrors] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)({});
|
|
1106
|
+
const [questionLength, setQuestionLength] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(0);
|
|
1107
|
+
const [isButtonDisabled, setButtonDisabled] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(false);
|
|
1108
|
+
const nameRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
|
|
1109
|
+
const questionRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
|
|
1110
|
+
const isQuestionLengthValid = QUESTION_MAX_LENGTH >= questionLength;
|
|
1111
|
+
const questionLengthRemaining = QUESTION_MAX_LENGTH - questionLength;
|
|
1112
|
+
const questionLengthExceeded = questionLength - QUESTION_MAX_LENGTH;
|
|
1113
|
+
let questionHint = `You have ${questionLengthRemaining} characters remaining`;
|
|
1114
|
+
if (!isQuestionLengthValid) {
|
|
1115
|
+
questionHint = `You have ${questionLengthExceeded} characters too many`;
|
|
1116
|
+
}
|
|
1117
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
1118
|
+
if (Object.keys(errors).length) {
|
|
1119
|
+
document.querySelector('.govuk-error-summary')?.focus();
|
|
1120
|
+
}
|
|
1121
|
+
}, [errors]);
|
|
1122
|
+
const onQuestionChange = e => {
|
|
1123
|
+
setQuestionLength(e.target.value.length);
|
|
1124
|
+
};
|
|
1125
|
+
const buttonLabel = isButtonDisabled ? 'Requesting...' : 'Request Chat';
|
|
1126
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
1127
|
+
if (isButtonDisabled) {
|
|
1128
|
+
setLiveRegionText(buttonLabel);
|
|
1129
|
+
}
|
|
1130
|
+
}, [isButtonDisabled]);
|
|
1131
|
+
const onRequestChat = async e => {
|
|
1132
|
+
e.preventDefault();
|
|
1133
|
+
if (isButtonDisabled) {
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
const errs = {};
|
|
1137
|
+
if (nameRef.current.value.length === 0) {
|
|
1138
|
+
errs.name = 'Enter your name';
|
|
1139
|
+
}
|
|
1140
|
+
if (questionRef.current.value.length === 0) {
|
|
1141
|
+
errs.question = 'Enter your question';
|
|
1142
|
+
}
|
|
1143
|
+
if (questionRef.current.value.length > QUESTION_MAX_LENGTH) {
|
|
1144
|
+
errs.question = 'Your question must be 500 characters or less';
|
|
1145
|
+
}
|
|
1146
|
+
if (Object.keys(errs).length === 0) {
|
|
1147
|
+
try {
|
|
1148
|
+
setButtonDisabled(true);
|
|
1149
|
+
const threadId = uuid__WEBPACK_IMPORTED_MODULE_1__.v4();
|
|
1150
|
+
const customerId = await fetchCustomerId();
|
|
1151
|
+
const thread = await fetchThread(threadId);
|
|
1152
|
+
sdk.getCustomer().setName(nameRef.current.value);
|
|
1153
|
+
await thread.startChat(questionRef.current.value || 'Begin conversation');
|
|
1154
|
+
setCustomerId(customerId);
|
|
1155
|
+
setThreadId(threadId);
|
|
1156
|
+
setThread(thread);
|
|
1157
|
+
thread.setCustomField('threadid', threadId);
|
|
1158
|
+
} catch (err) {
|
|
1159
|
+
console.log('[Request Chat Error]', err);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
setErrors(errs);
|
|
1163
|
+
};
|
|
1164
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_3__.PanelHeader, null), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1165
|
+
className: "wc-body"
|
|
1166
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1167
|
+
className: "wc-content"
|
|
1168
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
1169
|
+
href: "#",
|
|
1170
|
+
className: "wc-back-link govuk-back-link",
|
|
1171
|
+
onClick: onPreChatScreen
|
|
1172
|
+
}, "What you can use webchat for"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_errorSummary_error_summary_jsx__WEBPACK_IMPORTED_MODULE_6__.ErrorSummary, {
|
|
1173
|
+
errors: errors
|
|
1174
|
+
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h3", {
|
|
1175
|
+
className: "wc-heading",
|
|
1176
|
+
"aria-live": "polite"
|
|
1177
|
+
}, "Your name and question"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("form", null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1178
|
+
className: (0,_lib_classnames_js__WEBPACK_IMPORTED_MODULE_2__.classnames)('wc-form-group', 'govuk-form-group', errors.name && 'govuk-form-group--error')
|
|
1179
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("label", {
|
|
1180
|
+
className: "wc-label govuk-label",
|
|
1181
|
+
htmlFor: "wc-name"
|
|
1182
|
+
}, "Your name"), errors.name && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
1183
|
+
className: "govuk-error-message"
|
|
1184
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("span", {
|
|
1185
|
+
className: "govuk-visually-hidden"
|
|
1186
|
+
}, "Error:"), " ", errors.name), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("input", {
|
|
1187
|
+
ref: nameRef,
|
|
1188
|
+
className: (0,_lib_classnames_js__WEBPACK_IMPORTED_MODULE_2__.classnames)('wc-input', 'govuk-input', errors.name && 'govuk-input--error'),
|
|
1189
|
+
id: "wc-name",
|
|
1190
|
+
name: "name",
|
|
1191
|
+
type: "text",
|
|
1192
|
+
"data-testid": "request-chat-user-name"
|
|
1193
|
+
})), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1194
|
+
className: "wc-form-group govuk-character-count",
|
|
1195
|
+
"data-module": "govuk-character-count",
|
|
1196
|
+
"data-maxlength": "500"
|
|
1197
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1198
|
+
className: (0,_lib_classnames_js__WEBPACK_IMPORTED_MODULE_2__.classnames)('govuk-form-group', errors.question && 'govuk-form-group--error')
|
|
1199
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("label", {
|
|
1200
|
+
className: "wc-label govuk-label",
|
|
1201
|
+
htmlFor: "wc-question"
|
|
1202
|
+
}, "Your question"), errors.question && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
1203
|
+
className: "govuk-error-message"
|
|
1204
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("span", {
|
|
1205
|
+
className: "govuk-visually-hidden"
|
|
1206
|
+
}, "Error:"), errors.question), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("textarea", {
|
|
1207
|
+
ref: questionRef,
|
|
1208
|
+
id: "wc-question",
|
|
1209
|
+
name: "question",
|
|
1210
|
+
rows: "5",
|
|
1211
|
+
"aria-describedby": "wc-question-info",
|
|
1212
|
+
onChange: onQuestionChange,
|
|
1213
|
+
className: (0,_lib_classnames_js__WEBPACK_IMPORTED_MODULE_2__.classnames)('wc-textarea', 'govuk-textarea', 'govuk-js-character-count', !isQuestionLengthValid || errors.question ? 'govuk-textarea--error' : ''),
|
|
1214
|
+
"data-testid": "request-chat-user-question"
|
|
1215
|
+
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1216
|
+
id: "wc-question-info",
|
|
1217
|
+
className: "wc-hint govuk-hint govuk-char-count__msg",
|
|
1218
|
+
style: {
|
|
1219
|
+
color: `${!isQuestionLengthValid ? '#d4351c' : ''}`
|
|
1220
|
+
},
|
|
1221
|
+
"aria-hidden": "true"
|
|
1222
|
+
}, questionHint), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1223
|
+
className: "govuk-character-count__sr-status govuk-visually-hidden",
|
|
1224
|
+
"aria-live": "polite"
|
|
1225
|
+
}, questionHint))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1226
|
+
className: "wc-inset-text govuk-inset-text"
|
|
1227
|
+
}, "By selecting 'Request chat' you agree to the terms of our\xA0", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
1228
|
+
href: "https://check-for-flooding.service.gov.uk/privacy-notice",
|
|
1229
|
+
target: "_blank",
|
|
1230
|
+
rel: "noreferrer",
|
|
1231
|
+
className: "govuk-link"
|
|
1232
|
+
}, "privacy notice"), "."), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("button", {
|
|
1233
|
+
className: "wc-button govuk-button govuk-!-margin-top-1",
|
|
1234
|
+
"data-module": "govuk-button",
|
|
1235
|
+
onClick: onRequestChat,
|
|
1236
|
+
"aria-disabled": isButtonDisabled
|
|
1237
|
+
}, buttonLabel)))));
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
/***/ }),
|
|
1241
|
+
|
|
1242
|
+
/***/ "./src/client/components/screens/settings.jsx":
|
|
1243
|
+
/*!****************************************************!*\
|
|
1244
|
+
!*** ./src/client/components/screens/settings.jsx ***!
|
|
1245
|
+
\****************************************************/
|
|
1246
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1247
|
+
|
|
1248
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1249
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1250
|
+
/* harmony export */ Settings: () => (/* binding */ Settings)
|
|
1251
|
+
/* harmony export */ });
|
|
1252
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
1253
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
1254
|
+
/* harmony import */ var _panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../panel/panel-header.jsx */ "./src/client/components/panel/panel-header.jsx");
|
|
1255
|
+
/* harmony import */ var _store_useApp_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../store/useApp.js */ "./src/client/store/useApp.js");
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
function Settings({
|
|
1260
|
+
onCancel
|
|
1261
|
+
}) {
|
|
1262
|
+
const {
|
|
1263
|
+
settings,
|
|
1264
|
+
setSettings
|
|
1265
|
+
} = (0,_store_useApp_js__WEBPACK_IMPORTED_MODULE_2__.useApp)();
|
|
1266
|
+
const [optionAudio, setOptionAudio] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(settings.audio);
|
|
1267
|
+
const [optionScroll, setOptionScroll] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(settings.scroll);
|
|
1268
|
+
const onSave = e => {
|
|
1269
|
+
e.preventDefault();
|
|
1270
|
+
setSettings({
|
|
1271
|
+
audio: optionAudio,
|
|
1272
|
+
scroll: optionScroll
|
|
1273
|
+
});
|
|
1274
|
+
onCancel(e);
|
|
1275
|
+
};
|
|
1276
|
+
const handleKeyPress = e => {
|
|
1277
|
+
if ((e.key === 'Enter' || e.key === ' ') && e.target.id === 'settings-save') {
|
|
1278
|
+
onSave(e);
|
|
1279
|
+
} else if ((e.key === 'Enter' || e.key === ' ') && e.target.id === 'settings-cancel') {
|
|
1280
|
+
onCancel(e);
|
|
1281
|
+
}
|
|
1282
|
+
};
|
|
1283
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__.PanelHeader, null), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1284
|
+
className: "wc-body"
|
|
1285
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1286
|
+
className: "wc-content"
|
|
1287
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("fieldset", {
|
|
1288
|
+
className: "govuk-fieldset govuk-!-margin-bottom-4"
|
|
1289
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("legend", {
|
|
1290
|
+
className: "govuk-fieldset__legend govuk-fieldset__legend"
|
|
1291
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h3", {
|
|
1292
|
+
id: "wc-subtitle",
|
|
1293
|
+
className: "wc-heading"
|
|
1294
|
+
}, "Change settings")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1295
|
+
className: "govuk-checkboxes govuk-checkboxes--small",
|
|
1296
|
+
"data-module": "govuk-checkboxes"
|
|
1297
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1298
|
+
className: "govuk-checkboxes__item"
|
|
1299
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("input", {
|
|
1300
|
+
id: "audio",
|
|
1301
|
+
name: "audio",
|
|
1302
|
+
type: "checkbox",
|
|
1303
|
+
value: "audio",
|
|
1304
|
+
className: "govuk-checkboxes__input",
|
|
1305
|
+
defaultChecked: optionAudio,
|
|
1306
|
+
onChange: () => setOptionAudio(!optionAudio)
|
|
1307
|
+
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("label", {
|
|
1308
|
+
className: "wc-label govuk-label govuk-checkboxes__label",
|
|
1309
|
+
htmlFor: "audio"
|
|
1310
|
+
}, "Play a sound when receiving a new message")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1311
|
+
className: "govuk-checkboxes__item"
|
|
1312
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("input", {
|
|
1313
|
+
id: "scroll",
|
|
1314
|
+
name: "scroll",
|
|
1315
|
+
type: "checkbox",
|
|
1316
|
+
value: "scroll",
|
|
1317
|
+
className: "govuk-checkboxes__input",
|
|
1318
|
+
defaultChecked: optionScroll,
|
|
1319
|
+
onChange: () => setOptionScroll(!optionScroll)
|
|
1320
|
+
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("label", {
|
|
1321
|
+
className: "wc-label govuk-label govuk-checkboxes__label",
|
|
1322
|
+
htmlFor: "scroll"
|
|
1323
|
+
}, "Scroll automatically to a new message")))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1324
|
+
className: "govuk-button-group"
|
|
1325
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
1326
|
+
id: "settings-save",
|
|
1327
|
+
href: "#",
|
|
1328
|
+
className: "wc-button govuk-button",
|
|
1329
|
+
"data-module": "govuk-button",
|
|
1330
|
+
role: "button",
|
|
1331
|
+
onClick: onSave,
|
|
1332
|
+
onKeyDown: handleKeyPress
|
|
1333
|
+
}, "Save"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
1334
|
+
id: "settings-cancel",
|
|
1335
|
+
href: "#",
|
|
1336
|
+
className: "wc-link govuk-link",
|
|
1337
|
+
"data-module": "govuk-button",
|
|
1338
|
+
role: "button",
|
|
1339
|
+
onClick: onCancel,
|
|
1340
|
+
onKeyDown: handleKeyPress
|
|
1341
|
+
}, "Cancel")))));
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
/***/ }),
|
|
1345
|
+
|
|
1346
|
+
/***/ "./src/client/components/screens/unavailable.jsx":
|
|
1347
|
+
/*!*******************************************************!*\
|
|
1348
|
+
!*** ./src/client/components/screens/unavailable.jsx ***!
|
|
1349
|
+
\*******************************************************/
|
|
1350
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1351
|
+
|
|
1352
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1353
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1354
|
+
/* harmony export */ Unavailable: () => (/* binding */ Unavailable)
|
|
1355
|
+
/* harmony export */ });
|
|
1356
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
1357
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
1358
|
+
/* harmony import */ var _panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../panel/panel-header.jsx */ "./src/client/components/panel/panel-header.jsx");
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
function Unavailable() {
|
|
1362
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__.PanelHeader, null), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
1363
|
+
className: "wc-body"
|
|
1364
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h3", {
|
|
1365
|
+
id: "wc-subtitle",
|
|
1366
|
+
className: "govuk-heading-m"
|
|
1367
|
+
}, "Webchat is currently not available"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
1368
|
+
className: "govuk-body-s"
|
|
1369
|
+
}, "Try again later, or call Floodline:"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
1370
|
+
className: "govuk-body-s"
|
|
1371
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("strong", null, "Floodline helpline"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("br", null), "Telephone: 0345 988 1188", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("br", null), "Textphone: 0345 602 6340", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("br", null), "Open 24 hours a day, 7 days a week", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("br", null), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
1372
|
+
className: "govuk-link",
|
|
1373
|
+
href: "https://gov.uk/call-charges"
|
|
1374
|
+
}, "Find out more about call charges")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
1375
|
+
className: "govuk-body-s"
|
|
1376
|
+
}, "We're running webchat as a trial, it will not always be available.")));
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
/***/ }),
|
|
1380
|
+
|
|
1381
|
+
/***/ "./src/client/components/skip-link.jsx":
|
|
1382
|
+
/*!*********************************************!*\
|
|
1383
|
+
!*** ./src/client/components/skip-link.jsx ***!
|
|
1384
|
+
\*********************************************/
|
|
1385
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1386
|
+
|
|
1387
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1388
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1389
|
+
/* harmony export */ SkipLink: () => (/* binding */ SkipLink)
|
|
1390
|
+
/* harmony export */ });
|
|
1391
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
1392
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
1393
|
+
/* harmony import */ var react_dom__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react-dom */ "react-dom");
|
|
1394
|
+
/* harmony import */ var react_dom__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react_dom__WEBPACK_IMPORTED_MODULE_1__);
|
|
1395
|
+
/* harmony import */ var _store_useApp__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../store/useApp */ "./src/client/store/useApp.js");
|
|
1396
|
+
|
|
1397
|
+
|
|
1398
|
+
|
|
1399
|
+
const SkipLink = () => {
|
|
1400
|
+
const {
|
|
1401
|
+
threadId,
|
|
1402
|
+
setInstigatorId
|
|
1403
|
+
} = (0,_store_useApp__WEBPACK_IMPORTED_MODULE_2__.useApp)();
|
|
1404
|
+
if (!threadId) {
|
|
1405
|
+
return null;
|
|
1406
|
+
}
|
|
1407
|
+
const targetContainer = document.getElementById('skip-links');
|
|
1408
|
+
if (!targetContainer) {
|
|
1409
|
+
return null;
|
|
1410
|
+
}
|
|
1411
|
+
const onClick = e => {
|
|
1412
|
+
e.preventDefault();
|
|
1413
|
+
setInstigatorId(e.target.id);
|
|
1414
|
+
window.location.hash = '#webchat';
|
|
1415
|
+
};
|
|
1416
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, /*#__PURE__*/(0,react_dom__WEBPACK_IMPORTED_MODULE_1__.createPortal)( /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
1417
|
+
id: "webchat-skip-link",
|
|
1418
|
+
href: "#webchat",
|
|
1419
|
+
className: "govuk-skip-link",
|
|
1420
|
+
"data-module": "govuk-skip-link",
|
|
1421
|
+
onClick: onClick,
|
|
1422
|
+
"data-wc-skiplink": true,
|
|
1423
|
+
"data-wc-open-btn": true
|
|
1424
|
+
}, "Skip to webchat"), targetContainer));
|
|
1425
|
+
};
|
|
1426
|
+
|
|
1427
|
+
/***/ }),
|
|
1428
|
+
|
|
1429
|
+
/***/ "./src/client/hooks/useFocusedElements.js":
|
|
1430
|
+
/*!************************************************!*\
|
|
1431
|
+
!*** ./src/client/hooks/useFocusedElements.js ***!
|
|
1432
|
+
\************************************************/
|
|
1433
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1434
|
+
|
|
1435
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1436
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1437
|
+
/* harmony export */ getFocusableElements: () => (/* binding */ getFocusableElements),
|
|
1438
|
+
/* harmony export */ useFocusedElements: () => (/* binding */ useFocusedElements)
|
|
1439
|
+
/* harmony export */ });
|
|
1440
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
1441
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
1442
|
+
|
|
1443
|
+
const ariaHidden = 'aria-hidden';
|
|
1444
|
+
const dataWcInert = 'data-wc-inert';
|
|
1445
|
+
const setAriaHidden = isInert => {
|
|
1446
|
+
for (const node of document.body.children) {
|
|
1447
|
+
if (node.id !== 'wc-panel') {
|
|
1448
|
+
// We only want to toggle elements that aren't already inert
|
|
1449
|
+
if (isInert && !node.getAttribute(ariaHidden)) {
|
|
1450
|
+
node.setAttribute(ariaHidden, 'true');
|
|
1451
|
+
node.setAttribute(dataWcInert, '');
|
|
1452
|
+
} else if (node.hasAttribute(dataWcInert)) {
|
|
1453
|
+
node.removeAttribute(ariaHidden);
|
|
1454
|
+
node.removeAttribute(dataWcInert);
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
};
|
|
1459
|
+
const getFocusableElements = () => {
|
|
1460
|
+
const selectors = ['#wc-panel a:not([disabled])', '#wc-panel button:not([disabled])', '#wc-panel select:not([disabled])', '#wc-panel input:not([disabled])', '#wc-panel textarea:not([disabled])', '#wc-panel *[tabindex="0"]:not([disabled])'];
|
|
1461
|
+
const elements = document.body.querySelectorAll(selectors.join(','));
|
|
1462
|
+
return Array.from(elements).filter(e => !e.closest('[hidden]') && !e.closest('[aria-hidden="true"]'));
|
|
1463
|
+
};
|
|
1464
|
+
const useFocusedElements = screen => {
|
|
1465
|
+
const [panelElements, setPanelElements] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)([]);
|
|
1466
|
+
const onKeyDown = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(e => {
|
|
1467
|
+
const webchatPanelElement = document.querySelector('#wc-panel');
|
|
1468
|
+
if (e.key === 'Tab') {
|
|
1469
|
+
if (webchatPanelElement && !document.activeElement.closest('#wc-panel')) {
|
|
1470
|
+
webchatPanelElement.focus();
|
|
1471
|
+
}
|
|
1472
|
+
if (e.shiftKey) {
|
|
1473
|
+
if (document.activeElement === panelElements[0]) {
|
|
1474
|
+
panelElements[panelElements.length - 1].focus();
|
|
1475
|
+
e.preventDefault();
|
|
1476
|
+
} else if (document.activeElement === document.querySelector('#wc-panel')) {
|
|
1477
|
+
panelElements[panelElements.length - 1]?.focus();
|
|
1478
|
+
e.preventDefault();
|
|
1479
|
+
}
|
|
1480
|
+
} else if (document.activeElement === panelElements[panelElements.length - 1]) {
|
|
1481
|
+
panelElements[0].focus();
|
|
1482
|
+
e.preventDefault();
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
}, [panelElements]);
|
|
1486
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
1487
|
+
setPanelElements(getFocusableElements());
|
|
1488
|
+
}, [screen]);
|
|
1489
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
1490
|
+
setAriaHidden(true);
|
|
1491
|
+
const panelElement = document.querySelector('#wc-panel');
|
|
1492
|
+
panelElement.focus();
|
|
1493
|
+
document.addEventListener('keydown', onKeyDown);
|
|
1494
|
+
return () => {
|
|
1495
|
+
setAriaHidden();
|
|
1496
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
1497
|
+
};
|
|
1498
|
+
}, [panelElements]);
|
|
1499
|
+
};
|
|
1500
|
+
|
|
1501
|
+
|
|
1502
|
+
/***/ }),
|
|
1503
|
+
|
|
1504
|
+
/***/ "./src/client/hooks/useTextareaAutosize.js":
|
|
1505
|
+
/*!*************************************************!*\
|
|
1506
|
+
!*** ./src/client/hooks/useTextareaAutosize.js ***!
|
|
1507
|
+
\*************************************************/
|
|
1508
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1509
|
+
|
|
1510
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1511
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1512
|
+
/* harmony export */ useTextareaAutosize: () => (/* binding */ useTextareaAutosize)
|
|
1513
|
+
/* harmony export */ });
|
|
1514
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
1515
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
1516
|
+
|
|
1517
|
+
const useTextareaAutosize = (textAreaRef, value) => {
|
|
1518
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
1519
|
+
if (textAreaRef) {
|
|
1520
|
+
textAreaRef.style.height = '0px';
|
|
1521
|
+
const scrollHeight = textAreaRef.scrollHeight;
|
|
1522
|
+
textAreaRef.style.height = `${scrollHeight}px`;
|
|
1523
|
+
}
|
|
1524
|
+
}, [textAreaRef, value]);
|
|
1525
|
+
};
|
|
1526
|
+
|
|
1527
|
+
/***/ }),
|
|
1528
|
+
|
|
1529
|
+
/***/ "./src/client/lib/agent-status-headline.js":
|
|
1530
|
+
/*!*************************************************!*\
|
|
1531
|
+
!*** ./src/client/lib/agent-status-headline.js ***!
|
|
1532
|
+
\*************************************************/
|
|
1533
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1534
|
+
|
|
1535
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1536
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1537
|
+
/* harmony export */ agentStatusHeadline: () => (/* binding */ agentStatusHeadline)
|
|
1538
|
+
/* harmony export */ });
|
|
1539
|
+
const agentStatusHeadline = (availability, agentStatus, agentName) => {
|
|
1540
|
+
if (availability === 'UNAVAILABLE') {
|
|
1541
|
+
return 'Webchat is not currently available';
|
|
1542
|
+
}
|
|
1543
|
+
if (!agentStatus) {
|
|
1544
|
+
return 'Connecting to Floodline';
|
|
1545
|
+
}
|
|
1546
|
+
switch (agentStatus) {
|
|
1547
|
+
case 'closed':
|
|
1548
|
+
case 'resolved':
|
|
1549
|
+
return agentName ? `${agentName} ended the session` : 'Session ended by advisor';
|
|
1550
|
+
default:
|
|
1551
|
+
return agentName ? `You are speaking with ${agentName}` : 'No advisers currently available';
|
|
1552
|
+
}
|
|
1553
|
+
};
|
|
1554
|
+
|
|
1555
|
+
/***/ }),
|
|
1556
|
+
|
|
1557
|
+
/***/ "./src/client/lib/check-availability.js":
|
|
1558
|
+
/*!**********************************************!*\
|
|
1559
|
+
!*** ./src/client/lib/check-availability.js ***!
|
|
1560
|
+
\**********************************************/
|
|
1561
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1562
|
+
|
|
1563
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1564
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1565
|
+
/* harmony export */ checkAvailability: () => (/* binding */ checkAvailability)
|
|
1566
|
+
/* harmony export */ });
|
|
1567
|
+
async function checkAvailability(endpoint) {
|
|
1568
|
+
const response = await fetch(endpoint);
|
|
1569
|
+
const data = await response.json();
|
|
1570
|
+
return {
|
|
1571
|
+
availability: data.availability || 'UNAVAILABLE'
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
/***/ }),
|
|
1576
|
+
|
|
1577
|
+
/***/ "./src/client/lib/classnames.js":
|
|
1578
|
+
/*!**************************************!*\
|
|
1579
|
+
!*** ./src/client/lib/classnames.js ***!
|
|
1580
|
+
\**************************************/
|
|
1581
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1582
|
+
|
|
1583
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1584
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1585
|
+
/* harmony export */ classnames: () => (/* binding */ classnames)
|
|
1586
|
+
/* harmony export */ });
|
|
1587
|
+
const classnames = (...classes) => classes.filter(classname => classname && typeof classname === 'string').join(' ');
|
|
1588
|
+
|
|
1589
|
+
/***/ }),
|
|
1590
|
+
|
|
1591
|
+
/***/ "./src/client/lib/history.js":
|
|
1592
|
+
/*!***********************************!*\
|
|
1593
|
+
!*** ./src/client/lib/history.js ***!
|
|
1594
|
+
\***********************************/
|
|
1595
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1596
|
+
|
|
1597
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1598
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1599
|
+
/* harmony export */ historyPushState: () => (/* binding */ historyPushState),
|
|
1600
|
+
/* harmony export */ historyReplaceState: () => (/* binding */ historyReplaceState)
|
|
1601
|
+
/* harmony export */ });
|
|
1602
|
+
const historyPushState = () => {
|
|
1603
|
+
const url = window.location.href.split('#')[0];
|
|
1604
|
+
window.history.pushState({
|
|
1605
|
+
history: true
|
|
1606
|
+
}, null, `${url}#webchat`);
|
|
1607
|
+
};
|
|
1608
|
+
const historyReplaceState = () => {
|
|
1609
|
+
if (window.history.state?.history) {
|
|
1610
|
+
return window.history.back();
|
|
1611
|
+
}
|
|
1612
|
+
const url = window.location.href.split('#')[0];
|
|
1613
|
+
return window.history.replaceState(null, null, url);
|
|
1614
|
+
};
|
|
1615
|
+
|
|
1616
|
+
/***/ }),
|
|
1617
|
+
|
|
1618
|
+
/***/ "./src/client/lib/message-notification.js":
|
|
1619
|
+
/*!************************************************!*\
|
|
1620
|
+
!*** ./src/client/lib/message-notification.js ***!
|
|
1621
|
+
\************************************************/
|
|
1622
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1623
|
+
|
|
1624
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1625
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1626
|
+
/* harmony export */ messageNotification: () => (/* binding */ messageNotification)
|
|
1627
|
+
/* harmony export */ });
|
|
1628
|
+
const messageNotification = audioUrl => {
|
|
1629
|
+
let buffer;
|
|
1630
|
+
const context = new (window.AudioContext || window.webkitAudioContext)();
|
|
1631
|
+
if (context.state === 'suspended') {
|
|
1632
|
+
const events = ['touchstart', 'touchend', 'mousedown', 'wheel', 'keydown', 'click'];
|
|
1633
|
+
const unlock = _e => {
|
|
1634
|
+
events.forEach(event => {
|
|
1635
|
+
document.body.removeEventListener(event, unlock);
|
|
1636
|
+
});
|
|
1637
|
+
context.resume();
|
|
1638
|
+
};
|
|
1639
|
+
events.forEach(event => {
|
|
1640
|
+
document.body.addEventListener(event, unlock, false);
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
fetch(audioUrl).then(response => response.arrayBuffer()).then(data => context.decodeAudioData(data)).then(decodedData => {
|
|
1644
|
+
buffer = decodedData;
|
|
1645
|
+
}).catch(console.error);
|
|
1646
|
+
return () => {
|
|
1647
|
+
const source = context.createBufferSource();
|
|
1648
|
+
source.buffer = buffer;
|
|
1649
|
+
source.connect(context.destination);
|
|
1650
|
+
source.start();
|
|
1651
|
+
};
|
|
1652
|
+
};
|
|
1653
|
+
|
|
1654
|
+
/***/ }),
|
|
1655
|
+
|
|
1656
|
+
/***/ "./src/client/lib/transform-messages.js":
|
|
1657
|
+
/*!**********************************************!*\
|
|
1658
|
+
!*** ./src/client/lib/transform-messages.js ***!
|
|
1659
|
+
\**********************************************/
|
|
1660
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1661
|
+
|
|
1662
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1663
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1664
|
+
/* harmony export */ formatTranscript: () => (/* binding */ formatTranscript),
|
|
1665
|
+
/* harmony export */ transformMessage: () => (/* binding */ transformMessage),
|
|
1666
|
+
/* harmony export */ transformMessages: () => (/* binding */ transformMessages)
|
|
1667
|
+
/* harmony export */ });
|
|
1668
|
+
/* harmony import */ var luxon__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! luxon */ "luxon");
|
|
1669
|
+
/* harmony import */ var luxon__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(luxon__WEBPACK_IMPORTED_MODULE_0__);
|
|
1670
|
+
|
|
1671
|
+
const transformMessage = message => {
|
|
1672
|
+
return {
|
|
1673
|
+
id: message.id,
|
|
1674
|
+
text: message.messageContent?.text,
|
|
1675
|
+
createdAt: new Date(message.createdAt),
|
|
1676
|
+
user: message.authorEndUserIdentity?.fullName?.trim() || null,
|
|
1677
|
+
assignee: message.authorUser?.firstName || null,
|
|
1678
|
+
direction: message.direction
|
|
1679
|
+
};
|
|
1680
|
+
};
|
|
1681
|
+
const transformMessages = messages => messages.map(message => transformMessage(message));
|
|
1682
|
+
const formatTranscript = messages => {
|
|
1683
|
+
const now = luxon__WEBPACK_IMPORTED_MODULE_0__.DateTime.local();
|
|
1684
|
+
now.setZone('Europe/London');
|
|
1685
|
+
let string = `Floodline webchat transcript, ${now.toFormat('HH:mm:ss a, dd LLLL yyyy')}\n\n`;
|
|
1686
|
+
for (const message of messages) {
|
|
1687
|
+
const {
|
|
1688
|
+
text,
|
|
1689
|
+
direction,
|
|
1690
|
+
user,
|
|
1691
|
+
assignee,
|
|
1692
|
+
createdAt
|
|
1693
|
+
} = message;
|
|
1694
|
+
const author = direction === 'inbound' ? user : `${assignee} (Floodline adviser)`;
|
|
1695
|
+
const date = luxon__WEBPACK_IMPORTED_MODULE_0__.DateTime.fromJSDate(new Date(createdAt)).setZone('Europe/London').toFormat('HH:mm:ss a, dd LLLL yyyy');
|
|
1696
|
+
string += `[${date}] ${author}: \n${text}\n\n`;
|
|
1697
|
+
}
|
|
1698
|
+
string = string.replace(/<a\b[^>]*>/i, '').replace(/<\/a>/i, '');
|
|
1699
|
+
return encodeURIComponent(string);
|
|
1700
|
+
};
|
|
1701
|
+
|
|
1702
|
+
/***/ }),
|
|
1703
|
+
|
|
1704
|
+
/***/ "./src/client/store/AppProvider.jsx":
|
|
1705
|
+
/*!******************************************!*\
|
|
1706
|
+
!*** ./src/client/store/AppProvider.jsx ***!
|
|
1707
|
+
\******************************************/
|
|
194
1708
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
195
1709
|
|
|
196
1710
|
__webpack_require__.r(__webpack_exports__);
|
|
197
1711
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
198
|
-
/* harmony export */
|
|
199
|
-
/* harmony export */
|
|
200
|
-
/* harmony export */ setAriaHidden: () => (/* binding */ setAriaHidden)
|
|
1712
|
+
/* harmony export */ AppContext: () => (/* binding */ AppContext),
|
|
1713
|
+
/* harmony export */ AppProvider: () => (/* binding */ AppProvider)
|
|
201
1714
|
/* harmony export */ });
|
|
202
1715
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
203
1716
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
204
|
-
/* harmony import */ var
|
|
205
|
-
/* harmony import */ var
|
|
206
|
-
/* harmony import */ var
|
|
207
|
-
/* harmony import */ var
|
|
208
|
-
/* harmony import */ var
|
|
209
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
210
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
211
|
-
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
212
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
213
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
214
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
215
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
1717
|
+
/* harmony import */ var _nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @nice-devone/nice-cxone-chat-web-sdk */ "@nice-devone/nice-cxone-chat-web-sdk");
|
|
1718
|
+
/* harmony import */ var _nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__);
|
|
1719
|
+
/* harmony import */ var _lib_message_notification_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../lib/message-notification.js */ "./src/client/lib/message-notification.js");
|
|
1720
|
+
/* harmony import */ var _reducer_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./reducer.js */ "./src/client/store/reducer.js");
|
|
1721
|
+
/* harmony import */ var _constants_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./constants.js */ "./src/client/store/constants.js");
|
|
216
1722
|
|
|
217
1723
|
|
|
218
1724
|
|
|
219
1725
|
|
|
220
1726
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
1727
|
+
const AppContext = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.createContext)(_reducer_js__WEBPACK_IMPORTED_MODULE_3__.initialState);
|
|
1728
|
+
const AppProvider = ({
|
|
1729
|
+
sdk,
|
|
1730
|
+
availability,
|
|
1731
|
+
options,
|
|
1732
|
+
children
|
|
1733
|
+
}) => {
|
|
1734
|
+
const [state, dispatch] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useReducer)(_reducer_js__WEBPACK_IMPORTED_MODULE_3__.reducer, _reducer_js__WEBPACK_IMPORTED_MODULE_3__.initialState);
|
|
1735
|
+
const playSound = (0,_lib_message_notification_js__WEBPACK_IMPORTED_MODULE_2__.messageNotification)(options.audioUrl);
|
|
1736
|
+
|
|
1737
|
+
/**
|
|
1738
|
+
* SDK event handlers
|
|
1739
|
+
*/
|
|
1740
|
+
const onLiveChatRecovered = e => {
|
|
1741
|
+
dispatch({
|
|
1742
|
+
type: 'SET_AGENT',
|
|
1743
|
+
payload: e.detail.data.inboxAssignee
|
|
1744
|
+
});
|
|
1745
|
+
dispatch({
|
|
1746
|
+
type: 'SET_AGENT_STATUS',
|
|
1747
|
+
payload: e.detail.data.contact.status
|
|
1748
|
+
});
|
|
1749
|
+
dispatch({
|
|
1750
|
+
type: 'SET_UNSEEN_COUNT',
|
|
1751
|
+
payload: e.detail.data.contact.customerStatistics.unseenMessagesCount
|
|
1752
|
+
});
|
|
1753
|
+
};
|
|
1754
|
+
const onAssignedAgentChanged = e => {
|
|
1755
|
+
dispatch({
|
|
1756
|
+
type: 'SET_AGENT',
|
|
1757
|
+
payload: e.detail.data.inboxAssignee
|
|
1758
|
+
});
|
|
1759
|
+
dispatch({
|
|
1760
|
+
type: 'SET_AGENT_STATUS',
|
|
1761
|
+
payload: e.detail.data.case.status
|
|
1762
|
+
});
|
|
1763
|
+
};
|
|
1764
|
+
const onAgentTypingStarted = () => {
|
|
1765
|
+
dispatch({
|
|
1766
|
+
type: 'SET_AGENT_TYPING',
|
|
1767
|
+
payload: true
|
|
1768
|
+
});
|
|
1769
|
+
};
|
|
1770
|
+
const onAgentTypingEnded = () => {
|
|
1771
|
+
dispatch({
|
|
1772
|
+
type: 'SET_AGENT_TYPING',
|
|
1773
|
+
payload: false
|
|
1774
|
+
});
|
|
1775
|
+
dispatch({
|
|
1776
|
+
type: 'SET_LIVE_REGION_TEXT'
|
|
1777
|
+
});
|
|
1778
|
+
};
|
|
1779
|
+
const onMessageCreated = e => {
|
|
1780
|
+
dispatch({
|
|
1781
|
+
type: 'SET_MESSAGE',
|
|
1782
|
+
payload: e.detail.data.message
|
|
1783
|
+
});
|
|
1784
|
+
dispatch({
|
|
1785
|
+
type: 'SET_AGENT_STATUS',
|
|
1786
|
+
payload: e.detail.data.case.status
|
|
1787
|
+
});
|
|
1788
|
+
dispatch({
|
|
1789
|
+
type: 'SET_UNSEEN_COUNT',
|
|
1790
|
+
payload: e.detail.data.case.customerStatistics.unseenMessagesCount
|
|
1791
|
+
});
|
|
1792
|
+
const isAudioOn = JSON.parse(window.localStorage.getItem(_constants_js__WEBPACK_IMPORTED_MODULE_4__.SETTINGS_STORAGE_KEY)).audio;
|
|
1793
|
+
if (isAudioOn && e.detail.data.message.direction === 'outbound') {
|
|
1794
|
+
playSound();
|
|
275
1795
|
}
|
|
276
|
-
}, [panelElements]);
|
|
277
|
-
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () {
|
|
278
|
-
setPanelElements(getFocusableElements());
|
|
279
|
-
}, [screen]);
|
|
280
|
-
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(function () {
|
|
281
|
-
setAriaHidden(true);
|
|
282
|
-
document.querySelector('#wc-panel').focus();
|
|
283
|
-
document.addEventListener('keydown', onKeyDown);
|
|
284
|
-
return function () {
|
|
285
|
-
var _document$body$queryS;
|
|
286
|
-
setAriaHidden();
|
|
287
|
-
(_document$body$queryS = document.body.querySelector('.wc-availability__link')) === null || _document$body$queryS === void 0 ? void 0 : _document$body$queryS.focus();
|
|
288
|
-
document.removeEventListener('keydown', onKeyDown);
|
|
289
|
-
};
|
|
290
|
-
}, [panelElements]);
|
|
291
|
-
var onBack = function onBack(e) {
|
|
292
|
-
e.preventDefault();
|
|
293
|
-
setScreen(screen - 1);
|
|
294
1796
|
};
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
1797
|
+
const onContactStatusChanged = e => {
|
|
1798
|
+
dispatch({
|
|
1799
|
+
type: 'SET_AGENT_STATUS',
|
|
1800
|
+
payload: e.detail.data.case.status
|
|
1801
|
+
});
|
|
1802
|
+
};
|
|
1803
|
+
const onMatchMedia = e => {
|
|
1804
|
+
dispatch({
|
|
1805
|
+
type: 'TOGGLE_IS_MOBILE',
|
|
1806
|
+
payload: e.matches
|
|
1807
|
+
});
|
|
1808
|
+
};
|
|
1809
|
+
const onKeydown = () => {
|
|
1810
|
+
dispatch({
|
|
1811
|
+
type: 'TOGGLE_IS_KEYBOARD',
|
|
1812
|
+
payload: true
|
|
1813
|
+
});
|
|
1814
|
+
};
|
|
1815
|
+
const onPointerdown = () => {
|
|
1816
|
+
dispatch({
|
|
1817
|
+
type: 'TOGGLE_IS_KEYBOARD',
|
|
1818
|
+
payload: false
|
|
1819
|
+
});
|
|
1820
|
+
};
|
|
1821
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
1822
|
+
sdk.onChatEvent(_nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__.ChatEvent.LIVECHAT_RECOVERED, onLiveChatRecovered);
|
|
1823
|
+
sdk.onChatEvent(_nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__.ChatEvent.MESSAGE_CREATED, onMessageCreated);
|
|
1824
|
+
sdk.onChatEvent(_nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__.ChatEvent.AGENT_TYPING_STARTED, onAgentTypingStarted);
|
|
1825
|
+
sdk.onChatEvent(_nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__.ChatEvent.AGENT_TYPING_ENDED, onAgentTypingEnded);
|
|
1826
|
+
sdk.onChatEvent(_nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__.ChatEvent.ASSIGNED_AGENT_CHANGED, onAssignedAgentChanged);
|
|
1827
|
+
sdk.onChatEvent(_nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__.ChatEvent.CONTACT_STATUS_CHANGED, onContactStatusChanged);
|
|
1828
|
+
// We need to know if it is a mobile and if it is a keyboard interaction
|
|
1829
|
+
window.matchMedia('(max-width: 640px)').addEventListener('change', onMatchMedia);
|
|
1830
|
+
window.addEventListener('keydown', onKeydown);
|
|
1831
|
+
window.addEventListener('pointerdown', onPointerdown);
|
|
1832
|
+
// Tidying up
|
|
1833
|
+
return () => {
|
|
1834
|
+
window.removeEventListener('change', onMatchMedia);
|
|
1835
|
+
window.removeEventListener('keydown', onKeydown);
|
|
1836
|
+
window.removeEventListener('pointerdown', onPointerdown);
|
|
1837
|
+
};
|
|
1838
|
+
}, [sdk]);
|
|
335
1839
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
1840
|
+
/**
|
|
1841
|
+
* Initialize customerId, threadId and whether the webchat should be open
|
|
1842
|
+
*/
|
|
1843
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
1844
|
+
dispatch({
|
|
1845
|
+
type: 'SET_AVAILABILITY',
|
|
1846
|
+
payload: availability
|
|
1847
|
+
});
|
|
1848
|
+
setCustomerId(window.localStorage.getItem(_constants_js__WEBPACK_IMPORTED_MODULE_4__.CUSTOMER_ID_STORAGE_KEY));
|
|
1849
|
+
setThreadId(window.localStorage.getItem(_constants_js__WEBPACK_IMPORTED_MODULE_4__.THREAD_ID_STORAGE_KEY));
|
|
1850
|
+
setSettings(JSON.parse(window.localStorage.getItem(_constants_js__WEBPACK_IMPORTED_MODULE_4__.SETTINGS_STORAGE_KEY)) || state.settings);
|
|
1851
|
+
}, []);
|
|
341
1852
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
1853
|
+
/**
|
|
1854
|
+
* Set browser history on start chat click
|
|
1855
|
+
*/
|
|
1856
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
1857
|
+
if (window.location.hash === '#webchat') {
|
|
1858
|
+
setChatVisibility(true);
|
|
1859
|
+
}
|
|
1860
|
+
const onBrowserNavigation = () => {
|
|
1861
|
+
if (window.location.hash === '#webchat') {
|
|
1862
|
+
setChatVisibility(true);
|
|
1863
|
+
} else {
|
|
1864
|
+
setChatVisibility(false);
|
|
1865
|
+
}
|
|
1866
|
+
};
|
|
1867
|
+
window.addEventListener('popstate', onBrowserNavigation);
|
|
1868
|
+
return () => {
|
|
1869
|
+
window.removeEventListener('popstate', onBrowserNavigation);
|
|
1870
|
+
};
|
|
1871
|
+
}, []);
|
|
348
1872
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
1873
|
+
/**
|
|
1874
|
+
* State update functions
|
|
1875
|
+
*/
|
|
1876
|
+
const setChatVisibility = payload => {
|
|
1877
|
+
dispatch({
|
|
1878
|
+
type: 'SET_CHAT_VISIBILITY',
|
|
1879
|
+
payload
|
|
1880
|
+
});
|
|
355
1881
|
};
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
1882
|
+
const setCustomerId = customerId => {
|
|
1883
|
+
dispatch({
|
|
1884
|
+
type: 'SET_CUSTOMER_ID',
|
|
1885
|
+
payload: customerId
|
|
1886
|
+
});
|
|
1887
|
+
};
|
|
1888
|
+
const setThreadId = threadId => {
|
|
1889
|
+
dispatch({
|
|
1890
|
+
type: 'SET_THREAD_ID',
|
|
1891
|
+
payload: threadId
|
|
1892
|
+
});
|
|
1893
|
+
};
|
|
1894
|
+
const setThread = thread => {
|
|
1895
|
+
dispatch({
|
|
1896
|
+
type: 'SET_THREAD',
|
|
1897
|
+
payload: thread
|
|
1898
|
+
});
|
|
1899
|
+
};
|
|
1900
|
+
const setMessages = messages => {
|
|
1901
|
+
dispatch({
|
|
1902
|
+
type: 'SET_MESSAGES',
|
|
1903
|
+
payload: messages
|
|
1904
|
+
});
|
|
1905
|
+
};
|
|
1906
|
+
const setSettings = data => {
|
|
1907
|
+
dispatch({
|
|
1908
|
+
type: 'SET_SETTINGS',
|
|
1909
|
+
payload: data
|
|
1910
|
+
});
|
|
1911
|
+
};
|
|
1912
|
+
const setUnseenCount = unseenCount => {
|
|
1913
|
+
dispatch({
|
|
1914
|
+
type: 'SET_UNSEEN_COUNT',
|
|
1915
|
+
payload: unseenCount
|
|
1916
|
+
});
|
|
1917
|
+
};
|
|
1918
|
+
const setInstigatorId = id => {
|
|
1919
|
+
dispatch({
|
|
1920
|
+
type: 'SET_INSTIGATOR_ID',
|
|
1921
|
+
payload: id
|
|
1922
|
+
});
|
|
1923
|
+
};
|
|
1924
|
+
const setLiveRegionText = text => {
|
|
1925
|
+
dispatch({
|
|
1926
|
+
type: 'SET_LIVE_REGION_TEXT',
|
|
1927
|
+
payload: text
|
|
1928
|
+
});
|
|
1929
|
+
};
|
|
1930
|
+
|
|
1931
|
+
/**
|
|
1932
|
+
* Application-wide state and state functions
|
|
1933
|
+
*/
|
|
1934
|
+
const store = (0,react__WEBPACK_IMPORTED_MODULE_0__.useMemo)(() => ({
|
|
1935
|
+
...state,
|
|
1936
|
+
sdk,
|
|
1937
|
+
setSettings,
|
|
1938
|
+
setCustomerId,
|
|
1939
|
+
setThreadId,
|
|
1940
|
+
setThread,
|
|
1941
|
+
setMessages,
|
|
1942
|
+
setUnseenCount,
|
|
1943
|
+
setChatVisibility,
|
|
1944
|
+
setInstigatorId,
|
|
1945
|
+
setLiveRegionText,
|
|
1946
|
+
onLiveChatRecovered,
|
|
1947
|
+
onAssignedAgentChanged,
|
|
1948
|
+
onAgentTypingStarted,
|
|
1949
|
+
onAgentTypingEnded,
|
|
1950
|
+
onMessageCreated,
|
|
1951
|
+
onContactStatusChanged
|
|
1952
|
+
}));
|
|
1953
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(AppContext.Provider, {
|
|
1954
|
+
value: store
|
|
1955
|
+
}, children);
|
|
1956
|
+
};
|
|
392
1957
|
|
|
393
1958
|
/***/ }),
|
|
394
1959
|
|
|
395
|
-
/***/ "./src/client/
|
|
396
|
-
|
|
397
|
-
!*** ./src/client/
|
|
398
|
-
|
|
1960
|
+
/***/ "./src/client/store/actions-map.js":
|
|
1961
|
+
/*!*****************************************!*\
|
|
1962
|
+
!*** ./src/client/store/actions-map.js ***!
|
|
1963
|
+
\*****************************************/
|
|
399
1964
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
400
1965
|
|
|
401
1966
|
__webpack_require__.r(__webpack_exports__);
|
|
402
1967
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
403
|
-
/* harmony export */
|
|
1968
|
+
/* harmony export */ actionsMap: () => (/* binding */ actionsMap)
|
|
404
1969
|
/* harmony export */ });
|
|
405
|
-
/* harmony import */ var
|
|
406
|
-
/* harmony import */ var
|
|
1970
|
+
/* harmony import */ var _lib_transform_messages__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../lib/transform-messages */ "./src/client/lib/transform-messages.js");
|
|
1971
|
+
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constants */ "./src/client/store/constants.js");
|
|
407
1972
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
1973
|
+
|
|
1974
|
+
const setSettings = (state, payload) => {
|
|
1975
|
+
if (payload) {
|
|
1976
|
+
window.localStorage.setItem(_constants__WEBPACK_IMPORTED_MODULE_1__.SETTINGS_STORAGE_KEY, JSON.stringify(payload));
|
|
1977
|
+
} else {
|
|
1978
|
+
window.localStorage.removeItem(_constants__WEBPACK_IMPORTED_MODULE_1__.SETTINGS_STORAGE_KEY);
|
|
1979
|
+
}
|
|
1980
|
+
return {
|
|
1981
|
+
...state,
|
|
1982
|
+
settings: payload
|
|
1983
|
+
};
|
|
1984
|
+
};
|
|
1985
|
+
const setCustomerId = (state, payload) => {
|
|
1986
|
+
if (payload) {
|
|
1987
|
+
window.localStorage.setItem(_constants__WEBPACK_IMPORTED_MODULE_1__.CUSTOMER_ID_STORAGE_KEY, payload);
|
|
1988
|
+
} else {
|
|
1989
|
+
window.localStorage.removeItem(_constants__WEBPACK_IMPORTED_MODULE_1__.CUSTOMER_ID_STORAGE_KEY);
|
|
1990
|
+
}
|
|
1991
|
+
return {
|
|
1992
|
+
...state,
|
|
1993
|
+
customerId: payload
|
|
1994
|
+
};
|
|
1995
|
+
};
|
|
1996
|
+
const setThreadId = (state, payload) => {
|
|
1997
|
+
if (payload) {
|
|
1998
|
+
window.localStorage.setItem(_constants__WEBPACK_IMPORTED_MODULE_1__.THREAD_ID_STORAGE_KEY, payload);
|
|
1999
|
+
} else {
|
|
2000
|
+
window.localStorage.removeItem(_constants__WEBPACK_IMPORTED_MODULE_1__.THREAD_ID_STORAGE_KEY);
|
|
2001
|
+
}
|
|
2002
|
+
return {
|
|
2003
|
+
...state,
|
|
2004
|
+
threadId: payload
|
|
2005
|
+
};
|
|
2006
|
+
};
|
|
2007
|
+
const setChatVisibility = (state, payload) => {
|
|
2008
|
+
return {
|
|
2009
|
+
...state,
|
|
2010
|
+
isChatOpen: payload
|
|
2011
|
+
};
|
|
2012
|
+
};
|
|
2013
|
+
const setAvailability = (state, payload) => {
|
|
2014
|
+
return {
|
|
2015
|
+
...state,
|
|
2016
|
+
availability: payload
|
|
2017
|
+
};
|
|
2018
|
+
};
|
|
2019
|
+
const setThread = (state, payload) => {
|
|
2020
|
+
return {
|
|
2021
|
+
...state,
|
|
2022
|
+
thread: payload
|
|
2023
|
+
};
|
|
2024
|
+
};
|
|
2025
|
+
const setMessages = (state, payload) => {
|
|
2026
|
+
return {
|
|
2027
|
+
...state,
|
|
2028
|
+
messages: (0,_lib_transform_messages__WEBPACK_IMPORTED_MODULE_0__.transformMessages)(payload).reverse()
|
|
2029
|
+
};
|
|
2030
|
+
};
|
|
2031
|
+
const setMessage = (state, payload) => {
|
|
2032
|
+
return {
|
|
2033
|
+
...state,
|
|
2034
|
+
message: (0,_lib_transform_messages__WEBPACK_IMPORTED_MODULE_0__.transformMessage)(payload),
|
|
2035
|
+
messages: [...state.messages, (0,_lib_transform_messages__WEBPACK_IMPORTED_MODULE_0__.transformMessage)(payload)]
|
|
2036
|
+
};
|
|
2037
|
+
};
|
|
2038
|
+
const setAgent = (state, payload) => {
|
|
2039
|
+
return {
|
|
2040
|
+
...state,
|
|
2041
|
+
agent: payload
|
|
2042
|
+
};
|
|
2043
|
+
};
|
|
2044
|
+
const setAgentIsTyping = (state, payload) => {
|
|
2045
|
+
return {
|
|
2046
|
+
...state,
|
|
2047
|
+
isAgentTyping: payload
|
|
2048
|
+
};
|
|
2049
|
+
};
|
|
2050
|
+
const setAgentStatus = (state, payload) => {
|
|
2051
|
+
return {
|
|
2052
|
+
...state,
|
|
2053
|
+
agentStatus: payload
|
|
2054
|
+
};
|
|
2055
|
+
};
|
|
2056
|
+
const setUnseenCount = (state, payload) => {
|
|
2057
|
+
return {
|
|
2058
|
+
...state,
|
|
2059
|
+
unseenCount: payload
|
|
2060
|
+
};
|
|
2061
|
+
};
|
|
2062
|
+
const setInstigatorId = (state, payload) => {
|
|
2063
|
+
return {
|
|
2064
|
+
...state,
|
|
2065
|
+
instigatorId: payload
|
|
2066
|
+
};
|
|
2067
|
+
};
|
|
2068
|
+
const setLiveRegionText = (state, payload) => {
|
|
2069
|
+
return {
|
|
2070
|
+
...state,
|
|
2071
|
+
liveRegionText: payload
|
|
2072
|
+
};
|
|
2073
|
+
};
|
|
2074
|
+
const toggleIsMobile = (state, payload) => {
|
|
2075
|
+
return {
|
|
2076
|
+
...state,
|
|
2077
|
+
isMobile: payload
|
|
2078
|
+
};
|
|
2079
|
+
};
|
|
2080
|
+
const toggleIsKeyboard = (state, payload) => {
|
|
2081
|
+
return {
|
|
2082
|
+
...state,
|
|
2083
|
+
isKeyboard: payload
|
|
2084
|
+
};
|
|
2085
|
+
};
|
|
2086
|
+
const actionsMap = {
|
|
2087
|
+
SET_CHAT_VISIBILITY: setChatVisibility,
|
|
2088
|
+
SET_AVAILABILITY: setAvailability,
|
|
2089
|
+
SET_SETTINGS: setSettings,
|
|
2090
|
+
SET_CUSTOMER_ID: setCustomerId,
|
|
2091
|
+
SET_THREAD_ID: setThreadId,
|
|
2092
|
+
SET_THREAD: setThread,
|
|
2093
|
+
SET_MESSAGE: setMessage,
|
|
2094
|
+
SET_MESSAGES: setMessages,
|
|
2095
|
+
SET_AGENT: setAgent,
|
|
2096
|
+
SET_AGENT_TYPING: setAgentIsTyping,
|
|
2097
|
+
SET_AGENT_STATUS: setAgentStatus,
|
|
2098
|
+
SET_UNSEEN_COUNT: setUnseenCount,
|
|
2099
|
+
SET_INSTIGATOR_ID: setInstigatorId,
|
|
2100
|
+
SET_LIVE_REGION_TEXT: setLiveRegionText,
|
|
2101
|
+
TOGGLE_IS_MOBILE: toggleIsMobile,
|
|
2102
|
+
TOGGLE_IS_KEYBOARD: toggleIsKeyboard
|
|
2103
|
+
};
|
|
418
2104
|
|
|
419
2105
|
/***/ }),
|
|
420
2106
|
|
|
421
|
-
/***/ "./src/client/
|
|
422
|
-
|
|
423
|
-
!*** ./src/client/
|
|
424
|
-
|
|
2107
|
+
/***/ "./src/client/store/constants.js":
|
|
2108
|
+
/*!***************************************!*\
|
|
2109
|
+
!*** ./src/client/store/constants.js ***!
|
|
2110
|
+
\***************************************/
|
|
425
2111
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
426
2112
|
|
|
427
2113
|
__webpack_require__.r(__webpack_exports__);
|
|
428
2114
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
429
|
-
/* harmony export */
|
|
2115
|
+
/* harmony export */ CUSTOMER_ID_STORAGE_KEY: () => (/* binding */ CUSTOMER_ID_STORAGE_KEY),
|
|
2116
|
+
/* harmony export */ SETTINGS_STORAGE_KEY: () => (/* binding */ SETTINGS_STORAGE_KEY),
|
|
2117
|
+
/* harmony export */ THREAD_ID_STORAGE_KEY: () => (/* binding */ THREAD_ID_STORAGE_KEY)
|
|
430
2118
|
/* harmony export */ });
|
|
431
|
-
|
|
432
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return { value: void 0, done: !0 }; } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable || "" === iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } throw new TypeError(_typeof(iterable) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
433
|
-
|
|
434
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
435
|
-
function checkAvailability(_x) {
|
|
436
|
-
return _checkAvailability.apply(this, arguments);
|
|
437
|
-
}
|
|
438
|
-
function _checkAvailability() {
|
|
439
|
-
_checkAvailability = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(endpoint) {
|
|
440
|
-
var response, data;
|
|
441
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
442
|
-
while (1) switch (_context.prev = _context.next) {
|
|
443
|
-
case 0:
|
|
444
|
-
_context.next = 2;
|
|
445
|
-
return fetch(endpoint);
|
|
446
|
-
case 2:
|
|
447
|
-
response = _context.sent;
|
|
448
|
-
_context.next = 5;
|
|
449
|
-
return response.json();
|
|
450
|
-
case 5:
|
|
451
|
-
data = _context.sent;
|
|
452
|
-
return _context.abrupt("return", {
|
|
453
|
-
availability: data.availability || 'UNAVAILABLE'
|
|
454
|
-
});
|
|
455
|
-
case 7:
|
|
456
|
-
case "end":
|
|
457
|
-
return _context.stop();
|
|
458
|
-
}
|
|
459
|
-
}, _callee);
|
|
460
|
-
}));
|
|
461
|
-
return _checkAvailability.apply(this, arguments);
|
|
462
|
-
}
|
|
2119
|
+
const SETTINGS_STORAGE_KEY = 'webchat_settings';
|
|
2120
|
+
const CUSTOMER_ID_STORAGE_KEY = 'webchat_customer_id';
|
|
2121
|
+
const THREAD_ID_STORAGE_KEY = 'webchat_thread_id';
|
|
463
2122
|
|
|
464
2123
|
/***/ }),
|
|
465
2124
|
|
|
466
|
-
/***/ "./src/client/
|
|
467
|
-
|
|
468
|
-
!*** ./src/client/
|
|
469
|
-
|
|
2125
|
+
/***/ "./src/client/store/reducer.js":
|
|
2126
|
+
/*!*************************************!*\
|
|
2127
|
+
!*** ./src/client/store/reducer.js ***!
|
|
2128
|
+
\*************************************/
|
|
470
2129
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
471
2130
|
|
|
472
2131
|
__webpack_require__.r(__webpack_exports__);
|
|
473
2132
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
474
|
-
/* harmony export */
|
|
2133
|
+
/* harmony export */ initialState: () => (/* binding */ initialState),
|
|
2134
|
+
/* harmony export */ reducer: () => (/* binding */ reducer)
|
|
475
2135
|
/* harmony export */ });
|
|
476
|
-
var
|
|
477
|
-
|
|
478
|
-
|
|
2136
|
+
/* harmony import */ var _actions_map__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./actions-map */ "./src/client/store/actions-map.js");
|
|
2137
|
+
|
|
2138
|
+
const initialState = {
|
|
2139
|
+
availability: null,
|
|
2140
|
+
customerId: null,
|
|
2141
|
+
threadId: null,
|
|
2142
|
+
thread: null,
|
|
2143
|
+
messages: [],
|
|
2144
|
+
unseenCount: 0,
|
|
2145
|
+
instigatorId: null,
|
|
2146
|
+
agent: null,
|
|
2147
|
+
agentStatus: null,
|
|
2148
|
+
isAgentTyping: false,
|
|
2149
|
+
isChatOpen: false,
|
|
2150
|
+
isMobile: window.matchMedia('(max-width: 640px)').matches,
|
|
2151
|
+
isKeyboard: false,
|
|
2152
|
+
settings: {
|
|
2153
|
+
audio: true,
|
|
2154
|
+
scroll: true
|
|
2155
|
+
}
|
|
2156
|
+
};
|
|
2157
|
+
const reducer = (state, action) => {
|
|
2158
|
+
const {
|
|
2159
|
+
type,
|
|
2160
|
+
payload
|
|
2161
|
+
} = action;
|
|
2162
|
+
const fn = _actions_map__WEBPACK_IMPORTED_MODULE_0__.actionsMap[type];
|
|
2163
|
+
if (fn) {
|
|
2164
|
+
const actionFunction = fn.bind(undefined, state, payload);
|
|
2165
|
+
return actionFunction();
|
|
479
2166
|
}
|
|
480
|
-
return
|
|
481
|
-
return classname && typeof classname === 'string';
|
|
482
|
-
}).join(' ');
|
|
2167
|
+
return state;
|
|
483
2168
|
};
|
|
484
2169
|
|
|
485
2170
|
/***/ }),
|
|
486
2171
|
|
|
487
|
-
/***/ "./src/client/
|
|
488
|
-
|
|
489
|
-
!*** ./src/client/
|
|
490
|
-
|
|
2172
|
+
/***/ "./src/client/store/useApp.js":
|
|
2173
|
+
/*!************************************!*\
|
|
2174
|
+
!*** ./src/client/store/useApp.js ***!
|
|
2175
|
+
\************************************/
|
|
491
2176
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
492
2177
|
|
|
493
2178
|
__webpack_require__.r(__webpack_exports__);
|
|
494
2179
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
495
|
-
/* harmony export */
|
|
496
|
-
/* harmony export */ useWebchatOpenState: () => (/* binding */ useWebchatOpenState)
|
|
2180
|
+
/* harmony export */ useApp: () => (/* binding */ useApp)
|
|
497
2181
|
/* harmony export */ });
|
|
498
|
-
/* harmony import */ var
|
|
2182
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
2183
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
2184
|
+
/* harmony import */ var _AppProvider_jsx__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./AppProvider.jsx */ "./src/client/store/AppProvider.jsx");
|
|
2185
|
+
|
|
499
2186
|
|
|
500
|
-
|
|
501
|
-
var useMessageThread = _external_sync_store__WEBPACK_IMPORTED_MODULE_0__["default"].create([]);
|
|
2187
|
+
const useApp = () => (0,react__WEBPACK_IMPORTED_MODULE_0__.useContext)(_AppProvider_jsx__WEBPACK_IMPORTED_MODULE_1__.AppContext);
|
|
502
2188
|
|
|
503
2189
|
/***/ }),
|
|
504
2190
|
|
|
505
|
-
/***/ "./src/client/
|
|
506
|
-
|
|
507
|
-
!*** ./src/client/
|
|
508
|
-
|
|
2191
|
+
/***/ "./src/client/store/useChatSdk.js":
|
|
2192
|
+
/*!****************************************!*\
|
|
2193
|
+
!*** ./src/client/store/useChatSdk.js ***!
|
|
2194
|
+
\****************************************/
|
|
509
2195
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
510
2196
|
|
|
511
2197
|
__webpack_require__.r(__webpack_exports__);
|
|
512
2198
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
513
|
-
/* harmony export */
|
|
2199
|
+
/* harmony export */ useChatSdk: () => (/* binding */ useChatSdk)
|
|
514
2200
|
/* harmony export */ });
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
function ExternalSyncStore(initialValue) {
|
|
533
|
-
_classCallCheck(this, ExternalSyncStore);
|
|
534
|
-
this._value = initialValue;
|
|
535
|
-
this._listeners = [];
|
|
536
|
-
}
|
|
537
|
-
_createClass(ExternalSyncStore, [{
|
|
538
|
-
key: "update",
|
|
539
|
-
value: function update(value) {
|
|
540
|
-
this._value = value;
|
|
541
|
-
this.emitChange();
|
|
542
|
-
}
|
|
543
|
-
}, {
|
|
544
|
-
key: "subscribe",
|
|
545
|
-
value: function subscribe(listener) {
|
|
546
|
-
var _this = this;
|
|
547
|
-
this._listeners = [].concat(_toConsumableArray(this._listeners), [listener]);
|
|
548
|
-
return function () {
|
|
549
|
-
_this._listeners = _this._listeners.filter(function (l) {
|
|
550
|
-
return l !== listener;
|
|
551
|
-
});
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
}, {
|
|
555
|
-
key: "emitChange",
|
|
556
|
-
value: function emitChange() {
|
|
557
|
-
var _iterator = _createForOfIteratorHelper(this._listeners),
|
|
558
|
-
_step;
|
|
2201
|
+
const useChatSdk = sdk => {
|
|
2202
|
+
const connect = async () => sdk.authorize();
|
|
2203
|
+
const fetchCustomerId = async () => {
|
|
2204
|
+
const response = await connect();
|
|
2205
|
+
return response?.consumerIdentity.idOnExternalPlatform;
|
|
2206
|
+
};
|
|
2207
|
+
const fetchThread = async threadId => {
|
|
2208
|
+
await connect();
|
|
2209
|
+
return sdk.getThread(threadId);
|
|
2210
|
+
};
|
|
2211
|
+
const fetchMessages = async (thread, threadId) => {
|
|
2212
|
+
await connect();
|
|
2213
|
+
const recovered = await thread.recover(threadId);
|
|
2214
|
+
const allMessages = [];
|
|
2215
|
+
let fetchedMessages = recovered.messages;
|
|
2216
|
+
while (fetchedMessages.length) {
|
|
2217
|
+
fetchedMessages.map(msg => allMessages.push(msg));
|
|
559
2218
|
try {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
listener();
|
|
563
|
-
}
|
|
2219
|
+
const response = await thread.loadMoreMessages();
|
|
2220
|
+
fetchedMessages = response.data.messages;
|
|
564
2221
|
} catch (err) {
|
|
565
|
-
|
|
566
|
-
} finally {
|
|
567
|
-
_iterator.f();
|
|
2222
|
+
fetchedMessages = [];
|
|
568
2223
|
}
|
|
569
2224
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
2225
|
+
return allMessages;
|
|
2226
|
+
};
|
|
2227
|
+
return {
|
|
2228
|
+
connect,
|
|
2229
|
+
fetchCustomerId,
|
|
2230
|
+
fetchThread,
|
|
2231
|
+
fetchMessages
|
|
2232
|
+
};
|
|
2233
|
+
};
|
|
2234
|
+
|
|
2235
|
+
/***/ }),
|
|
2236
|
+
|
|
2237
|
+
/***/ "@nice-devone/nice-cxone-chat-web-sdk":
|
|
2238
|
+
/*!*******************************************************!*\
|
|
2239
|
+
!*** external "@nice-devone/nice-cxone-chat-web-sdk" ***!
|
|
2240
|
+
\*******************************************************/
|
|
2241
|
+
/***/ ((module) => {
|
|
2242
|
+
|
|
2243
|
+
module.exports = require("@nice-devone/nice-cxone-chat-web-sdk");
|
|
2244
|
+
|
|
2245
|
+
/***/ }),
|
|
2246
|
+
|
|
2247
|
+
/***/ "lodash.debounce":
|
|
2248
|
+
/*!**********************************!*\
|
|
2249
|
+
!*** external "lodash.debounce" ***!
|
|
2250
|
+
\**********************************/
|
|
2251
|
+
/***/ ((module) => {
|
|
2252
|
+
|
|
2253
|
+
module.exports = require("lodash.debounce");
|
|
2254
|
+
|
|
2255
|
+
/***/ }),
|
|
2256
|
+
|
|
2257
|
+
/***/ "luxon":
|
|
2258
|
+
/*!************************!*\
|
|
2259
|
+
!*** external "luxon" ***!
|
|
2260
|
+
\************************/
|
|
2261
|
+
/***/ ((module) => {
|
|
589
2262
|
|
|
2263
|
+
module.exports = require("luxon");
|
|
590
2264
|
|
|
591
2265
|
/***/ }),
|
|
592
2266
|
|
|
@@ -618,6 +2292,16 @@ module.exports = require("react-dom");
|
|
|
618
2292
|
|
|
619
2293
|
module.exports = require("react-dom/client");
|
|
620
2294
|
|
|
2295
|
+
/***/ }),
|
|
2296
|
+
|
|
2297
|
+
/***/ "uuid":
|
|
2298
|
+
/*!***********************!*\
|
|
2299
|
+
!*** external "uuid" ***!
|
|
2300
|
+
\***********************/
|
|
2301
|
+
/***/ ((module) => {
|
|
2302
|
+
|
|
2303
|
+
module.exports = require("uuid");
|
|
2304
|
+
|
|
621
2305
|
/***/ })
|
|
622
2306
|
|
|
623
2307
|
/******/ });
|
|
@@ -702,49 +2386,39 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
702
2386
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
703
2387
|
/* harmony import */ var react_dom_client__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react-dom/client */ "react-dom/client");
|
|
704
2388
|
/* harmony import */ var react_dom_client__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react_dom_client__WEBPACK_IMPORTED_MODULE_1__);
|
|
705
|
-
/* harmony import */ var
|
|
706
|
-
/* harmony import */ var
|
|
707
|
-
|
|
708
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return { value: void 0, done: !0 }; } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable || "" === iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } throw new TypeError(_typeof(iterable) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
709
|
-
|
|
710
|
-
|
|
2389
|
+
/* harmony import */ var _nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @nice-devone/nice-cxone-chat-web-sdk */ "@nice-devone/nice-cxone-chat-web-sdk");
|
|
2390
|
+
/* harmony import */ var _nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_2__);
|
|
2391
|
+
/* harmony import */ var _components_availability_availability_jsx__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./components/availability/availability.jsx */ "./src/client/components/availability/availability.jsx");
|
|
2392
|
+
/* harmony import */ var _lib_check_availability__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./lib/check-availability */ "./src/client/lib/check-availability.js");
|
|
2393
|
+
/* harmony import */ var _store_AppProvider_jsx__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./store/AppProvider.jsx */ "./src/client/store/AppProvider.jsx");
|
|
2394
|
+
/* harmony import */ var _store_constants_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./store/constants.js */ "./src/client/store/constants.js");
|
|
711
2395
|
|
|
712
2396
|
|
|
713
2397
|
|
|
714
2398
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
function
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
root.render( /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_components_availability_availability_jsx__WEBPACK_IMPORTED_MODULE_2__.Availability, {
|
|
739
|
-
availability: availability
|
|
740
|
-
}));
|
|
741
|
-
case 12:
|
|
742
|
-
case "end":
|
|
743
|
-
return _context.stop();
|
|
744
|
-
}
|
|
745
|
-
}, _callee, null, [[1, 8]]);
|
|
746
|
-
}));
|
|
747
|
-
return _init.apply(this, arguments);
|
|
2399
|
+
|
|
2400
|
+
|
|
2401
|
+
|
|
2402
|
+
async function init(container, options) {
|
|
2403
|
+
const sdk = new _nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_2__.ChatSdk({
|
|
2404
|
+
brandId: options.brandId,
|
|
2405
|
+
channelId: options.channelId,
|
|
2406
|
+
customerId: window.localStorage.getItem(_store_constants_js__WEBPACK_IMPORTED_MODULE_6__.CUSTOMER_ID_STORAGE_KEY) || '',
|
|
2407
|
+
environment: options.environment
|
|
2408
|
+
});
|
|
2409
|
+
const root = (0,react_dom_client__WEBPACK_IMPORTED_MODULE_1__.createRoot)(container);
|
|
2410
|
+
let availability;
|
|
2411
|
+
try {
|
|
2412
|
+
const result = await (0,_lib_check_availability__WEBPACK_IMPORTED_MODULE_4__.checkAvailability)(options.availabilityEndpoint);
|
|
2413
|
+
availability = result.availability;
|
|
2414
|
+
} catch (e) {
|
|
2415
|
+
availability = 'UNAVAILABLE';
|
|
2416
|
+
}
|
|
2417
|
+
root.render( /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_store_AppProvider_jsx__WEBPACK_IMPORTED_MODULE_5__.AppProvider, {
|
|
2418
|
+
sdk: sdk,
|
|
2419
|
+
availability: availability,
|
|
2420
|
+
options: options
|
|
2421
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_components_availability_availability_jsx__WEBPACK_IMPORTED_MODULE_3__.Availability, null)));
|
|
748
2422
|
}
|
|
749
2423
|
})();
|
|
750
2424
|
|