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

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/README.md +83 -1
  2. package/dist/client.js +2146 -472
  3. package/dist/client.js.map +1 -1
  4. package/dist/server.js +181 -241
  5. package/dist/server.js.map +1 -1
  6. package/main.scss +10 -6
  7. package/package.json +6 -2
  8. package/src/client/components/availability/availability.jsx +71 -54
  9. package/src/client/components/availability/availability.scss +15 -33
  10. package/src/client/components/chat/chat.jsx +233 -0
  11. package/src/client/components/chat/chat.scss +233 -0
  12. package/src/client/components/errorSummary/error-summary.jsx +34 -0
  13. package/src/client/components/live-region.jsx +55 -0
  14. package/src/client/components/message/message.jsx +20 -0
  15. package/src/client/components/panel/panel-footer.jsx +9 -0
  16. package/src/client/components/panel/panel-header.jsx +54 -14
  17. package/src/client/components/panel/panel.jsx +128 -71
  18. package/src/client/components/panel/panel.scss +63 -22
  19. package/src/client/components/screens/end-chat.jsx +77 -0
  20. package/src/client/components/screens/feedback.jsx +66 -0
  21. package/src/client/components/screens/pre-chat.jsx +50 -30
  22. package/src/client/components/screens/request-chat.jsx +177 -4
  23. package/src/client/components/screens/settings.jsx +97 -0
  24. package/src/client/components/screens/unavailable.jsx +23 -0
  25. package/src/client/components/skip-link.jsx +42 -0
  26. package/src/client/hooks/useFocusedElements.js +80 -0
  27. package/src/client/hooks/useTextareaAutosize.js +13 -0
  28. package/src/client/index.jsx +15 -1
  29. package/src/client/lib/agent-status-headline.js +17 -0
  30. package/src/client/lib/check-availability.js +1 -0
  31. package/src/client/lib/history.js +13 -0
  32. package/src/client/lib/message-notification.js +36 -0
  33. package/src/client/lib/transform-messages.js +34 -0
  34. package/src/client/scss/_objects.scss +33 -0
  35. package/src/client/scss/_settings.scss +101 -0
  36. package/src/client/scss/_tools.scss +33 -0
  37. package/src/client/scss/_utilities.scss +25 -0
  38. package/src/client/store/AppProvider.jsx +187 -0
  39. package/src/client/store/actions-map.js +152 -0
  40. package/src/client/store/constants.js +3 -0
  41. package/src/client/store/reducer.js +31 -0
  42. package/src/client/store/useApp.js +5 -0
  43. package/src/client/store/useChatSdk.js +37 -0
  44. package/src/server/index.js +15 -6
  45. package/src/server/lib/client.js +31 -35
  46. package/src/server/lib/utils.js +16 -8
  47. package/src/client/lib/external-stores.js +0 -4
  48. package/src/client/lib/external-sync-store.js +0 -42
@@ -0,0 +1,233 @@
1
+ import React, { useEffect, useRef, useState } from 'react'
2
+
3
+ import { PanelHeader } from '../panel/panel-header.jsx'
4
+ import { PanelFooter } from '../panel/panel-footer.jsx'
5
+ import { Message } from '../message/message.jsx'
6
+
7
+ import { useApp } from '../../store/useApp.js'
8
+ import { useTextareaAutosize } from '../../hooks/useTextareaAutosize.js'
9
+ import { formatTranscript } from '../../lib/transform-messages.js'
10
+ import { agentStatusHeadline } from '../../lib/agent-status-headline.js'
11
+
12
+ export function Chat ({ onEndChatScreen, onSettingsScreen }) {
13
+ const { availability, thread, messages, agent, agentStatus, isAgentTyping, isChatOpen, settings, isKeyboard, setLiveRegionText } = useApp()
14
+
15
+ const [userMessage, setUserMessage] = useState('')
16
+ const [focusVisibleWithin, setFocusVisibleWithin] = useState(false)
17
+
18
+ const messageRef = useRef()
19
+
20
+ useTextareaAutosize(messageRef.current, userMessage)
21
+
22
+ useEffect(() => {
23
+ if (settings.scroll && messages.length !== 0) {
24
+ const chatBody = document.querySelector('.wc-body')
25
+ chatBody.scrollTop = chatBody.scrollHeight
26
+ }
27
+ }, [messages, isAgentTyping])
28
+
29
+ useEffect(() => {
30
+ const label = document.querySelector('.wc-form__label')
31
+
32
+ if (userMessage.length === 0) {
33
+ label.classList.remove('govuk-visually-hidden')
34
+ } else {
35
+ label.classList.add('govuk-visually-hidden')
36
+ }
37
+ }, [userMessage])
38
+
39
+ const onChange = e => {
40
+ setUserMessage(e.target?.value)
41
+ }
42
+
43
+ const agentName = agent?.nickname || agent?.firstName
44
+
45
+ const connectionHeadlineText = agentStatusHeadline(availability, agentStatus, agentName)
46
+
47
+ useEffect(() => {
48
+ if (connectionHeadlineText) {
49
+ setLiveRegionText(`Floodline Webchat - ${connectionHeadlineText}`)
50
+ }
51
+
52
+ return () => {
53
+ setLiveRegionText()
54
+ }
55
+ }, [connectionHeadlineText])
56
+
57
+ useEffect(() => {
58
+ if (isAgentTyping && isChatOpen) {
59
+ setLiveRegionText(`${agentName} is typing...`)
60
+ }
61
+
62
+ return () => {
63
+ setLiveRegionText()
64
+ }
65
+ }, [isAgentTyping, isChatOpen])
66
+
67
+ useEffect(() => {
68
+ const lastAgentMessage = messages[messages.length - 1]
69
+
70
+ if (agentStatus !== 'closed' && lastAgentMessage?.direction === 'outbound') {
71
+ setLiveRegionText(`${agentName} said: ${lastAgentMessage.text}`)
72
+ }
73
+
74
+ return () => {
75
+ setLiveRegionText()
76
+ }
77
+ }, [messages])
78
+
79
+ const sendMessage = () => {
80
+ if (messageRef.current.value.length === 0 || agentStatus === 'closed') {
81
+ return
82
+ }
83
+
84
+ try {
85
+ const message = messageRef.current.value.trim()
86
+ thread.sendTextMessage(message)
87
+ setLiveRegionText(`You said: ${message}`)
88
+ } catch (err) {
89
+ console.log('[Chat Error] sendMessage', err)
90
+ }
91
+
92
+ setUserMessage('')
93
+ }
94
+
95
+ const handleSubmit = e => {
96
+ e.preventDefault()
97
+ sendMessage()
98
+ }
99
+
100
+ const saveChat = () => {
101
+ const transcript = formatTranscript(messages)
102
+
103
+ const saveChatLink = document.querySelector('#transcript-download')
104
+
105
+ saveChatLink.setAttribute('href', `data:text/plain;charset=utf-8,${transcript}`)
106
+ }
107
+
108
+ const handleKeyPress = e => {
109
+ if (e.key === 'Enter' && !e.shiftKey) {
110
+ switch (e.target.id) {
111
+ case 'text-area':
112
+ e.preventDefault()
113
+ sendMessage()
114
+ break
115
+ case 'end-chat':
116
+ onEndChatScreen(e)
117
+ break
118
+ case 'wc-settings':
119
+ onSettingsScreen(e)
120
+ break
121
+ case 'transcript-download':
122
+ saveChat()
123
+ break
124
+ default:
125
+ break
126
+ }
127
+ }
128
+ if (e.key === ' ') {
129
+ if (e.target.id === 'end-chat') {
130
+ onEndChatScreen(e)
131
+ }
132
+ if (e.target.id === 'wc-settings') {
133
+ onSettingsScreen(e)
134
+ }
135
+ }
136
+ }
137
+
138
+ return (
139
+ <>
140
+ <PanelHeader />
141
+
142
+ <div className='wc-status'>
143
+ <p className='wc-status__availability'>{connectionHeadlineText}</p>
144
+ <a
145
+ id='end-chat'
146
+ className='wc-status__link'
147
+ href='#'
148
+ data-module='govuk-button'
149
+ role='button'
150
+ onClick={onEndChatScreen}
151
+ onKeyDown={handleKeyPress}
152
+ >
153
+ End chat
154
+ </a>
155
+ </div>
156
+
157
+ <div className='wc-body' tabIndex='0'>
158
+ <ul className='wc-chat'>
159
+ {messages.length
160
+ ? messages.map((msg, index) => <Message key={msg.id} message={msg} previousMessage={messages[index - 1]} />)
161
+ : null}
162
+ {isAgentTyping
163
+ ? (
164
+ <li className='wc-chat__message outbound'>
165
+ <div className='wc-chat__from'>{agentName} is typing</div>
166
+ <div className='wc-chat__text outbound'>
167
+ <svg width='28' height='16' x='0px' y='0px' viewBox='0 0 28 16'>
168
+ <circle stroke='none' cx='3' cy='8' r='3' fill='currentColor' />
169
+ <circle stroke='none' cx='14' cy='8' r='3' fill='currentColor' />
170
+ <circle stroke='none' cx='25' cy='8' r='3' fill='currentColor' />
171
+ </svg>
172
+ </div>
173
+ </li>
174
+ )
175
+ : null}
176
+ </ul>
177
+ </div>
178
+
179
+ <PanelFooter>
180
+ <form className={`wc-form${focusVisibleWithin ? ' wc-focus-within' : ''}`} noValidate onSubmit={handleSubmit}>
181
+ <label className='govuk-label wc-form__label' htmlFor='wc-form-textarea'>
182
+ Your message<span className='govuk-visually-hidden'> (enter key submits)</span>
183
+ </label>
184
+
185
+ <textarea
186
+ ref={messageRef}
187
+ rows='1'
188
+ aria-required='true'
189
+ className='wc-form__textarea'
190
+ id='text-area'
191
+ name='message'
192
+ onChange={onChange}
193
+ onKeyDown={handleKeyPress}
194
+ onFocus={() => { setFocusVisibleWithin(isKeyboard) }}
195
+ onBlur={() => { setFocusVisibleWithin(false) }}
196
+ value={userMessage}
197
+ />
198
+
199
+ <input
200
+ type='submit'
201
+ className='wc-form__button govuk-button'
202
+ value='Send'
203
+ data-prevent-double-click='true'
204
+ />
205
+ </form>
206
+
207
+ <div className='wc-footer__settings'>
208
+ <a
209
+ href='#'
210
+ id='wc-settings'
211
+ className='wc-footer__settings-link'
212
+ data-module='govuk-button'
213
+ onKeyDown={handleKeyPress}
214
+ onClick={onSettingsScreen}
215
+ >
216
+ Settings
217
+ </a>
218
+ <a
219
+ href='#'
220
+ id='transcript-download'
221
+ className='wc-footer__settings-link'
222
+ data-module='govuk-button'
223
+ download='floodline-webchat-transcript.txt'
224
+ onKeyDown={handleKeyPress}
225
+ onClick={saveChat}
226
+ >
227
+ Save chat
228
+ </a>
229
+ </div>
230
+ </PanelFooter>
231
+ </>
232
+ )
233
+ }
@@ -0,0 +1,233 @@
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
+ }
39
+
40
+ .wc-body[tabindex="0"]:focus-visible {
41
+ outline: 3px solid transparent;
42
+ outline-offset: -2px;
43
+ box-shadow:
44
+ inset 0 0 0 2px $govuk-focus-colour,
45
+ inset 0 0 0 4px govuk-colour('black'),
46
+ 0 0 0 1px $govuk-focus-colour;
47
+ }
48
+
49
+ .wc-chat {
50
+ @extend %govuk-body-s;
51
+ line-height: 1.25;
52
+ font-size: 14px;
53
+ overflow: auto;
54
+ list-style: none;
55
+ padding: 0;
56
+
57
+ &__message {
58
+ margin: 5px 15px 0;
59
+ @include mq ($from: tablet) {
60
+ margin-left: 10px;
61
+ margin-right: 10px;
62
+ }
63
+
64
+ &:first-child {
65
+ padding-top: 15px;
66
+ }
67
+
68
+ &.inbound {
69
+ text-align: right;
70
+ }
71
+ }
72
+
73
+ &__from {
74
+ line-height: 1.25;
75
+ color: govuk-colour('dark-grey');
76
+ margin-top: 2px;
77
+ margin-bottom: 2px;
78
+ }
79
+
80
+ &__text {
81
+ font-size: 16px;
82
+ padding: 10px 12.5px;
83
+ margin-bottom: 0;
84
+ display: inline-block;
85
+ border: 1px solid transparent;
86
+
87
+ @media (forced-colors: active) {
88
+ border-color: currentColor;
89
+ }
90
+
91
+ &.inbound {
92
+ color: govuk-colour('white');
93
+ background-color: govuk-colour('blue');
94
+ border-radius: 10px 0 10px 10px;
95
+ }
96
+
97
+ &.outbound {
98
+ background-color: govuk-colour('light-grey');
99
+ border-radius: 0 10px 10px;
100
+ }
101
+
102
+ svg {
103
+ display: block;
104
+ color: govuk-colour('dark-grey');
105
+ }
106
+
107
+ @media (forced-colors: active) {
108
+ svg {
109
+ color: currentColor;
110
+ }
111
+ }
112
+
113
+
114
+ svg circle {
115
+ animation: 1s blink infinite;
116
+ fill: currentColor;
117
+
118
+ &:nth-child(2) {
119
+ animation-delay: 250ms
120
+ }
121
+
122
+ &:nth-child(3) {
123
+ animation-delay: 500ms
124
+ }
125
+ }
126
+ }
127
+ }
128
+
129
+ .wc-form {
130
+ position: relative;
131
+ display: flex;
132
+ flex-wrap: nowrap;
133
+ align-items: baseline;
134
+ border-top: 1px solid govuk-colour('black');
135
+ border-bottom: 1px solid govuk-colour('black');
136
+
137
+ &__label {
138
+ position: absolute;
139
+ pointer-events: none;
140
+ font-size: 16px;
141
+ line-height: 20px;
142
+ margin: 20px;
143
+ @include mq ($from: tablet) {
144
+ margin: 18px 18px 19px;
145
+ }
146
+ left: 0;
147
+ bottom: 0;
148
+ color: $govuk-secondary-text-colour;
149
+ z-index: 3;
150
+ }
151
+
152
+ &__textarea {
153
+ @extend %govuk-body-s;
154
+ box-sizing: border-box;
155
+ min-height: auto;
156
+ font-size: 16px;
157
+ line-height: 20px;
158
+ max-height: 120px;
159
+ flex: 1 1 auto;
160
+ align-self: flex-end;
161
+ margin: 20px;
162
+ @include mq ($from: tablet) {
163
+ margin: 18px 18px 19px;
164
+ }
165
+ padding: 0;
166
+ border: 0;
167
+ height: 20px;
168
+ resize: none;
169
+ overflow-x: hidden;
170
+ overscroll-behavior: contain;
171
+
172
+ &:focus {
173
+ outline: none;
174
+ box-shadow: none;
175
+ z-index: 2;
176
+ }
177
+ }
178
+
179
+ &__button {
180
+ margin: 10px 15px 12px 0;
181
+ @include mq ($from: tablet) {
182
+ margin-right: 10px;
183
+ }
184
+ font-size: 16px;
185
+ position: relative;
186
+ flex: 0 0 auto;
187
+ align-self: flex-end;
188
+ display: flex;
189
+ flex-direction: row;
190
+ flex-wrap: nowrap;
191
+ align-items: center;
192
+ width: auto;
193
+ cursor: pointer;
194
+ }
195
+
196
+ &.wc-focus-within::after {
197
+ @include focus($glow: 5px, $strong: 2px, $background: 0, $inset: 0);
198
+ left: 4px;
199
+ right: 4px;
200
+ top: 4px;
201
+ bottom: 4px;
202
+ }
203
+ }
204
+
205
+ .wc-body:focus-visible + .wc-footer .wc-form {
206
+ border-top: 1px solid transparent;
207
+ }
208
+
209
+ .wc-footer {
210
+ position: relative;
211
+ flex: 0 0 0;
212
+
213
+ &__settings {
214
+ @include govuk-responsive-padding(2);
215
+
216
+ display: flex;
217
+ flex-direction: row;
218
+
219
+ &-link {
220
+ @extend %wc-link-button;
221
+
222
+ &:first-child {
223
+ margin-right: govuk-spacing(3);
224
+ }
225
+ }
226
+ }
227
+
228
+ &__input {
229
+ @include govuk-responsive-padding(2);
230
+
231
+ border-top: 1px solid govuk-colour('black');
232
+ }
233
+ }
@@ -0,0 +1,34 @@
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
+ }
@@ -0,0 +1,55 @@
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' aria-live='polite' aria-atomic='true'>
48
+ {textA}
49
+ </div>
50
+ <div className='wc-live' aria-live='polite' aria-atomic='true'>
51
+ {textB}
52
+ </div>
53
+ </>
54
+ )
55
+ }
@@ -0,0 +1,20 @@
1
+ import React from 'react'
2
+ import { classnames } from '../../lib/classnames'
3
+
4
+ export function Message ({ message, previousMessage }) {
5
+ const outbound = message.direction === 'outbound'
6
+
7
+ const messageOwnerSameAsPrevious = message?.direction === previousMessage?.direction
8
+
9
+ return (
10
+ <li className={classnames('wc-chat__message', outbound ? 'outbound' : 'inbound')}>
11
+ <div className='wc-chat__from'>
12
+ {messageOwnerSameAsPrevious ? null : <span>{outbound ? message.assignee : 'You'}</span>}
13
+ <span className='govuk-visually-hidden'>:</span>
14
+ </div>
15
+ <div className={classnames('wc-chat__text', outbound ? 'outbound' : 'inbound')}>
16
+ {message.text}
17
+ </div>
18
+ </li>
19
+ )
20
+ }
@@ -0,0 +1,9 @@
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,7 +1,30 @@
1
1
  import React from 'react'
2
+ import { useApp } from '../../store/useApp.js'
3
+ import { historyReplaceState } from '../../lib/history.js'
2
4
 
3
- export function PanelHeader ({ screen, isConnected, onBack, onClose }) {
4
- let ButtonComponent = (
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 = (
5
28
  <button className='wc-header__close' aria-label='Close the webchat' onClick={onClose}>
6
29
  <svg aria-hidden='true' focusable='false' width='20' height='20' viewBox='0 0 20 20'>
7
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' />
@@ -9,27 +32,44 @@ export function PanelHeader ({ screen, isConnected, onBack, onClose }) {
9
32
  </button>
10
33
  )
11
34
 
12
- if (isConnected) {
13
- ButtonComponent = (
14
- <button className='wc-hide-btn' aria-label='Minimise the webchat' data-wc-hide-btn>
15
- <svg aria-hidden='true' focusable='false' width='20' height='20' viewBox='0 0 20 20'>
16
- <path d='M10 14.4l-7-7L4.4 6l5.6 5.6L15.6 6 17 7.4l-7 7z' fill='currentColor' />
17
- </svg>
18
- </button>
19
- )
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
+ }
20
54
  }
21
55
 
22
- const BackButtonComponent = !isConnected && screen !== 0 ? <a href='#' className='wc-header__link govuk-back-link govuk-back-link--inverse' onClick={onBack}>Back</a> : null
56
+ if (!threadId && isMobileAndNoHistory) {
57
+ RightButtonComponent = CloseButtonComponent
58
+ }
59
+
60
+ if (isMobileAndHasHistory) {
61
+ RightButtonComponent = null
62
+ }
23
63
 
24
64
  return (
25
65
  <div className='wc-header'>
26
- {BackButtonComponent}
66
+ {isMobileAndHasHistory ? BackButtonComponent : null}
27
67
 
28
- <h2 id='wc-header-title' className='wc-header__title govuk-heading-s'>
68
+ <h2 id='wc-header-title' className='wc-header__title'>
29
69
  Floodline Webchat
30
70
  </h2>
31
71
 
32
- {ButtonComponent}
72
+ {RightButtonComponent}
33
73
  </div>
34
74
  )
35
75
  }