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