@defra/flood-webchat 0.0.1-beta.50 → 0.0.1-beta.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/package.json +1 -1
  2. package/docs/assets/create-a-new-release.png +0 -0
  3. package/docs/assets/example-pre-release.png +0 -0
  4. package/docs/assets/example-release.png +0 -0
  5. package/docs/development-guide.md +0 -5
  6. package/docs/how-to-publish.md +0 -41
  7. package/jest.config.mjs +0 -29
  8. package/src/client/components/availability/availability.jsx +0 -130
  9. package/src/client/components/availability/availability.scss +0 -77
  10. package/src/client/components/chat/chat.jsx +0 -233
  11. package/src/client/components/chat/chat.scss +0 -260
  12. package/src/client/components/errorSummary/error-summary.jsx +0 -34
  13. package/src/client/components/live-region.jsx +0 -55
  14. package/src/client/components/message/message.jsx +0 -21
  15. package/src/client/components/panel/panel-footer.jsx +0 -9
  16. package/src/client/components/panel/panel-header.jsx +0 -75
  17. package/src/client/components/panel/panel.jsx +0 -163
  18. package/src/client/components/panel/panel.scss +0 -112
  19. package/src/client/components/screens/end-chat.jsx +0 -77
  20. package/src/client/components/screens/feedback.jsx +0 -65
  21. package/src/client/components/screens/pre-chat.jsx +0 -62
  22. package/src/client/components/screens/request-chat.jsx +0 -183
  23. package/src/client/components/screens/settings.jsx +0 -97
  24. package/src/client/components/screens/unavailable.jsx +0 -23
  25. package/src/client/components/skip-link.jsx +0 -42
  26. package/src/client/hooks/useFocusedElements.js +0 -80
  27. package/src/client/hooks/useTextareaAutosize.js +0 -13
  28. package/src/client/index.jsx +0 -33
  29. package/src/client/lib/agent-status-headline.js +0 -17
  30. package/src/client/lib/check-availability.js +0 -8
  31. package/src/client/lib/classnames.js +0 -1
  32. package/src/client/lib/history.js +0 -13
  33. package/src/client/lib/message-notification.js +0 -30
  34. package/src/client/lib/transform-messages.js +0 -47
  35. package/src/client/scss/_objects.scss +0 -33
  36. package/src/client/scss/_settings.scss +0 -101
  37. package/src/client/scss/_tools.scss +0 -33
  38. package/src/client/scss/_utilities.scss +0 -25
  39. package/src/client/store/AppProvider.jsx +0 -183
  40. package/src/client/store/actions-map.js +0 -152
  41. package/src/client/store/constants.js +0 -3
  42. package/src/client/store/reducer.js +0 -31
  43. package/src/client/store/useApp.js +0 -5
  44. package/src/client/store/useChatSdk.js +0 -37
  45. package/src/server/index.js +0 -60
  46. package/src/server/lib/client.js +0 -88
  47. package/src/server/lib/utils.js +0 -23
  48. package/webpack.config.mjs +0 -30
@@ -1,260 +0,0 @@
1
- @keyframes blink {
2
- 50% {
3
- fill: transparent
4
- }
5
- }
6
-
7
- .wc-status {
8
- display: flex;
9
- position: relative;
10
- padding: 15px;
11
- @include mq ($from: tablet) {
12
- padding: 10px;
13
- }
14
-
15
- &::after {
16
- position: absolute;
17
- content: "";
18
- bottom: 0;
19
- left: 15px;
20
- right: 15px;
21
- height: 0;
22
- border-bottom: 1px solid $govuk-border-colour;
23
- @include mq ($from: tablet) {
24
- left: 10px;
25
- right: 10px;
26
- }
27
- }
28
-
29
- &__availability {
30
- font-size: 16px;
31
- margin-bottom: 0;
32
- }
33
-
34
- &__link{
35
- @extend %wc-link-button;
36
- margin-left: auto;
37
-
38
- &:link {
39
- color: govuk-colour('black');
40
- }
41
- }
42
- }
43
-
44
- .wc-body[tabindex="0"]:focus-visible {
45
- outline: 3px solid transparent;
46
- outline-offset: -2px;
47
- box-shadow:
48
- inset 0 0 0 2px $govuk-focus-colour,
49
- inset 0 0 0 4px govuk-colour('black'),
50
- 0 0 0 1px $govuk-focus-colour;
51
- }
52
-
53
- .wc-chat {
54
- @extend %govuk-body-s;
55
- line-height: 1.25;
56
- font-size: 14px;
57
- overflow: auto;
58
- list-style: none;
59
- padding: 0;
60
-
61
- &__message {
62
- display: flex;
63
- flex-direction: column;
64
- margin: 5px 15px 0;
65
- max-width: 80%;
66
- width: fit-content;
67
-
68
- &.inbound {
69
- margin-left: auto;
70
- }
71
-
72
- @include mq ($from: tablet) {
73
- margin-left: 10px;
74
- margin-right: 10px;
75
- }
76
-
77
- &:first-child {
78
- padding-top: 15px;
79
- }
80
- }
81
-
82
- &__from {
83
- line-height: 1.25;
84
- color: govuk-colour('dark-grey');
85
- margin-top: 2px;
86
- margin-bottom: 2px;
87
-
88
- .inbound {
89
- display: block;
90
- text-align: right;
91
- }
92
- }
93
-
94
- &__text {
95
- font-size: 16px;
96
- padding: 10px 12.5px;
97
- margin-bottom: 0;
98
- display: inline-block;
99
- border: 1px solid transparent;
100
- overflow-wrap: anywhere;
101
-
102
- @media (forced-colors: active) {
103
- border-color: currentColor;
104
- }
105
-
106
- &.inbound {
107
- color: govuk-colour('white');
108
- background-color: govuk-colour('blue');
109
- border-radius: 10px 0 10px 10px;
110
-
111
- .govuk-link:visited {
112
- color: govuk-colour('white');
113
- }
114
-
115
- .govuk-link:focus {
116
- color: govuk-colour('black');
117
- }
118
- }
119
-
120
- &.outbound {
121
- background-color: govuk-colour('light-grey');
122
- border-radius: 0 10px 10px;
123
- }
124
-
125
- svg {
126
- display: block;
127
- color: govuk-colour('dark-grey');
128
- }
129
-
130
- @media (forced-colors: active) {
131
- svg {
132
- color: currentColor;
133
- }
134
- }
135
-
136
-
137
- svg circle {
138
- animation: 1s blink infinite;
139
- fill: currentColor;
140
-
141
- &:nth-child(2) {
142
- animation-delay: 250ms
143
- }
144
-
145
- &:nth-child(3) {
146
- animation-delay: 500ms
147
- }
148
- }
149
- }
150
- }
151
-
152
- .wc-form {
153
- position: relative;
154
- display: flex;
155
- flex-wrap: nowrap;
156
- align-items: baseline;
157
- border-top: 1px solid govuk-colour('black');
158
- border-bottom: 1px solid govuk-colour('black');
159
-
160
- &__label {
161
- position: absolute;
162
- pointer-events: none;
163
- font-size: 16px;
164
- line-height: 20px;
165
- margin: 20px;
166
- @include mq ($from: tablet) {
167
- margin: 18px 18px 19px;
168
- }
169
- left: 0;
170
- bottom: 0;
171
- color: $govuk-secondary-text-colour;
172
- z-index: 3;
173
- }
174
-
175
- &__textarea {
176
- @extend %govuk-body-s;
177
- box-sizing: border-box;
178
- min-height: auto;
179
- font-size: 16px;
180
- line-height: 20px;
181
- max-height: 120px;
182
- flex: 1 1 auto;
183
- align-self: flex-end;
184
- margin: 20px;
185
- @include mq ($from: tablet) {
186
- margin: 18px 18px 19px;
187
- }
188
- padding: 0;
189
- border: 0;
190
- height: 20px;
191
- resize: none;
192
- overflow-x: hidden;
193
- overscroll-behavior: contain;
194
-
195
- &:focus {
196
- outline: none;
197
- box-shadow: none;
198
- z-index: 2;
199
- }
200
- }
201
-
202
- &__button {
203
- margin: 10px 15px 12px 0;
204
- @include mq ($from: tablet) {
205
- margin-right: 10px;
206
- }
207
- font-size: 16px;
208
- position: relative;
209
- flex: 0 0 auto;
210
- align-self: flex-end;
211
- display: flex;
212
- flex-direction: row;
213
- flex-wrap: nowrap;
214
- align-items: center;
215
- width: auto;
216
- cursor: pointer;
217
- }
218
-
219
- &.wc-focus-within::after {
220
- @include focus($glow: 5px, $strong: 2px, $background: 0, $inset: 0);
221
- left: 4px;
222
- right: 4px;
223
- top: 4px;
224
- bottom: 4px;
225
- }
226
- }
227
-
228
- .wc-body:focus-visible + .wc-footer .wc-form {
229
- border-top: 1px solid transparent;
230
- }
231
-
232
- .wc-footer {
233
- position: relative;
234
- flex: 0 0 0;
235
-
236
- &__settings {
237
- @include govuk-responsive-padding(2);
238
-
239
- display: flex;
240
- flex-direction: row;
241
-
242
- &-link {
243
- @extend %wc-link-button;
244
-
245
- &:first-child {
246
- margin-right: govuk-spacing(3);
247
- }
248
-
249
- &:link {
250
- color: govuk-colour('black');
251
- }
252
- }
253
- }
254
-
255
- &__input {
256
- @include govuk-responsive-padding(2);
257
-
258
- border-top: 1px solid govuk-colour('black');
259
- }
260
- }
@@ -1,34 +0,0 @@
1
- import React from 'react'
2
-
3
- export const ErrorSummary = ({ errors }) => {
4
- const errs = Object.keys(errors)
5
-
6
- const goToInput = e => {
7
- e.preventDefault()
8
- const key = e.target.getAttribute('data-key')
9
- document.querySelector(`#wc-${key}`).focus()
10
- }
11
-
12
- if (errs.length === 0) {
13
- return null
14
- }
15
-
16
- return (
17
- <div className='govuk-error-summary govuk-!-static-margin-bottom-7' data-module='govuk-error-summary' tabIndex='-1'>
18
- <div role='alert'>
19
- <h2 id='wc-error' className='wc-error-summary__title govuk-error-summary__title'>
20
- There is a problem
21
- </h2>
22
- <div className='govuk-error-summary__body'>
23
- <ul className='govuk-list govuk-error-summary__list wc-error-summary__list'>
24
- {errs.map(key => (
25
- <li key={key}>
26
- <a href='#' data-key={key} onClick={goToInput}>{errors[key]}</a>
27
- </li>
28
- ))}
29
- </ul>
30
- </div>
31
- </div>
32
- </div>
33
- )
34
- }
@@ -1,55 +0,0 @@
1
- import React, { useEffect, useState, useCallback } from 'react'
2
- import debounce from 'lodash.debounce'
3
- import { useApp } from '../store/useApp'
4
-
5
- const DEBOUNCE_MILLISECONDS = 2000
6
-
7
- export const LiveRegion = () => {
8
- const { agentStatus, liveRegionText, setLiveRegionText } = useApp()
9
-
10
- const [textA, setTextA] = useState()
11
- const [textB, setTextB] = useState()
12
-
13
- const isSessionEnded = agentStatus === 'closed' || agentStatus === null
14
-
15
- const clearText = () => {
16
- setTextA()
17
- setTextB()
18
- }
19
-
20
- const setText = useCallback(debounce(text => {
21
- if (textA) {
22
- setTextB(text)
23
- } else {
24
- setTextA(text)
25
- }
26
- }, DEBOUNCE_MILLISECONDS), [textA, textB])
27
-
28
- useEffect(() => {
29
- if (liveRegionText) {
30
- clearText()
31
- setText(liveRegionText)
32
- }
33
-
34
- if (isSessionEnded) {
35
- clearText()
36
- setLiveRegionText()
37
- }
38
-
39
- return () => {
40
- clearText()
41
- setLiveRegionText()
42
- }
43
- }, [liveRegionText])
44
-
45
- return (
46
- <>
47
- <div className='wc-live' role='status' aria-atomic='true'>
48
- {textA}
49
- </div>
50
- <div className='wc-live' role='status' aria-atomic='true'>
51
- {textB}
52
- </div>
53
- </>
54
- )
55
- }
@@ -1,21 +0,0 @@
1
- import React from 'react'
2
- import { classnames } from '../../lib/classnames'
3
- import { formatMessage } from '../../lib/transform-messages'
4
-
5
- export function Message ({ message, previousMessage }) {
6
- const outbound = message.direction === 'outbound'
7
-
8
- const messageOwnerSameAsPrevious = message?.direction === previousMessage?.direction
9
-
10
- return (
11
- <li className={classnames('wc-chat__message', outbound ? 'outbound' : 'inbound')}>
12
- <div className='wc-chat__from'>
13
- {messageOwnerSameAsPrevious ? null : <span className={classnames(outbound ? 'outbound' : 'inbound')}>{outbound ? message.assignee : 'You'}</span>}
14
- <span className='govuk-visually-hidden'>:</span>
15
- </div>
16
- <div className={classnames('wc-chat__text', outbound ? 'outbound' : 'inbound')}>
17
- {formatMessage(message.text)}
18
- </div>
19
- </li>
20
- )
21
- }
@@ -1,9 +0,0 @@
1
- import React from 'react'
2
-
3
- export function PanelFooter ({ children }) {
4
- return (
5
- <div className='wc-footer'>
6
- {children}
7
- </div>
8
- )
9
- }
@@ -1,75 +0,0 @@
1
- import React from 'react'
2
- import { useApp } from '../../store/useApp.js'
3
- import { historyReplaceState } from '../../lib/history.js'
4
-
5
- export function PanelHeader () {
6
- const { thread, threadId, setChatVisibility, setUnseenCount, isMobile } = useApp()
7
-
8
- const onClose = e => {
9
- e.preventDefault()
10
- setChatVisibility(false)
11
- historyReplaceState()
12
-
13
- if (threadId) {
14
- thread?.lastMessageSeen()
15
- setUnseenCount(0)
16
- }
17
- }
18
-
19
- const BackButtonComponent = (
20
- <button className='wc-header__back' aria-label='Close the webchat' onClick={onClose}>
21
- <svg aria-hidden='true' focusable='false' width='20' height='20' viewBox='0 0 20 20'>
22
- <path d='M4.828,11L12.314,18.485L10.899,19.899L1,10L10.899,0.101L12.314,1.515L4.828,9L19,9L19,11L4.828,11Z' fill='currentColor' />
23
- </svg>
24
- </button>
25
- )
26
-
27
- const CloseButtonComponent = (
28
- <button className='wc-header__close' aria-label='Close the webchat' onClick={onClose}>
29
- <svg aria-hidden='true' focusable='false' width='20' height='20' viewBox='0 0 20 20'>
30
- <path 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' fill='currentColor' />
31
- </svg>
32
- </button>
33
- )
34
-
35
- const MinimiseButtonComponent = (
36
- <button className='wc-header__hide' aria-label='Minimise the webchat' onClick={onClose}>
37
- <svg aria-hidden='true' focusable='false' width='20' height='20' viewBox='0 0 20 20'>
38
- <path d='M10 14.4l-7-7L4.4 6l5.6 5.6L15.6 6 17 7.4l-7 7z' fill='currentColor' />
39
- </svg>
40
- </button>
41
- )
42
-
43
- const isMobileAndHasHistory = isMobile && window.history.state
44
- const isMobileAndNoHistory = isMobile && !window.history.state
45
-
46
- let RightButtonComponent = CloseButtonComponent
47
-
48
- if (threadId) {
49
- RightButtonComponent = MinimiseButtonComponent
50
-
51
- if (isMobileAndNoHistory) {
52
- RightButtonComponent = MinimiseButtonComponent
53
- }
54
- }
55
-
56
- if (!threadId && isMobileAndNoHistory) {
57
- RightButtonComponent = CloseButtonComponent
58
- }
59
-
60
- if (isMobileAndHasHistory) {
61
- RightButtonComponent = null
62
- }
63
-
64
- return (
65
- <div className='wc-header'>
66
- {isMobileAndHasHistory ? BackButtonComponent : null}
67
-
68
- <h2 id='wc-header' className='wc-header__title'>
69
- Floodline webchat
70
- </h2>
71
-
72
- {RightButtonComponent}
73
- </div>
74
- )
75
- }
@@ -1,163 +0,0 @@
1
- import React, { useEffect, useState, useCallback } from 'react'
2
- import { createPortal } from 'react-dom'
3
- import { classnames } from '../../lib/classnames.js'
4
-
5
- import { PreChat } from '../screens/pre-chat.jsx'
6
- import { RequestChat } from '../screens/request-chat.jsx'
7
- import { Chat } from '../chat/chat.jsx'
8
- import { Unavailable } from '../screens/unavailable.jsx'
9
- import { EndChat } from '../screens/end-chat.jsx'
10
- import { Settings } from '../screens/settings.jsx'
11
- import { Feedback } from '../screens/feedback.jsx'
12
- import { LiveRegion } from '../live-region.jsx'
13
-
14
- import { useApp } from '../../store/useApp.js'
15
- import { useChatSdk } from '../../store/useChatSdk.js'
16
- import { useFocusedElements } from '../../hooks/useFocusedElements.js'
17
- import { historyReplaceState } from '../../lib/history.js'
18
-
19
- export function Panel () {
20
- const { sdk, availability, instigatorId, thread, threadId, setThread, setThreadId, setChatVisibility, setMessages, setUnseenCount, isMobile, isKeyboard } = useApp()
21
- const { fetchThread, fetchMessages } = useChatSdk(sdk)
22
-
23
- const [screen, setScreen] = useState(threadId ? 2 : 0)
24
-
25
- useFocusedElements(screen)
26
-
27
- const onEscapeKey = useCallback(e => {
28
- if (e.key === 'Escape' || e.key === 'Esc') {
29
- if (threadId) {
30
- thread?.lastMessageSeen()
31
- setUnseenCount(0)
32
- }
33
- setChatVisibility(false)
34
- historyReplaceState()
35
- }
36
- }, [thread, threadId, setUnseenCount, setChatVisibility])
37
-
38
- /**
39
- * Focus previously focused element when closing the webchat
40
- */
41
- useEffect(() => {
42
- return () => {
43
- document.getElementById(instigatorId)?.focus()
44
- }
45
- }, [])
46
-
47
- /**
48
- * We need ammend classes on the body element to handle mobile behaviour
49
- */
50
- useEffect(() => {
51
- document.body.classList.remove('wc-u-hidden')
52
- document.getElementsByTagName('html')[0].classList.add('wc-u-html')
53
- document.body.classList.add('wc-u-body')
54
- return () => {
55
- document.getElementsByTagName('html')[0].classList.remove('wc-u-html')
56
- document.body.classList.remove('wc-u-body')
57
- }
58
- }, [isMobile])
59
-
60
- /**
61
- * Initializes the eventListener for pressing the escape key
62
- */
63
- useEffect(() => {
64
- document.addEventListener('keydown', onEscapeKey)
65
-
66
- return () => {
67
- document.removeEventListener('keydown', onEscapeKey)
68
- }
69
- }, [onEscapeKey, setChatVisibility])
70
-
71
- /**
72
- * Recovers the thread if there is a threadId but no thread loaded in to state
73
- */
74
- useEffect(() => {
75
- const recover = async () => {
76
- try {
77
- const fetchedThread = await fetchThread(threadId)
78
- setThread(fetchedThread)
79
-
80
- const fetchedMessages = await fetchMessages(fetchedThread, threadId)
81
- setMessages(fetchedMessages)
82
- } catch (err) {
83
- console.log('[Chat Error] fetchThread', err)
84
-
85
- setThreadId()
86
- setThread()
87
- setScreen(0)
88
- }
89
- }
90
-
91
- if (threadId) {
92
- if (thread) {
93
- thread.lastMessageSeen()
94
- setUnseenCount(0)
95
- setScreen(2)
96
- } else {
97
- recover()
98
- }
99
- }
100
- }, [thread, threadId])
101
-
102
- const handleScreenChange = newScreen => e => {
103
- e.preventDefault()
104
- setScreen(newScreen)
105
- }
106
-
107
- const goToPreChatScreen = handleScreenChange(0)
108
- const goToRequestChatScreen = handleScreenChange(1)
109
- const goToChatScreen = handleScreenChange(2)
110
- const goToEndChatScreen = handleScreenChange(3)
111
- const goToFeedbackScreen = handleScreenChange(4)
112
- const goToSettingsScreen = handleScreenChange(5)
113
-
114
- let ScreenComponent
115
-
116
- switch (screen) {
117
- case 0:
118
- ScreenComponent = <PreChat onContinue={goToRequestChatScreen} />
119
- break
120
- case 1:
121
- ScreenComponent = <RequestChat onPreChatScreen={goToPreChatScreen} />
122
- break
123
- case 2:
124
- ScreenComponent = <Chat onSettingsScreen={goToSettingsScreen} onEndChatScreen={goToEndChatScreen} />
125
- break
126
- case 3:
127
- ScreenComponent = <EndChat onChatScreen={goToChatScreen} onEndChatConfirm={goToFeedbackScreen} />
128
- break
129
- case 4:
130
- ScreenComponent = (
131
- <Feedback onCancel={() => {
132
- setChatVisibility(false)
133
- historyReplaceState()
134
- }}
135
- />
136
- )
137
- break
138
- case 5:
139
- ScreenComponent = <Settings onCancel={goToChatScreen} />
140
- break
141
- default:
142
- ScreenComponent = <PreChat onContinue={goToRequestChatScreen} />
143
- }
144
-
145
- if (availability === 'UNAVAILABLE') {
146
- ScreenComponent = <Unavailable />
147
- }
148
-
149
- const Component = (
150
- <div id='wc-panel' role='dialog' className={classnames('wc-panel', isKeyboard && 'wc-focus-visible')} tabIndex='-1' aria-modal='true' aria-labelledby='wc-header wc-subtitle'>
151
- <div className='wc-panel__inner'>
152
- {ScreenComponent}
153
- </div>
154
- <LiveRegion />
155
- </div>
156
- )
157
-
158
- return (
159
- <>
160
- {createPortal(Component, document.body)}
161
- </>
162
- )
163
- }