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