@defra/flood-webchat 0.0.1-beta.26 → 0.0.1-beta.28
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/dist/client.js +256 -105
- package/dist/client.js.map +1 -1
- package/main.scss +10 -6
- package/package.json +1 -1
- package/src/client/components/availability/availability.jsx +9 -4
- package/src/client/components/availability/availability.scss +8 -134
- package/src/client/components/chat/chat.jsx +50 -51
- package/src/client/components/chat/chat.scss +113 -35
- package/src/client/components/errorSummary/error-summary.jsx +2 -2
- package/src/client/components/message/message.jsx +4 -4
- package/src/client/components/panel/panel-header.jsx +40 -11
- package/src/client/components/panel/panel.jsx +21 -4
- package/src/client/components/panel/panel.scss +62 -22
- package/src/client/components/screens/end-chat.jsx +6 -4
- package/src/client/components/screens/feedback.jsx +5 -5
- package/src/client/components/screens/pre-chat.jsx +45 -44
- package/src/client/components/screens/request-chat.jsx +74 -67
- package/src/client/components/screens/settings.jsx +39 -37
- package/src/client/hooks/useFocusedElements.js +12 -2
- package/src/client/lib/history.js +13 -0
- package/src/client/scss/_objects.scss +33 -0
- package/src/client/scss/_settings.scss +75 -0
- package/src/client/scss/_tools.scss +33 -0
- package/src/client/scss/_utilities.scss +25 -0
- package/src/client/store/AppProvider.jsx +39 -4
- package/src/client/store/actions-map.js +17 -1
- package/src/client/store/reducer.js +2 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
.wc-availability__inner {
|
|
3
2
|
max-width: 960px;
|
|
4
3
|
margin-left: auto;
|
|
@@ -27,42 +26,21 @@
|
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
.wc-availability__link {
|
|
29
|
+
@extend %govuk-link;
|
|
30
|
+
display: inline-block;
|
|
30
31
|
@include govuk-font($size: 19);
|
|
31
|
-
position:relative;
|
|
32
|
-
display:inline-block;
|
|
33
32
|
margin-right: 5px;
|
|
34
|
-
margin-bottom: 0;
|
|
35
|
-
fill: govuk-colour('black');
|
|
36
|
-
|
|
37
|
-
.govuk-visually-hidden, .wc-availability__unseen {
|
|
38
|
-
pointer-events: none;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
&:hover {
|
|
42
|
-
color: $govuk-link-hover-colour;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
&:active {
|
|
46
|
-
color: govuk-colour('black');
|
|
47
|
-
}
|
|
48
33
|
|
|
49
|
-
&:visited {
|
|
50
|
-
color:
|
|
34
|
+
&:visited:not(:hover):not(:focus) {
|
|
35
|
+
color: govuk-colour('blue');
|
|
51
36
|
}
|
|
52
37
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
background-color: transparent;
|
|
56
|
-
text-decoration: underline;
|
|
57
|
-
color: $govuk-focus-colour;
|
|
38
|
+
.govuk-visually-hidden, .wc-availability__unseen {
|
|
39
|
+
pointer-events: none;
|
|
58
40
|
}
|
|
59
41
|
|
|
60
|
-
&:hover:not(:focus):not(:active) {
|
|
61
|
-
color:
|
|
62
|
-
|
|
63
|
-
.wc-availability__unseen {
|
|
64
|
-
background-color: govuk-colour('dark-blue');
|
|
65
|
-
}
|
|
42
|
+
&:hover:not(:focus):not(:active) .wc-availability__unseen {
|
|
43
|
+
background-color: govuk-colour('dark-blue');
|
|
66
44
|
}
|
|
67
45
|
}
|
|
68
46
|
|
|
@@ -83,107 +61,3 @@
|
|
|
83
61
|
padding-right: 7px;
|
|
84
62
|
}
|
|
85
63
|
}
|
|
86
|
-
|
|
87
|
-
// Define a mixin for the common styles
|
|
88
|
-
@mixin link-icon-styles {
|
|
89
|
-
position: relative;
|
|
90
|
-
display: inline-block;
|
|
91
|
-
margin-right: 5px;
|
|
92
|
-
fill: govuk-colour('black');
|
|
93
|
-
@include govuk-font($size: 19);
|
|
94
|
-
|
|
95
|
-
&:last-of-type {
|
|
96
|
-
margin-right: 0;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
@include mq ($from: tablet) {
|
|
100
|
-
margin-right: 10px;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
&__icon {
|
|
104
|
-
color: govuk-colour('black');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
svg {
|
|
108
|
-
position: relative;
|
|
109
|
-
display: inline-block;
|
|
110
|
-
color: currentcolor;
|
|
111
|
-
vertical-align: top;
|
|
112
|
-
margin-right: 7px;
|
|
113
|
-
top: 1px;
|
|
114
|
-
|
|
115
|
-
@include mq ($from: tablet) {
|
|
116
|
-
margin-right: 8px;
|
|
117
|
-
top: 4px;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
&:hover {
|
|
122
|
-
color: $govuk-link-hover-colour;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
&:active {
|
|
126
|
-
color: govuk-colour('black');
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
.defra-link-icon {
|
|
131
|
-
@include link-icon-styles;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
.wc-open-btn {
|
|
135
|
-
@include link-icon-styles;
|
|
136
|
-
margin-bottom: 0;
|
|
137
|
-
|
|
138
|
-
&:visited {
|
|
139
|
-
color: $govuk-link-colour;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
span {
|
|
143
|
-
pointer-events: none;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
svg {
|
|
147
|
-
@include mq ($from: 'tablet') {
|
|
148
|
-
top: 3px;
|
|
149
|
-
}
|
|
150
|
-
color: govuk-colour('black');
|
|
151
|
-
pointer-events: none;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
&:focus {
|
|
155
|
-
box-shadow: none;
|
|
156
|
-
background-color: transparent;
|
|
157
|
-
text-decoration: underline;
|
|
158
|
-
color: $govuk-focus-colour;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
&:hover:not(:focus):not(:active) {
|
|
162
|
-
color: $govuk-link-hover-colour;
|
|
163
|
-
|
|
164
|
-
svg {
|
|
165
|
-
color: govuk-colour('dark-blue');
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
.wc-open-btn__unseen {
|
|
169
|
-
background-color: govuk-colour('dark-blue');
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
&__unseen {
|
|
174
|
-
display: inline-block;
|
|
175
|
-
position: relative;
|
|
176
|
-
border-radius: 10px;
|
|
177
|
-
background-color: govuk-colour('black');
|
|
178
|
-
color: #ffffff;
|
|
179
|
-
font-weight: bold;
|
|
180
|
-
font-size: 14px;
|
|
181
|
-
padding: 0 6px;
|
|
182
|
-
margin-left: 5px;
|
|
183
|
-
@include mq ($from: tablet) {
|
|
184
|
-
top: -1px;
|
|
185
|
-
padding-left: 7px;
|
|
186
|
-
padding-right: 7px;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
@@ -9,9 +9,10 @@ import { useTextareaAutosize } from '../../hooks/useTextareaAutosize.js'
|
|
|
9
9
|
import { formatTranscript } from '../../lib/transform-messages.js'
|
|
10
10
|
|
|
11
11
|
export function Chat ({ onEndChatScreen, onSettingsScreen }) {
|
|
12
|
-
const { availability, thread, messages, agent, agentStatus, isAgentTyping, settings } = useApp()
|
|
12
|
+
const { availability, thread, messages, agent, agentStatus, isAgentTyping, settings, isKeyboard } = useApp()
|
|
13
13
|
|
|
14
14
|
const [userMessage, setUserMessage] = useState('')
|
|
15
|
+
const [focusVisibleWithin, setFocusVisibleWithin] = useState(false)
|
|
15
16
|
|
|
16
17
|
const messageRef = useRef()
|
|
17
18
|
|
|
@@ -94,61 +95,59 @@ export function Chat ({ onEndChatScreen, onSettingsScreen }) {
|
|
|
94
95
|
<PanelHeader />
|
|
95
96
|
|
|
96
97
|
<div className='wc-status'>
|
|
97
|
-
<p className='wc-status__availability
|
|
98
|
-
<a className='wc-status__link
|
|
98
|
+
<p className='wc-status__availability'>{connectionHeadlineText}</p>
|
|
99
|
+
<a className='wc-status__link' href='#' data-module='govuk-button' onClick={onEndChatScreen}>End chat</a>
|
|
99
100
|
</div>
|
|
100
101
|
|
|
101
|
-
<div className='wc-body'>
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
{messages
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
<
|
|
110
|
-
|
|
111
|
-
<
|
|
112
|
-
<
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
</ul>
|
|
122
|
-
</div>
|
|
102
|
+
<div className='wc-body' tabIndex='0'>
|
|
103
|
+
<ul className='wc-chat'>
|
|
104
|
+
{messages.length
|
|
105
|
+
? messages.map((msg, index) => <Message key={msg.id} message={msg} previousMessage={messages[index - 1]} />)
|
|
106
|
+
: null}
|
|
107
|
+
{isAgentTyping
|
|
108
|
+
? (
|
|
109
|
+
<li className='wc-chat__message outbound'>
|
|
110
|
+
<div className='wc-chat__from'>{agentName} is typing</div>
|
|
111
|
+
<div className='wc-chat__text outbound'>
|
|
112
|
+
<svg width='28' height='16' x='0px' y='0px' viewBox='0 0 28 16'>
|
|
113
|
+
<circle stroke='none' cx='3' cy='8' r='3' fill='currentColor' />
|
|
114
|
+
<circle stroke='none' cx='14' cy='8' r='3' fill='currentColor' />
|
|
115
|
+
<circle stroke='none' cx='25' cy='8' r='3' fill='currentColor' />
|
|
116
|
+
</svg>
|
|
117
|
+
</div>
|
|
118
|
+
</li>
|
|
119
|
+
)
|
|
120
|
+
: null}
|
|
121
|
+
</ul>
|
|
123
122
|
</div>
|
|
124
123
|
|
|
125
124
|
<PanelFooter>
|
|
126
|
-
<
|
|
127
|
-
<
|
|
128
|
-
<
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
</
|
|
125
|
+
<form className={`wc-form${focusVisibleWithin ? ' wc-focus-within' : ''}`} noValidate onSubmit={handleSubmit}>
|
|
126
|
+
<label className='govuk-label wc-form__label' htmlFor='wc-form-textarea'>
|
|
127
|
+
Your message<span className='govuk-visually-hidden'> (enter key submits)</span>
|
|
128
|
+
</label>
|
|
129
|
+
|
|
130
|
+
<textarea
|
|
131
|
+
ref={messageRef}
|
|
132
|
+
rows='1'
|
|
133
|
+
aria-required='true'
|
|
134
|
+
className='wc-form__textarea'
|
|
135
|
+
id='wc-form-textarea'
|
|
136
|
+
name='message'
|
|
137
|
+
onChange={onChange}
|
|
138
|
+
onKeyDown={handleKeyPress}
|
|
139
|
+
onFocus={() => { setFocusVisibleWithin(isKeyboard) }}
|
|
140
|
+
onBlur={() => { setFocusVisibleWithin(false) }}
|
|
141
|
+
value={userMessage}
|
|
142
|
+
/>
|
|
143
|
+
|
|
144
|
+
<input
|
|
145
|
+
type='submit'
|
|
146
|
+
className='wc-form__button govuk-button'
|
|
147
|
+
value='Send'
|
|
148
|
+
data-prevent-double-click='true'
|
|
149
|
+
/>
|
|
150
|
+
</form>
|
|
152
151
|
|
|
153
152
|
<div className='wc-footer__settings'>
|
|
154
153
|
<a
|
|
@@ -6,37 +6,64 @@
|
|
|
6
6
|
|
|
7
7
|
.wc-status {
|
|
8
8
|
display: flex;
|
|
9
|
-
|
|
10
|
-
padding:
|
|
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
|
+
}
|
|
11
28
|
|
|
12
29
|
&__availability {
|
|
30
|
+
font-size: 16px;
|
|
13
31
|
margin-bottom: 0;
|
|
14
32
|
}
|
|
15
33
|
|
|
16
34
|
&__link {
|
|
35
|
+
@extend %wc-link-button;
|
|
17
36
|
margin-left: auto;
|
|
18
37
|
}
|
|
19
38
|
}
|
|
20
39
|
|
|
21
|
-
.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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;
|
|
28
47
|
}
|
|
29
48
|
|
|
30
49
|
.wc-chat {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
50
|
+
@extend %govuk-body-s;
|
|
51
|
+
line-height: 1.25;
|
|
52
|
+
font-size: 14px;
|
|
53
|
+
overflow: auto;
|
|
54
|
+
list-style: none;
|
|
55
|
+
padding: 0;
|
|
37
56
|
|
|
38
57
|
&__message {
|
|
39
|
-
margin
|
|
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
|
+
}
|
|
40
67
|
|
|
41
68
|
&.inbound {
|
|
42
69
|
text-align: right;
|
|
@@ -44,24 +71,27 @@
|
|
|
44
71
|
}
|
|
45
72
|
|
|
46
73
|
&__from {
|
|
74
|
+
line-height: 1.25;
|
|
47
75
|
color: govuk-colour('dark-grey');
|
|
48
|
-
margin-
|
|
76
|
+
margin-top: 2px;
|
|
77
|
+
margin-bottom: 2px;
|
|
49
78
|
}
|
|
50
79
|
|
|
51
80
|
&__text {
|
|
52
|
-
|
|
81
|
+
font-size: 16px;
|
|
82
|
+
padding: 10px 12.5px;
|
|
53
83
|
margin-bottom: 0;
|
|
54
84
|
display: inline-block;
|
|
55
85
|
|
|
56
86
|
&.inbound {
|
|
57
87
|
color: govuk-colour('white');
|
|
58
88
|
background-color: govuk-colour('blue');
|
|
59
|
-
border-radius:
|
|
89
|
+
border-radius: 10px 0 10px 10px;
|
|
60
90
|
}
|
|
61
91
|
|
|
62
92
|
&.outbound {
|
|
63
93
|
background-color: govuk-colour('light-grey');
|
|
64
|
-
border-radius: 0
|
|
94
|
+
border-radius: 0 10px 10px;
|
|
65
95
|
}
|
|
66
96
|
|
|
67
97
|
svg {
|
|
@@ -87,48 +117,96 @@
|
|
|
87
117
|
.wc-form {
|
|
88
118
|
position: relative;
|
|
89
119
|
display: flex;
|
|
90
|
-
flex-
|
|
91
|
-
align-items:
|
|
92
|
-
|
|
120
|
+
flex-wrap: nowrap;
|
|
121
|
+
align-items: baseline;
|
|
122
|
+
border-top: 1px solid govuk-colour('black');
|
|
123
|
+
border-bottom: 1px solid govuk-colour('black');
|
|
93
124
|
|
|
94
125
|
&__label {
|
|
95
126
|
position: absolute;
|
|
96
|
-
|
|
97
|
-
|
|
127
|
+
pointer-events: none;
|
|
128
|
+
font-size: 16px;
|
|
129
|
+
line-height: 20px;
|
|
130
|
+
margin: 20px;
|
|
131
|
+
@include mq ($from: tablet) {
|
|
132
|
+
margin: 18px 18px 19px;
|
|
133
|
+
}
|
|
134
|
+
left: 0;
|
|
135
|
+
bottom: 0;
|
|
136
|
+
color: $govuk-secondary-text-colour;
|
|
98
137
|
z-index: 3;
|
|
99
|
-
margin-bottom: 0;
|
|
100
|
-
color: govuk-colour('dark-grey');
|
|
101
138
|
}
|
|
102
139
|
|
|
103
140
|
&__textarea {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
margin-bottom: 0;
|
|
141
|
+
@extend %govuk-body-s;
|
|
142
|
+
box-sizing: border-box;
|
|
107
143
|
min-height: auto;
|
|
144
|
+
font-size: 16px;
|
|
145
|
+
line-height: 20px;
|
|
108
146
|
max-height: 120px;
|
|
147
|
+
flex: 1 1 auto;
|
|
148
|
+
align-self: flex-end;
|
|
149
|
+
margin: 20px;
|
|
150
|
+
@include mq ($from: tablet) {
|
|
151
|
+
margin: 18px 18px 19px;
|
|
152
|
+
}
|
|
153
|
+
padding: 0;
|
|
154
|
+
border: 0;
|
|
155
|
+
height: 20px;
|
|
109
156
|
resize: none;
|
|
110
|
-
border: none;
|
|
111
157
|
overflow-x: hidden;
|
|
112
158
|
overscroll-behavior: contain;
|
|
113
|
-
|
|
114
|
-
|
|
159
|
+
|
|
160
|
+
&:focus {
|
|
161
|
+
outline: none;
|
|
162
|
+
box-shadow: none;
|
|
163
|
+
z-index: 2;
|
|
164
|
+
}
|
|
115
165
|
}
|
|
116
166
|
|
|
117
167
|
&__button {
|
|
118
|
-
margin:
|
|
168
|
+
margin: 10px 15px 12px 0;
|
|
169
|
+
@include mq ($from: tablet) {
|
|
170
|
+
margin-right: 10px;
|
|
171
|
+
}
|
|
172
|
+
font-size: 16px;
|
|
173
|
+
position: relative;
|
|
174
|
+
flex: 0 0 auto;
|
|
175
|
+
align-self: flex-end;
|
|
176
|
+
display: flex;
|
|
177
|
+
flex-direction: row;
|
|
178
|
+
flex-wrap: nowrap;
|
|
179
|
+
align-items: center;
|
|
119
180
|
width: auto;
|
|
181
|
+
cursor: pointer;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
&.wc-focus-within::after {
|
|
185
|
+
@include focus($glow: 5px, $strong: 2px, $background: 0, $inset: 0);
|
|
186
|
+
left: 4px;
|
|
187
|
+
right: 4px;
|
|
188
|
+
top: 4px;
|
|
189
|
+
bottom: 4px;
|
|
120
190
|
}
|
|
121
191
|
}
|
|
122
192
|
|
|
193
|
+
.wc-body:focus-visible + .wc-footer .wc-form {
|
|
194
|
+
border-top: 1px solid transparent;
|
|
195
|
+
}
|
|
196
|
+
|
|
123
197
|
.wc-footer {
|
|
198
|
+
position: relative;
|
|
199
|
+
flex: 0 0 0;
|
|
200
|
+
|
|
124
201
|
&__settings {
|
|
125
202
|
@include govuk-responsive-padding(2);
|
|
126
203
|
|
|
127
204
|
display: flex;
|
|
128
205
|
flex-direction: row;
|
|
129
|
-
border-top: 1px solid govuk-colour('black');
|
|
130
206
|
|
|
131
207
|
&-link {
|
|
208
|
+
@extend %wc-link-button;
|
|
209
|
+
|
|
132
210
|
&:first-child {
|
|
133
211
|
margin-right: govuk-spacing(3);
|
|
134
212
|
}
|
|
@@ -16,11 +16,11 @@ export const ErrorSummary = ({ errors }) => {
|
|
|
16
16
|
return (
|
|
17
17
|
<div className='govuk-error-summary govuk-!-static-margin-bottom-7' data-module='govuk-error-summary' tabIndex='-1'>
|
|
18
18
|
<div role='alert'>
|
|
19
|
-
<h2 id='wc-error' className='govuk-error-summary__title'>
|
|
19
|
+
<h2 id='wc-error' className='wc-error-summary__title govuk-error-summary__title'>
|
|
20
20
|
There is a problem
|
|
21
21
|
</h2>
|
|
22
22
|
<div className='govuk-error-summary__body'>
|
|
23
|
-
<ul className='govuk-list govuk-error-summary__list'>
|
|
23
|
+
<ul className='govuk-list govuk-error-summary__list wc-error-summary__list'>
|
|
24
24
|
{errs.map(key => (
|
|
25
25
|
<li key={key}>
|
|
26
26
|
<a href='#' data-key={key} onClick={goToInput}>{errors[key]}</a>
|
|
@@ -7,14 +7,14 @@ export function Message ({ message, previousMessage }) {
|
|
|
7
7
|
const messageOwnerSameAsPrevious = message?.direction === previousMessage?.direction
|
|
8
8
|
|
|
9
9
|
return (
|
|
10
|
-
<li className={classnames('wc-chat__message
|
|
11
|
-
<div className='wc-chat__from
|
|
10
|
+
<li className={classnames('wc-chat__message', outbound ? 'outbound' : 'inbound')}>
|
|
11
|
+
<div className='wc-chat__from'>
|
|
12
12
|
{messageOwnerSameAsPrevious ? null : <span>{outbound ? message.assignee : 'You'}</span>}
|
|
13
13
|
<span className='govuk-visually-hidden'>:</span>
|
|
14
14
|
</div>
|
|
15
|
-
<
|
|
15
|
+
<div className={classnames('wc-chat__text', outbound ? 'outbound' : 'inbound')}>
|
|
16
16
|
{message.text}
|
|
17
|
-
</
|
|
17
|
+
</div>
|
|
18
18
|
</li>
|
|
19
19
|
)
|
|
20
20
|
}
|
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { useApp } from '../../store/useApp.js'
|
|
3
|
+
import { historyReplaceState } from '../../lib/history.js'
|
|
3
4
|
|
|
4
5
|
export function PanelHeader () {
|
|
5
|
-
const { thread, setChatVisibility, setUnseenCount,
|
|
6
|
+
const { thread, threadId, setChatVisibility, setUnseenCount, isMobile } = useApp()
|
|
6
7
|
|
|
7
8
|
const onClose = e => {
|
|
8
9
|
e.preventDefault()
|
|
9
10
|
setChatVisibility(false)
|
|
11
|
+
historyReplaceState()
|
|
12
|
+
|
|
10
13
|
if (threadId) {
|
|
11
14
|
thread?.lastMessageSeen()
|
|
12
15
|
setUnseenCount(0)
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
|
|
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 = (
|
|
17
28
|
<button className='wc-header__close' aria-label='Close the webchat' onClick={onClose}>
|
|
18
29
|
<svg aria-hidden='true' focusable='false' width='20' height='20' viewBox='0 0 20 20'>
|
|
19
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' />
|
|
@@ -21,23 +32,41 @@ export function PanelHeader () {
|
|
|
21
32
|
</button>
|
|
22
33
|
)
|
|
23
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
|
+
let RightButtonComponent = CloseButtonComponent
|
|
44
|
+
|
|
24
45
|
if (thread) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
46
|
+
RightButtonComponent = MinimiseButtonComponent
|
|
47
|
+
|
|
48
|
+
if (isMobile && !window.history.state) {
|
|
49
|
+
RightButtonComponent = MinimiseButtonComponent
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!thread && isMobile && !window.history.state) {
|
|
54
|
+
RightButtonComponent = CloseButtonComponent
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (isMobile && window.history.state) {
|
|
58
|
+
RightButtonComponent = null
|
|
32
59
|
}
|
|
33
60
|
|
|
34
61
|
return (
|
|
35
62
|
<div className='wc-header'>
|
|
36
|
-
|
|
63
|
+
{window.history.state ? BackButtonComponent : null}
|
|
64
|
+
|
|
65
|
+
<h2 id='wc-header-title' className='wc-header__title'>
|
|
37
66
|
Floodline Webchat
|
|
38
67
|
</h2>
|
|
39
68
|
|
|
40
|
-
{
|
|
69
|
+
{RightButtonComponent}
|
|
41
70
|
</div>
|
|
42
71
|
)
|
|
43
72
|
}
|
|
@@ -12,9 +12,10 @@ import { Feedback } from '../screens/feedback.jsx'
|
|
|
12
12
|
import { useApp } from '../../store/useApp.js'
|
|
13
13
|
import { useChatSdk } from '../../store/useChatSdk.js'
|
|
14
14
|
import { useFocusedElements } from '../../hooks/useFocusedElements.js'
|
|
15
|
+
import { historyReplaceState } from '../../lib/history.js'
|
|
15
16
|
|
|
16
17
|
export function Panel () {
|
|
17
|
-
const { sdk, availability, thread, threadId, setThread, setThreadId, setChatVisibility, setMessages, setUnseenCount } = useApp()
|
|
18
|
+
const { sdk, availability, thread, threadId, setThread, setThreadId, setChatVisibility, setMessages, setUnseenCount, isMobile } = useApp()
|
|
18
19
|
const { fetchThread, fetchMessages } = useChatSdk(sdk)
|
|
19
20
|
|
|
20
21
|
const [screen, setScreen] = useState(threadId ? 2 : 0)
|
|
@@ -28,17 +29,31 @@ export function Panel () {
|
|
|
28
29
|
setUnseenCount(0)
|
|
29
30
|
}
|
|
30
31
|
setChatVisibility(false)
|
|
32
|
+
historyReplaceState()
|
|
31
33
|
}
|
|
32
34
|
}, [thread, threadId, setUnseenCount, setChatVisibility])
|
|
33
35
|
|
|
36
|
+
/**
|
|
37
|
+
* We need ammend classes on the body element to handle mobile behaviour
|
|
38
|
+
*/
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
document.body.classList.remove('wc-u-hidden')
|
|
41
|
+
document.getElementsByTagName('html')[0].classList.add('wc-u-html')
|
|
42
|
+
document.body.classList.add('wc-u-body')
|
|
43
|
+
return () => {
|
|
44
|
+
document.getElementsByTagName('html')[0].classList.remove('wc-u-html')
|
|
45
|
+
document.body.classList.remove('wc-u-body')
|
|
46
|
+
}
|
|
47
|
+
}, [isMobile])
|
|
48
|
+
|
|
34
49
|
/**
|
|
35
50
|
* Initializes the eventListener for pressing the escape key
|
|
36
51
|
*/
|
|
37
52
|
useEffect(() => {
|
|
38
|
-
|
|
53
|
+
document.addEventListener('keydown', onEscapeKey)
|
|
39
54
|
|
|
40
55
|
return () => {
|
|
41
|
-
document.removeEventListener('keydown',
|
|
56
|
+
document.removeEventListener('keydown', onEscapeKey)
|
|
42
57
|
}
|
|
43
58
|
}, [onEscapeKey, setChatVisibility])
|
|
44
59
|
|
|
@@ -115,7 +130,9 @@ export function Panel () {
|
|
|
115
130
|
|
|
116
131
|
const Component = (
|
|
117
132
|
<div id='wc-panel' role='dialog' className='wc-panel' tabIndex='-1' aria-modal='true' aria-labelledby='wc-header-title'>
|
|
118
|
-
|
|
133
|
+
<div className='wc-panel__inner'>
|
|
134
|
+
{ScreenComponent}
|
|
135
|
+
</div>
|
|
119
136
|
</div>
|
|
120
137
|
)
|
|
121
138
|
|