@defra/flood-webchat 0.0.1-beta.1 → 0.0.1-beta.11
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 +1316 -214
- package/dist/client.js.map +1 -1
- package/dist/server.js +181 -240
- package/dist/server.js.map +1 -1
- package/main.scss +4 -3
- package/package.json +9 -3
- package/src/client/components/availability/availability.jsx +43 -46
- package/src/client/components/chat/chat.jsx +143 -0
- package/src/client/components/chat/chat.scss +134 -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 +39 -0
- package/src/client/components/panel/panel.jsx +113 -0
- package/src/client/components/panel/panel.scss +72 -0
- package/src/client/components/screens/end-chat.jsx +17 -0
- package/src/client/components/screens/pre-chat.jsx +55 -0
- package/src/client/components/screens/request-chat.jsx +170 -0
- package/src/client/components/screens/unavailable.jsx +23 -0
- package/src/client/hooks/useFocusedElements.js +71 -0
- package/src/client/hooks/useTextareaAutosize.js +13 -0
- package/src/client/index.jsx +15 -1
- package/src/client/lib/check-availability.js +1 -0
- package/src/client/lib/transform-messages.js +14 -0
- package/src/client/store/AppProvider.jsx +114 -0
- package/src/client/store/actions-map.js +97 -0
- package/src/client/store/reducer.js +29 -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,76 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
15
15
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
16
16
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
17
17
|
/* harmony import */ var _lib_classnames__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../lib/classnames */ "./src/client/lib/classnames.js");
|
|
18
|
-
/* harmony import */ var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var buttonRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
|
|
38
|
-
var onClick = function onClick() {
|
|
39
|
-
setOpen(!isOpen);
|
|
40
|
-
};
|
|
41
|
-
var onKeyDown = function onKeyDown(event) {
|
|
18
|
+
/* harmony import */ var _panel_panel_jsx__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../panel/panel.jsx */ "./src/client/components/panel/panel.jsx");
|
|
19
|
+
/* harmony import */ var _store_useApp__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../store/useApp */ "./src/client/store/useApp.js");
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function Availability() {
|
|
25
|
+
const {
|
|
26
|
+
availability,
|
|
27
|
+
messages,
|
|
28
|
+
isChatOpen,
|
|
29
|
+
setChatVisibility
|
|
30
|
+
} = (0,_store_useApp__WEBPACK_IMPORTED_MODULE_3__.useApp)();
|
|
31
|
+
const [isFixed, setIsFixed] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(false);
|
|
32
|
+
const buttonRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
|
|
33
|
+
const onClick = () => {
|
|
34
|
+
setChatVisibility(!isChatOpen);
|
|
35
|
+
};
|
|
36
|
+
const onKeyDown = event => {
|
|
42
37
|
if (event.key === ' ') {
|
|
43
38
|
event.preventDefault();
|
|
44
39
|
}
|
|
45
40
|
};
|
|
46
|
-
|
|
41
|
+
const onKeyUp = event => {
|
|
47
42
|
if (event.key === ' ') {
|
|
48
|
-
|
|
43
|
+
setChatVisibility(!isChatOpen);
|
|
49
44
|
}
|
|
50
45
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
setFixed(!isOpen && isBelowFold);
|
|
46
|
+
const intersectionCallback = entries => {
|
|
47
|
+
const [entry] = entries;
|
|
48
|
+
const isBelowFold = !entry.isIntersecting && entry.boundingClientRect.top > 0;
|
|
49
|
+
setIsFixed(!isChatOpen && isBelowFold);
|
|
56
50
|
};
|
|
57
|
-
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(
|
|
58
|
-
|
|
59
|
-
var observer = new window.IntersectionObserver(intersectionCallback, {
|
|
51
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
52
|
+
const observer = new window.IntersectionObserver(intersectionCallback, {
|
|
60
53
|
rootMargin: '35px'
|
|
61
54
|
});
|
|
62
|
-
|
|
55
|
+
const parentElement = buttonRef.current?.parentElement;
|
|
63
56
|
if (parentElement) {
|
|
64
57
|
observer.observe(parentElement);
|
|
65
58
|
}
|
|
66
|
-
return
|
|
59
|
+
return () => {
|
|
67
60
|
if (parentElement) {
|
|
68
61
|
observer.unobserve(parentElement);
|
|
69
62
|
}
|
|
70
63
|
};
|
|
71
|
-
}, [buttonRef,
|
|
72
|
-
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(
|
|
64
|
+
}, [buttonRef, isChatOpen]);
|
|
65
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
73
66
|
document.documentElement.classList.toggle('wc-scroll-padding', isFixed);
|
|
74
67
|
document.body.classList.toggle('wc-scroll-padding', isFixed);
|
|
75
68
|
}, [isFixed]);
|
|
76
|
-
|
|
69
|
+
let TextComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, "Show Chat");
|
|
70
|
+
if (!messages.length) {
|
|
71
|
+
TextComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement((react__WEBPACK_IMPORTED_MODULE_0___default().Fragment), null, "Start Chat");
|
|
72
|
+
}
|
|
73
|
+
switch (availability) {
|
|
77
74
|
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'),
|
|
75
|
+
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", {
|
|
76
|
+
className: (0,_lib_classnames__WEBPACK_IMPORTED_MODULE_1__.classnames)('wc-availability', isFixed && 'wc-availability--fixed', isChatOpen && 'wc-open'),
|
|
80
77
|
ref: buttonRef
|
|
81
78
|
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
82
79
|
className: "wc-availability__inner"
|
|
83
80
|
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
84
81
|
className: "wc-availability__link",
|
|
85
82
|
href: "#webchat",
|
|
86
|
-
role: "button",
|
|
87
83
|
draggable: "false",
|
|
88
84
|
onClick: onClick,
|
|
89
85
|
onKeyUp: onKeyUp,
|
|
90
86
|
onKeyDown: onKeyDown
|
|
91
|
-
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(
|
|
87
|
+
}, TextComponent))), isChatOpen && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_panel_panel_jsx__WEBPACK_IMPORTED_MODULE_2__.Panel, null));
|
|
92
88
|
case 'EXISTING':
|
|
93
89
|
case 'UNAVAILABLE':
|
|
94
90
|
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
@@ -100,25 +96,841 @@ function Availability(props) {
|
|
|
100
96
|
}, "Checking availability");
|
|
101
97
|
}
|
|
102
98
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
99
|
+
|
|
100
|
+
/***/ }),
|
|
101
|
+
|
|
102
|
+
/***/ "./src/client/components/chat/chat.jsx":
|
|
103
|
+
/*!*********************************************!*\
|
|
104
|
+
!*** ./src/client/components/chat/chat.jsx ***!
|
|
105
|
+
\*********************************************/
|
|
106
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
107
|
+
|
|
108
|
+
__webpack_require__.r(__webpack_exports__);
|
|
109
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
110
|
+
/* harmony export */ Chat: () => (/* binding */ Chat)
|
|
111
|
+
/* harmony export */ });
|
|
112
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
113
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
114
|
+
/* harmony import */ var sanitize_html__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! sanitize-html */ "sanitize-html");
|
|
115
|
+
/* harmony import */ var sanitize_html__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(sanitize_html__WEBPACK_IMPORTED_MODULE_1__);
|
|
116
|
+
/* harmony import */ var _panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../panel/panel-header.jsx */ "./src/client/components/panel/panel-header.jsx");
|
|
117
|
+
/* harmony import */ var _panel_panel_footer_jsx__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../panel/panel-footer.jsx */ "./src/client/components/panel/panel-footer.jsx");
|
|
118
|
+
/* harmony import */ var _message_message_jsx__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../message/message.jsx */ "./src/client/components/message/message.jsx");
|
|
119
|
+
/* harmony import */ var _store_useApp_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../store/useApp.js */ "./src/client/store/useApp.js");
|
|
120
|
+
/* harmony import */ var _hooks_useTextareaAutosize_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../hooks/useTextareaAutosize.js */ "./src/client/hooks/useTextareaAutosize.js");
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
function Chat({
|
|
129
|
+
onEndChat
|
|
130
|
+
}) {
|
|
131
|
+
const {
|
|
132
|
+
availability,
|
|
133
|
+
thread,
|
|
134
|
+
messages,
|
|
135
|
+
agent,
|
|
136
|
+
agentStatus,
|
|
137
|
+
isAgentTyping
|
|
138
|
+
} = (0,_store_useApp_js__WEBPACK_IMPORTED_MODULE_5__.useApp)();
|
|
139
|
+
const [userMessage, setUserMessage] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)('');
|
|
140
|
+
const messageRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
|
|
141
|
+
(0,_hooks_useTextareaAutosize_js__WEBPACK_IMPORTED_MODULE_6__.useTextareaAutosize)(messageRef.current, userMessage);
|
|
142
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
143
|
+
if (messages.length !== 0) {
|
|
144
|
+
const chatBody = document.querySelector('.wc-body');
|
|
145
|
+
chatBody.scrollTop = chatBody.scrollHeight;
|
|
146
|
+
}
|
|
147
|
+
}, [messages, isAgentTyping]);
|
|
148
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
149
|
+
const label = document.querySelector('.wc-form__label');
|
|
150
|
+
if (userMessage.length === 0) {
|
|
151
|
+
label.classList.remove('govuk-visually-hidden');
|
|
152
|
+
} else {
|
|
153
|
+
label.classList.add('govuk-visually-hidden');
|
|
154
|
+
}
|
|
155
|
+
}, [userMessage]);
|
|
156
|
+
const onChange = e => {
|
|
157
|
+
setUserMessage(e.target?.value);
|
|
158
|
+
};
|
|
159
|
+
const agentName = agent?.nickname || agent?.firstName;
|
|
160
|
+
let connectionHeadlineText = 'Connecting to Floodline';
|
|
161
|
+
if (agentStatus === 'closed') {
|
|
162
|
+
connectionHeadlineText = agentName ? `${agentName} ended the session` : 'Session ended by advisor';
|
|
163
|
+
} else if (agentStatus) {
|
|
164
|
+
if (agentName) {
|
|
165
|
+
connectionHeadlineText = `You are speaking with ${agentName}`;
|
|
166
|
+
} else {
|
|
167
|
+
connectionHeadlineText = 'No advisers currently available';
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (availability === 'UNAVAILABLE') {
|
|
171
|
+
connectionHeadlineText = 'Webchat is not currently available';
|
|
112
172
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
173
|
+
const sendMessage = e => {
|
|
174
|
+
e.preventDefault();
|
|
175
|
+
if (messageRef.current.value.length === 0) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
thread.sendTextMessage(sanitize_html__WEBPACK_IMPORTED_MODULE_1___default()(messageRef.current.value.trim()));
|
|
180
|
+
} catch (err) {
|
|
181
|
+
console.log('[Chat Error] sendMessage', err);
|
|
182
|
+
}
|
|
183
|
+
setUserMessage('');
|
|
184
|
+
};
|
|
185
|
+
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_2__.PanelHeader, null), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
186
|
+
className: "wc-status"
|
|
187
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
188
|
+
className: "wc-status__availability govuk-body-s"
|
|
189
|
+
}, connectionHeadlineText), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
190
|
+
className: "wc-status__link govuk-!-font-size-16",
|
|
191
|
+
href: "#",
|
|
192
|
+
"data-module": "govuk-button",
|
|
193
|
+
onClick: onEndChat
|
|
194
|
+
}, "End chat")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
195
|
+
className: "wc-body"
|
|
196
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
197
|
+
className: "wc-chat__body"
|
|
198
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("ul", {
|
|
199
|
+
className: "wc-chat__messages"
|
|
200
|
+
}, messages.length ? messages.map((msg, index) => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_message_message_jsx__WEBPACK_IMPORTED_MODULE_4__.Message, {
|
|
201
|
+
key: msg.id,
|
|
202
|
+
message: msg,
|
|
203
|
+
previousMessage: messages[index - 1]
|
|
204
|
+
})) : null, isAgentTyping ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("li", {
|
|
205
|
+
className: "wc-chat__message govuk-body outbound"
|
|
206
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
207
|
+
className: "wc-chat__from govuk-!-font-size-14"
|
|
208
|
+
}, agentName, " is typing"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
209
|
+
className: "wc-chat__text outbound"
|
|
210
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("svg", {
|
|
211
|
+
width: "28",
|
|
212
|
+
height: "16",
|
|
213
|
+
x: "0px",
|
|
214
|
+
y: "0px",
|
|
215
|
+
viewBox: "0 0 28 16"
|
|
216
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("circle", {
|
|
217
|
+
stroke: "none",
|
|
218
|
+
cx: "3",
|
|
219
|
+
cy: "8",
|
|
220
|
+
r: "3",
|
|
221
|
+
fill: "currentColor"
|
|
222
|
+
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("circle", {
|
|
223
|
+
stroke: "none",
|
|
224
|
+
cx: "14",
|
|
225
|
+
cy: "8",
|
|
226
|
+
r: "3",
|
|
227
|
+
fill: "currentColor"
|
|
228
|
+
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("circle", {
|
|
229
|
+
stroke: "none",
|
|
230
|
+
cx: "25",
|
|
231
|
+
cy: "8",
|
|
232
|
+
r: "3",
|
|
233
|
+
fill: "currentColor"
|
|
234
|
+
})))) : null))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_panel_panel_footer_jsx__WEBPACK_IMPORTED_MODULE_3__.PanelFooter, null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
235
|
+
className: "wc-footer__input"
|
|
236
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("form", {
|
|
237
|
+
className: "wc-form",
|
|
238
|
+
noValidate: true
|
|
239
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("label", {
|
|
240
|
+
className: "govuk-label wc-form__label govuk-!-font-size-16",
|
|
241
|
+
htmlFor: "wc-form-textarea"
|
|
242
|
+
}, "Your message", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("span", {
|
|
243
|
+
className: "govuk-visually-hidden"
|
|
244
|
+
}, " (enter key submits)")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("textarea", {
|
|
245
|
+
ref: messageRef,
|
|
246
|
+
rows: "1",
|
|
247
|
+
"aria-required": "true",
|
|
248
|
+
className: "wc-form__textarea govuk-textarea govuk-!-font-size-16",
|
|
249
|
+
id: "wc-form-textarea",
|
|
250
|
+
name: "message",
|
|
251
|
+
onChange: onChange,
|
|
252
|
+
value: userMessage
|
|
253
|
+
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("input", {
|
|
254
|
+
type: "submit",
|
|
255
|
+
className: "wc-form__button govuk-button govuk-!-font-size-16",
|
|
256
|
+
value: "Send",
|
|
257
|
+
"data-prevent-double-click": "true",
|
|
258
|
+
onClick: sendMessage
|
|
259
|
+
}))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
260
|
+
className: "wc-footer__settings"
|
|
261
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
262
|
+
href: "#",
|
|
263
|
+
className: "wc-footer__settings-link",
|
|
264
|
+
"data-module": "govuk-button"
|
|
265
|
+
}, "Settings"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
266
|
+
href: "#",
|
|
267
|
+
className: "wc-footer__settings-link",
|
|
268
|
+
"data-module": "govuk-button",
|
|
269
|
+
download: "transcript.txt"
|
|
270
|
+
}, "Save chat"))));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/***/ }),
|
|
274
|
+
|
|
275
|
+
/***/ "./src/client/components/message/message.jsx":
|
|
276
|
+
/*!***************************************************!*\
|
|
277
|
+
!*** ./src/client/components/message/message.jsx ***!
|
|
278
|
+
\***************************************************/
|
|
279
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
280
|
+
|
|
281
|
+
__webpack_require__.r(__webpack_exports__);
|
|
282
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
283
|
+
/* harmony export */ Message: () => (/* binding */ Message)
|
|
284
|
+
/* harmony export */ });
|
|
285
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
286
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
287
|
+
/* harmony import */ var _lib_classnames__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../lib/classnames */ "./src/client/lib/classnames.js");
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
function Message({
|
|
291
|
+
message,
|
|
292
|
+
previousMessage
|
|
293
|
+
}) {
|
|
294
|
+
const outbound = message.direction === 'outbound';
|
|
295
|
+
const messageOwnerSameAsPrevious = message?.direction === previousMessage?.direction;
|
|
296
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("li", {
|
|
297
|
+
className: (0,_lib_classnames__WEBPACK_IMPORTED_MODULE_1__.classnames)('wc-chat__message govuk-body', outbound ? 'outbound' : 'inbound')
|
|
298
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
299
|
+
className: "wc-chat__from govuk-!-font-size-14"
|
|
300
|
+
}, 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
301
|
className: "govuk-visually-hidden"
|
|
117
|
-
}, " ",
|
|
302
|
+
}, ":")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
303
|
+
className: (0,_lib_classnames__WEBPACK_IMPORTED_MODULE_1__.classnames)('wc-chat__text', 'govuk-body-s', outbound ? 'outbound' : 'inbound')
|
|
304
|
+
}, message.text));
|
|
118
305
|
}
|
|
119
306
|
|
|
120
307
|
/***/ }),
|
|
121
308
|
|
|
309
|
+
/***/ "./src/client/components/panel/panel-footer.jsx":
|
|
310
|
+
/*!******************************************************!*\
|
|
311
|
+
!*** ./src/client/components/panel/panel-footer.jsx ***!
|
|
312
|
+
\******************************************************/
|
|
313
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
314
|
+
|
|
315
|
+
__webpack_require__.r(__webpack_exports__);
|
|
316
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
317
|
+
/* harmony export */ PanelFooter: () => (/* binding */ PanelFooter)
|
|
318
|
+
/* harmony export */ });
|
|
319
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
320
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
321
|
+
|
|
322
|
+
function PanelFooter({
|
|
323
|
+
children
|
|
324
|
+
}) {
|
|
325
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
326
|
+
className: "wc-footer"
|
|
327
|
+
}, children);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/***/ }),
|
|
331
|
+
|
|
332
|
+
/***/ "./src/client/components/panel/panel-header.jsx":
|
|
333
|
+
/*!******************************************************!*\
|
|
334
|
+
!*** ./src/client/components/panel/panel-header.jsx ***!
|
|
335
|
+
\******************************************************/
|
|
336
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
337
|
+
|
|
338
|
+
__webpack_require__.r(__webpack_exports__);
|
|
339
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
340
|
+
/* harmony export */ PanelHeader: () => (/* binding */ PanelHeader)
|
|
341
|
+
/* harmony export */ });
|
|
342
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
343
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
344
|
+
/* harmony import */ var _store_useApp_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../store/useApp.js */ "./src/client/store/useApp.js");
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
function PanelHeader() {
|
|
348
|
+
const {
|
|
349
|
+
thread,
|
|
350
|
+
setChatVisibility
|
|
351
|
+
} = (0,_store_useApp_js__WEBPACK_IMPORTED_MODULE_1__.useApp)();
|
|
352
|
+
const onClose = e => {
|
|
353
|
+
e.preventDefault();
|
|
354
|
+
setChatVisibility(false);
|
|
355
|
+
};
|
|
356
|
+
let ButtonComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("button", {
|
|
357
|
+
className: "wc-header__close",
|
|
358
|
+
"aria-label": "Close the webchat",
|
|
359
|
+
onClick: onClose
|
|
360
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("svg", {
|
|
361
|
+
"aria-hidden": "true",
|
|
362
|
+
focusable: "false",
|
|
363
|
+
width: "20",
|
|
364
|
+
height: "20",
|
|
365
|
+
viewBox: "0 0 20 20"
|
|
366
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("path", {
|
|
367
|
+
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",
|
|
368
|
+
fill: "currentColor"
|
|
369
|
+
})));
|
|
370
|
+
if (thread) {
|
|
371
|
+
ButtonComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("button", {
|
|
372
|
+
className: "wc-header__hide",
|
|
373
|
+
"aria-label": "Minimise the webchat",
|
|
374
|
+
onClick: onClose
|
|
375
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("svg", {
|
|
376
|
+
"aria-hidden": "true",
|
|
377
|
+
focusable: "false",
|
|
378
|
+
width: "20",
|
|
379
|
+
height: "20",
|
|
380
|
+
viewBox: "0 0 20 20"
|
|
381
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("path", {
|
|
382
|
+
d: "M10 14.4l-7-7L4.4 6l5.6 5.6L15.6 6 17 7.4l-7 7z",
|
|
383
|
+
fill: "currentColor"
|
|
384
|
+
})));
|
|
385
|
+
}
|
|
386
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
387
|
+
className: "wc-header"
|
|
388
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h2", {
|
|
389
|
+
id: "wc-header-title",
|
|
390
|
+
className: "wc-header__title govuk-heading-s"
|
|
391
|
+
}, "Floodline Webchat"), ButtonComponent);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/***/ }),
|
|
395
|
+
|
|
396
|
+
/***/ "./src/client/components/panel/panel.jsx":
|
|
397
|
+
/*!***********************************************!*\
|
|
398
|
+
!*** ./src/client/components/panel/panel.jsx ***!
|
|
399
|
+
\***********************************************/
|
|
400
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
401
|
+
|
|
402
|
+
__webpack_require__.r(__webpack_exports__);
|
|
403
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
404
|
+
/* harmony export */ Panel: () => (/* binding */ Panel)
|
|
405
|
+
/* harmony export */ });
|
|
406
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
407
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
408
|
+
/* harmony import */ var react_dom__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react-dom */ "react-dom");
|
|
409
|
+
/* harmony import */ var react_dom__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react_dom__WEBPACK_IMPORTED_MODULE_1__);
|
|
410
|
+
/* harmony import */ var _screens_pre_chat_jsx__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../screens/pre-chat.jsx */ "./src/client/components/screens/pre-chat.jsx");
|
|
411
|
+
/* harmony import */ var _screens_request_chat_jsx__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../screens/request-chat.jsx */ "./src/client/components/screens/request-chat.jsx");
|
|
412
|
+
/* harmony import */ var _chat_chat_jsx__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../chat/chat.jsx */ "./src/client/components/chat/chat.jsx");
|
|
413
|
+
/* harmony import */ var _screens_unavailable_jsx__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../screens/unavailable.jsx */ "./src/client/components/screens/unavailable.jsx");
|
|
414
|
+
/* harmony import */ var _screens_end_chat_jsx__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../screens/end-chat.jsx */ "./src/client/components/screens/end-chat.jsx");
|
|
415
|
+
/* harmony import */ var _store_useApp_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../store/useApp.js */ "./src/client/store/useApp.js");
|
|
416
|
+
/* harmony import */ var _store_useChatSdk_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../../store/useChatSdk.js */ "./src/client/store/useChatSdk.js");
|
|
417
|
+
/* harmony import */ var _hooks_useFocusedElements_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../hooks/useFocusedElements.js */ "./src/client/hooks/useFocusedElements.js");
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
function Panel() {
|
|
429
|
+
const {
|
|
430
|
+
sdk,
|
|
431
|
+
availability,
|
|
432
|
+
thread,
|
|
433
|
+
threadId,
|
|
434
|
+
setThread,
|
|
435
|
+
setThreadId,
|
|
436
|
+
setChatVisibility,
|
|
437
|
+
setMessages
|
|
438
|
+
} = (0,_store_useApp_js__WEBPACK_IMPORTED_MODULE_7__.useApp)();
|
|
439
|
+
const {
|
|
440
|
+
fetchThread,
|
|
441
|
+
fetchMessages
|
|
442
|
+
} = (0,_store_useChatSdk_js__WEBPACK_IMPORTED_MODULE_8__.useChatSdk)(sdk);
|
|
443
|
+
const [screen, setScreen] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(threadId ? 2 : 0);
|
|
444
|
+
(0,_hooks_useFocusedElements_js__WEBPACK_IMPORTED_MODULE_9__.useFocusedElements)(screen);
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Initializes the eventListener for pressing the escape key
|
|
448
|
+
*/
|
|
449
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
450
|
+
const escapeKeyEvent = document.addEventListener('keydown', onEscapeKey);
|
|
451
|
+
return () => {
|
|
452
|
+
document.removeEventListener('keydown', escapeKeyEvent);
|
|
453
|
+
};
|
|
454
|
+
}, []);
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Recovers the thread if there is a threadId but no thread loaded in to state
|
|
458
|
+
*/
|
|
459
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
460
|
+
const recover = async () => {
|
|
461
|
+
try {
|
|
462
|
+
const fetchedThread = await fetchThread(threadId);
|
|
463
|
+
setThread(fetchedThread);
|
|
464
|
+
const fetchedMessages = await fetchMessages(fetchedThread, threadId);
|
|
465
|
+
setMessages(fetchedMessages);
|
|
466
|
+
} catch (err) {
|
|
467
|
+
console.log('[Chat Error] fetchThread', err);
|
|
468
|
+
setThreadId();
|
|
469
|
+
setThread();
|
|
470
|
+
setScreen(0);
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
if (threadId) {
|
|
474
|
+
thread ? setScreen(2) : recover();
|
|
475
|
+
}
|
|
476
|
+
}, [thread, threadId]);
|
|
477
|
+
const onEscapeKey = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(e => {
|
|
478
|
+
if (e.key === 'Escape' || e.key === 'Esc') {
|
|
479
|
+
setChatVisibility(false);
|
|
480
|
+
}
|
|
481
|
+
}, []);
|
|
482
|
+
const handleScreenChange = newScreen => e => {
|
|
483
|
+
e.preventDefault();
|
|
484
|
+
setScreen(newScreen);
|
|
485
|
+
};
|
|
486
|
+
const onForward = handleScreenChange(screen + 1);
|
|
487
|
+
const onBack = handleScreenChange(screen - 1);
|
|
488
|
+
const onEndChat = handleScreenChange(3);
|
|
489
|
+
const onResume = handleScreenChange(2);
|
|
490
|
+
const onEndChatConfirm = e => {
|
|
491
|
+
e.preventDefault();
|
|
492
|
+
console.log('confirmed end chat');
|
|
493
|
+
};
|
|
494
|
+
let ScreenComponent;
|
|
495
|
+
switch (screen) {
|
|
496
|
+
case 0:
|
|
497
|
+
ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_screens_pre_chat_jsx__WEBPACK_IMPORTED_MODULE_2__.PreChat, {
|
|
498
|
+
onForward: onForward
|
|
499
|
+
});
|
|
500
|
+
break;
|
|
501
|
+
case 1:
|
|
502
|
+
ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_screens_request_chat_jsx__WEBPACK_IMPORTED_MODULE_3__.RequestChat, {
|
|
503
|
+
onBack: onBack
|
|
504
|
+
});
|
|
505
|
+
break;
|
|
506
|
+
case 2:
|
|
507
|
+
ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_chat_chat_jsx__WEBPACK_IMPORTED_MODULE_4__.Chat, {
|
|
508
|
+
setScreen: setScreen,
|
|
509
|
+
onEndChat: onEndChat
|
|
510
|
+
});
|
|
511
|
+
break;
|
|
512
|
+
case 3:
|
|
513
|
+
ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_screens_end_chat_jsx__WEBPACK_IMPORTED_MODULE_6__.EndChat, {
|
|
514
|
+
onResume: onResume,
|
|
515
|
+
onEndChatConfirm: onEndChatConfirm
|
|
516
|
+
});
|
|
517
|
+
break;
|
|
518
|
+
default:
|
|
519
|
+
ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_screens_pre_chat_jsx__WEBPACK_IMPORTED_MODULE_2__.PreChat, {
|
|
520
|
+
onForward: onForward
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
if (availability === 'UNAVAILABLE') {
|
|
524
|
+
ScreenComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_screens_unavailable_jsx__WEBPACK_IMPORTED_MODULE_5__.Unavailable, null);
|
|
525
|
+
}
|
|
526
|
+
const Component = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
527
|
+
id: "wc-panel",
|
|
528
|
+
className: "wc-panel",
|
|
529
|
+
role: "dialog",
|
|
530
|
+
tabIndex: "-1",
|
|
531
|
+
"aria-modal": "true",
|
|
532
|
+
"aria-labelledby": "wc-header-title"
|
|
533
|
+
}, ScreenComponent);
|
|
534
|
+
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));
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/***/ }),
|
|
538
|
+
|
|
539
|
+
/***/ "./src/client/components/screens/end-chat.jsx":
|
|
540
|
+
/*!****************************************************!*\
|
|
541
|
+
!*** ./src/client/components/screens/end-chat.jsx ***!
|
|
542
|
+
\****************************************************/
|
|
543
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
544
|
+
|
|
545
|
+
__webpack_require__.r(__webpack_exports__);
|
|
546
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
547
|
+
/* harmony export */ EndChat: () => (/* binding */ EndChat)
|
|
548
|
+
/* harmony export */ });
|
|
549
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
550
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
551
|
+
/* harmony import */ var _panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../panel/panel-header.jsx */ "./src/client/components/panel/panel-header.jsx");
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
function EndChat({
|
|
555
|
+
onResume,
|
|
556
|
+
onEndChatConfirm
|
|
557
|
+
}) {
|
|
558
|
+
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", {
|
|
559
|
+
className: "wc-body"
|
|
560
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h3", {
|
|
561
|
+
className: "govuk-heading-s",
|
|
562
|
+
"aria-live": "polite"
|
|
563
|
+
}, "Are you sure you want to end the chat?"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
564
|
+
className: "govuk-button-group"
|
|
565
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
566
|
+
href: "#",
|
|
567
|
+
className: "govuk-button govuk-!-font-size-16",
|
|
568
|
+
"data-module": "govuk-button",
|
|
569
|
+
onClick: onEndChatConfirm
|
|
570
|
+
}, "Yes, end chat"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
571
|
+
href: "#",
|
|
572
|
+
className: "govuk-link govuk-!-font-size-16",
|
|
573
|
+
onClick: onResume
|
|
574
|
+
}, "No, resume chat"))));
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/***/ }),
|
|
578
|
+
|
|
579
|
+
/***/ "./src/client/components/screens/pre-chat.jsx":
|
|
580
|
+
/*!****************************************************!*\
|
|
581
|
+
!*** ./src/client/components/screens/pre-chat.jsx ***!
|
|
582
|
+
\****************************************************/
|
|
583
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
584
|
+
|
|
585
|
+
__webpack_require__.r(__webpack_exports__);
|
|
586
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
587
|
+
/* harmony export */ PreChat: () => (/* binding */ PreChat)
|
|
588
|
+
/* harmony export */ });
|
|
589
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
590
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
591
|
+
/* harmony import */ var _panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../panel/panel-header.jsx */ "./src/client/components/panel/panel-header.jsx");
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
function PreChat({
|
|
595
|
+
onForward
|
|
596
|
+
}) {
|
|
597
|
+
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", {
|
|
598
|
+
className: "wc-body"
|
|
599
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h3", {
|
|
600
|
+
className: "govuk-heading-s",
|
|
601
|
+
"aria-live": "polite"
|
|
602
|
+
}, "What you can use webchat for"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
603
|
+
className: "govuk-body-s"
|
|
604
|
+
}, "Webchat lets you talk directly to a Floodline adviser."), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
605
|
+
className: "govuk-body-s"
|
|
606
|
+
}, "You can use webchat to get:"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("ul", {
|
|
607
|
+
className: "govuk-list govuk-list--bullet govuk-body-s"
|
|
608
|
+
}, /*#__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", {
|
|
609
|
+
className: "govuk-body-s"
|
|
610
|
+
}, 'There are other ways to ', /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
611
|
+
className: "govuk-link",
|
|
612
|
+
href: "https://www.gov.uk/sign-up-for-flood-warnings"
|
|
613
|
+
}, "sign up for flood warnings"), ' and ', /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
614
|
+
className: "govuk-link",
|
|
615
|
+
href: "https://www.fws.environment-agency.gov.uk/app/olr/login"
|
|
616
|
+
}, "manage your flood warnings account"), "."), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
617
|
+
className: "govuk-body-s"
|
|
618
|
+
}, "Do not use webchat to ", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
619
|
+
className: "govuk-link",
|
|
620
|
+
href: "https://www.gov.uk/report-flood-cause"
|
|
621
|
+
}, "report a flood"), "."), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("button", {
|
|
622
|
+
className: "govuk-button govuk-!-font-size-16",
|
|
623
|
+
"data-module": "govuk-button",
|
|
624
|
+
onClick: onForward
|
|
625
|
+
}, "Continue"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h3", {
|
|
626
|
+
className: "govuk-heading-s"
|
|
627
|
+
}, "Other flood information"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
628
|
+
className: "govuk-body-s"
|
|
629
|
+
}, "Call Floodline for all other flood and flood warning information."), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
630
|
+
className: "govuk-body-s"
|
|
631
|
+
}, /*#__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", {
|
|
632
|
+
className: "govuk-link",
|
|
633
|
+
href: "https://gov.uk/call-charges"
|
|
634
|
+
}, "Find out more about call charges"))));
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/***/ }),
|
|
638
|
+
|
|
639
|
+
/***/ "./src/client/components/screens/request-chat.jsx":
|
|
640
|
+
/*!********************************************************!*\
|
|
641
|
+
!*** ./src/client/components/screens/request-chat.jsx ***!
|
|
642
|
+
\********************************************************/
|
|
643
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
644
|
+
|
|
645
|
+
__webpack_require__.r(__webpack_exports__);
|
|
646
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
647
|
+
/* harmony export */ RequestChat: () => (/* binding */ RequestChat)
|
|
648
|
+
/* harmony export */ });
|
|
649
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
650
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
651
|
+
/* harmony import */ var uuid__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! uuid */ "uuid");
|
|
652
|
+
/* harmony import */ var uuid__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(uuid__WEBPACK_IMPORTED_MODULE_1__);
|
|
653
|
+
/* harmony import */ var _lib_classnames_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../lib/classnames.js */ "./src/client/lib/classnames.js");
|
|
654
|
+
/* harmony import */ var _panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../panel/panel-header.jsx */ "./src/client/components/panel/panel-header.jsx");
|
|
655
|
+
/* harmony import */ var _store_useApp_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../store/useApp.js */ "./src/client/store/useApp.js");
|
|
656
|
+
/* harmony import */ var _store_useChatSdk_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../store/useChatSdk.js */ "./src/client/store/useChatSdk.js");
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
const QUESTION_MAX_LENGTH = 500;
|
|
664
|
+
function RequestChat({
|
|
665
|
+
onBack
|
|
666
|
+
}) {
|
|
667
|
+
const {
|
|
668
|
+
sdk,
|
|
669
|
+
setCustomerId,
|
|
670
|
+
setThreadId,
|
|
671
|
+
setThread
|
|
672
|
+
} = (0,_store_useApp_js__WEBPACK_IMPORTED_MODULE_4__.useApp)();
|
|
673
|
+
const {
|
|
674
|
+
fetchCustomerId,
|
|
675
|
+
fetchThread
|
|
676
|
+
} = (0,_store_useChatSdk_js__WEBPACK_IMPORTED_MODULE_5__.useChatSdk)(sdk);
|
|
677
|
+
const [errors, setErrors] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)({});
|
|
678
|
+
const [questionLength, setQuestionLength] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(0);
|
|
679
|
+
const nameRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
|
|
680
|
+
const questionRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
|
|
681
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
682
|
+
if (Object.keys(errors).length) {
|
|
683
|
+
document.querySelector('.govuk-error-summary')?.focus();
|
|
684
|
+
}
|
|
685
|
+
}, [errors]);
|
|
686
|
+
const onQuestionChange = e => {
|
|
687
|
+
setQuestionLength(e.target.value.length);
|
|
688
|
+
};
|
|
689
|
+
const onRequestChat = async e => {
|
|
690
|
+
e.preventDefault();
|
|
691
|
+
const errs = {};
|
|
692
|
+
if (nameRef.current.value.length === 0) {
|
|
693
|
+
errs.name = 'Enter your name';
|
|
694
|
+
}
|
|
695
|
+
if (questionRef.current.value.length === 0) {
|
|
696
|
+
errs.question = 'Enter your question';
|
|
697
|
+
}
|
|
698
|
+
if (questionRef.current.value.length > QUESTION_MAX_LENGTH) {
|
|
699
|
+
errs.question = 'Your question must be 500 characters or less';
|
|
700
|
+
}
|
|
701
|
+
if (Object.keys(errs).length === 0) {
|
|
702
|
+
try {
|
|
703
|
+
const threadId = uuid__WEBPACK_IMPORTED_MODULE_1__.v4();
|
|
704
|
+
const customerId = await fetchCustomerId();
|
|
705
|
+
const thread = await fetchThread(threadId);
|
|
706
|
+
sdk.getCustomer().setName(nameRef.current.value);
|
|
707
|
+
await thread.startChat(questionRef.current.value || 'Begin conversation');
|
|
708
|
+
setCustomerId(customerId);
|
|
709
|
+
setThreadId(threadId);
|
|
710
|
+
setThread(thread);
|
|
711
|
+
} catch (err) {
|
|
712
|
+
console.log('[Request Chat Error]', err);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
setErrors(errs);
|
|
716
|
+
};
|
|
717
|
+
const isQuestionLengthValid = QUESTION_MAX_LENGTH >= questionLength;
|
|
718
|
+
const questionLengthRemaining = QUESTION_MAX_LENGTH - questionLength;
|
|
719
|
+
const questionLengthExceeded = questionLength - QUESTION_MAX_LENGTH;
|
|
720
|
+
let questionHint = `You have ${questionLengthRemaining} characters remaining`;
|
|
721
|
+
if (!isQuestionLengthValid) {
|
|
722
|
+
questionHint = `You have ${questionLengthExceeded} characters too many`;
|
|
723
|
+
}
|
|
724
|
+
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", {
|
|
725
|
+
className: "wc-body"
|
|
726
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
727
|
+
href: "#",
|
|
728
|
+
className: "wc-back-link govuk-back-link",
|
|
729
|
+
onClick: onBack
|
|
730
|
+
}, "What you can use webchat for"), Object.keys(errors).length > 0 ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
731
|
+
className: "govuk-error-summary govuk-!-static-margin-bottom-7",
|
|
732
|
+
"data-module": "govuk-error-summary",
|
|
733
|
+
tabIndex: "-1"
|
|
734
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
735
|
+
role: "alert"
|
|
736
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h2", {
|
|
737
|
+
id: "wc-error",
|
|
738
|
+
className: "govuk-error-summary__title"
|
|
739
|
+
}, "There is a problem"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
740
|
+
className: "govuk-error-summary__body"
|
|
741
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("ul", {
|
|
742
|
+
className: "govuk-list govuk-error-summary__list"
|
|
743
|
+
}, Object.keys(errors).map(key => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("li", {
|
|
744
|
+
key: key
|
|
745
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("a", {
|
|
746
|
+
href: `#${key}`
|
|
747
|
+
}, errors[key]))))))) : null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h3", {
|
|
748
|
+
className: "govuk-heading-s",
|
|
749
|
+
"aria-live": "polite"
|
|
750
|
+
}, "Your name and question"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("form", null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
751
|
+
className: (0,_lib_classnames_js__WEBPACK_IMPORTED_MODULE_2__.classnames)('govuk-form-group', errors.name && 'govuk-form-group--error')
|
|
752
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("label", {
|
|
753
|
+
className: "govuk-label",
|
|
754
|
+
htmlFor: "wc-name"
|
|
755
|
+
}, "Your name"), errors.name && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
756
|
+
className: "govuk-error-message"
|
|
757
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("span", {
|
|
758
|
+
className: "govuk-visually-hidden"
|
|
759
|
+
}, "Error:"), " ", errors.name), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("input", {
|
|
760
|
+
ref: nameRef,
|
|
761
|
+
className: (0,_lib_classnames_js__WEBPACK_IMPORTED_MODULE_2__.classnames)('govuk-input', errors.name && 'govuk-input--error'),
|
|
762
|
+
id: "wc-name",
|
|
763
|
+
name: "name",
|
|
764
|
+
type: "text",
|
|
765
|
+
"data-testid": "request-chat-user-name"
|
|
766
|
+
})), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
767
|
+
className: "govuk-character-count",
|
|
768
|
+
"data-module": "govuk-character-count",
|
|
769
|
+
"data-maxlength": "500"
|
|
770
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
771
|
+
className: (0,_lib_classnames_js__WEBPACK_IMPORTED_MODULE_2__.classnames)('govuk-form-group', errors.question && 'govuk-form-group--error')
|
|
772
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("label", {
|
|
773
|
+
className: "govuk-label",
|
|
774
|
+
htmlFor: "wc-question"
|
|
775
|
+
}, "Your question"), errors.question && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
776
|
+
className: "govuk-error-message"
|
|
777
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("span", {
|
|
778
|
+
className: "govuk-visually-hidden"
|
|
779
|
+
}, "Error:"), errors.question), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("textarea", {
|
|
780
|
+
ref: questionRef,
|
|
781
|
+
id: "wc-question",
|
|
782
|
+
name: "question",
|
|
783
|
+
rows: "5",
|
|
784
|
+
"aria-describedby": "wc-question-info",
|
|
785
|
+
onChange: onQuestionChange,
|
|
786
|
+
className: (0,_lib_classnames_js__WEBPACK_IMPORTED_MODULE_2__.classnames)('govuk-textarea', 'govuk-js-character-count', !isQuestionLengthValid || errors.question ? 'govuk-textarea--error' : ''),
|
|
787
|
+
"data-testid": "request-chat-user-question"
|
|
788
|
+
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
789
|
+
id: "wc-question-info",
|
|
790
|
+
className: "govuk-hint govuk-character-count__message",
|
|
791
|
+
style: {
|
|
792
|
+
color: `${!isQuestionLengthValid ? '#d4351c' : ''}`
|
|
793
|
+
},
|
|
794
|
+
"aria-hidden": "true"
|
|
795
|
+
}, questionHint), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("div", {
|
|
796
|
+
className: "govuk-character-count__sr-status govuk-visually-hidden",
|
|
797
|
+
"aria-live": "polite"
|
|
798
|
+
}, questionHint))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("button", {
|
|
799
|
+
className: "govuk-button govuk-!-margin-top-1 govuk-!-font-size-16",
|
|
800
|
+
"data-module": "govuk-button",
|
|
801
|
+
onClick: onRequestChat
|
|
802
|
+
}, "Request chat"))));
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/***/ }),
|
|
806
|
+
|
|
807
|
+
/***/ "./src/client/components/screens/unavailable.jsx":
|
|
808
|
+
/*!*******************************************************!*\
|
|
809
|
+
!*** ./src/client/components/screens/unavailable.jsx ***!
|
|
810
|
+
\*******************************************************/
|
|
811
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
812
|
+
|
|
813
|
+
__webpack_require__.r(__webpack_exports__);
|
|
814
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
815
|
+
/* harmony export */ Unavailable: () => (/* binding */ Unavailable)
|
|
816
|
+
/* harmony export */ });
|
|
817
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
818
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
819
|
+
/* harmony import */ var _panel_panel_header_jsx__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../panel/panel-header.jsx */ "./src/client/components/panel/panel-header.jsx");
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
function Unavailable() {
|
|
823
|
+
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", {
|
|
824
|
+
className: "wc-body"
|
|
825
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("h3", {
|
|
826
|
+
id: "wc-subtitle",
|
|
827
|
+
className: "govuk-heading-m"
|
|
828
|
+
}, "Webchat is currently not available"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
829
|
+
className: "govuk-body-s"
|
|
830
|
+
}, "Try again later, or call Floodline:"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
831
|
+
className: "govuk-body-s"
|
|
832
|
+
}, /*#__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", {
|
|
833
|
+
className: "govuk-link",
|
|
834
|
+
href: "https://gov.uk/call-charges"
|
|
835
|
+
}, "Find out more about call charges")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement("p", {
|
|
836
|
+
className: "govuk-body-s"
|
|
837
|
+
}, "We're running webchat as a trial, it will not always be available.")));
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/***/ }),
|
|
841
|
+
|
|
842
|
+
/***/ "./src/client/hooks/useFocusedElements.js":
|
|
843
|
+
/*!************************************************!*\
|
|
844
|
+
!*** ./src/client/hooks/useFocusedElements.js ***!
|
|
845
|
+
\************************************************/
|
|
846
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
847
|
+
|
|
848
|
+
__webpack_require__.r(__webpack_exports__);
|
|
849
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
850
|
+
/* harmony export */ getFocusableElements: () => (/* binding */ getFocusableElements),
|
|
851
|
+
/* harmony export */ useFocusedElements: () => (/* binding */ useFocusedElements)
|
|
852
|
+
/* harmony export */ });
|
|
853
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
854
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
855
|
+
|
|
856
|
+
const setAriaHidden = bool => {
|
|
857
|
+
for (const node of document.body.children) {
|
|
858
|
+
if (node.id !== 'wc-panel') {
|
|
859
|
+
bool ? node.setAttribute('aria-hidden', 'true') : node.removeAttribute('aria-hidden');
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
const getFocusableElements = () => {
|
|
864
|
+
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])'];
|
|
865
|
+
const elements = document.body.querySelectorAll(selectors.join(','));
|
|
866
|
+
return Array.from(elements).filter(e => !e.closest('[hidden]') && !e.closest('[aria-hidden="true"]'));
|
|
867
|
+
};
|
|
868
|
+
const useFocusedElements = screen => {
|
|
869
|
+
const [panelElements, setPanelElements] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)([]);
|
|
870
|
+
const onKeyDown = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(e => {
|
|
871
|
+
const webchatPanelElement = document.querySelector('#wc-panel');
|
|
872
|
+
if (e.key === 'Tab') {
|
|
873
|
+
if (webchatPanelElement && !document.activeElement.closest('#wc-panel')) {
|
|
874
|
+
webchatPanelElement.focus();
|
|
875
|
+
}
|
|
876
|
+
if (e.shiftKey) {
|
|
877
|
+
if (document.activeElement === panelElements[0]) {
|
|
878
|
+
panelElements[panelElements.length - 1].focus();
|
|
879
|
+
e.preventDefault();
|
|
880
|
+
} else if (document.activeElement === document.querySelector('#wc-panel')) {
|
|
881
|
+
panelElements[panelElements.length - 1]?.focus();
|
|
882
|
+
e.preventDefault();
|
|
883
|
+
}
|
|
884
|
+
} else if (document.activeElement === panelElements[panelElements.length - 1]) {
|
|
885
|
+
panelElements[0].focus();
|
|
886
|
+
e.preventDefault();
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}, [panelElements]);
|
|
890
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
891
|
+
setPanelElements(getFocusableElements());
|
|
892
|
+
}, [screen]);
|
|
893
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
894
|
+
setAriaHidden(true);
|
|
895
|
+
const panelElement = document.querySelector('#wc-panel');
|
|
896
|
+
panelElement.focus();
|
|
897
|
+
document.addEventListener('keydown', onKeyDown);
|
|
898
|
+
return () => {
|
|
899
|
+
setAriaHidden();
|
|
900
|
+
document.body.querySelector('.wc-availability__link')?.focus();
|
|
901
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
902
|
+
};
|
|
903
|
+
}, [panelElements]);
|
|
904
|
+
};
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
/***/ }),
|
|
908
|
+
|
|
909
|
+
/***/ "./src/client/hooks/useTextareaAutosize.js":
|
|
910
|
+
/*!*************************************************!*\
|
|
911
|
+
!*** ./src/client/hooks/useTextareaAutosize.js ***!
|
|
912
|
+
\*************************************************/
|
|
913
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
914
|
+
|
|
915
|
+
__webpack_require__.r(__webpack_exports__);
|
|
916
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
917
|
+
/* harmony export */ useTextareaAutosize: () => (/* binding */ useTextareaAutosize)
|
|
918
|
+
/* harmony export */ });
|
|
919
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
920
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
921
|
+
|
|
922
|
+
const useTextareaAutosize = (textAreaRef, value) => {
|
|
923
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
924
|
+
if (textAreaRef) {
|
|
925
|
+
textAreaRef.style.height = '0px';
|
|
926
|
+
const scrollHeight = textAreaRef.scrollHeight;
|
|
927
|
+
textAreaRef.style.height = `${scrollHeight}px`;
|
|
928
|
+
}
|
|
929
|
+
}, [textAreaRef, value]);
|
|
930
|
+
};
|
|
931
|
+
|
|
932
|
+
/***/ }),
|
|
933
|
+
|
|
122
934
|
/***/ "./src/client/lib/check-availability.js":
|
|
123
935
|
/*!**********************************************!*\
|
|
124
936
|
!*** ./src/client/lib/check-availability.js ***!
|
|
@@ -129,37 +941,12 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
129
941
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
130
942
|
/* harmony export */ checkAvailability: () => (/* binding */ checkAvailability)
|
|
131
943
|
/* 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);
|
|
944
|
+
async function checkAvailability(endpoint) {
|
|
945
|
+
const response = await fetch(endpoint);
|
|
946
|
+
const data = await response.json();
|
|
947
|
+
return {
|
|
948
|
+
availability: data.availability || 'UNAVAILABLE'
|
|
949
|
+
};
|
|
163
950
|
}
|
|
164
951
|
|
|
165
952
|
/***/ }),
|
|
@@ -174,120 +961,414 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
174
961
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
175
962
|
/* harmony export */ classnames: () => (/* binding */ classnames)
|
|
176
963
|
/* harmony export */ });
|
|
177
|
-
|
|
178
|
-
for (var _len = arguments.length, classes = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
179
|
-
classes[_key] = arguments[_key];
|
|
180
|
-
}
|
|
181
|
-
return classes.filter(function (classname) {
|
|
182
|
-
return classname && typeof classname === 'string';
|
|
183
|
-
}).join(' ');
|
|
184
|
-
};
|
|
964
|
+
const classnames = (...classes) => classes.filter(classname => classname && typeof classname === 'string').join(' ');
|
|
185
965
|
|
|
186
966
|
/***/ }),
|
|
187
967
|
|
|
188
|
-
/***/ "./src/client/lib/
|
|
189
|
-
|
|
190
|
-
!*** ./src/client/lib/
|
|
191
|
-
|
|
968
|
+
/***/ "./src/client/lib/transform-messages.js":
|
|
969
|
+
/*!**********************************************!*\
|
|
970
|
+
!*** ./src/client/lib/transform-messages.js ***!
|
|
971
|
+
\**********************************************/
|
|
192
972
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
193
973
|
|
|
194
974
|
__webpack_require__.r(__webpack_exports__);
|
|
195
975
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
196
|
-
/* harmony export */
|
|
197
|
-
/* harmony export */
|
|
976
|
+
/* harmony export */ transformMessage: () => (/* binding */ transformMessage),
|
|
977
|
+
/* harmony export */ transformMessages: () => (/* binding */ transformMessages)
|
|
198
978
|
/* harmony export */ });
|
|
199
|
-
/* harmony import */ var
|
|
979
|
+
/* harmony import */ var sanitize_html__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! sanitize-html */ "sanitize-html");
|
|
980
|
+
/* harmony import */ var sanitize_html__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(sanitize_html__WEBPACK_IMPORTED_MODULE_0__);
|
|
200
981
|
|
|
201
|
-
|
|
202
|
-
|
|
982
|
+
const transformMessage = message => {
|
|
983
|
+
return {
|
|
984
|
+
id: message.id,
|
|
985
|
+
text: sanitize_html__WEBPACK_IMPORTED_MODULE_0___default()(message.messageContent?.text),
|
|
986
|
+
createdAt: new Date(message.createdAt),
|
|
987
|
+
user: message.authorEndUserIdentity?.fullName?.trim() || null,
|
|
988
|
+
assignee: message.authorUser?.firstName || null,
|
|
989
|
+
direction: message.direction
|
|
990
|
+
};
|
|
991
|
+
};
|
|
992
|
+
const transformMessages = messages => messages.map(message => transformMessage(message));
|
|
203
993
|
|
|
204
994
|
/***/ }),
|
|
205
995
|
|
|
206
|
-
/***/ "./src/client/
|
|
207
|
-
|
|
208
|
-
!*** ./src/client/
|
|
209
|
-
|
|
996
|
+
/***/ "./src/client/store/AppProvider.jsx":
|
|
997
|
+
/*!******************************************!*\
|
|
998
|
+
!*** ./src/client/store/AppProvider.jsx ***!
|
|
999
|
+
\******************************************/
|
|
210
1000
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
211
1001
|
|
|
212
1002
|
__webpack_require__.r(__webpack_exports__);
|
|
213
1003
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
214
|
-
/* harmony export */
|
|
1004
|
+
/* harmony export */ AppContext: () => (/* binding */ AppContext),
|
|
1005
|
+
/* harmony export */ AppProvider: () => (/* binding */ AppProvider)
|
|
215
1006
|
/* harmony export */ });
|
|
216
1007
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
217
1008
|
/* 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
|
-
|
|
1009
|
+
/* 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");
|
|
1010
|
+
/* 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__);
|
|
1011
|
+
/* harmony import */ var _reducer_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./reducer.js */ "./src/client/store/reducer.js");
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
const AppContext = /*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.createContext)(_reducer_js__WEBPACK_IMPORTED_MODULE_2__.initialState);
|
|
1016
|
+
const AppProvider = ({
|
|
1017
|
+
sdk,
|
|
1018
|
+
availability,
|
|
1019
|
+
children
|
|
1020
|
+
}) => {
|
|
1021
|
+
const [state, dispatch] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useReducer)(_reducer_js__WEBPACK_IMPORTED_MODULE_2__.reducer, _reducer_js__WEBPACK_IMPORTED_MODULE_2__.initialState);
|
|
1022
|
+
|
|
1023
|
+
/**
|
|
1024
|
+
* SDK event handlers
|
|
1025
|
+
*/
|
|
1026
|
+
const onLiveChatRecovered = e => {
|
|
1027
|
+
dispatch({
|
|
1028
|
+
type: 'SET_AGENT',
|
|
1029
|
+
payload: e.detail.data.inboxAssignee
|
|
1030
|
+
});
|
|
1031
|
+
dispatch({
|
|
1032
|
+
type: 'SET_AGENT_STATUS',
|
|
1033
|
+
payload: e.detail.data.contact.status
|
|
1034
|
+
});
|
|
1035
|
+
};
|
|
1036
|
+
const onAssignedAgentChanged = e => {
|
|
1037
|
+
dispatch({
|
|
1038
|
+
type: 'SET_AGENT',
|
|
1039
|
+
payload: e.detail.data.inboxAssignee
|
|
1040
|
+
});
|
|
1041
|
+
dispatch({
|
|
1042
|
+
type: 'SET_AGENT_STATUS',
|
|
1043
|
+
payload: e.detail.data.case.status
|
|
1044
|
+
});
|
|
1045
|
+
};
|
|
1046
|
+
const onAgentTypingStarted = () => {
|
|
1047
|
+
dispatch({
|
|
1048
|
+
type: 'SET_AGENT_TYPING',
|
|
1049
|
+
payload: true
|
|
1050
|
+
});
|
|
1051
|
+
};
|
|
1052
|
+
const onAgentTypingEnded = () => {
|
|
1053
|
+
dispatch({
|
|
1054
|
+
type: 'SET_AGENT_TYPING',
|
|
1055
|
+
payload: false
|
|
1056
|
+
});
|
|
1057
|
+
};
|
|
1058
|
+
const onMessageCreated = e => {
|
|
1059
|
+
setMessage(e.detail.data.message);
|
|
1060
|
+
dispatch({
|
|
1061
|
+
type: 'SET_AGENT_STATUS',
|
|
1062
|
+
payload: e.detail.data.case.status
|
|
1063
|
+
});
|
|
1064
|
+
};
|
|
1065
|
+
const onContactStatusChanged = e => {
|
|
1066
|
+
dispatch({
|
|
1067
|
+
type: 'SET_AGENT_STATUS',
|
|
1068
|
+
payload: e.detail.data.case.status
|
|
1069
|
+
});
|
|
1070
|
+
};
|
|
1071
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
1072
|
+
sdk.onChatEvent(_nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__.ChatEvent.LIVECHAT_RECOVERED, onLiveChatRecovered);
|
|
1073
|
+
sdk.onChatEvent(_nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__.ChatEvent.MESSAGE_CREATED, onMessageCreated);
|
|
1074
|
+
sdk.onChatEvent(_nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__.ChatEvent.AGENT_TYPING_STARTED, onAgentTypingStarted);
|
|
1075
|
+
sdk.onChatEvent(_nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__.ChatEvent.AGENT_TYPING_ENDED, onAgentTypingEnded);
|
|
1076
|
+
sdk.onChatEvent(_nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__.ChatEvent.ASSIGNED_AGENT_CHANGED, onAssignedAgentChanged);
|
|
1077
|
+
sdk.onChatEvent(_nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_1__.ChatEvent.CONTACT_STATUS_CHANGED, onContactStatusChanged);
|
|
1078
|
+
}, [sdk]);
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* Initialize customerId, threadId and whether the webchat should be open
|
|
1082
|
+
*/
|
|
1083
|
+
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
|
|
1084
|
+
dispatch({
|
|
1085
|
+
type: 'SET_AVAILABILITY',
|
|
1086
|
+
payload: availability
|
|
1087
|
+
});
|
|
1088
|
+
setCustomerId(window.localStorage.getItem(_reducer_js__WEBPACK_IMPORTED_MODULE_2__.CUSTOMER_ID_STORAGE_KEY));
|
|
1089
|
+
setThreadId(window.localStorage.getItem(_reducer_js__WEBPACK_IMPORTED_MODULE_2__.THREAD_ID_STORAGE_KEY));
|
|
1090
|
+
if (window.location.hash === '#webchat') {
|
|
1091
|
+
setChatVisibility(true);
|
|
243
1092
|
}
|
|
244
|
-
},
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
});
|
|
253
|
-
};
|
|
1093
|
+
}, []);
|
|
1094
|
+
|
|
1095
|
+
/**
|
|
1096
|
+
* State update functions
|
|
1097
|
+
*/
|
|
1098
|
+
const setChatVisibility = payload => {
|
|
1099
|
+
if (!payload) {
|
|
1100
|
+
window.location.hash = '';
|
|
254
1101
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
1102
|
+
dispatch({
|
|
1103
|
+
type: 'SET_CHAT_VISIBILITY',
|
|
1104
|
+
payload
|
|
1105
|
+
});
|
|
1106
|
+
};
|
|
1107
|
+
const setCustomerId = customerId => {
|
|
1108
|
+
dispatch({
|
|
1109
|
+
type: 'SET_CUSTOMER_ID',
|
|
1110
|
+
payload: customerId
|
|
1111
|
+
});
|
|
1112
|
+
};
|
|
1113
|
+
const setThreadId = threadId => {
|
|
1114
|
+
dispatch({
|
|
1115
|
+
type: 'SET_THREAD_ID',
|
|
1116
|
+
payload: threadId
|
|
1117
|
+
});
|
|
1118
|
+
};
|
|
1119
|
+
const setThread = thread => {
|
|
1120
|
+
dispatch({
|
|
1121
|
+
type: 'SET_THREAD',
|
|
1122
|
+
payload: thread
|
|
1123
|
+
});
|
|
1124
|
+
};
|
|
1125
|
+
const setMessage = message => {
|
|
1126
|
+
dispatch({
|
|
1127
|
+
type: 'SET_MESSAGE',
|
|
1128
|
+
payload: message
|
|
1129
|
+
});
|
|
1130
|
+
};
|
|
1131
|
+
const setMessages = messages => {
|
|
1132
|
+
dispatch({
|
|
1133
|
+
type: 'SET_MESSAGES',
|
|
1134
|
+
payload: messages
|
|
1135
|
+
});
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
/**
|
|
1139
|
+
* Application-wide state and state functions
|
|
1140
|
+
*/
|
|
1141
|
+
const store = (0,react__WEBPACK_IMPORTED_MODULE_0__.useMemo)(() => ({
|
|
1142
|
+
...state,
|
|
1143
|
+
sdk,
|
|
1144
|
+
setCustomerId,
|
|
1145
|
+
setThreadId,
|
|
1146
|
+
setThread,
|
|
1147
|
+
setMessage,
|
|
1148
|
+
setMessages,
|
|
1149
|
+
setChatVisibility
|
|
1150
|
+
}));
|
|
1151
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(AppContext.Provider, {
|
|
1152
|
+
value: store
|
|
1153
|
+
}, children);
|
|
1154
|
+
};
|
|
1155
|
+
|
|
1156
|
+
/***/ }),
|
|
1157
|
+
|
|
1158
|
+
/***/ "./src/client/store/actions-map.js":
|
|
1159
|
+
/*!*****************************************!*\
|
|
1160
|
+
!*** ./src/client/store/actions-map.js ***!
|
|
1161
|
+
\*****************************************/
|
|
1162
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1163
|
+
|
|
1164
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1165
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1166
|
+
/* harmony export */ actionsMap: () => (/* binding */ actionsMap)
|
|
1167
|
+
/* harmony export */ });
|
|
1168
|
+
/* harmony import */ var _lib_transform_messages__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../lib/transform-messages */ "./src/client/lib/transform-messages.js");
|
|
1169
|
+
/* harmony import */ var _reducer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./reducer */ "./src/client/store/reducer.js");
|
|
1170
|
+
|
|
1171
|
+
|
|
1172
|
+
const setCustomerId = (state, payload) => {
|
|
1173
|
+
if (payload) {
|
|
1174
|
+
window.localStorage.setItem(_reducer__WEBPACK_IMPORTED_MODULE_1__.CUSTOMER_ID_STORAGE_KEY, payload);
|
|
1175
|
+
} else {
|
|
1176
|
+
window.localStorage.removeItem(_reducer__WEBPACK_IMPORTED_MODULE_1__.CUSTOMER_ID_STORAGE_KEY);
|
|
1177
|
+
}
|
|
1178
|
+
return {
|
|
1179
|
+
...state,
|
|
1180
|
+
customerId: payload
|
|
1181
|
+
};
|
|
1182
|
+
};
|
|
1183
|
+
const setThreadId = (state, payload) => {
|
|
1184
|
+
if (payload) {
|
|
1185
|
+
window.localStorage.setItem(_reducer__WEBPACK_IMPORTED_MODULE_1__.THREAD_ID_STORAGE_KEY, payload);
|
|
1186
|
+
} else {
|
|
1187
|
+
window.localStorage.removeItem(_reducer__WEBPACK_IMPORTED_MODULE_1__.THREAD_ID_STORAGE_KEY);
|
|
1188
|
+
}
|
|
1189
|
+
return {
|
|
1190
|
+
...state,
|
|
1191
|
+
threadId: payload
|
|
1192
|
+
};
|
|
1193
|
+
};
|
|
1194
|
+
const setChatVisibility = (state, payload) => {
|
|
1195
|
+
return {
|
|
1196
|
+
...state,
|
|
1197
|
+
isChatOpen: payload
|
|
1198
|
+
};
|
|
1199
|
+
};
|
|
1200
|
+
const setAvailability = (state, payload) => {
|
|
1201
|
+
return {
|
|
1202
|
+
...state,
|
|
1203
|
+
availability: payload
|
|
1204
|
+
};
|
|
1205
|
+
};
|
|
1206
|
+
const setThread = (state, payload) => {
|
|
1207
|
+
return {
|
|
1208
|
+
...state,
|
|
1209
|
+
thread: payload
|
|
1210
|
+
};
|
|
1211
|
+
};
|
|
1212
|
+
const setMessage = (state, payload) => {
|
|
1213
|
+
return {
|
|
1214
|
+
...state,
|
|
1215
|
+
messages: [...state.messages, (0,_lib_transform_messages__WEBPACK_IMPORTED_MODULE_0__.transformMessage)(payload)]
|
|
1216
|
+
};
|
|
1217
|
+
};
|
|
1218
|
+
const setMessages = (state, payload) => {
|
|
1219
|
+
return {
|
|
1220
|
+
...state,
|
|
1221
|
+
messages: (0,_lib_transform_messages__WEBPACK_IMPORTED_MODULE_0__.transformMessages)(payload).reverse()
|
|
1222
|
+
};
|
|
1223
|
+
};
|
|
1224
|
+
const setAgent = (state, payload) => {
|
|
1225
|
+
return {
|
|
1226
|
+
...state,
|
|
1227
|
+
agent: payload
|
|
1228
|
+
};
|
|
1229
|
+
};
|
|
1230
|
+
const setAgentIsTyping = (state, payload) => {
|
|
1231
|
+
return {
|
|
1232
|
+
...state,
|
|
1233
|
+
isAgentTyping: payload
|
|
1234
|
+
};
|
|
1235
|
+
};
|
|
1236
|
+
const setAgentStatus = (state, payload) => {
|
|
1237
|
+
return {
|
|
1238
|
+
...state,
|
|
1239
|
+
agentStatus: payload
|
|
1240
|
+
};
|
|
1241
|
+
};
|
|
1242
|
+
const actionsMap = {
|
|
1243
|
+
SET_CHAT_VISIBILITY: setChatVisibility,
|
|
1244
|
+
SET_AVAILABILITY: setAvailability,
|
|
1245
|
+
SET_CUSTOMER_ID: setCustomerId,
|
|
1246
|
+
SET_THREAD_ID: setThreadId,
|
|
1247
|
+
SET_THREAD: setThread,
|
|
1248
|
+
SET_MESSAGE: setMessage,
|
|
1249
|
+
SET_MESSAGES: setMessages,
|
|
1250
|
+
SET_AGENT: setAgent,
|
|
1251
|
+
SET_AGENT_TYPING: setAgentIsTyping,
|
|
1252
|
+
SET_AGENT_STATUS: setAgentStatus
|
|
1253
|
+
};
|
|
1254
|
+
|
|
1255
|
+
/***/ }),
|
|
1256
|
+
|
|
1257
|
+
/***/ "./src/client/store/reducer.js":
|
|
1258
|
+
/*!*************************************!*\
|
|
1259
|
+
!*** ./src/client/store/reducer.js ***!
|
|
1260
|
+
\*************************************/
|
|
1261
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1262
|
+
|
|
1263
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1264
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1265
|
+
/* harmony export */ CUSTOMER_ID_STORAGE_KEY: () => (/* binding */ CUSTOMER_ID_STORAGE_KEY),
|
|
1266
|
+
/* harmony export */ THREAD_ID_STORAGE_KEY: () => (/* binding */ THREAD_ID_STORAGE_KEY),
|
|
1267
|
+
/* harmony export */ initialState: () => (/* binding */ initialState),
|
|
1268
|
+
/* harmony export */ reducer: () => (/* binding */ reducer)
|
|
1269
|
+
/* harmony export */ });
|
|
1270
|
+
/* harmony import */ var _actions_map__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./actions-map */ "./src/client/store/actions-map.js");
|
|
1271
|
+
|
|
1272
|
+
const CUSTOMER_ID_STORAGE_KEY = 'webchat_customer_id';
|
|
1273
|
+
const THREAD_ID_STORAGE_KEY = 'webchat_thread_id';
|
|
1274
|
+
const initialState = {
|
|
1275
|
+
availability: null,
|
|
1276
|
+
customerId: null,
|
|
1277
|
+
threadId: null,
|
|
1278
|
+
thread: null,
|
|
1279
|
+
messages: [],
|
|
1280
|
+
agent: null,
|
|
1281
|
+
agentStatus: null,
|
|
1282
|
+
isAgentTyping: false,
|
|
1283
|
+
isChatOpen: false
|
|
1284
|
+
};
|
|
1285
|
+
const reducer = (state, action) => {
|
|
1286
|
+
const {
|
|
1287
|
+
type,
|
|
1288
|
+
payload
|
|
1289
|
+
} = action;
|
|
1290
|
+
const fn = _actions_map__WEBPACK_IMPORTED_MODULE_0__.actionsMap[type];
|
|
1291
|
+
if (fn) {
|
|
1292
|
+
const actionFunction = fn.bind(undefined, state, payload);
|
|
1293
|
+
return actionFunction();
|
|
1294
|
+
}
|
|
1295
|
+
return state;
|
|
1296
|
+
};
|
|
1297
|
+
|
|
1298
|
+
/***/ }),
|
|
1299
|
+
|
|
1300
|
+
/***/ "./src/client/store/useApp.js":
|
|
1301
|
+
/*!************************************!*\
|
|
1302
|
+
!*** ./src/client/store/useApp.js ***!
|
|
1303
|
+
\************************************/
|
|
1304
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1305
|
+
|
|
1306
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1307
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1308
|
+
/* harmony export */ useApp: () => (/* binding */ useApp)
|
|
1309
|
+
/* harmony export */ });
|
|
1310
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
|
1311
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
1312
|
+
/* harmony import */ var _AppProvider_jsx__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./AppProvider.jsx */ "./src/client/store/AppProvider.jsx");
|
|
1313
|
+
|
|
1314
|
+
|
|
1315
|
+
const useApp = () => (0,react__WEBPACK_IMPORTED_MODULE_0__.useContext)(_AppProvider_jsx__WEBPACK_IMPORTED_MODULE_1__.AppContext);
|
|
1316
|
+
|
|
1317
|
+
/***/ }),
|
|
1318
|
+
|
|
1319
|
+
/***/ "./src/client/store/useChatSdk.js":
|
|
1320
|
+
/*!****************************************!*\
|
|
1321
|
+
!*** ./src/client/store/useChatSdk.js ***!
|
|
1322
|
+
\****************************************/
|
|
1323
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1324
|
+
|
|
1325
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1326
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1327
|
+
/* harmony export */ useChatSdk: () => (/* binding */ useChatSdk)
|
|
1328
|
+
/* harmony export */ });
|
|
1329
|
+
const useChatSdk = sdk => {
|
|
1330
|
+
const connect = async () => sdk.authorize();
|
|
1331
|
+
const fetchCustomerId = async () => {
|
|
1332
|
+
const response = await connect();
|
|
1333
|
+
return response?.consumerIdentity.idOnExternalPlatform;
|
|
1334
|
+
};
|
|
1335
|
+
const fetchThread = async threadId => {
|
|
1336
|
+
await connect();
|
|
1337
|
+
return sdk.getThread(threadId);
|
|
1338
|
+
};
|
|
1339
|
+
const fetchMessages = async (thread, threadId) => {
|
|
1340
|
+
await connect();
|
|
1341
|
+
const recovered = await thread.recover(threadId);
|
|
1342
|
+
const allMessages = [];
|
|
1343
|
+
let fetchedMessages = recovered.messages;
|
|
1344
|
+
while (fetchedMessages.length) {
|
|
1345
|
+
fetchedMessages.map(msg => allMessages.push(msg));
|
|
260
1346
|
try {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
listener();
|
|
264
|
-
}
|
|
1347
|
+
const response = await thread.loadMoreMessages();
|
|
1348
|
+
fetchedMessages = response.data.messages;
|
|
265
1349
|
} catch (err) {
|
|
266
|
-
|
|
267
|
-
} finally {
|
|
268
|
-
_iterator.f();
|
|
1350
|
+
fetchedMessages = [];
|
|
269
1351
|
}
|
|
270
1352
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return ExternalSyncStore;
|
|
289
|
-
}();
|
|
1353
|
+
return allMessages;
|
|
1354
|
+
};
|
|
1355
|
+
return {
|
|
1356
|
+
connect,
|
|
1357
|
+
fetchCustomerId,
|
|
1358
|
+
fetchThread,
|
|
1359
|
+
fetchMessages
|
|
1360
|
+
};
|
|
1361
|
+
};
|
|
1362
|
+
|
|
1363
|
+
/***/ }),
|
|
1364
|
+
|
|
1365
|
+
/***/ "@nice-devone/nice-cxone-chat-web-sdk":
|
|
1366
|
+
/*!*******************************************************!*\
|
|
1367
|
+
!*** external "@nice-devone/nice-cxone-chat-web-sdk" ***!
|
|
1368
|
+
\*******************************************************/
|
|
1369
|
+
/***/ ((module) => {
|
|
290
1370
|
|
|
1371
|
+
module.exports = require("@nice-devone/nice-cxone-chat-web-sdk");
|
|
291
1372
|
|
|
292
1373
|
/***/ }),
|
|
293
1374
|
|
|
@@ -301,6 +1382,16 @@ module.exports = require("react");
|
|
|
301
1382
|
|
|
302
1383
|
/***/ }),
|
|
303
1384
|
|
|
1385
|
+
/***/ "react-dom":
|
|
1386
|
+
/*!****************************!*\
|
|
1387
|
+
!*** external "react-dom" ***!
|
|
1388
|
+
\****************************/
|
|
1389
|
+
/***/ ((module) => {
|
|
1390
|
+
|
|
1391
|
+
module.exports = require("react-dom");
|
|
1392
|
+
|
|
1393
|
+
/***/ }),
|
|
1394
|
+
|
|
304
1395
|
/***/ "react-dom/client":
|
|
305
1396
|
/*!***********************************!*\
|
|
306
1397
|
!*** external "react-dom/client" ***!
|
|
@@ -309,6 +1400,26 @@ module.exports = require("react");
|
|
|
309
1400
|
|
|
310
1401
|
module.exports = require("react-dom/client");
|
|
311
1402
|
|
|
1403
|
+
/***/ }),
|
|
1404
|
+
|
|
1405
|
+
/***/ "sanitize-html":
|
|
1406
|
+
/*!********************************!*\
|
|
1407
|
+
!*** external "sanitize-html" ***!
|
|
1408
|
+
\********************************/
|
|
1409
|
+
/***/ ((module) => {
|
|
1410
|
+
|
|
1411
|
+
module.exports = require("sanitize-html");
|
|
1412
|
+
|
|
1413
|
+
/***/ }),
|
|
1414
|
+
|
|
1415
|
+
/***/ "uuid":
|
|
1416
|
+
/*!***********************!*\
|
|
1417
|
+
!*** external "uuid" ***!
|
|
1418
|
+
\***********************/
|
|
1419
|
+
/***/ ((module) => {
|
|
1420
|
+
|
|
1421
|
+
module.exports = require("uuid");
|
|
1422
|
+
|
|
312
1423
|
/***/ })
|
|
313
1424
|
|
|
314
1425
|
/******/ });
|
|
@@ -393,49 +1504,40 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
393
1504
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
394
1505
|
/* harmony import */ var react_dom_client__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react-dom/client */ "react-dom/client");
|
|
395
1506
|
/* 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
|
-
|
|
1507
|
+
/* 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");
|
|
1508
|
+
/* 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__);
|
|
1509
|
+
/* harmony import */ var _components_availability_availability_jsx__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./components/availability/availability.jsx */ "./src/client/components/availability/availability.jsx");
|
|
1510
|
+
/* harmony import */ var _lib_check_availability__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./lib/check-availability */ "./src/client/lib/check-availability.js");
|
|
1511
|
+
/* harmony import */ var _store_AppProvider_jsx__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./store/AppProvider.jsx */ "./src/client/store/AppProvider.jsx");
|
|
1512
|
+
/* harmony import */ var _store_reducer_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./store/reducer.js */ "./src/client/store/reducer.js");
|
|
402
1513
|
|
|
403
1514
|
|
|
404
1515
|
|
|
405
1516
|
|
|
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
|
-
|
|
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);
|
|
1517
|
+
|
|
1518
|
+
|
|
1519
|
+
|
|
1520
|
+
async function init(container, options) {
|
|
1521
|
+
const sdk = new _nice_devone_nice_cxone_chat_web_sdk__WEBPACK_IMPORTED_MODULE_2__.ChatSdk({
|
|
1522
|
+
brandId: options.brandId,
|
|
1523
|
+
channelId: options.channelId,
|
|
1524
|
+
customerId: window.localStorage.getItem(_store_reducer_js__WEBPACK_IMPORTED_MODULE_6__.CUSTOMER_ID_STORAGE_KEY) || '',
|
|
1525
|
+
environment: options.environment
|
|
1526
|
+
});
|
|
1527
|
+
const root = (0,react_dom_client__WEBPACK_IMPORTED_MODULE_1__.createRoot)(container);
|
|
1528
|
+
let availability;
|
|
1529
|
+
try {
|
|
1530
|
+
const result = await (0,_lib_check_availability__WEBPACK_IMPORTED_MODULE_4__.checkAvailability)(options.availabilityEndpoint);
|
|
1531
|
+
availability = result.availability;
|
|
1532
|
+
} catch (e) {
|
|
1533
|
+
availability = 'UNAVAILABLE';
|
|
1534
|
+
}
|
|
1535
|
+
root.render( /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_store_AppProvider_jsx__WEBPACK_IMPORTED_MODULE_5__.AppProvider, {
|
|
1536
|
+
sdk: sdk,
|
|
1537
|
+
availability: availability
|
|
1538
|
+
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default().createElement(_components_availability_availability_jsx__WEBPACK_IMPORTED_MODULE_3__.Availability, {
|
|
1539
|
+
availability: availability
|
|
1540
|
+
})));
|
|
439
1541
|
}
|
|
440
1542
|
})();
|
|
441
1543
|
|