contentoh-components-library 21.5.2 → 21.5.3

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 (293) hide show
  1. package/dist/components/organisms/Table/styles.js +1 -1
  2. package/dist/components/pages/MultipleEdition/saveData.js +19 -9
  3. package/dist/components/pages/MultipleEdition/styles.js +1 -1
  4. package/dist/components/pages/MultipleEdition/utils.js +153 -86
  5. package/package.json +1 -4
  6. package/src/components/atoms/Avatar/index.js +2 -8
  7. package/src/components/atoms/ButtonV2/ButtonV2.stories.js +0 -1
  8. package/src/components/atoms/ButtonV2/index.js +0 -1
  9. package/src/components/atoms/ButtonV2/styles.js +0 -16
  10. package/src/components/atoms/CheckBox/CheckBox.stories.js +0 -5
  11. package/src/components/atoms/CheckBox/index.js +1 -5
  12. package/src/components/atoms/CheckBox/styles.js +3 -9
  13. package/src/components/atoms/GeneralButton/styles.js +0 -46
  14. package/src/components/atoms/GeneralInput/index.js +0 -3
  15. package/src/components/atoms/GeneralInput/styles.js +1 -19
  16. package/src/components/atoms/InputFormatter/index.js +1 -2
  17. package/src/components/atoms/InputFormatter/styles.js +4 -9
  18. package/src/components/atoms/ProductImage/index.js +11 -24
  19. package/src/components/atoms/ProductImage/styles.js +0 -7
  20. package/src/components/atoms/SliderToolTip/styles.js +1 -1
  21. package/src/components/atoms/TabSection/index.js +1 -1
  22. package/src/components/atoms/TabSection/styles.js +3 -0
  23. package/src/components/molecules/BoxAttribute/index.js +25 -32
  24. package/src/components/molecules/BoxAttribute/styles.js +1 -1
  25. package/src/components/molecules/BoxButtons/index.js +22 -23
  26. package/src/components/molecules/CarouselImagesLogin/index.js +1 -1
  27. package/src/components/molecules/GalleryElement/index.js +1 -76
  28. package/src/components/molecules/GalleryHeader/index.js +0 -1
  29. package/src/components/molecules/HeaderTop/index.js +6 -52
  30. package/src/components/molecules/ProductNameHeader/index.js +1 -19
  31. package/src/components/molecules/SignInLogin/index.js +11 -11
  32. package/src/components/molecules/StatusAsignationInfo/FinancedCompanies.js +63 -501
  33. package/src/components/molecules/StatusAsignationInfo/index.js +1 -1
  34. package/src/components/molecules/StripeCardSelector/CardSelector.stories.js +2 -1
  35. package/src/components/molecules/TagAndInput/index.js +6 -8
  36. package/src/components/organisms/Chat/Chat.stories.js +7 -27
  37. package/src/components/organisms/Chat/ContainerItems/index.js +2 -18
  38. package/src/components/organisms/Chat/ContainerItems/styles.js +2 -14
  39. package/src/components/organisms/Chat/ContentChat/index.js +12 -88
  40. package/src/components/organisms/Chat/Footer/index.js +0 -11
  41. package/src/components/organisms/Chat/index.js +4 -46
  42. package/src/components/organisms/Chat/styles.js +0 -4
  43. package/src/components/organisms/DashboardMetric/index.js +3 -6
  44. package/src/components/organisms/FullProductNameHeader/index.js +1 -13
  45. package/src/components/organisms/GridProducts/GridProducts.stories.js +107 -682
  46. package/src/components/organisms/InputGroup/index.js +144 -292
  47. package/src/components/organisms/InputGroup/styles.js +0 -31
  48. package/src/components/organisms/Modal/Modal.stories.js +1 -2
  49. package/src/components/organisms/Modal/index.js +2 -9
  50. package/src/components/organisms/Modal/styles.js +1 -8
  51. package/src/components/organisms/OrderDetail/utils/Table/utils.js +16 -6
  52. package/src/components/pages/Dashboard/Dashboard.stories.js +38 -33
  53. package/src/components/pages/Dashboard/index.js +7 -36
  54. package/src/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +60 -56
  55. package/src/components/pages/ProviderProductEdition/index.js +133 -148
  56. package/src/components/pages/ProviderProductEdition/styles.js +1 -5
  57. package/src/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +0 -4
  58. package/src/components/pages/RetailerProductEdition/index.js +300 -293
  59. package/src/components/pages/RetailerProductEdition/styles.js +0 -4
  60. package/src/components/pages/RetailerProductEdition/utils.js +0 -37
  61. package/src/global-files/data.js +10 -6
  62. package/src/global-files/variables.js +0 -6
  63. package/src/index.js +0 -12
  64. package/src/assets/images/Icons/addv2.svg +0 -8
  65. package/src/assets/images/Icons/beenhere.svg +0 -9
  66. package/src/assets/images/Icons/checkv2.svg +0 -8
  67. package/src/assets/images/Icons/close-magenta.svg +0 -9
  68. package/src/assets/images/Icons/close.svg +0 -8
  69. package/src/assets/images/Icons/closeCircle.svg +0 -8
  70. package/src/assets/images/Icons/delete-forever-red.svg +0 -9
  71. package/src/assets/images/Icons/delete-forever-white.svg +0 -10
  72. package/src/assets/images/Icons/edit.svg +0 -8
  73. package/src/assets/images/Icons/fullscreen.svg +0 -3
  74. package/src/assets/images/Icons/infoNR.svg +0 -8
  75. package/src/assets/images/Icons/options.svg +0 -3
  76. package/src/assets/images/Icons/save-white-gray.svg +0 -9
  77. package/src/assets/images/Icons/save-white.svg +0 -9
  78. package/src/assets/images/Icons/save.svg +0 -8
  79. package/src/assets/images/Icons/search.svg +0 -3
  80. package/src/assets/images/Icons/settings.svg +0 -8
  81. package/src/assets/images/Icons/trash.svg +0 -8
  82. package/src/assets/images/Icons/undo.svg +0 -8
  83. package/src/assets/images/Icons/upload-file-white.svg +0 -4
  84. package/src/assets/images/Icons/upload-file.svg +0 -10
  85. package/src/assets/images/Icons/upload_file.svg +0 -10
  86. package/src/assets/images/Icons/warningv2.svg +0 -3
  87. package/src/assets/images/checkBox/checkrosa.svg +0 -3
  88. package/src/assets/images/checkBox/checkverde.svg +0 -3
  89. package/src/assets/images/flagsv2/highPriority.svg +0 -3
  90. package/src/assets/images/flagsv2/lowPriority.svg +0 -3
  91. package/src/assets/images/flagsv2/mediumPriority.svg +0 -3
  92. package/src/assets/images/flagsv2/noPriority.svg +0 -3
  93. package/src/assets/images/generalButton/closeIconWhite.svg +0 -4
  94. package/src/assets/images/generalButton/closeIconv2.svg +0 -4
  95. package/src/assets/images/generalButton/saveIconpink.svg +0 -3
  96. package/src/components/atoms/CharsMissing/Wysiwyg.stories.js +0 -12
  97. package/src/components/atoms/CharsMissing/index.js +0 -60
  98. package/src/components/atoms/CharsMissing/styles.js +0 -44
  99. package/src/components/atoms/CustomChip/CustomChip.stories.js +0 -16
  100. package/src/components/atoms/CustomChip/index.js +0 -34
  101. package/src/components/atoms/CustomChip/styles.js +0 -6
  102. package/src/components/atoms/FeatureTagv2/FeatureTagv2.stories.js +0 -16
  103. package/src/components/atoms/FeatureTagv2/index.js +0 -10
  104. package/src/components/atoms/FeatureTagv2/styles.js +0 -56
  105. package/src/components/atoms/GeneralInputv2/GeneralInputv2.stories.js +0 -33
  106. package/src/components/atoms/GeneralInputv2/index.js +0 -155
  107. package/src/components/atoms/GeneralInputv2/styles.js +0 -67
  108. package/src/components/atoms/InputFormatterv2/Wysiwyg.stories.js +0 -12
  109. package/src/components/atoms/InputFormatterv2/index.js +0 -148
  110. package/src/components/atoms/InputFormatterv2/styles.js +0 -39
  111. package/src/components/atoms/InputImages/InputImages.stories.js +0 -19
  112. package/src/components/atoms/InputImages/index.js +0 -25
  113. package/src/components/atoms/InputImages/styles.js +0 -17
  114. package/src/components/atoms/Multiselect/Multiselect.stories.js +0 -364
  115. package/src/components/atoms/Multiselect/index.js +0 -351
  116. package/src/components/atoms/Multiselect/styles.js +0 -33
  117. package/src/components/atoms/NumberMandatory/NumberMandatory.stories.js +0 -19
  118. package/src/components/atoms/NumberMandatory/index.js +0 -16
  119. package/src/components/atoms/NumberMandatory/styles.js +0 -11
  120. package/src/components/atoms/ObservationFlag/ObservationFlag.stories.js +0 -20
  121. package/src/components/atoms/ObservationFlag/index.js +0 -167
  122. package/src/components/atoms/ObservationFlag/styles.js +0 -104
  123. package/src/components/atoms/PriorityFlagv2/PriorityFlagv2.stories.js +0 -20
  124. package/src/components/atoms/PriorityFlagv2/index.js +0 -20
  125. package/src/components/atoms/PriorityFlagv2/styles.js +0 -6
  126. package/src/components/atoms/ProductImagev2/ProductImagev2.stories.js +0 -28
  127. package/src/components/atoms/ProductImagev2/index.js +0 -16
  128. package/src/components/atoms/ProductImagev2/styles.js +0 -62
  129. package/src/components/atoms/Progress/Progress.stories.js +0 -25
  130. package/src/components/atoms/Progress/index.js +0 -74
  131. package/src/components/atoms/Progress/styles.js +0 -98
  132. package/src/components/atoms/ScreenHeaderv2/ScreenHeaderv2.stories.js +0 -53
  133. package/src/components/atoms/ScreenHeaderv2/index.js +0 -134
  134. package/src/components/atoms/ScreenHeaderv2/styles.js +0 -103
  135. package/src/components/atoms/Selectv2/VersionSelect.js +0 -27
  136. package/src/components/atoms/Selectv2/index.js +0 -35
  137. package/src/components/atoms/Selectv2/style.js +0 -93
  138. package/src/components/atoms/TabSectionv2/TabSection.stories.js +0 -25
  139. package/src/components/atoms/TabSectionv2/index.js +0 -9
  140. package/src/components/atoms/TabSectionv2/styles.js +0 -20
  141. package/src/components/atoms/TooltipLight/Tooltip.stories.js +0 -20
  142. package/src/components/atoms/TooltipLight/index.js +0 -46
  143. package/src/components/atoms/TooltipLight/styles.js +0 -65
  144. package/src/components/atoms/WordsMissing/Wysiwyg.stories.js +0 -12
  145. package/src/components/atoms/WordsMissing/index.js +0 -60
  146. package/src/components/atoms/WordsMissing/styles.js +0 -10
  147. package/src/components/molecules/AddGroup/AddGroup.stories.js +0 -15
  148. package/src/components/molecules/AddGroup/index.js +0 -84
  149. package/src/components/molecules/AddGroup/styles.js +0 -141
  150. package/src/components/molecules/AsignationInfo/AsignationInfo.stories.js +0 -17
  151. package/src/components/molecules/AsignationInfo/index.js +0 -108
  152. package/src/components/molecules/AsignationInfo/styles.js +0 -86
  153. package/src/components/molecules/EditionActiveImagev2/EditionActiveImagev2.stories.js +0 -12
  154. package/src/components/molecules/EditionActiveImagev2/index.js +0 -15
  155. package/src/components/molecules/EditionActiveImagev2/styles.js +0 -7
  156. package/src/components/molecules/EditionTabs/EditionTabs.stories.js +0 -12
  157. package/src/components/molecules/EditionTabs/index.js +0 -33
  158. package/src/components/molecules/EditionTabs/styles.js +0 -24
  159. package/src/components/molecules/FeaturesBarv2/FeaturesBarv2.stories.js +0 -20
  160. package/src/components/molecules/FeaturesBarv2/index.js +0 -32
  161. package/src/components/molecules/FeaturesBarv2/styles.js +0 -17
  162. package/src/components/molecules/GalleryElementv2/GalleryElementv2.stories.js +0 -30
  163. package/src/components/molecules/GalleryElementv2/index.js +0 -142
  164. package/src/components/molecules/GalleryElementv2/styles.js +0 -119
  165. package/src/components/molecules/GalleryHeaderv2/GalleryHeaderv2.stories.js +0 -10
  166. package/src/components/molecules/GalleryHeaderv2/index.js +0 -25
  167. package/src/components/molecules/GalleryHeaderv2/styles.js +0 -47
  168. package/src/components/molecules/GroupSelect/GroupSelect.stories.js +0 -35
  169. package/src/components/molecules/GroupSelect/SelectItem.js +0 -105
  170. package/src/components/molecules/GroupSelect/index.js +0 -190
  171. package/src/components/molecules/GroupSelect/styles.js +0 -124
  172. package/src/components/molecules/HeaderTopv2/HeaderTopv2.stories.js +0 -10
  173. package/src/components/molecules/HeaderTopv2/index.js +0 -100
  174. package/src/components/molecules/HeaderTopv2/styles.js +0 -33
  175. package/src/components/molecules/ImageSelectorv2/ImageSelectorv2.stories.js +0 -46
  176. package/src/components/molecules/ImageSelectorv2/index.js +0 -22
  177. package/src/components/molecules/ImageSelectorv2/styles.js +0 -15
  178. package/src/components/molecules/Phase/Phase.stories.js +0 -107
  179. package/src/components/molecules/Phase/index.js +0 -391
  180. package/src/components/molecules/Phase/styles.js +0 -97
  181. package/src/components/molecules/ProductNameHeaderv2/ProductNameHeaderv2.stories.js +0 -37
  182. package/src/components/molecules/ProductNameHeaderv2/index.js +0 -12
  183. package/src/components/molecules/ProductNameHeaderv2/styles.js +0 -10
  184. package/src/components/molecules/ProductSkuStatus/ProductSkuStatus.stories.js +0 -37
  185. package/src/components/molecules/ProductSkuStatus/index.js +0 -26
  186. package/src/components/molecules/ProductSkuStatus/styles.js +0 -7
  187. package/src/components/molecules/RetailerSelectorv2/RetailerSelectorv2.stories.js +0 -35
  188. package/src/components/molecules/RetailerSelectorv2/index.js +0 -80
  189. package/src/components/molecules/RetailerSelectorv2/styles.js +0 -21
  190. package/src/components/molecules/ServiceDataValidator/ServiceDataValidator.stories.js +0 -90
  191. package/src/components/molecules/ServiceDataValidator/index.js +0 -49
  192. package/src/components/molecules/ServiceDataValidator/styles.js +0 -36
  193. package/src/components/molecules/StatusRetailer/StatusAsignationInfo.stories.js +0 -17
  194. package/src/components/molecules/StatusRetailer/index.js +0 -55
  195. package/src/components/molecules/StatusRetailer/styles.js +0 -85
  196. package/src/components/molecules/TabsMenuv2/TabsMenuv2.stories.js +0 -19
  197. package/src/components/molecules/TabsMenuv2/index.js +0 -112
  198. package/src/components/molecules/TabsMenuv2/styles.js +0 -19
  199. package/src/components/molecules/TagAndInputv2/TagAndInputv2.stories.js +0 -24
  200. package/src/components/molecules/TagAndInputv2/index.js +0 -86
  201. package/src/components/molecules/TagAndInputv2/styles.js +0 -35
  202. package/src/components/molecules/Validation/Validation.stories.js +0 -12
  203. package/src/components/molecules/Validation/index.js +0 -77
  204. package/src/components/molecules/Validation/styles.js +0 -19
  205. package/src/components/molecules/VersionItemv2/VersionItemv2.stories.js +0 -14
  206. package/src/components/molecules/VersionItemv2/index.js +0 -59
  207. package/src/components/molecules/VersionItemv2/styles.js +0 -47
  208. package/src/components/organisms/BarButtons/BarButtons.stories.js +0 -13
  209. package/src/components/organisms/BarButtons/index.js +0 -150
  210. package/src/components/organisms/BarButtons/styles.js +0 -54
  211. package/src/components/organisms/Chatv2/ChatLists/ChatLists.stories.js +0 -65
  212. package/src/components/organisms/Chatv2/ChatLists/Rotoplas.jpeg +0 -0
  213. package/src/components/organisms/Chatv2/ChatLists/THD.png +0 -0
  214. package/src/components/organisms/Chatv2/ChatLists/index.js +0 -141
  215. package/src/components/organisms/Chatv2/ChatLists/styles.js +0 -162
  216. package/src/components/organisms/Chatv2/Chatv2.stories.js +0 -184
  217. package/src/components/organisms/Chatv2/ContainerItems/ContainerItems.stories.js +0 -142
  218. package/src/components/organisms/Chatv2/ContainerItems/index.js +0 -538
  219. package/src/components/organisms/Chatv2/ContainerItems/styles.js +0 -360
  220. package/src/components/organisms/Chatv2/ContentChat/ContentChat.stories.js +0 -102
  221. package/src/components/organisms/Chatv2/ContentChat/Rotoplas.jpeg +0 -0
  222. package/src/components/organisms/Chatv2/ContentChat/THD.png +0 -0
  223. package/src/components/organisms/Chatv2/ContentChat/index.js +0 -1016
  224. package/src/components/organisms/Chatv2/ContentChat/styles.js +0 -44
  225. package/src/components/organisms/Chatv2/Footer/Footer.stories.js +0 -22
  226. package/src/components/organisms/Chatv2/Footer/index.js +0 -668
  227. package/src/components/organisms/Chatv2/Footer/styles.js +0 -290
  228. package/src/components/organisms/Chatv2/Header/Header.stories.js +0 -66
  229. package/src/components/organisms/Chatv2/Header/index.js +0 -93
  230. package/src/components/organisms/Chatv2/Header/styles.js +0 -49
  231. package/src/components/organisms/Chatv2/index.js +0 -281
  232. package/src/components/organisms/Chatv2/styles.js +0 -85
  233. package/src/components/organisms/CompleteServices/CompleteServices.stories.js +0 -91
  234. package/src/components/organisms/CompleteServices/index.js +0 -82
  235. package/src/components/organisms/CompleteServices/styles.js +0 -35
  236. package/src/components/organisms/DragAndDropPhases/DragAndDropPhases.stories.js +0 -13
  237. package/src/components/organisms/DragAndDropPhases/index.js +0 -336
  238. package/src/components/organisms/DragAndDropPhases/styles.js +0 -107
  239. package/src/components/organisms/DragPrueba/DragPrueba.stories.js +0 -12
  240. package/src/components/organisms/DragPrueba/index.js +0 -57
  241. package/src/components/organisms/DragPrueba/styles.js +0 -8
  242. package/src/components/organisms/EditGroup/EditGroup.stories.js +0 -20
  243. package/src/components/organisms/EditGroup/index.js +0 -321
  244. package/src/components/organisms/EditGroup/styles.js +0 -207
  245. package/src/components/organisms/FullProductNamev2/FullProductNamev2.stories.js +0 -28
  246. package/src/components/organisms/FullProductNamev2/index.js +0 -101
  247. package/src/components/organisms/FullProductNamev2/styles.js +0 -49
  248. package/src/components/organisms/FullTabsMenuv2/FullTabsMenuv2.stories.js +0 -22
  249. package/src/components/organisms/FullTabsMenuv2/index.js +0 -142
  250. package/src/components/organisms/FullTabsMenuv2/styles.js +0 -47
  251. package/src/components/organisms/ImageDataTablev2/ImageDataTablev2.stories.js +0 -24
  252. package/src/components/organisms/ImageDataTablev2/index.js +0 -124
  253. package/src/components/organisms/ImageDataTablev2/styles.js +0 -18
  254. package/src/components/organisms/ImagePreviewerv2/ImagePreviewerv2.stories.js +0 -38
  255. package/src/components/organisms/ImagePreviewerv2/index.js +0 -22
  256. package/src/components/organisms/ImagePreviewerv2/styles.js +0 -7
  257. package/src/components/organisms/ImageUploader/ImageUploader.stories.js +0 -15
  258. package/src/components/organisms/ImageUploader/index.js +0 -62
  259. package/src/components/organisms/ImageUploader/styles.js +0 -29
  260. package/src/components/organisms/ImageVisor/ImageVisor.stories.js +0 -15
  261. package/src/components/organisms/ImageVisor/index.js +0 -143
  262. package/src/components/organisms/ImageVisor/styles.js +0 -106
  263. package/src/components/organisms/InputGroupv2/InputGroupv2.stories.js +0 -31
  264. package/src/components/organisms/InputGroupv2/index.js +0 -296
  265. package/src/components/organisms/InputGroupv2/styles.js +0 -90
  266. package/src/components/organisms/MandatoryBar/MandatoryBar.stories.js +0 -18
  267. package/src/components/organisms/MandatoryBar/index.js +0 -31
  268. package/src/components/organisms/MandatoryBar/styles.js +0 -12
  269. package/src/components/organisms/ProductImageModalv2/ProductImageModalv2.stories.js +0 -90
  270. package/src/components/organisms/ProductImageModalv2/index.js +0 -105
  271. package/src/components/organisms/ProductImageModalv2/styles.js +0 -71
  272. package/src/components/organisms/RenameImagesBar/RenameImagesBar.stories.js +0 -18
  273. package/src/components/organisms/RenameImagesBar/index.js +0 -30
  274. package/src/components/organisms/RenameImagesBar/styles.js +0 -12
  275. package/src/components/organisms/Table/Table.stories.js +0 -609
  276. package/src/components/organisms/Table/index.js +0 -84
  277. package/src/components/organisms/Table/styles.js +0 -114
  278. package/src/components/organisms/VersionSelectorv2/VersionSelectorv2.stories.js +0 -15
  279. package/src/components/organisms/VersionSelectorv2/index.js +0 -105
  280. package/src/components/organisms/VersionSelectorv2/styles.js +0 -45
  281. package/src/components/pages/MultipleEdition/MultipleEdition.stories.js +0 -17
  282. package/src/components/pages/MultipleEdition/components/ImageUploader.js +0 -62
  283. package/src/components/pages/MultipleEdition/components/ImageUploaderStyles.js +0 -29
  284. package/src/components/pages/MultipleEdition/components/ImageVisor.js +0 -143
  285. package/src/components/pages/MultipleEdition/components/styles.js +0 -106
  286. package/src/components/pages/MultipleEdition/index.js +0 -248
  287. package/src/components/pages/MultipleEdition/saveData.js +0 -92
  288. package/src/components/pages/MultipleEdition/styles.js +0 -201
  289. package/src/components/pages/MultipleEdition/utils.js +0 -1073
  290. package/src/components/pages/ProductEditionv2/ProductEditionv2.stories.js +0 -213
  291. package/src/components/pages/ProductEditionv2/index.js +0 -1758
  292. package/src/components/pages/ProductEditionv2/styles.js +0 -154
  293. package/src/components/pages/RetailerProductEdition/generateThumnail.js +0 -21
@@ -1,1016 +0,0 @@
1
- import ReactHowler from "react-howler";
2
- import { Container } from "./styles";
3
- import { useEffect, useState } from "react";
4
- import { NotFound } from "../../../atoms/NotFound";
5
- import { Header } from "../Header";
6
- import { faComments as IconChat } from "@fortawesome/free-solid-svg-icons";
7
- import { Loading } from "../../../atoms/Loading";
8
- import { ContainerItems } from "../ContainerItems";
9
- import { Footer } from "../Footer";
10
- import { ChatLists } from "../ChatLists";
11
- import { CustomIcon } from "../../../atoms/CustomIcon";
12
- import { fetchGET, fetchPOST } from "../../../../global-files/handle_http";
13
- import {
14
- encodeUriJson,
15
- isStringEmpty,
16
- isValidNaturalNumber,
17
- } from "../../../../global-files/utils";
18
- import newMessage from "../../../../assets/sounds/newMessage.mp3";
19
-
20
- export const ContentChat = (props) => {
21
- const {
22
- chatType, // "merchant_product" | "order_product" | "ticket"
23
- chatContainerType, // "fixed" | "popUp"
24
- dataChat, // { data | error }
25
- showBtnClose, // boolean
26
- onClickBtnClose, // () => {}
27
- showPopUpChat, // boolean
28
- ticketCompany, // id de la compañía que creó el ticket
29
- activeRetailer, // object retailer
30
- } = props;
31
- const [companies, setCompanies] = useState({}); /* {
32
- companyId: {
33
- name: string,
34
- statusChat: string => current | open | closed
35
- items: [{..}] ,
36
- enabledLoadMore: boolean
37
- },
38
- ...
39
- } chat orderProduct */
40
- const [singleChat, setSingleChat] = useState({
41
- items: undefined,
42
- enabledLoadMore: false,
43
- statusChat: undefined,
44
- }); // chat merchantProduct o ticket
45
- const [activeCompanyId, setActiveCompanyId] = useState(); // number
46
- const [allUsers, setAllUsers] = useState({}); // {...}
47
- const [currentUser, setCurrentUser] = useState({
48
- id: undefined,
49
- companyId: undefined,
50
- });
51
- const [currentArticle, setCurrentArticle] = useState({
52
- status: undefined,
53
- version: undefined,
54
- });
55
- const [lastUpdateDate, setLastUpdateDate] = useState(); // string
56
- const [isLoading, setIsLoading] = useState(true); // boolean
57
- const [showChatsList, setShowChatsList] = useState(false); // boolean
58
- const [processUpdateID, setProcessUpdateID] = useState(); // number
59
- const [startUpdate, setStartUpdate] = useState(0); // number
60
- const [runUpdate, setRunUpdate] = useState(0); // number
61
- const [errorChat, setErrorChat] = useState({
62
- existError: false,
63
- code: undefined,
64
- message: undefined,
65
- errorDetail: undefined,
66
- });
67
- const [errorUpdate, setErrorUpdate] = useState({
68
- startDate: undefined, // Date()
69
- lastDate: undefined, // Date()
70
- });
71
- const [playSound, setPlaySound] = useState(false);
72
-
73
- // matar update al desmontar el componente del chat
74
- useEffect(() => {
75
- return () => {
76
- if (processUpdateID !== undefined) clearTimeout(processUpdateID);
77
- };
78
- }, []);
79
-
80
- const stopUpdate = () => {
81
- if (processUpdateID !== undefined) {
82
- clearTimeout(processUpdateID);
83
- setProcessUpdateID(undefined);
84
- }
85
- };
86
-
87
- // al cargar el componente
88
- useEffect(() => {
89
- //if (dataChat && showPopUpChat) {
90
- if (Object.keys(dataChat || {}).length) {
91
- stopUpdate();
92
- if (dataChat.code) {
93
- setErrorChat({
94
- existError: true,
95
- code: dataChat.code,
96
- message: dataChat.message,
97
- errorDetail: dataChat.errorDetail,
98
- });
99
- setIsLoading(false);
100
- return;
101
- }
102
- if (chatType === "merchant_product") getInitialMerchantProduct();
103
- else if (chatType === "order_product") getInitialOrderProduct();
104
- else if (chatType === "product_status") getInitialProductStatus();
105
- else getInitialTicket();
106
- }
107
- if (!showPopUpChat) {
108
- stopUpdate();
109
- }
110
- }, [dataChat, showPopUpChat]);
111
-
112
- // comenzar temporizador del update de 20s
113
- useEffect(() => {
114
- // return; // -- descomentarizar para hacer pruebas sin update
115
- if (startUpdate === 0) return;
116
- const processID = setTimeout(() => {
117
- setRunUpdate((prev) => prev + 1);
118
- }, 15000);
119
- setProcessUpdateID(processID);
120
- return () => clearTimeout(processID);
121
- }, [startUpdate]);
122
-
123
- // ejecutar update
124
- useEffect(() => {
125
- if (chatType === "merchant_product") {
126
- if (singleChat.items) getUpdateLatestMerchantProduct(true);
127
- else getInitialMerchantProduct();
128
- } else if (chatType === "order_product") {
129
- if (companies) getUpdateLatestOrderProduct(true);
130
- else getInitialOrderProduct();
131
- } else if (chatType === "product_status") {
132
- getInitialProductStatus();
133
- } else {
134
- if (singleChat.items) getUpdateLatestTicket(true);
135
- else getInitialTicket();
136
- }
137
- }, [runUpdate]);
138
-
139
- /*=======================================================================
140
- PETICION GET INICIAL SEGUN EL TIPO DE CHAT
141
- ======================================================================= */
142
- const getInitialProductStatus = async () => {
143
- const paramsQuery = {
144
- articleData: JSON.stringify({
145
- articleId: JSON.stringify(dataChat.id),
146
- version: JSON.stringify(dataChat.version),
147
- retailerId: JSON.stringify(dataChat.retailerId),
148
- status: dataChat.status,
149
- })
150
- };
151
- const paramsHeaders = { Authorization: dataChat.userToken };
152
- const response = await fetchGET(
153
- process.env.REACT_APP_READ_MESSAGES,
154
- paramsQuery,
155
- paramsHeaders
156
- );
157
- if (!response.body) {
158
- setErrorChat({
159
- existError: true,
160
- code: 400,
161
- message: response.message,
162
- errorDetail: response.errorDetail,
163
- });
164
- setIsLoading(false);
165
- return;
166
- }
167
- // success
168
- setStartUpdate((prev) => prev + 1);
169
- setCurrentUser({
170
- id: response.body.data.currentUserId,
171
- companyId: response.body.data.currentCompanyId,
172
- });
173
- setLastUpdateDate(response.body.data.lastUpdateDate);
174
- setAllUsers(response.body.users);
175
- setSingleChat({
176
- items: response.body.items,
177
- enabledLoadMore: response.body.items.length === 50,
178
- });
179
- setErrorChat({ existError: false });
180
- setIsLoading(false);
181
- };
182
-
183
- const getInitialMerchantProduct = async () => {
184
- const paramsQuery = {
185
- getType: "initial",
186
- id: JSON.stringify(dataChat.id),
187
- version: JSON.stringify(dataChat.version),
188
- };
189
- const paramsHeaders = { Authorization: dataChat.userToken };
190
- const response = await fetchGET(
191
- process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
192
- paramsQuery,
193
- paramsHeaders
194
- );
195
- if (!response.body) {
196
- setErrorChat({
197
- existError: true,
198
- code: 400,
199
- message: response.message,
200
- errorDetail: response.errorDetail,
201
- });
202
- setIsLoading(false);
203
- return;
204
- }
205
- // success
206
- setStartUpdate((prev) => prev + 1);
207
- setCurrentUser({
208
- id: response.body.data.currentUserId,
209
- companyId: response.body.data.currentCompanyId,
210
- });
211
- setLastUpdateDate(response.body.data.lastUpdateDate);
212
- setAllUsers(response.body.users);
213
- setSingleChat({
214
- items: response.body.items,
215
- enabledLoadMore: response.body.items.length === 50,
216
- });
217
- setErrorChat({ existError: false });
218
- setIsLoading(false);
219
- };
220
-
221
- const getInitialOrderProduct = async () => {
222
- clearTimeout(processUpdateID); // finalizamos el temporizador
223
- const paramsQuery = {
224
- getType: "initial",
225
- id: JSON.stringify(dataChat.id),
226
- orderId: JSON.stringify(dataChat.orderId),
227
- retailerId: JSON.stringify(dataChat.retailerId),
228
- };
229
- const paramsHeaders = { Authorization: dataChat.userToken };
230
- const response = await fetchGET(
231
- process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
232
- paramsQuery,
233
- paramsHeaders
234
- );
235
- setStartUpdate((prev) => prev + 1); // TEMPORAL
236
- if (!response.body) {
237
- setErrorChat({
238
- existError: true,
239
- code: 400,
240
- message: response.message,
241
- errorDetail: response.errorDetail,
242
- });
243
- setIsLoading(false);
244
- return;
245
- }
246
- // success
247
- setCurrentUser({
248
- id: response.body.data.currentUserId,
249
- companyId: response.body.data.currentCompanyId,
250
- });
251
- setLastUpdateDate(response.body.data.lastUpdateDate);
252
- setCurrentArticle({
253
- status: response.body.data.status,
254
- version: response.body.data.version,
255
- });
256
- setAllUsers(response.body.users);
257
- const companiesList = response.body.companies;
258
- const companiesIdList = Object.keys(companiesList);
259
- let companyActive;
260
- // encontrar el chat inicial a cargar y si se debe permitir cargar mas
261
- for (const companyId of companiesIdList) {
262
- if (companiesList[companyId].items.length < 50) {
263
- companiesList[companyId].enabledLoadMore = false;
264
- } else {
265
- companiesList[companyId].enabledLoadMore = true;
266
- }
267
-
268
- if (companiesList[companyId].statusChat === "current") {
269
- companyActive = Number(companyId);
270
- }
271
- }
272
- if (!companyActive && companiesIdList.length) {
273
- companyActive = Number(companiesIdList[0]);
274
- }
275
- setCompanies(companiesList);
276
- if (companyActive) setActiveCompanyId(companyActive);
277
- setErrorChat({ existError: false });
278
- setIsLoading(false);
279
- };
280
-
281
- const getInitialTicket = async () => {
282
- stopUpdate(); // finalizamos el temporizador
283
- const dataUser = {
284
- id: dataChat.currentUser?.id,
285
- companyId: dataChat.currentUser?.companyId,
286
- isUserTech: dataChat.currentUser?.isUserTech,
287
- };
288
- const paramsQuery = {
289
- //id: JSON.stringify(dataChat.id),
290
- id: dataChat.id,
291
- getType: "initial",
292
- //currentUser: encodeUriJson(dataUser),
293
- currentUser: encodeURIComponent(JSON.stringify(dataUser)),
294
- currentItemsFront: encodeUriJson(getItemsIdSingleChat()),
295
- };
296
- const response = await fetchGET(
297
- process.env.REACT_APP_TICKETS_CHAT_ENDPOINT,
298
- paramsQuery,
299
- { Authorization: dataChat.currentUser?.token }
300
- );
301
- // programar update en 20s
302
- setStartUpdate((prev) => prev + 1);
303
- if (!response.body) {
304
- setErrorChat({
305
- existError: true,
306
- code: 400,
307
- message: response.message,
308
- errorDetail: response.errorDetail,
309
- });
310
- setIsLoading(false);
311
- return;
312
- }
313
- // success
314
- setLastUpdateDate(response.body.data.lastUpdateDate);
315
- setAllUsers(response.body.users);
316
- setSingleChat({
317
- items: response.body.items,
318
- enabledLoadMore: response.body.items.length === 50,
319
- statusChat: dataChat.statusChat,
320
- });
321
- setErrorChat({ existError: false });
322
- setIsLoading(false);
323
- };
324
-
325
- /*=======================================================================
326
- PETICION GET LOAD_MORE SEGUN EL TIPO DE CHAT
327
- ======================================================================= */
328
- const getLoadMoreMerchantProduct = async () => {
329
- clearTimeout(processUpdateID); // finalizamos el temporizador
330
- let date = singleChat.items[singleChat.items.length - 1].date;
331
- const paramsQuery = {
332
- getType: "loadMore",
333
- id: JSON.stringify(dataChat.id),
334
- version: JSON.stringify(dataChat.version),
335
- date: encodeURIComponent(date),
336
- };
337
- const response = await fetchGET(
338
- process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
339
- paramsQuery
340
- );
341
- //setStartUpdate((prev) => prev + 1); // comendar un nuevo temporizador
342
- if (!response.body) {
343
- return {
344
- title: response.message,
345
- message: response.errorDetail,
346
- };
347
- }
348
- // success
349
- // actualizar la lista de los users
350
- updateAllUsers(response.body.users);
351
- // actualizar los items del chat
352
- let newSingleChat = { ...singleChat };
353
- newSingleChat.items = addOldItemsChat(
354
- newSingleChat.items,
355
- response.body.items
356
- );
357
- newSingleChat.enabledLoadMore = response.body.items.length === 50;
358
- setSingleChat(newSingleChat);
359
- };
360
-
361
- const getLoadMoreOrderProduct = async () => {
362
- clearTimeout(processUpdateID); // finalizamos el temporizador
363
- let company = companies[activeCompanyId];
364
- let date = company.items[company.items.length - 1].date;
365
- const paramsQuery = {
366
- getType: "loadMore",
367
- id: JSON.stringify(dataChat.id),
368
- orderId: JSON.stringify(dataChat.orderId),
369
- version: JSON.stringify(currentArticle.version),
370
- currentCompanyId: JSON.stringify(currentUser.companyId),
371
- date: encodeURIComponent(date),
372
- othersCompanyId: JSON.stringify([activeCompanyId]),
373
- };
374
- const response = await fetchGET(
375
- process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
376
- paramsQuery
377
- );
378
- //setStartUpdate((prev) => prev + 1); // comendar un nuevo temporizador
379
- if (!response.body) {
380
- return {
381
- title: response.message,
382
- message: response.errorDetail,
383
- };
384
- }
385
- // success
386
- // actualizar la lista de los users
387
- updateAllUsers(response.body.users);
388
- // actualizar los items del chat y la lista de users
389
- company.items = addOldItemsChat(company.items, response.body.items);
390
- company.enabledLoadMore = response.body.items.length === 50;
391
- setCompanies((prev) => ({
392
- ...prev,
393
- [activeCompanyId]: company,
394
- }));
395
- };
396
-
397
- // este GET obtiene la lista de compañoas con las que se puede chatear
398
- const getLoadMoreTicket = async () => {
399
- stopUpdate(); // finalizamos el temporizador
400
- let date = singleChat.items[singleChat.items.length - 1].date;
401
- const dataUser = {
402
- id: dataChat.currentUser?.id,
403
- companyId: dataChat.currentUser?.companyId,
404
- isUserTech: dataChat.currentUser?.isUserTech,
405
- };
406
- const paramsQuery = {
407
- id: JSON.stringify(dataChat.id),
408
- getType: "loadMore",
409
- date: encodeURIComponent(date),
410
- currentUser: encodeUriJson(dataUser),
411
- currentItemsFront: encodeUriJson(getItemsIdSingleChat()),
412
- };
413
- const response = await fetchGET(
414
- process.env.REACT_APP_TICKETS_CHAT_ENDPOINT,
415
- paramsQuery,
416
- { Authorization: dataChat.currentUser?.token }
417
- );
418
- //programar update en 20s
419
- setStartUpdate((prev) => prev + 1);
420
- if (!response.body) {
421
- return {
422
- title: response.message,
423
- message: response.errorDetail,
424
- };
425
- }
426
- // success
427
- // actualizar la lista de los users
428
- updateAllUsers(response.body.users);
429
- // actualizar los items del chat
430
- let newSingleChat = { ...singleChat };
431
- newSingleChat.items = addOldItemsChat(
432
- newSingleChat.items,
433
- response.body.items
434
- );
435
- newSingleChat.enabledLoadMore = response.body.items.length === 50;
436
- setSingleChat(newSingleChat);
437
- };
438
-
439
- /*=======================================================================
440
- PETICION GET UPDATE_LATEST SEGUN EL TIPO DE CHAT
441
- ======================================================================= */
442
- const getUpdateLatestMerchantProduct = async (fromUpdate = false) => {
443
- const paramsQuery = {
444
- getType: "updateLatest",
445
- id: JSON.stringify(dataChat.id),
446
- version: JSON.stringify(dataChat.version),
447
- date: encodeURIComponent(lastUpdateDate),
448
- };
449
- const paramsHeaders = { Authorization: dataChat.userToken };
450
- const response = await fetchGET(
451
- process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
452
- paramsQuery,
453
- paramsHeaders
454
- );
455
- if (!response.body) {
456
- console.log("ERROR updateLatest:", {
457
- message: response.message,
458
- errorDetail: response.errorDetail,
459
- });
460
- return;
461
- }
462
- // success
463
- setStartUpdate((prev) => prev + 1);
464
- setLastUpdateDate(response.body.data.lastUpdateDate);
465
- // actualizar la lista de los users
466
- updateAllUsers(response.body.users);
467
- // actualizar los items del chat
468
- let newSingleChat = { ...singleChat };
469
- newSingleChat.items = addNewItemsChat(
470
- newSingleChat.items,
471
- response.body.items,
472
- fromUpdate
473
- );
474
- setSingleChat(newSingleChat);
475
- };
476
-
477
- const getUpdateLatestOrderProduct = async (fromUpdate = false) => {
478
- const paramsQuery = {
479
- getType: "updateLatest",
480
- id: JSON.stringify(dataChat.id),
481
- orderId: JSON.stringify(dataChat.orderId),
482
- retailerId: JSON.stringify(dataChat.retailerId),
483
- version: JSON.stringify(currentArticle.version),
484
- status: currentArticle.status,
485
- currentCompanyId: JSON.stringify(currentUser.companyId),
486
- othersCompanyId: encodeURIComponent(
487
- JSON.stringify(Object.keys(companies))
488
- ),
489
- date: encodeURIComponent(lastUpdateDate),
490
- };
491
- const response = await fetchGET(
492
- process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
493
- paramsQuery
494
- );
495
- if (!response.body) {
496
- console.log("ERROR update: ", {
497
- message: response.message,
498
- errorDetail: response.errorDetail,
499
- });
500
- return;
501
- }
502
- // success
503
- setStartUpdate((prev) => prev + 1);
504
- // cuando cambie la lista de chats por un cambio de version o estatus
505
- if (response.body.data.status) {
506
- setIsLoading(true);
507
- setTimeout(() => {
508
- setLastUpdateDate(response.body.data.lastUpdateDate);
509
- setCurrentArticle({
510
- status: response.body.data.status,
511
- version: response.body.data.version,
512
- });
513
- setAllUsers(response.body.users);
514
- const companiesList = response.body.companies;
515
- const companiesIdList = Object.keys(companiesList);
516
- let companyActive;
517
- // encontrar el chat inicial a cargar y si se debe permitir cargar mas
518
- for (const companyId of companiesIdList) {
519
- if (companiesList[companyId].items.length < 50) {
520
- companiesList[companyId].enabledLoadMore = false;
521
- } else {
522
- companiesList[companyId].enabledLoadMore = true;
523
- }
524
-
525
- if (companiesList[companyId].statusChat === "current") {
526
- companyActive = Number(companyId);
527
- }
528
- }
529
- if (!companyActive && companiesIdList.length) {
530
- companyActive = Number(companiesIdList[0]);
531
- }
532
- setCompanies(companiesList);
533
- if (companyActive) setActiveCompanyId(companyActive);
534
- setErrorChat({ existError: false });
535
- setIsLoading(false);
536
- }, 2000);
537
- }
538
- // cuando se hizo un update de los mismos chats
539
- else {
540
- setLastUpdateDate(response.body.data.lastUpdateDate);
541
- // actualizar la lista de los users
542
- updateAllUsers(response.body.users);
543
- // actualizar los items de los chats
544
- let companiesList = { ...companies };
545
- Object.keys(response.body.companies).forEach((companyId) => {
546
- companiesList[companyId].items = addNewItemsChat(
547
- companiesList[companyId].items,
548
- response.body.companies[companyId].items,
549
- fromUpdate
550
- );
551
- });
552
- setCompanies(companiesList);
553
- }
554
- };
555
-
556
- const getUpdateLatestTicket = async (fromUpdate = false) => {
557
- if (singleChat.statusChat === "closed") return;
558
- const dataUser = {
559
- id: dataChat.currentUser?.id,
560
- companyId: dataChat.currentUser?.companyId,
561
- isUserTech: dataChat.currentUser?.isUserTech,
562
- };
563
- const paramsQuery = {
564
- id: JSON.stringify(dataChat.id),
565
- getType: "updateLatest",
566
- date: encodeURIComponent(lastUpdateDate),
567
- currentUser: encodeUriJson(dataUser),
568
- currentItemsFront: encodeUriJson(getItemsIdSingleChat()),
569
- };
570
- const response = await fetchGET(
571
- process.env.REACT_APP_TICKETS_CHAT_ENDPOINT,
572
- paramsQuery,
573
- { Authorization: dataChat.currentUser?.token }
574
- );
575
- //programar update en 20s
576
- setStartUpdate((prev) => prev + 1);
577
- if (!response.body) {
578
- if (errorUpdate.startDate) {
579
- setErrorUpdate((prev) => ({
580
- ...prev,
581
- lastDate: new Date(),
582
- }));
583
- } else {
584
- setErrorUpdate((prev) => ({
585
- startDate: new Date(),
586
- }));
587
- }
588
- console.log("ERROR updateLatest:", {
589
- message: response.message,
590
- errorDetail: response.errorDetail,
591
- });
592
- return;
593
- }
594
- // limpiar error update
595
- if (errorUpdate.startDate) {
596
- setErrorUpdate({});
597
- }
598
- // success
599
- setLastUpdateDate(response.body.data.lastUpdateDate);
600
- // actualizar la lista de los users
601
- updateAllUsers(response.body.users);
602
- // actualizar los items del chat
603
- if (response.body.items.length === 0) return;
604
- let newSingleChat = { ...singleChat };
605
- newSingleChat.items = addNewItemsChat(
606
- newSingleChat.items,
607
- response.body.items,
608
- fromUpdate
609
- );
610
- newSingleChat.statusChat = response.body.data.statusChat;
611
-
612
- setSingleChat(newSingleChat);
613
- };
614
-
615
- /*=======================================================================
616
- FUNCION QUE EJECUTA EL MICROSERVICIO CREATE-ITEM
617
- Este metodo recibe los items que queremos agregar al chat.
618
- requiere:
619
- => items: [ { type , value } , ... ]
620
- NOTA: si se quiere agregar un mensaje mandar un array con un object
621
- example: [ {
622
- type: "message" ,
623
- value: "mi mensaje"
624
- } ]
625
- ======================================================================= */
626
- const createItemsChat = async (items = []) => {
627
- if (items.length === 0) {
628
- return {
629
- message:
630
- "No se especifico ningun mensaje, imagen o archivo nuevo " +
631
- "que se quiera enviar al chat",
632
- errorDetail: "Reporta esto a TI",
633
- };
634
- }
635
- for (const item of items) {
636
- if (!["message", "img", "file"].includes(item.type)) {
637
- return {
638
- message:
639
- "Uno de los elementos que se quiere enviar al chat " +
640
- `no es un tipo valido "${item.type}"`,
641
- errorDetail: "Reporta esto a TI",
642
- };
643
- }
644
- if (isStringEmpty(item.value)) {
645
- return {
646
- message:
647
- "Uno de los elementos que se quiere enviar al chat " +
648
- `contiene un valor vacio`,
649
- errorDetail: "Reporta esto a TI",
650
- };
651
- }
652
- }
653
- let errorCreate;
654
- stopUpdate(); // finalizamos el temporizador
655
-
656
- // enviar items a la BD
657
- if (chatType === "merchant_product") {
658
- errorCreate = await createItemsMerchantProduct(items);
659
- } else if (chatType === "product_status") {
660
- errorCreate = await createItemsProductStatus(items);
661
- } else if (chatType === "order_product") {
662
- errorCreate = await createItemsOrderProduct(items);
663
- } else errorCreate = await createItemsTicket(items);
664
-
665
- // actualizar chat para que aparezcan los items enviados
666
- if (["merchant_product", "product_status"].includes(chatType)) {
667
- await getUpdateLatestMerchantProduct();
668
- } else if (chatType === "order_product") {
669
- await getUpdateLatestOrderProduct();
670
- } else await getUpdateLatestTicket();
671
-
672
- // cuando no se pudieron guardar los items
673
- if (errorCreate) {
674
- return errorCreate;
675
- }
676
- };
677
-
678
- const createItemsMerchantProduct = async (items = []) => {
679
- const { id, version, orderId } = dataChat;
680
- const { id: retailerId } = activeRetailer;
681
- const paramsBody = { id, version, items, retailerId };
682
- if (chatType === "product_status") paramsBody["orderId"] = orderId;
683
- const paramsHeaders = { Authorization: dataChat.userToken };
684
- const response = await fetchPOST(
685
- process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
686
- paramsBody,
687
- paramsHeaders
688
- );
689
- if (!response.body) {
690
- return {
691
- message: response.message,
692
- errorDetail: response.errorDetail,
693
- };
694
- }
695
- };
696
- const createItemsProductStatus = async (items = []) => {
697
- const { id, version, orderId, status } = dataChat;
698
- const { id: retailerId } = activeRetailer;
699
- const paramsBody = { id, version, items, retailerId, orderId, status };
700
- const paramsHeaders = { Authorization: dataChat.userToken };
701
- const response = await fetchPOST(
702
- process.env.REACT_APP_CREATE_MESSAGES,
703
- paramsBody,
704
- paramsHeaders
705
- );
706
- if (!response.body) {
707
- return {
708
- message: response.message,
709
- errorDetail: response.errorDetail,
710
- };
711
- }
712
- };
713
-
714
- const createItemsOrderProduct = async (items = []) => {
715
- const paramsBody = {
716
- id: dataChat.id,
717
- version: currentArticle.version,
718
- items,
719
- orderId: dataChat.orderId,
720
- retailerId: activeRetailer?.id,
721
- };
722
- const paramsHeaders = { Authorization: dataChat.userToken };
723
- const response = await fetchPOST(
724
- process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
725
- paramsBody,
726
- paramsHeaders
727
- );
728
- if (!response.body) {
729
- return {
730
- message: response.message,
731
- errorDetail: response.errorDetail,
732
- };
733
- }
734
- };
735
-
736
- const createItemsTicket = async (items = []) => {
737
- const paramsBody = {
738
- id: JSON.stringify(dataChat.id),
739
- userId: JSON.stringify(dataChat.currentUser.id),
740
- items: JSON.stringify(items),
741
- };
742
- const paramsHeaders = { Authorization: dataChat.userToken };
743
- const response = await fetchPOST(
744
- process.env.REACT_APP_TICKETS_CHAT_ENDPOINT,
745
- paramsBody,
746
- paramsHeaders
747
- );
748
- if (!response.body) {
749
- return {
750
- message: response.message,
751
- errorDetail: response.errorDetail,
752
- };
753
- }
754
- };
755
-
756
- /*=======================================================================
757
- SECCION DE FUNCIONES
758
- ======================================================================= */
759
- const isSingleChat = () => {
760
- if (
761
- chatType === "merchant_product" ||
762
- chatType === "ticket" ||
763
- chatType === "product_status"
764
- ) {
765
- return true;
766
- }
767
- if (companies && Object.keys(companies).length < 2) return true;
768
- else return false;
769
- };
770
-
771
- const getItemsIdSingleChat = () => {
772
- const itemsId = {};
773
- if (Array.isArray(singleChat.items)) {
774
- singleChat.items.forEach((item) => {
775
- if (isValidNaturalNumber(item.id)) itemsId[item.id] = true;
776
- });
777
- }
778
- return itemsId;
779
- };
780
-
781
- const getChatCompany = () => {
782
- if (chatType === "merchant_product" || chatType === "ticket") {
783
- return undefined;
784
- }
785
- if (companies && companies[activeCompanyId]) {
786
- return {
787
- ...companies[activeCompanyId],
788
- id: activeCompanyId,
789
- };
790
- }
791
- return undefined;
792
- };
793
-
794
- const addOldItemsChat = (currentItems = [], newItems = []) => {
795
- let items = currentItems.slice();
796
- let itemsId = {};
797
- items.forEach((item) => {
798
- itemsId[item.id] = true;
799
- });
800
- newItems.forEach((item) => {
801
- if (!itemsId[item.id]) {
802
- items.push(item);
803
- itemsId[item.id] = true;
804
- }
805
- });
806
- return items;
807
- };
808
-
809
- const addNewItemsChat = (
810
- currentItems = [],
811
- newItems = [],
812
- fromUpdate = false
813
- ) => {
814
- let itemsId = {};
815
- currentItems.forEach((item) => {
816
- itemsId[item.id] = item;
817
- });
818
- let thereAreNewItems = false;
819
- newItems.forEach((newitem) => {
820
- if (!itemsId[newitem.id]) {
821
- itemsId[newitem.id] = newitem;
822
- thereAreNewItems = true;
823
- }
824
- });
825
- if (thereAreNewItems && fromUpdate) {
826
- setPlaySound(true);
827
- setTimeout(() => {
828
- setPlaySound(false);
829
- }, 5000);
830
- }
831
- if (chatType !== "ticket") {
832
- return Object.values(itemsId).sort((a, b) => {
833
- if (a.id > b.id) return 1;
834
- if (a.id < b.id) return -1;
835
- return 0;
836
- });
837
- } else {
838
- return Object.values(itemsId).reverse();
839
- }
840
- };
841
-
842
- const updateAllUsers = (newUsers = {}) => {
843
- let currentUsers = { ...allUsers };
844
- Object.keys(newUsers).forEach((userId) => {
845
- if (!currentUsers[userId]) {
846
- currentUsers[userId] = newUsers[userId];
847
- }
848
- });
849
- setAllUsers(currentUsers);
850
- };
851
-
852
- const renderBodyChat = () => {
853
- if (isLoading) return <Loading />;
854
- if (errorChat.existError) {
855
- return (
856
- <NotFound
857
- code={errorChat.code}
858
- message={errorChat.message}
859
- details={errorChat.errorDetail}
860
- />
861
- );
862
- }
863
- // cuando se quiere ver la lista de chats
864
- if (showChatsList) {
865
- return (
866
- <ChatLists
867
- companies={companies}
868
- currentCompanyId={currentUser?.companyId}
869
- onClickCompany={(companyIdSelected) => {
870
- setActiveCompanyId(Number(companyIdSelected));
871
- setShowChatsList(false);
872
- }}
873
- />
874
- );
875
- }
876
- // mostrar chat?
877
- let items;
878
- let enabledLoadMore;
879
- if (["merchant_product", "ticket", "product_status"].includes(chatType)) {
880
- items = singleChat.items;
881
- enabledLoadMore = singleChat.enabledLoadMore;
882
- }
883
- // ORDER_PRODUCT
884
- else if (companies) {
885
- // caso 0 chats
886
- if (Object.keys(companies).length === 0) {
887
- return (
888
- <div className="container-chatEmpty">
889
- <CustomIcon
890
- className="icon-chat"
891
- transparent
892
- size={35}
893
- icon={IconChat}
894
- type={"gray"}
895
- />
896
- <label>
897
- De acuerdo al estatus del producto, tu compañia no tiene
898
- disponible ningun chat abierto o cerrado
899
- </label>
900
- </div>
901
- );
902
- }
903
- // caso 1 o mas chats
904
- if (companies[activeCompanyId]) {
905
- items = companies[activeCompanyId].items;
906
- enabledLoadMore = companies[activeCompanyId].enabledLoadMore;
907
- }
908
- }
909
- if (items) {
910
- let containerItems = null;
911
- if (items.length) {
912
- containerItems = (
913
- <ContainerItems
914
- items={items}
915
- users={allUsers}
916
- showBtnLoadMore={enabledLoadMore}
917
- chatType={chatType}
918
- activeCompanyId={activeCompanyId}
919
- ticketCompany={ticketCompany}
920
- currentUser={
921
- ["merchant_product", "order_product", "product_status"].includes(
922
- chatType
923
- )
924
- ? currentUser
925
- : dataChat.currentUser
926
- }
927
- onClickBtnLoadMore={
928
- chatType === "merchant_product"
929
- ? getLoadMoreMerchantProduct
930
- : chatType === "order_product"
931
- ? getLoadMoreOrderProduct
932
- : getLoadMoreTicket
933
- }
934
- />
935
- );
936
- } else {
937
- containerItems = (
938
- <div className="container-chatEmpty">
939
- <CustomIcon
940
- className="icon-chat"
941
- size={35}
942
- icon={IconChat}
943
- type={"gray"}
944
- transparent
945
- />
946
- <label>Este chat no tiene mensajes</label>
947
- </div>
948
- );
949
- }
950
- return (
951
- <>
952
- {containerItems}
953
- <Footer
954
- chatType={chatType}
955
- dataChat={
956
- chatType === "merchant_product"
957
- ? { id: dataChat.id, version: dataChat.version }
958
- : chatType === "order_product"
959
- ? { id: dataChat.id, version: currentArticle.version }
960
- : chatType === "ticket"
961
- ? { id: dataChat.id }
962
- : chatType === "product_status"
963
- ? {
964
- id: dataChat.id,
965
- version: dataChat.version,
966
- retailerId: dataChat.retailerId,
967
- }
968
- : undefined
969
- }
970
- chatCompany={getChatCompany()}
971
- statusChat={
972
- chatType === "order_product"
973
- ? getChatCompany()?.statusChat
974
- : chatType === "ticket"
975
- ? singleChat.statusChat
976
- : undefined
977
- }
978
- messageDisabled={
979
- chatType === "order_product"
980
- ? `La conversación con ${getChatCompany()?.name} ha finalizado`
981
- : chatType === "ticket"
982
- ? "Ticket cerrado"
983
- : `La conversación ha finalizado`
984
- }
985
- createItemsChat={createItemsChat}
986
- errorUpdate={errorUpdate}
987
- />
988
- </>
989
- );
990
- }
991
- return <Loading />;
992
- };
993
-
994
- return (
995
- <>
996
- <Container>
997
- {/* header */}
998
- {(chatContainerType !== "fixed" || !isSingleChat()) && (
999
- <Header
1000
- showBtnClose={showBtnClose}
1001
- onClickBtnClose={onClickBtnClose}
1002
- showChatsList={showChatsList}
1003
- chatCompany={getChatCompany()}
1004
- multipleCompanies={!isSingleChat()}
1005
- onClickBtnChooseChat={() => {
1006
- setShowChatsList(true);
1007
- }}
1008
- />
1009
- )}
1010
- {/* body */}
1011
- {renderBodyChat()}
1012
- </Container>
1013
- <ReactHowler src={newMessage} playing={playSound} />
1014
- </>
1015
- );
1016
- };