@defra/flood-webchat 0.0.1-beta.4 → 0.0.1-beta.40

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