@defra/flood-webchat 0.0.1-beta.3 → 0.0.1-beta.31
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 +1918 -215
- package/dist/client.js.map +1 -1
- package/dist/server.js +181 -240
- package/dist/server.js.map +1 -1
- package/main.scss +11 -6
- package/package.json +6 -2
- package/src/client/components/availability/availability.jsx +62 -49
- package/src/client/components/availability/availability.scss +7 -33
- package/src/client/components/chat/chat.jsx +176 -0
- package/src/client/components/chat/chat.scss +221 -0
- package/src/client/components/errorSummary/error-summary.jsx +34 -0
- package/src/client/components/message/message.jsx +20 -0
- package/src/client/components/panel/panel-footer.jsx +9 -0
- package/src/client/components/panel/panel-header.jsx +75 -0
- package/src/client/components/panel/panel.jsx +144 -0
- package/src/client/components/panel/panel.scss +112 -0
- package/src/client/components/screens/end-chat.jsx +39 -0
- package/src/client/components/screens/feedback.jsx +23 -0
- package/src/client/components/screens/pre-chat.jsx +62 -0
- package/src/client/components/screens/request-chat.jsx +173 -0
- package/src/client/components/screens/settings.jsx +69 -0
- package/src/client/components/screens/unavailable.jsx +23 -0
- package/src/client/components/skip-link.jsx +34 -0
- package/src/client/hooks/useFocusedElements.js +81 -0
- package/src/client/hooks/useTextareaAutosize.js +13 -0
- package/src/client/index.jsx +15 -1
- package/src/client/lib/check-availability.js +1 -0
- package/src/client/lib/history.js +13 -0
- package/src/client/lib/message-notification.js +36 -0
- package/src/client/lib/transform-messages.js +34 -0
- package/src/client/scss/_objects.scss +33 -0
- package/src/client/scss/_settings.scss +75 -0
- package/src/client/scss/_tools.scss +33 -0
- package/src/client/scss/_utilities.scss +25 -0
- package/src/client/store/AppProvider.jsx +174 -0
- package/src/client/store/actions-map.js +135 -0
- package/src/client/store/constants.js +3 -0
- package/src/client/store/reducer.js +30 -0
- package/src/client/store/useApp.js +5 -0
- package/src/client/store/useChatSdk.js +37 -0
- package/src/server/index.js +15 -6
- package/src/server/lib/client.js +31 -35
- package/src/server/lib/utils.js +18 -9
- package/src/client/lib/external-stores.js +0 -4
- package/src/client/lib/external-sync-store.js +0 -42
package/src/server/lib/utils.js
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
const { DateTime } = require('luxon')
|
|
2
|
+
|
|
3
|
+
const getHour = time => Number(time.split(':')[0])
|
|
4
|
+
|
|
5
|
+
const isWithinHours = (days, date) => {
|
|
6
|
+
const now = date ? DateTime.fromISO(date) : DateTime.local()
|
|
7
|
+
now.setZone('Europe/London')
|
|
8
|
+
|
|
9
|
+
const newDate = date ? new Date(date) : new Date()
|
|
10
|
+
|
|
11
|
+
const today = newDate.toLocaleDateString('en-GB', { weekday: 'long' })
|
|
12
|
+
const dateParts = newDate.toLocaleDateString('en-GB').split('/')
|
|
13
|
+
|
|
14
|
+
const todaysAvailability = days.find(item => item.day === today)
|
|
15
|
+
const todaysDateTimeOpen = DateTime.local(Number(dateParts[2]), Number(dateParts[1]), Number(dateParts[0]), getHour(todaysAvailability.openTime))
|
|
16
|
+
const todaysDateTimeClose = DateTime.local(Number(dateParts[2]), Number(dateParts[1]), Number(dateParts[0]), getHour(todaysAvailability.closeTime))
|
|
17
|
+
|
|
18
|
+
return now.diff(todaysDateTimeOpen).milliseconds >= 0 && now.diff(todaysDateTimeClose).milliseconds <= 0
|
|
10
19
|
}
|
|
11
20
|
|
|
12
21
|
module.exports = {
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { useSyncExternalStore } from 'react'
|
|
2
|
-
|
|
3
|
-
export default class ExternalSyncStore {
|
|
4
|
-
constructor (initialValue) {
|
|
5
|
-
this._value = initialValue
|
|
6
|
-
this._listeners = []
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
update (value) {
|
|
10
|
-
this._value = value
|
|
11
|
-
this.emitChange()
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
subscribe (listener) {
|
|
15
|
-
this._listeners = [...this._listeners, listener]
|
|
16
|
-
return () => {
|
|
17
|
-
this._listeners = this._listeners.filter(l => l !== listener)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
emitChange () {
|
|
22
|
-
for (const listener of this._listeners) {
|
|
23
|
-
listener()
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
getSnapshot () {
|
|
28
|
-
return this._value
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
static create (initialValue) {
|
|
32
|
-
const store = new ExternalSyncStore(initialValue)
|
|
33
|
-
const boundSubscribe = store.subscribe.bind(store)
|
|
34
|
-
const boundGetSnapshot = store.getSnapshot.bind(store)
|
|
35
|
-
const boundUpdate = store.update.bind(store)
|
|
36
|
-
|
|
37
|
-
return () => [
|
|
38
|
-
useSyncExternalStore(boundSubscribe, boundGetSnapshot),
|
|
39
|
-
boundUpdate
|
|
40
|
-
]
|
|
41
|
-
}
|
|
42
|
-
}
|