@defra/flood-webchat 0.0.1-beta.8 → 1.0.1

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 (50) hide show
  1. package/README.md +89 -1
  2. package/dist/client.js +1 -754
  3. package/dist/server.js +1 -383
  4. package/main.scss +12 -8
  5. package/package.json +27 -22
  6. package/src/client/components/availability/availability.jsx +89 -54
  7. package/src/client/components/availability/availability.scss +20 -32
  8. package/src/client/components/chat/chat.jsx +239 -0
  9. package/src/client/components/chat/chat.scss +258 -0
  10. package/src/client/components/errorSummary/error-summary.jsx +34 -0
  11. package/src/client/components/live-region.jsx +55 -0
  12. package/src/client/components/message/message.jsx +21 -0
  13. package/src/client/components/panel/panel-footer.jsx +9 -0
  14. package/src/client/components/panel/panel-header.jsx +55 -15
  15. package/src/client/components/panel/panel.jsx +128 -71
  16. package/src/client/components/panel/panel.scss +63 -22
  17. package/src/client/components/screens/end-chat.jsx +77 -0
  18. package/src/client/components/screens/feedback.jsx +65 -0
  19. package/src/client/components/screens/pre-chat.jsx +50 -30
  20. package/src/client/components/screens/request-chat.jsx +177 -4
  21. package/src/client/components/screens/settings.jsx +97 -0
  22. package/src/client/components/screens/unavailable.jsx +23 -0
  23. package/src/client/components/skip-link.jsx +42 -0
  24. package/src/client/hooks/useFocusedElements.js +80 -0
  25. package/src/client/hooks/useTextareaAutosize.js +13 -0
  26. package/src/client/index.jsx +18 -1
  27. package/src/client/lib/agent-status-headline.js +17 -0
  28. package/src/client/lib/check-availability.js +1 -0
  29. package/src/client/lib/history.js +16 -0
  30. package/src/client/lib/message-notification.js +30 -0
  31. package/src/client/lib/transform-messages.js +47 -0
  32. package/src/client/scss/_objects.scss +33 -0
  33. package/src/client/scss/_settings.scss +101 -0
  34. package/src/client/scss/_tools.scss +33 -0
  35. package/src/client/scss/_utilities.scss +25 -0
  36. package/src/client/store/AppProvider.jsx +184 -0
  37. package/src/client/store/actions-map.js +153 -0
  38. package/src/client/store/constants.js +5 -0
  39. package/src/client/store/reducer.js +31 -0
  40. package/src/client/store/useApp.js +5 -0
  41. package/src/client/store/useChatSdk.js +37 -0
  42. package/src/server/index.js +15 -6
  43. package/src/server/lib/client.js +31 -37
  44. package/src/server/lib/utils.js +10 -2
  45. package/webpack.config.mjs +0 -2
  46. package/webpack.prod.mjs +7 -0
  47. package/dist/client.js.map +0 -1
  48. package/dist/server.js.map +0 -1
  49. package/src/client/lib/external-stores.js +0 -4
  50. package/src/client/lib/external-sync-store.js +0 -42
package/README.md CHANGED
@@ -5,5 +5,93 @@
5
5
  - [How to Publish](./docs/how-to-publish.md)
6
6
 
7
7
  ## Usage
8
- TBC
8
+
9
+ ### Installation
10
+
11
+ Run:
12
+
13
+ ```shell
14
+ npm i @defra/flood-webchat
15
+ ```
16
+
17
+ ### Assets
18
+
19
+ You need to copy `./assets/audio/notification.mp3` to your 'assets' directory. This is the notification sound users will
20
+ hear when they receive a message.
21
+
22
+ ### Server Side Javascript
23
+
24
+ You will need to implement an endpoint on your server which checks the availability of webchat. An express example can
25
+ be seen below:
26
+
27
+ ```js
28
+
29
+ import getAvailability from '@defra/flood-webchat'
30
+ //... the rest of your server setup
31
+ const webchatOptions = {
32
+ clientId: process.env.CXONE_CLIENT_ID,
33
+ clientSecret: process.env.CXONE_CLIENT_SECRET,
34
+ accessKey: process.env.CXONE_ACCESS_KEY,
35
+ accessSecret: process.env.CXONE_ACCESS_SECRET,
36
+ skillEndpoint: process.env.CXONE_SKILL_ENDPOINT,
37
+ hoursEndpoint: process.env.CXONE_HOURS_ENDPOINT,
38
+ maxQueueCount: process.env.CXONE_MAX_QUEUE_COUNT
39
+ }
40
+
41
+ app.get('/webchat-availability', async (req, res, next) => {
42
+ try {
43
+ const response = await getAvailability(webchatOptions)
44
+ return res.status(200).json(response)
45
+ } catch (err) {
46
+ next(err)
47
+ }
48
+ })
49
+ ```
50
+
51
+ ### Client Side Javascript
52
+
53
+ You will also need to initialise webchat in your client side code:
54
+
55
+ ```js
56
+ import * as webchat from '@defra/flood-webchat';
57
+
58
+ if (document.getElementById('wc-availability')) {
59
+ webchat.init(document.querySelector('#wc-availability'), {
60
+ brandId: 'your brand id',
61
+ channelId: 'your channel id',
62
+ environmentName: 'your environment name',
63
+ availabilityEndpoint: '/webchat-availability',
64
+ audioUrl: 'path/to/notification.mp3'
65
+ })
66
+ }
67
+ ```
68
+
69
+ ### HTML
70
+
71
+ In your html, will need to add the "Start Chat" link with some placeholder text for if webchat is not supported in the
72
+ user's browser.
73
+
74
+ ```html
75
+
76
+ <div id="wc-availability">
77
+ <p>Webchat is not supported with your browser</p>
78
+ </div>
79
+ ```
80
+
81
+ Add this html below the govuk main skip link, for the webchat skip link to be added to the page:
82
+
83
+ ```html
84
+ <div id="webchat-skip-link-container"></div>
85
+ ```
86
+
87
+ And finally a script tag, to prevent the webchat widget "flashing" on page load/reload.
88
+
89
+ ```html
90
+
91
+ <script>
92
+ if (window.location.hash === '#webchat' && window.matchMedia('(max-width: 640px)').matches) {
93
+ document.body.classList.add('wc-hidden')
94
+ }
95
+ </script>
96
+ ```
9
97