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