@defra/flood-webchat 0.0.1-beta.3 → 0.0.1-beta.31

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