@botonic/react 0.36.5 → 0.37.0

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 (126) hide show
  1. package/lib/cjs/components/button/index.js +1 -1
  2. package/lib/cjs/components/button/index.js.map +1 -1
  3. package/lib/cjs/components/custom-message.d.ts +1 -1
  4. package/lib/cjs/components/custom-message.js +4 -1
  5. package/lib/cjs/components/custom-message.js.map +1 -1
  6. package/lib/cjs/webchat/context/messages-reducer.js +6 -0
  7. package/lib/cjs/webchat/context/messages-reducer.js.map +1 -1
  8. package/lib/cjs/webchat/custom-messages/index.d.ts +1 -0
  9. package/lib/cjs/webchat/custom-messages/index.js +9 -0
  10. package/lib/cjs/webchat/custom-messages/index.js.map +1 -0
  11. package/lib/cjs/webchat/custom-messages/rating/icons/face-angry.d.ts +2 -0
  12. package/lib/cjs/webchat/custom-messages/rating/icons/face-angry.js +9 -0
  13. package/lib/cjs/webchat/custom-messages/rating/icons/face-angry.js.map +1 -0
  14. package/lib/cjs/webchat/custom-messages/rating/icons/face-frown.d.ts +2 -0
  15. package/lib/cjs/webchat/custom-messages/rating/icons/face-frown.js +9 -0
  16. package/lib/cjs/webchat/custom-messages/rating/icons/face-frown.js.map +1 -0
  17. package/lib/cjs/webchat/custom-messages/rating/icons/face-grin-beam.d.ts +2 -0
  18. package/lib/cjs/webchat/custom-messages/rating/icons/face-grin-beam.js +9 -0
  19. package/lib/cjs/webchat/custom-messages/rating/icons/face-grin-beam.js.map +1 -0
  20. package/lib/cjs/webchat/custom-messages/rating/icons/face-meh.d.ts +2 -0
  21. package/lib/cjs/webchat/custom-messages/rating/icons/face-meh.js +9 -0
  22. package/lib/cjs/webchat/custom-messages/rating/icons/face-meh.js.map +1 -0
  23. package/lib/cjs/webchat/custom-messages/rating/icons/face-smile.d.ts +2 -0
  24. package/lib/cjs/webchat/custom-messages/rating/icons/face-smile.js +9 -0
  25. package/lib/cjs/webchat/custom-messages/rating/icons/face-smile.js.map +1 -0
  26. package/lib/cjs/webchat/custom-messages/rating/icons/index.d.ts +6 -0
  27. package/lib/cjs/webchat/custom-messages/rating/icons/index.js +10 -0
  28. package/lib/cjs/webchat/custom-messages/rating/icons/index.js.map +1 -0
  29. package/lib/cjs/webchat/custom-messages/rating/icons/star.d.ts +2 -0
  30. package/lib/cjs/webchat/custom-messages/rating/icons/star.js +9 -0
  31. package/lib/cjs/webchat/custom-messages/rating/icons/star.js.map +1 -0
  32. package/lib/cjs/webchat/custom-messages/rating/index.d.ts +2 -0
  33. package/lib/cjs/webchat/custom-messages/rating/index.js +60 -0
  34. package/lib/cjs/webchat/custom-messages/rating/index.js.map +1 -0
  35. package/lib/cjs/webchat/custom-messages/rating/rating-selector.d.ts +11 -0
  36. package/lib/cjs/webchat/custom-messages/rating/rating-selector.js +23 -0
  37. package/lib/cjs/webchat/custom-messages/rating/rating-selector.js.map +1 -0
  38. package/lib/cjs/webchat/custom-messages/rating/smileys.d.ts +2 -0
  39. package/lib/cjs/webchat/custom-messages/rating/smileys.js +19 -0
  40. package/lib/cjs/webchat/custom-messages/rating/smileys.js.map +1 -0
  41. package/lib/cjs/webchat/custom-messages/rating/stars.d.ts +2 -0
  42. package/lib/cjs/webchat/custom-messages/rating/stars.js +11 -0
  43. package/lib/cjs/webchat/custom-messages/rating/stars.js.map +1 -0
  44. package/lib/cjs/webchat/custom-messages/rating/styles.d.ts +6 -0
  45. package/lib/cjs/webchat/custom-messages/rating/styles.js +25 -0
  46. package/lib/cjs/webchat/custom-messages/rating/styles.js.map +1 -0
  47. package/lib/cjs/webchat/custom-messages/rating/types.d.ts +13 -0
  48. package/lib/cjs/webchat/custom-messages/rating/types.js +9 -0
  49. package/lib/cjs/webchat/custom-messages/rating/types.js.map +1 -0
  50. package/lib/cjs/webchat/index.d.ts +1 -0
  51. package/lib/cjs/webchat/index.js +1 -0
  52. package/lib/cjs/webchat/index.js.map +1 -1
  53. package/lib/cjs/webchat/input-panel/send-button.js.map +1 -1
  54. package/lib/esm/components/button/index.js +1 -1
  55. package/lib/esm/components/button/index.js.map +1 -1
  56. package/lib/esm/components/custom-message.d.ts +1 -1
  57. package/lib/esm/components/custom-message.js +4 -1
  58. package/lib/esm/components/custom-message.js.map +1 -1
  59. package/lib/esm/webchat/context/messages-reducer.js +6 -0
  60. package/lib/esm/webchat/context/messages-reducer.js.map +1 -1
  61. package/lib/esm/webchat/custom-messages/index.d.ts +1 -0
  62. package/lib/esm/webchat/custom-messages/index.js +2 -0
  63. package/lib/esm/webchat/custom-messages/index.js.map +1 -0
  64. package/lib/esm/webchat/custom-messages/rating/icons/face-angry.d.ts +2 -0
  65. package/lib/esm/webchat/custom-messages/rating/icons/face-angry.js +5 -0
  66. package/lib/esm/webchat/custom-messages/rating/icons/face-angry.js.map +1 -0
  67. package/lib/esm/webchat/custom-messages/rating/icons/face-frown.d.ts +2 -0
  68. package/lib/esm/webchat/custom-messages/rating/icons/face-frown.js +5 -0
  69. package/lib/esm/webchat/custom-messages/rating/icons/face-frown.js.map +1 -0
  70. package/lib/esm/webchat/custom-messages/rating/icons/face-grin-beam.d.ts +2 -0
  71. package/lib/esm/webchat/custom-messages/rating/icons/face-grin-beam.js +5 -0
  72. package/lib/esm/webchat/custom-messages/rating/icons/face-grin-beam.js.map +1 -0
  73. package/lib/esm/webchat/custom-messages/rating/icons/face-meh.d.ts +2 -0
  74. package/lib/esm/webchat/custom-messages/rating/icons/face-meh.js +5 -0
  75. package/lib/esm/webchat/custom-messages/rating/icons/face-meh.js.map +1 -0
  76. package/lib/esm/webchat/custom-messages/rating/icons/face-smile.d.ts +2 -0
  77. package/lib/esm/webchat/custom-messages/rating/icons/face-smile.js +5 -0
  78. package/lib/esm/webchat/custom-messages/rating/icons/face-smile.js.map +1 -0
  79. package/lib/esm/webchat/custom-messages/rating/icons/index.d.ts +6 -0
  80. package/lib/esm/webchat/custom-messages/rating/icons/index.js +7 -0
  81. package/lib/esm/webchat/custom-messages/rating/icons/index.js.map +1 -0
  82. package/lib/esm/webchat/custom-messages/rating/icons/star.d.ts +2 -0
  83. package/lib/esm/webchat/custom-messages/rating/icons/star.js +5 -0
  84. package/lib/esm/webchat/custom-messages/rating/icons/star.js.map +1 -0
  85. package/lib/esm/webchat/custom-messages/rating/index.d.ts +2 -0
  86. package/lib/esm/webchat/custom-messages/rating/index.js +57 -0
  87. package/lib/esm/webchat/custom-messages/rating/index.js.map +1 -0
  88. package/lib/esm/webchat/custom-messages/rating/rating-selector.d.ts +11 -0
  89. package/lib/esm/webchat/custom-messages/rating/rating-selector.js +19 -0
  90. package/lib/esm/webchat/custom-messages/rating/rating-selector.js.map +1 -0
  91. package/lib/esm/webchat/custom-messages/rating/smileys.d.ts +2 -0
  92. package/lib/esm/webchat/custom-messages/rating/smileys.js +15 -0
  93. package/lib/esm/webchat/custom-messages/rating/smileys.js.map +1 -0
  94. package/lib/esm/webchat/custom-messages/rating/stars.d.ts +2 -0
  95. package/lib/esm/webchat/custom-messages/rating/stars.js +7 -0
  96. package/lib/esm/webchat/custom-messages/rating/stars.js.map +1 -0
  97. package/lib/esm/webchat/custom-messages/rating/styles.d.ts +6 -0
  98. package/lib/esm/webchat/custom-messages/rating/styles.js +21 -0
  99. package/lib/esm/webchat/custom-messages/rating/styles.js.map +1 -0
  100. package/lib/esm/webchat/custom-messages/rating/types.d.ts +13 -0
  101. package/lib/esm/webchat/custom-messages/rating/types.js +6 -0
  102. package/lib/esm/webchat/custom-messages/rating/types.js.map +1 -0
  103. package/lib/esm/webchat/index.d.ts +1 -0
  104. package/lib/esm/webchat/index.js +1 -0
  105. package/lib/esm/webchat/index.js.map +1 -1
  106. package/lib/esm/webchat/input-panel/send-button.js.map +1 -1
  107. package/package.json +2 -2
  108. package/src/components/button/index.tsx +2 -1
  109. package/src/components/custom-message.tsx +14 -11
  110. package/src/webchat/context/messages-reducer.ts +8 -0
  111. package/src/webchat/custom-messages/index.ts +1 -0
  112. package/src/webchat/custom-messages/rating/icons/face-angry.tsx +21 -0
  113. package/src/webchat/custom-messages/rating/icons/face-frown.tsx +21 -0
  114. package/src/webchat/custom-messages/rating/icons/face-grin-beam.tsx +21 -0
  115. package/src/webchat/custom-messages/rating/icons/face-meh.tsx +21 -0
  116. package/src/webchat/custom-messages/rating/icons/face-smile.tsx +21 -0
  117. package/src/webchat/custom-messages/rating/icons/index.ts +6 -0
  118. package/src/webchat/custom-messages/rating/icons/star.tsx +21 -0
  119. package/src/webchat/custom-messages/rating/index.tsx +99 -0
  120. package/src/webchat/custom-messages/rating/rating-selector.tsx +59 -0
  121. package/src/webchat/custom-messages/rating/smileys.tsx +27 -0
  122. package/src/webchat/custom-messages/rating/stars.tsx +9 -0
  123. package/src/webchat/custom-messages/rating/styles.ts +26 -0
  124. package/src/webchat/custom-messages/rating/types.ts +15 -0
  125. package/src/webchat/index.ts +1 -0
  126. package/src/webchat/input-panel/send-button.tsx +1 -1
@@ -0,0 +1,21 @@
1
+ import React from 'react'
2
+
3
+ import { RatingIconProps } from '../types'
4
+
5
+ export const FaceGrinBeamSvg = ({ color, selected }: RatingIconProps) => {
6
+ return selected ? (
7
+ <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512' color={color}>
8
+ <path
9
+ d='M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM388.1 312.8c12.3-3.8 24.3 6.9 19.3 18.7C382.4 390.6 324.2 432 256.3 432s-126.2-41.4-151.1-100.5c-5-11.8 7-22.5 19.3-18.7c39.7 12.2 84.5 19 131.8 19s92.1-6.8 131.8-19zm-170.5-84s0 0 0 0c0 0 0 0 0 0l-.2-.2c-.2-.2-.4-.5-.7-.9c-.6-.8-1.6-2-2.8-3.4c-2.5-2.8-6-6.6-10.2-10.3c-8.8-7.8-18.8-14-27.7-14s-18.9 6.2-27.7 14c-4.2 3.7-7.7 7.5-10.2 10.3c-1.2 1.4-2.2 2.6-2.8 3.4c-.3 .4-.6 .7-.7 .9l-.2 .2c0 0 0 0 0 0c0 0 0 0 0 0s0 0 0 0c-2.1 2.8-5.7 3.9-8.9 2.8s-5.5-4.1-5.5-7.6c0-17.9 6.7-35.6 16.6-48.8c9.8-13 23.9-23.2 39.4-23.2s29.6 10.2 39.4 23.2c9.9 13.2 16.6 30.9 16.6 48.8c0 3.4-2.2 6.5-5.5 7.6s-6.9 0-8.9-2.8c0 0 0 0 0 0s0 0 0 0zm160 0c0 0 0 0 0 0l-.2-.2c-.2-.2-.4-.5-.7-.9c-.6-.8-1.6-2-2.8-3.4c-2.5-2.8-6-6.6-10.2-10.3c-8.8-7.8-18.8-14-27.7-14s-18.9 6.2-27.7 14c-4.2 3.7-7.7 7.5-10.2 10.3c-1.2 1.4-2.2 2.6-2.8 3.4c-.3 .4-.6 .7-.7 .9l-.2 .2c0 0 0 0 0 0c0 0 0 0 0 0s0 0 0 0c-2.1 2.8-5.7 3.9-8.9 2.8s-5.5-4.1-5.5-7.6c0-17.9 6.7-35.6 16.6-48.8c9.8-13 23.9-23.2 39.4-23.2s29.6 10.2 39.4 23.2c9.9 13.2 16.6 30.9 16.6 48.8c0 3.4-2.2 6.5-5.5 7.6s-6.9 0-8.9-2.8c0 0 0 0 0 0s0 0 0 0s0 0 0 0z'
10
+ fill='currentColor'
11
+ />
12
+ </svg>
13
+ ) : (
14
+ <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512' color={color}>
15
+ <path
16
+ d='M464 256A208 208 0 1 0 48 256a208 208 0 1 0 416 0zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm349.5 52.4c18.7-4.4 35.9 12 25.5 28.1C350.4 374.6 306.3 400 255.9 400s-94.5-25.4-119.1-63.5c-10.4-16.1 6.8-32.5 25.5-28.1c28.9 6.8 60.5 10.5 93.6 10.5s64.7-3.7 93.6-10.5zM217.6 228.8s0 0 0 0c0 0 0 0 0 0l-.2-.2c-.2-.2-.4-.5-.7-.9c-.6-.8-1.6-2-2.8-3.4c-2.5-2.8-6-6.6-10.2-10.3c-8.8-7.8-18.8-14-27.7-14s-18.9 6.2-27.7 14c-4.2 3.7-7.7 7.5-10.2 10.3c-1.2 1.4-2.2 2.6-2.8 3.4c-.3 .4-.6 .7-.7 .9l-.2 .2c0 0 0 0 0 0c0 0 0 0 0 0s0 0 0 0c-2.1 2.8-5.7 3.9-8.9 2.8s-5.5-4.1-5.5-7.6c0-17.9 6.7-35.6 16.6-48.8c9.8-13 23.9-23.2 39.4-23.2s29.6 10.2 39.4 23.2c9.9 13.2 16.6 30.9 16.6 48.8c0 3.4-2.2 6.5-5.5 7.6s-6.9 0-8.9-2.8c0 0 0 0 0 0s0 0 0 0zm160 0c0 0 0 0 0 0l-.2-.2c-.2-.2-.4-.5-.7-.9c-.6-.8-1.6-2-2.8-3.4c-2.5-2.8-6-6.6-10.2-10.3c-8.8-7.8-18.8-14-27.7-14s-18.9 6.2-27.7 14c-4.2 3.7-7.7 7.5-10.2 10.3c-1.2 1.4-2.2 2.6-2.8 3.4c-.3 .4-.6 .7-.7 .9l-.2 .2c0 0 0 0 0 0c0 0 0 0 0 0s0 0 0 0c-2.1 2.8-5.7 3.9-8.9 2.8s-5.5-4.1-5.5-7.6c0-17.9 6.7-35.6 16.6-48.8c9.8-13 23.9-23.2 39.4-23.2s29.6 10.2 39.4 23.2c9.9 13.2 16.6 30.9 16.6 48.8c0 3.4-2.2 6.5-5.5 7.6s-6.9 0-8.9-2.8c0 0 0 0 0 0s0 0 0 0s0 0 0 0z'
17
+ fill='currentColor'
18
+ />
19
+ </svg>
20
+ )
21
+ }
@@ -0,0 +1,21 @@
1
+ import React from 'react'
2
+
3
+ import { RatingIconProps } from '../types'
4
+
5
+ export const FaceMehSvg = ({ color, selected }: RatingIconProps) => {
6
+ return selected ? (
7
+ <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512' color={color}>
8
+ <path
9
+ d='M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM176.4 176a32 32 0 1 1 0 64 32 32 0 1 1 0-64zm128 32a32 32 0 1 1 64 0 32 32 0 1 1 -64 0zM160 336l192 0c8.8 0 16 7.2 16 16s-7.2 16-16 16l-192 0c-8.8 0-16-7.2-16-16s7.2-16 16-16z'
10
+ fill='currentColor'
11
+ />
12
+ </svg>
13
+ ) : (
14
+ <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512' color={color}>
15
+ <path
16
+ d='M464 256A208 208 0 1 1 48 256a208 208 0 1 1 416 0zM256 0a256 256 0 1 0 0 512A256 256 0 1 0 256 0zM176.4 240a32 32 0 1 0 0-64 32 32 0 1 0 0 64zm192-32a32 32 0 1 0 -64 0 32 32 0 1 0 64 0zM184 328c-13.3 0-24 10.7-24 24s10.7 24 24 24l144 0c13.3 0 24-10.7 24-24s-10.7-24-24-24l-144 0z'
17
+ fill='currentColor'
18
+ />
19
+ </svg>
20
+ )
21
+ }
@@ -0,0 +1,21 @@
1
+ import React from 'react'
2
+
3
+ import { RatingIconProps } from '../types'
4
+
5
+ export const FaceSmileSvg = ({ color, selected }: RatingIconProps) => {
6
+ return selected ? (
7
+ <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512' color={color}>
8
+ <path
9
+ d='M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM164.1 325.5C182 346.2 212.6 368 256 368s74-21.8 91.9-42.5c5.8-6.7 15.9-7.4 22.6-1.6s7.4 15.9 1.6 22.6C349.8 372.1 311.1 400 256 400s-93.8-27.9-116.1-53.5c-5.8-6.7-5.1-16.8 1.6-22.6s16.8-5.1 22.6 1.6zM144.4 208a32 32 0 1 1 64 0 32 32 0 1 1 -64 0zm192-32a32 32 0 1 1 0 64 32 32 0 1 1 0-64z'
10
+ fill='currentColor'
11
+ />
12
+ </svg>
13
+ ) : (
14
+ <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512' color={color}>
15
+ <path
16
+ d='M464 256A208 208 0 1 0 48 256a208 208 0 1 0 416 0zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm177.6 62.1C192.8 334.5 218.8 352 256 352s63.2-17.5 78.4-33.9c9-9.7 24.2-10.4 33.9-1.4s10.4 24.2 1.4 33.9c-22 23.8-60 49.4-113.6 49.4s-91.7-25.5-113.6-49.4c-9-9.7-8.4-24.9 1.4-33.9s24.9-8.4 33.9 1.4zM144.4 208a32 32 0 1 1 64 0 32 32 0 1 1 -64 0zm192-32a32 32 0 1 1 0 64 32 32 0 1 1 0-64z'
17
+ fill='currentColor'
18
+ />
19
+ </svg>
20
+ )
21
+ }
@@ -0,0 +1,6 @@
1
+ export * from './face-angry'
2
+ export * from './face-frown'
3
+ export * from './face-grin-beam'
4
+ export * from './face-meh'
5
+ export * from './face-smile'
6
+ export * from './star'
@@ -0,0 +1,21 @@
1
+ import React from 'react'
2
+
3
+ import { RatingIconProps } from '../types'
4
+
5
+ export const StarSvg = ({ color, selected }: RatingIconProps) => {
6
+ return selected ? (
7
+ <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 576 512' color={color}>
8
+ <path
9
+ d='M316.9 18C311.6 7 300.4 0 288.1 0s-23.4 7-28.8 18L195 150.3 51.4 171.5c-12 1.8-22 10.2-25.7 21.7s-.7 24.2 7.9 32.7L137.8 329 113.2 474.7c-2 12 3 24.2 12.9 31.3s23 8 33.8 2.3l128.3-68.5 128.3 68.5c10.8 5.7 23.9 4.9 33.8-2.3s14.9-19.3 12.9-31.3L438.5 329 542.7 225.9c8.6-8.5 11.7-21.2 7.9-32.7s-13.7-19.9-25.7-21.7L381.2 150.3 316.9 18z'
10
+ fill='currentColor'
11
+ />
12
+ </svg>
13
+ ) : (
14
+ <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 576 512' color={color}>
15
+ <path
16
+ d='M287.9 0c9.2 0 17.6 5.2 21.6 13.5l68.6 141.3 153.2 22.6c9 1.3 16.5 7.6 19.3 16.3s.5 18.1-5.9 24.5L433.6 328.4l26.2 155.6c1.5 9-2.2 18.1-9.7 23.5s-17.3 6-25.3 1.7l-137-73.2L151 509.1c-8.1 4.3-17.9 3.7-25.3-1.7s-11.2-14.5-9.7-23.5l26.2-155.6L31.1 218.2c-6.5-6.4-8.7-15.9-5.9-24.5s10.3-14.9 19.3-16.3l153.2-22.6L266.3 13.5C270.4 5.2 278.7 0 287.9 0zm0 79L235.4 187.2c-3.5 7.1-10.2 12.1-18.1 13.3L99 217.9 184.9 303c5.5 5.5 8.1 13.3 6.8 21L171.4 443.7l105.2-56.2c7.1-3.8 15.6-3.8 22.6 0l105.2 56.2L384.2 324.1c-1.3-7.7 1.2-15.5 6.8-21l85.9-85.1L358.6 200.5c-7.8-1.2-14.6-6.1-18.1-13.3L287.9 79z'
17
+ fill='currentColor'
18
+ />
19
+ </svg>
20
+ )
21
+ }
@@ -0,0 +1,99 @@
1
+ import { INPUT, InputType } from '@botonic/core'
2
+ import merge from 'lodash.merge'
3
+ import React, { useContext, useState } from 'react'
4
+ import { ThemeContext } from 'styled-components'
5
+
6
+ import { Button, customMessage } from '../../../components'
7
+ import { WebchatContext } from '../../context'
8
+ import { RatingSelector } from './rating-selector'
9
+ import { MessageBubble } from './styles'
10
+ import { RatingType } from './types'
11
+
12
+ interface CustomRatingMessageProps {
13
+ payloads: string[]
14
+ messageText: string
15
+ buttonText: string
16
+ ratingType: RatingType
17
+ json: { messageId?: string; valueSent?: number }
18
+ }
19
+
20
+ const CustomRatingMessage: React.FC<CustomRatingMessageProps> = props => {
21
+ const { payloads, messageText, buttonText, ratingType } = props
22
+ const { webchatState, updateMessage, sendInput } = useContext(WebchatContext)
23
+
24
+ const theme = useContext(ThemeContext)
25
+ const color = theme?.brand?.color ?? ''
26
+
27
+ const [ratingValue, setRatingValue] = useState(
28
+ props.json?.valueSent ? props.json.valueSent : -1
29
+ )
30
+ const [showRating, setShowRating] = useState(true)
31
+
32
+ const ratingChanged = (newRating: number) => {
33
+ setRatingValue(newRating)
34
+ }
35
+
36
+ const updateMessageJSON = (messageId?: string) => {
37
+ if (messageId) {
38
+ const messageToUpdate = webchatState.messagesJSON.filter(m => {
39
+ return m.id === messageId
40
+ })[0]
41
+ const messageInfo = {
42
+ data: {
43
+ json: {
44
+ valueSent: ratingValue,
45
+ },
46
+ },
47
+ }
48
+ const updatedMsg = merge(messageToUpdate, messageInfo)
49
+ updateMessage(updatedMsg)
50
+ }
51
+ }
52
+
53
+ const handleButtonSend = () => {
54
+ if (ratingValue !== -1) {
55
+ setShowRating(false)
56
+
57
+ const payload = payloads[ratingValue - 1]
58
+
59
+ updateMessageJSON(props.json?.messageId)
60
+
61
+ const input = {
62
+ type: INPUT.POSTBACK as InputType,
63
+ payload,
64
+ }
65
+ void sendInput(input)
66
+ }
67
+ }
68
+
69
+ const disabled = ratingValue === -1
70
+
71
+ return (
72
+ <div className='rating-message-container'>
73
+ <MessageBubble className='rating-message-bubble'>
74
+ {messageText}
75
+ <RatingSelector
76
+ color={color}
77
+ onRatingChange={ratingChanged}
78
+ ratingValue={ratingValue}
79
+ ratingType={ratingType}
80
+ valueSent={props.json?.valueSent}
81
+ />
82
+ </MessageBubble>
83
+ {!props.json?.valueSent && showRating && (
84
+ <Button
85
+ autodisable={true}
86
+ disabled={disabled}
87
+ onClick={handleButtonSend}
88
+ >
89
+ {buttonText}
90
+ </Button>
91
+ )}
92
+ </div>
93
+ )
94
+ }
95
+
96
+ export default customMessage({
97
+ name: 'custom-rating',
98
+ component: CustomRatingMessage,
99
+ })
@@ -0,0 +1,59 @@
1
+ import React, { useState } from 'react'
2
+
3
+ import { Smileys } from './smileys'
4
+ import { Stars } from './stars'
5
+ import { RatingSelectorContainer } from './styles'
6
+ import { RatingType } from './types'
7
+
8
+ const NUMBER_OF_RATING_BUTTONS = 5
9
+ interface RatingSelectorProps {
10
+ color: string
11
+ isSent?: boolean
12
+ onRatingChange: (newRating: number) => void
13
+ ratingValue: number
14
+ ratingType: RatingType
15
+ valueSent?: number
16
+ }
17
+
18
+ export const RatingSelector = ({
19
+ color,
20
+ isSent,
21
+ onRatingChange,
22
+ ratingValue,
23
+ ratingType,
24
+ valueSent,
25
+ }: RatingSelectorProps) => {
26
+ const [hover, setHover] = useState<number>(valueSent ? valueSent : -1)
27
+
28
+ const onHover = (ratingNumber: number) => {
29
+ if (!valueSent) setHover(ratingNumber)
30
+ }
31
+
32
+ return (
33
+ <RatingSelectorContainer isSent={isSent}>
34
+ {Array.from({ length: NUMBER_OF_RATING_BUTTONS }, (_star, i) => {
35
+ const ratingNumber = i + 1
36
+
37
+ return (
38
+ <div
39
+ key={i}
40
+ onMouseEnter={() => onHover(ratingNumber)}
41
+ onMouseLeave={() => onHover(ratingValue)}
42
+ onClick={() => onRatingChange(ratingNumber)}
43
+ >
44
+ {ratingType === RatingType.Stars && (
45
+ <Stars color={color} ratingNumber={ratingNumber} hover={hover} />
46
+ )}
47
+ {ratingType === RatingType.Smileys && (
48
+ <Smileys
49
+ color={color}
50
+ ratingNumber={ratingNumber}
51
+ hover={hover}
52
+ />
53
+ )}
54
+ </div>
55
+ )
56
+ })}
57
+ </RatingSelectorContainer>
58
+ )
59
+ }
@@ -0,0 +1,27 @@
1
+ import React from 'react'
2
+
3
+ import {
4
+ FaceAngrySvg,
5
+ FaceFrownSvg,
6
+ FaceGrinBeamSvg,
7
+ FaceMehSvg,
8
+ FaceSmileSvg,
9
+ } from './icons'
10
+ import { RatingItemProps } from './types'
11
+
12
+ const SMILEY_MAP = {
13
+ 1: FaceAngrySvg,
14
+ 2: FaceFrownSvg,
15
+ 3: FaceMehSvg,
16
+ 4: FaceSmileSvg,
17
+ 5: FaceGrinBeamSvg,
18
+ } as const
19
+
20
+ export const Smileys = ({ color, ratingNumber, hover }: RatingItemProps) => {
21
+ const isSelected = hover === ratingNumber
22
+ const SmileyComponent = SMILEY_MAP[ratingNumber as keyof typeof SMILEY_MAP]
23
+
24
+ return SmileyComponent ? (
25
+ <SmileyComponent color={color} selected={isSelected} />
26
+ ) : null
27
+ }
@@ -0,0 +1,9 @@
1
+ import React from 'react'
2
+
3
+ import { StarSvg } from './icons/index'
4
+ import { RatingItemProps } from './types'
5
+
6
+ export const Stars = ({ color, ratingNumber, hover }: RatingItemProps) => {
7
+ const isSelected = hover >= ratingNumber
8
+ return <StarSvg color={color} selected={isSelected} />
9
+ }
@@ -0,0 +1,26 @@
1
+ import styled from 'styled-components'
2
+
3
+ // TODO: Review how define all this styles
4
+ export const MessageBubble = styled.div`
5
+ margin: 0px 0px 5px 0px;
6
+ `
7
+
8
+ interface RatingSelectorContainerProps {
9
+ isSent?: boolean
10
+ }
11
+
12
+ export const RatingSelectorContainer = styled.div<RatingSelectorContainerProps>`
13
+ display: flex;
14
+ justify-content: center;
15
+ gap: 8px;
16
+ margin-top: 16px;
17
+
18
+ & > div {
19
+ cursor: ${props => (props.isSent ? 'default' : 'pointer')};
20
+
21
+ svg {
22
+ height: 27px;
23
+ width: 27px;
24
+ }
25
+ }
26
+ `
@@ -0,0 +1,15 @@
1
+ export enum RatingType {
2
+ Stars = 'stars',
3
+ Smileys = 'smileys',
4
+ }
5
+
6
+ export interface RatingItemProps {
7
+ color: string
8
+ ratingNumber: number
9
+ hover: number
10
+ }
11
+
12
+ export interface RatingIconProps {
13
+ color: string
14
+ selected?: boolean
15
+ }
@@ -1,5 +1,6 @@
1
1
  // @ts-nocheck
2
2
  export { WebchatContext } from './context'
3
+ export * from './custom-messages'
3
4
  export { Webchat } from './webchat'
4
5
  export { WebchatDev } from './webchat-dev'
5
6
 
@@ -1,7 +1,7 @@
1
1
  import React, { useContext } from 'react'
2
2
 
3
3
  import SendButtonIcon from '../../assets/send-button.svg'
4
- import { ROLES, WEBCHAT } from '../../constants'
4
+ import { ROLES } from '../../constants'
5
5
  import { WebchatContext } from '../../webchat/context'
6
6
  import { Icon } from '../components/common'
7
7
  import { ConditionalAnimation } from '../components/conditional-animation'