contentoh-components-library 21.2.105 → 21.3.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 (248) hide show
  1. package/.env.development +5 -2
  2. package/.env.production +25 -25
  3. package/dist/assets/fonts/{roboto → Roboto}/LICENSE.txt +0 -0
  4. package/dist/assets/fonts/{roboto → Roboto}/Roboto-Black.ttf +0 -0
  5. package/dist/assets/fonts/{roboto → Roboto}/Roboto-BlackItalic.ttf +0 -0
  6. package/dist/assets/fonts/{roboto → Roboto}/Roboto-Bold.ttf +0 -0
  7. package/dist/assets/fonts/{roboto → Roboto}/Roboto-BoldItalic.ttf +0 -0
  8. package/dist/assets/fonts/{roboto → Roboto}/Roboto-Italic.ttf +0 -0
  9. package/dist/assets/fonts/{roboto → Roboto}/Roboto-Light.ttf +0 -0
  10. package/dist/assets/fonts/{roboto → Roboto}/Roboto-LightItalic.ttf +0 -0
  11. package/dist/assets/fonts/{roboto → Roboto}/Roboto-Medium.ttf +0 -0
  12. package/dist/assets/fonts/{roboto → Roboto}/Roboto-MediumItalic.ttf +0 -0
  13. package/dist/assets/fonts/{roboto → Roboto}/Roboto-Regular.ttf +0 -0
  14. package/dist/assets/fonts/{roboto → Roboto}/Roboto-Thin.ttf +0 -0
  15. package/dist/assets/fonts/{roboto → Roboto}/Roboto-ThinItalic.ttf +0 -0
  16. package/dist/assets/images/chatPopup/Spinner.gif +0 -0
  17. package/dist/assets/images/chatPopup/close.svg +3 -0
  18. package/dist/assets/images/chatPopup/defaultImage.png +0 -0
  19. package/dist/assets/images/chatPopup/defaultProfile.png +0 -0
  20. package/dist/assets/images/chatPopup/doc.svg +1 -0
  21. package/dist/assets/images/chatPopup/document.svg +1 -0
  22. package/dist/assets/images/chatPopup/iconChat.svg +19 -0
  23. package/dist/assets/images/chatPopup/iconPlus.svg +3 -0
  24. package/dist/assets/images/chatPopup/pdf.svg +75 -0
  25. package/dist/assets/images/chatPopup/remove.svg +4 -0
  26. package/dist/assets/images/chatPopup/send.svg +3 -0
  27. package/dist/assets/images/chatPopup/svgIcon.svg +109 -0
  28. package/dist/assets/images/chatPopup/upload_file.svg +3 -0
  29. package/dist/assets/images/chatPopup/xls.svg +53 -0
  30. package/dist/assets/images/customSelect/starIcon.svg +14 -0
  31. package/dist/assets/images/defaultImages/Spinner.gif +0 -0
  32. package/dist/assets/images/defaultImages/notFound.svg +124 -0
  33. package/dist/components/atoms/ButtonFileChooser/ButtonFileChooser.stories.js +72 -0
  34. package/dist/components/atoms/ButtonFileChooser/index.js +118 -0
  35. package/dist/components/atoms/ButtonFileChooser/styles.js +20 -0
  36. package/dist/components/atoms/ButtonV2/ButtonV2.stories.js +66 -0
  37. package/dist/components/atoms/ButtonV2/index.js +110 -0
  38. package/dist/components/atoms/ButtonV2/styles.js +53 -0
  39. package/dist/components/atoms/ChatPopUp/ChatPopUp.stories.js +28 -0
  40. package/dist/components/atoms/ChatPopUp/index.js +841 -0
  41. package/dist/components/atoms/ChatPopUp/styles.js +27 -0
  42. package/dist/components/atoms/ChatPopUp/utils/handlersChat.js +182 -0
  43. package/dist/components/atoms/CustomIcon/CustomIcon.stories.js +50 -0
  44. package/dist/components/atoms/CustomIcon/index.js +40 -0
  45. package/dist/components/atoms/CustomIcon/styles.js +33 -0
  46. package/dist/components/atoms/GeneralButton/index.js +2 -6
  47. package/dist/components/atoms/IconFile/IconFile.stories.js +48 -0
  48. package/dist/components/atoms/IconFile/index.js +249 -0
  49. package/dist/components/atoms/IconFile/styles.js +23 -0
  50. package/dist/components/atoms/Image/Image.stories.js +73 -0
  51. package/dist/components/atoms/Image/index.js +76 -0
  52. package/dist/components/atoms/Image/styles.js +43 -0
  53. package/dist/components/atoms/ImageLink/ImageLink.stories.js +63 -0
  54. package/dist/components/atoms/ImageLink/index.js +77 -0
  55. package/dist/components/atoms/ImageLink/styles.js +40 -0
  56. package/dist/components/atoms/ImagePreview/ImagePreview.stories.js +70 -0
  57. package/dist/components/atoms/ImagePreview/index.js +222 -0
  58. package/dist/components/atoms/ImagePreview/styles.js +44 -0
  59. package/dist/components/atoms/InputText/InputText.stories.js +60 -0
  60. package/dist/components/atoms/InputText/index.js +66 -0
  61. package/dist/components/atoms/InputText/styles.js +32 -0
  62. package/dist/components/atoms/NotFound/NotFound.stories.js +36 -0
  63. package/dist/components/atoms/NotFound/index.js +75 -0
  64. package/dist/components/atoms/NotFound/styles.js +20 -0
  65. package/dist/components/atoms/Select/VersionSelect.js +1 -2
  66. package/dist/components/atoms/SelectItemV2/SelectItemV2.stories.js +45 -0
  67. package/dist/components/atoms/SelectItemV2/index.js +57 -0
  68. package/dist/components/atoms/SelectItemV2/styles.js +30 -0
  69. package/dist/components/atoms/StatusTag/StatusTag.stories.js +48 -0
  70. package/dist/components/atoms/StatusTag/index.js +58 -0
  71. package/dist/components/atoms/StatusTag/styles.js +20 -0
  72. package/dist/components/atoms/Tooltip/Tooltip.stories.js +66 -0
  73. package/dist/components/atoms/Tooltip/index.js +72 -0
  74. package/dist/components/atoms/Tooltip/styles.js +20 -0
  75. package/dist/components/molecules/ButtonDownloadFile/DownloadFile.stories.js +66 -0
  76. package/dist/components/molecules/ButtonDownloadFile/index.js +179 -0
  77. package/dist/components/molecules/ButtonDownloadFile/styles.js +23 -0
  78. package/dist/components/molecules/CustomSelect/CustomSelect.stories.js +21 -22
  79. package/dist/components/molecules/CustomSelect/SelectItem.js +10 -1
  80. package/dist/components/molecules/Dropdown/Dropdown.stories.js +98 -0
  81. package/dist/components/molecules/Dropdown/index.js +150 -0
  82. package/dist/components/molecules/Dropdown/styles.js +26 -0
  83. package/dist/components/molecules/HeaderTop/index.js +10 -5
  84. package/dist/components/molecules/HeaderTop/styles.js +1 -1
  85. package/dist/components/molecules/ImageTooltip/ImageTooltip.stories.js +82 -0
  86. package/dist/components/molecules/ImageTooltip/index.js +85 -0
  87. package/dist/components/molecules/ImageTooltip/styles.js +33 -0
  88. package/dist/components/molecules/SelectV2/SelectV2.stories.js +119 -0
  89. package/dist/components/molecules/SelectV2/index.js +298 -0
  90. package/dist/components/molecules/SelectV2/styles.js +42 -0
  91. package/dist/components/organisms/Chat/Chat.stories.js +215 -0
  92. package/dist/components/organisms/Chat/ChatLists/ChatLists.stories.js +83 -0
  93. package/dist/components/organisms/Chat/ChatLists/index.js +160 -0
  94. package/dist/components/organisms/Chat/ChatLists/styles.js +29 -0
  95. package/dist/components/organisms/Chat/ContainerItems/ContainerItems.stories.js +176 -0
  96. package/dist/components/organisms/Chat/ContainerItems/index.js +569 -0
  97. package/dist/components/organisms/Chat/ContainerItems/styles.js +20 -0
  98. package/dist/components/organisms/Chat/ContentChat/ContentChat.stories.js +142 -0
  99. package/dist/components/organisms/Chat/ContentChat/index.js +1422 -0
  100. package/dist/components/organisms/Chat/ContentChat/styles.js +20 -0
  101. package/dist/components/organisms/Chat/Footer/Footer.stories.js +43 -0
  102. package/dist/components/organisms/Chat/Footer/index.js +984 -0
  103. package/dist/components/organisms/Chat/Footer/styles.js +32 -0
  104. package/dist/components/organisms/Chat/Header/Header.stories.js +96 -0
  105. package/dist/components/organisms/Chat/Header/index.js +84 -0
  106. package/dist/components/organisms/Chat/Header/styles.js +20 -0
  107. package/dist/components/organisms/Chat/index.js +327 -0
  108. package/dist/components/organisms/Chat/styles.js +29 -0
  109. package/dist/components/organisms/CreateVersion/RenderChilds.js +11 -11
  110. package/dist/components/organisms/CreateVersion/index.js +89 -30
  111. package/dist/components/organisms/Modal/Modal.stories.js +66 -0
  112. package/dist/components/organisms/Modal/index.js +95 -0
  113. package/dist/components/organisms/Modal/styles.js +20 -0
  114. package/dist/components/organisms/OrderDetail/OrderDetail.stories.js +1 -1
  115. package/dist/components/organisms/OrderDetail/index.js +11 -20
  116. package/dist/components/organisms/OrderDetail/styles.js +1 -1
  117. package/dist/components/organisms/OrderDetail/utils/Table/styles.js +1 -1
  118. package/dist/components/organisms/OrderDetail/utils/Table/utils.js +15 -45
  119. package/dist/components/organisms/RangeCalendar/RangeCalendar.stories.js +28 -0
  120. package/dist/components/organisms/RangeCalendar/index.js +140 -0
  121. package/dist/components/organisms/RangeCalendar/styles.js +27 -0
  122. package/dist/components/organisms/VersionSelector/index.js +2 -28
  123. package/dist/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +147 -69
  124. package/dist/components/pages/ProviderProductEdition/index.js +22 -2
  125. package/dist/components/pages/RegistrationLoginFirstStep/RegistrationLoginFirstStep.stories.js +37 -0
  126. package/dist/components/pages/RegistrationLoginFirstStep/index.js +269 -0
  127. package/dist/components/pages/RegistrationLoginFirstStep/styles.js +20 -0
  128. package/dist/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +67 -77
  129. package/dist/components/pages/RetailerProductEdition/index.js +24 -5
  130. package/dist/global-files/fonts.css +15 -3
  131. package/dist/global-files/handle_http.js +383 -0
  132. package/dist/global-files/utils.js +472 -0
  133. package/dist/global-files/variables.js +2 -0
  134. package/dist/index.js +267 -46
  135. package/package.json +12 -1
  136. package/src/assets/fonts/{roboto → Roboto}/LICENSE.txt +0 -0
  137. package/src/assets/fonts/{roboto → Roboto}/Roboto-Black.ttf +0 -0
  138. package/src/assets/fonts/{roboto → Roboto}/Roboto-BlackItalic.ttf +0 -0
  139. package/src/assets/fonts/{roboto → Roboto}/Roboto-Bold.ttf +0 -0
  140. package/src/assets/fonts/{roboto → Roboto}/Roboto-BoldItalic.ttf +0 -0
  141. package/src/assets/fonts/{roboto → Roboto}/Roboto-Italic.ttf +0 -0
  142. package/src/assets/fonts/{roboto → Roboto}/Roboto-Light.ttf +0 -0
  143. package/src/assets/fonts/{roboto → Roboto}/Roboto-LightItalic.ttf +0 -0
  144. package/src/assets/fonts/{roboto → Roboto}/Roboto-Medium.ttf +0 -0
  145. package/src/assets/fonts/{roboto → Roboto}/Roboto-MediumItalic.ttf +0 -0
  146. package/src/assets/fonts/{roboto → Roboto}/Roboto-Regular.ttf +0 -0
  147. package/src/assets/fonts/{roboto → Roboto}/Roboto-Thin.ttf +0 -0
  148. package/src/assets/fonts/{roboto → Roboto}/Roboto-ThinItalic.ttf +0 -0
  149. package/src/assets/images/customSelect/starIcon.svg +14 -0
  150. package/src/assets/images/defaultImages/Spinner.gif +0 -0
  151. package/src/assets/images/defaultImages/notFound.svg +124 -0
  152. package/src/components/atoms/ButtonFileChooser/ButtonFileChooser.stories.js +47 -0
  153. package/src/components/atoms/ButtonFileChooser/index.js +69 -0
  154. package/src/components/atoms/ButtonFileChooser/styles.js +4 -0
  155. package/src/components/atoms/ButtonV2/ButtonV2.stories.js +53 -0
  156. package/src/components/atoms/ButtonV2/index.js +85 -0
  157. package/src/components/atoms/ButtonV2/styles.js +217 -0
  158. package/src/components/atoms/CustomIcon/CustomIcon.stories.js +36 -0
  159. package/src/components/atoms/CustomIcon/index.js +41 -0
  160. package/src/components/atoms/CustomIcon/styles.js +85 -0
  161. package/src/components/atoms/GeneralButton/index.js +1 -4
  162. package/src/components/atoms/IconFile/IconFile.stories.js +35 -0
  163. package/src/components/atoms/IconFile/index.js +119 -0
  164. package/src/components/atoms/IconFile/styles.js +67 -0
  165. package/src/components/atoms/Image/Image.stories.js +51 -0
  166. package/src/components/atoms/Image/index.js +55 -0
  167. package/src/components/atoms/Image/styles.js +34 -0
  168. package/src/components/atoms/ImageLink/ImageLink.stories.js +43 -0
  169. package/src/components/atoms/ImageLink/index.js +57 -0
  170. package/src/components/atoms/ImageLink/styles.js +30 -0
  171. package/src/components/atoms/ImagePreview/ImagePreview.stories.js +52 -0
  172. package/src/components/atoms/ImagePreview/index.js +191 -0
  173. package/src/components/atoms/ImagePreview/styles.js +77 -0
  174. package/src/components/atoms/InputText/InputText.stories.js +39 -0
  175. package/src/components/atoms/InputText/index.js +61 -0
  176. package/src/components/atoms/InputText/styles.js +89 -0
  177. package/src/components/atoms/NotFound/NotFound.stories.js +19 -0
  178. package/src/components/atoms/NotFound/index.js +52 -0
  179. package/src/components/atoms/NotFound/styles.js +55 -0
  180. package/src/components/atoms/Select/VersionSelect.js +2 -4
  181. package/src/components/atoms/SelectItemV2/SelectItemV2.stories.js +26 -0
  182. package/src/components/atoms/SelectItemV2/index.js +61 -0
  183. package/src/components/atoms/SelectItemV2/styles.js +90 -0
  184. package/src/components/atoms/Tooltip/Tooltip.stories.js +51 -0
  185. package/src/components/atoms/Tooltip/index.js +59 -0
  186. package/src/components/atoms/Tooltip/styles.js +42 -0
  187. package/src/components/molecules/ButtonDownloadFile/DownloadFile.stories.js +54 -0
  188. package/src/components/molecules/ButtonDownloadFile/index.js +111 -0
  189. package/src/components/molecules/ButtonDownloadFile/styles.js +66 -0
  190. package/src/components/molecules/CustomSelect/CustomSelect.stories.js +20 -12
  191. package/src/components/molecules/CustomSelect/SelectItem.js +7 -0
  192. package/src/components/molecules/Dropdown/Dropdown.stories.js +103 -0
  193. package/src/components/molecules/Dropdown/index.js +150 -0
  194. package/src/components/molecules/Dropdown/styles.js +75 -0
  195. package/src/components/molecules/HeaderTop/index.js +11 -6
  196. package/src/components/molecules/HeaderTop/styles.js +4 -0
  197. package/src/components/molecules/ImageTooltip/ImageTooltip.stories.js +68 -0
  198. package/src/components/molecules/ImageTooltip/index.js +63 -0
  199. package/src/components/molecules/ImageTooltip/styles.js +18 -0
  200. package/src/components/molecules/SelectV2/SelectV2.stories.js +114 -0
  201. package/src/components/molecules/SelectV2/index.js +335 -0
  202. package/src/components/molecules/SelectV2/styles.js +105 -0
  203. package/src/components/organisms/Chat/Chat.stories.js +199 -0
  204. package/src/components/organisms/Chat/ChatLists/ChatLists.stories.js +65 -0
  205. package/src/components/organisms/Chat/ChatLists/Rotoplas.jpeg +0 -0
  206. package/src/components/organisms/Chat/ChatLists/THD.png +0 -0
  207. package/src/components/organisms/Chat/ChatLists/index.js +141 -0
  208. package/src/components/organisms/Chat/ChatLists/styles.js +162 -0
  209. package/src/components/organisms/Chat/ContainerItems/ContainerItems.stories.js +142 -0
  210. package/src/components/organisms/Chat/ContainerItems/index.js +549 -0
  211. package/src/components/organisms/Chat/ContainerItems/styles.js +328 -0
  212. package/src/components/organisms/Chat/ContentChat/ContentChat.stories.js +102 -0
  213. package/src/components/organisms/Chat/ContentChat/Rotoplas.jpeg +0 -0
  214. package/src/components/organisms/Chat/ContentChat/THD.png +0 -0
  215. package/src/components/organisms/Chat/ContentChat/index.js +900 -0
  216. package/src/components/organisms/Chat/ContentChat/styles.js +41 -0
  217. package/src/components/organisms/Chat/Footer/Footer.stories.js +22 -0
  218. package/src/components/organisms/Chat/Footer/index.js +669 -0
  219. package/src/components/organisms/Chat/Footer/styles.js +286 -0
  220. package/src/components/organisms/Chat/Header/Header.stories.js +66 -0
  221. package/src/components/organisms/Chat/Header/index.js +94 -0
  222. package/src/components/organisms/Chat/Header/styles.js +49 -0
  223. package/src/components/organisms/Chat/index.js +294 -0
  224. package/src/components/organisms/Chat/styles.js +42 -0
  225. package/src/components/organisms/CreateVersion/RenderChilds.js +34 -28
  226. package/src/components/organisms/CreateVersion/index.js +36 -16
  227. package/src/components/organisms/Modal/Modal.stories.js +55 -0
  228. package/src/components/organisms/Modal/index.js +97 -0
  229. package/src/components/organisms/Modal/styles.js +103 -0
  230. package/src/components/organisms/OrderDetail/OrderDetail.stories.js +1 -1
  231. package/src/components/organisms/OrderDetail/index.js +12 -19
  232. package/src/components/organisms/OrderDetail/styles.js +0 -1
  233. package/src/components/organisms/OrderDetail/utils/Table/styles.js +0 -26
  234. package/src/components/organisms/OrderDetail/utils/Table/utils.js +15 -30
  235. package/src/components/organisms/RangeCalendar/RangeCalendar.stories.js +11 -0
  236. package/src/components/organisms/RangeCalendar/index.js +117 -0
  237. package/src/components/organisms/RangeCalendar/styles.js +883 -0
  238. package/src/components/organisms/VersionSelector/index.js +3 -18
  239. package/src/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +166 -75
  240. package/src/components/pages/ProviderProductEdition/index.js +21 -2
  241. package/src/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +67 -79
  242. package/src/components/pages/RetailerProductEdition/index.js +14 -2
  243. package/src/global-files/customHooks.js +2 -2
  244. package/src/global-files/fonts.css +15 -3
  245. package/src/global-files/handle_http.js +231 -0
  246. package/src/global-files/utils.js +300 -0
  247. package/src/global-files/variables.js +2 -0
  248. package/src/index.js +17 -0
@@ -0,0 +1,900 @@
1
+ import { Container, ContainerError } from "./styles";
2
+ import { useEffect, useState } from "react";
3
+ import { Tooltip } from "../../../atoms/Tooltip";
4
+ import { NotFound } from "../../../atoms/NotFound";
5
+ import { ButtonV2 } from "../../../atoms/ButtonV2";
6
+ import { Header } from "../Header";
7
+ import {
8
+ faComments as IconChat,
9
+ faExclamationTriangle as IconWarning,
10
+ } from "@fortawesome/free-solid-svg-icons";
11
+ import { Loading } from "../../../atoms/Loading";
12
+ import { ContainerItems } from "../ContainerItems";
13
+ import { Footer } from "../Footer";
14
+ import { ChatLists } from "../ChatLists";
15
+ import { CustomIcon } from "../../../atoms/CustomIcon";
16
+ import { fetchGET, fetchPOST } from "../../../../global-files/handle_http";
17
+ import { Modal } from "../../Modal";
18
+ import { isStringEmpty } from "../../../../global-files/utils";
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
+ } = props;
28
+ const [companies, setCompanies] = useState({}); /* {
29
+ companyId: {
30
+ name: string,
31
+ statusChat: string => current | open | closed
32
+ items: [{..}] ,
33
+ enabledLoadMore: boolean
34
+ },
35
+ ...
36
+ } chat orderProduct */
37
+ const [singleChat, setSingleChat] = useState({
38
+ items: undefined,
39
+ enabledLoadMore: false,
40
+ statusChat: undefined,
41
+ }); // chat merchantProduct o ticket
42
+ const [activeCompanyId, setActiveCompanyId] = useState(); // number
43
+ const [allUsers, setAllUsers] = useState({}); // {...}
44
+ const [currentUser, setCurrentUser] = useState({
45
+ id: undefined,
46
+ companyId: undefined,
47
+ });
48
+ const [currentArticle, setCurrentArticle] = useState({
49
+ status: undefined,
50
+ version: undefined,
51
+ });
52
+ const [lastUpdateDate, setLastUpdateDate] = useState(); // string
53
+ const [isLoading, setIsLoading] = useState(true); // boolean
54
+ const [showChatsList, setShowChatsList] = useState(false); // boolean
55
+ const [processUpdateID, setProcessUpdateID] = useState(); // number
56
+ const [startUpdate, setStartUpdate] = useState(0); // number
57
+ const [runUpdate, setRunUpdate] = useState(0); // number
58
+ const [errorChat, setErrorChat] = useState({
59
+ existError: false,
60
+ code: undefined,
61
+ message: undefined,
62
+ errorDetail: undefined,
63
+ });
64
+ const [errorUpdate, setErrorUpdate] = useState({
65
+ startDate: undefined, // Date()
66
+ lastDate: undefined, // Date()
67
+ });
68
+
69
+ // matar update al desmontar el componente del chat
70
+ useEffect(() => {
71
+ return () => {
72
+ console.log("componente chat desmontado");
73
+ if (processUpdateID !== undefined) clearTimeout(processUpdateID);
74
+ };
75
+ }, []);
76
+ // al cargar el componente
77
+ useEffect(() => {
78
+ if (dataChat) {
79
+ stopUpdate();
80
+ if (dataChat.code) {
81
+ setErrorChat({
82
+ existError: true,
83
+ code: dataChat.code,
84
+ message: dataChat.message,
85
+ errorDetail: dataChat.errorDetail,
86
+ });
87
+ setIsLoading(false);
88
+ return;
89
+ }
90
+ if (chatType === "merchant_product") getInitialMerchantProduct();
91
+ else if (chatType === "order_product") getInitialOrderProduct();
92
+ else getInitialTicket();
93
+ }
94
+ }, [dataChat]);
95
+
96
+ // comenzar temporizador del update de 30s
97
+ useEffect(() => {
98
+ //return; -- descomentarizar para hacer pruebas sin update
99
+ if (startUpdate == 0) return;
100
+ console.log(`START UPDATE en 30s`);
101
+ const processID = setTimeout(() => {
102
+ setRunUpdate((prev) => prev + 1);
103
+ }, 30000);
104
+ setProcessUpdateID(processID);
105
+ }, [startUpdate]);
106
+
107
+ // ejecutar update
108
+ useEffect(() => {
109
+ if (runUpdate == 0) return;
110
+ if (chatType === "merchant_product") {
111
+ if (singleChat.items) getUpdateLatestMerchantProduct();
112
+ else getInitialMerchantProduct();
113
+ } else if (chatType === "order_product") {
114
+ if (companies) getUpdateLatestOrderProduct();
115
+ else getInitialOrderProduct();
116
+ } else {
117
+ if (singleChat.items) getUpdateLatestTicket();
118
+ else getInitialTicket();
119
+ }
120
+ }, [runUpdate]);
121
+
122
+ /*=======================================================================
123
+ PETICION GET INICIAL SEGUN EL TIPO DE CHAT
124
+ ======================================================================= */
125
+ const getInitialMerchantProduct = async () => {
126
+ const paramsQuery = {
127
+ getType: "initial",
128
+ id: JSON.stringify(dataChat.id),
129
+ version: JSON.stringify(dataChat.version),
130
+ };
131
+ const paramsHeaders = { Authorization: dataChat.userToken };
132
+ const response = await fetchGET(
133
+ process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
134
+ paramsQuery,
135
+ paramsHeaders
136
+ );
137
+ if (!response.body) {
138
+ setErrorChat({
139
+ existError: true,
140
+ code: 400,
141
+ message: response.message,
142
+ errorDetail: response.errorDetail,
143
+ });
144
+ setIsLoading(false);
145
+ return;
146
+ }
147
+ // success
148
+ console.log(response.body);
149
+ setCurrentUser({
150
+ id: response.body.data.currentUserId,
151
+ companyId: response.body.data.currentCompanyId,
152
+ });
153
+ setLastUpdateDate(response.body.data.lastUpdateDate);
154
+ setAllUsers(response.body.users);
155
+ setSingleChat({
156
+ items: response.body.items,
157
+ enabledLoadMore: response.body.items.length === 50,
158
+ });
159
+ setErrorChat({ existError: false });
160
+ setIsLoading(false);
161
+ };
162
+
163
+ const getInitialOrderProduct = async () => {
164
+ clearTimeout(processUpdateID); // finalizamos el temporizador
165
+ const paramsQuery = {
166
+ getType: "initial",
167
+ id: JSON.stringify(dataChat.id),
168
+ orderId: JSON.stringify(dataChat.orderId),
169
+ retailerId: JSON.stringify(dataChat.retailerId),
170
+ };
171
+ const paramsHeaders = { Authorization: dataChat.userToken };
172
+ const response = await fetchGET(
173
+ process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
174
+ paramsQuery,
175
+ paramsHeaders
176
+ );
177
+ setStartUpdate((prev) => prev + 1); // TEMPORAL
178
+ if (!response.body) {
179
+ setErrorChat({
180
+ existError: true,
181
+ code: 400,
182
+ message: response.message,
183
+ errorDetail: response.errorDetail,
184
+ });
185
+ setIsLoading(false);
186
+ return;
187
+ }
188
+ // success
189
+ console.log(response.body);
190
+ setCurrentUser({
191
+ id: response.body.data.currentUserId,
192
+ companyId: response.body.data.currentCompanyId,
193
+ });
194
+ setLastUpdateDate(response.body.data.lastUpdateDate);
195
+ setCurrentArticle({
196
+ status: response.body.data.status,
197
+ version: response.body.data.version,
198
+ });
199
+ setAllUsers(response.body.users);
200
+ const companiesList = response.body.companies;
201
+ const companiesIdList = Object.keys(companiesList);
202
+ let companyActive;
203
+ // encontrar el chat inicial a cargar y si se debe permitir cargar mas
204
+ for (const companyId of companiesIdList) {
205
+ if (companiesList[companyId].items.length < 50) {
206
+ companiesList[companyId].enabledLoadMore = false;
207
+ } else {
208
+ companiesList[companyId].enabledLoadMore = true;
209
+ }
210
+
211
+ if (companiesList[companyId].statusChat === "current") {
212
+ companyActive = Number(companyId);
213
+ }
214
+ }
215
+ if (!companyActive && companiesIdList.length) {
216
+ companyActive = Number(companiesIdList[0]);
217
+ }
218
+ //console.log("companies: ", companiesList);
219
+ //console.log("companyActive: ", companyActive);
220
+ setCompanies(companiesList);
221
+ if (companyActive) setActiveCompanyId(companyActive);
222
+ setErrorChat({ existError: false });
223
+ setIsLoading(false);
224
+ };
225
+
226
+ const getInitialTicket = async () => {
227
+ console.log("======== INITIAL chat =======");
228
+ stopUpdate(); // finalizamos el temporizador
229
+ const paramsQuery = {
230
+ getType: "initial",
231
+ id: JSON.stringify(dataChat.id),
232
+ isUserTech: JSON.stringify(dataChat.currentUser.isUserTech),
233
+ };
234
+ const response = await fetchGET(
235
+ process.env.REACT_APP_TICKETS_CHAT_ENDPOINT,
236
+ paramsQuery
237
+ );
238
+ // programar update en 30s
239
+ setStartUpdate((prev) => prev + 1);
240
+ if (!response.body) {
241
+ setErrorChat({
242
+ existError: true,
243
+ code: 400,
244
+ message: response.message,
245
+ errorDetail: response.errorDetail,
246
+ });
247
+ setIsLoading(false);
248
+ return;
249
+ }
250
+ // success
251
+ console.log(response.body);
252
+ setLastUpdateDate(response.body.data.lastUpdateDate);
253
+ setAllUsers(response.body.users);
254
+ setSingleChat({
255
+ items: response.body.items,
256
+ enabledLoadMore: response.body.items.length === 50,
257
+ statusChat: dataChat.statusChat,
258
+ });
259
+ setErrorChat({ existError: false });
260
+ setIsLoading(false);
261
+ };
262
+
263
+ /*=======================================================================
264
+ PETICION GET LOAD_MORE SEGUN EL TIPO DE CHAT
265
+ ======================================================================= */
266
+ const getLoadMoreMerchantProduct = async () => {
267
+ clearTimeout(processUpdateID); // finalizamos el temporizador
268
+ let date = singleChat.items[singleChat.items.length - 1].date;
269
+ const paramsQuery = {
270
+ getType: "loadMore",
271
+ id: JSON.stringify(dataChat.id),
272
+ version: JSON.stringify(dataChat.version),
273
+ date: encodeURIComponent(date),
274
+ };
275
+ const response = await fetchGET(
276
+ process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
277
+ paramsQuery
278
+ );
279
+ //setStartUpdate((prev) => prev + 1); // comendar un nuevo temporizador
280
+ if (!response.body) {
281
+ return {
282
+ title: response.message,
283
+ message: response.errorDetail,
284
+ };
285
+ }
286
+ // success
287
+ console.log(response.body);
288
+ // actualizar la lista de los users
289
+ updateAllUsers(response.body.users);
290
+ // actualizar los items del chat
291
+ let newSingleChat = { ...singleChat };
292
+ newSingleChat.items = addOldItemsChat(
293
+ newSingleChat.items,
294
+ response.body.items
295
+ );
296
+ newSingleChat.enabledLoadMore = response.body.items.length === 50;
297
+ setSingleChat(newSingleChat);
298
+ };
299
+
300
+ const getLoadMoreOrderProduct = async () => {
301
+ clearTimeout(processUpdateID); // finalizamos el temporizador
302
+ let company = companies[activeCompanyId];
303
+ let date = company.items[company.items.length - 1].date;
304
+ const paramsQuery = {
305
+ getType: "loadMore",
306
+ id: JSON.stringify(dataChat.id),
307
+ orderId: JSON.stringify(dataChat.orderId),
308
+ version: JSON.stringify(currentArticle.version),
309
+ currentCompanyId: JSON.stringify(currentUser.companyId),
310
+ date: encodeURIComponent(date),
311
+ othersCompanyId: JSON.stringify([activeCompanyId]),
312
+ };
313
+ const response = await fetchGET(
314
+ process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
315
+ paramsQuery
316
+ );
317
+ //setStartUpdate((prev) => prev + 1); // comendar un nuevo temporizador
318
+ if (!response.body) {
319
+ return {
320
+ title: response.message,
321
+ message: response.errorDetail,
322
+ };
323
+ }
324
+ // success
325
+ console.log(response.body);
326
+ // actualizar la lista de los users
327
+ updateAllUsers(response.body.users);
328
+ // actualizar los items del chat y la lista de users
329
+ company.items = addOldItemsChat(company.items, response.body.items);
330
+ company.enabledLoadMore = response.body.items.length === 50;
331
+ setCompanies((prev) => ({
332
+ ...prev,
333
+ [activeCompanyId]: company,
334
+ }));
335
+ };
336
+
337
+ // este GET obtiene la lista de compañoas con las que se puede chatear
338
+ const getLoadMoreTicket = async () => {
339
+ console.log("======== LOAD MORE chat =======");
340
+ stopUpdate(); // finalizamos el temporizador
341
+ let date = singleChat.items[singleChat.items.length - 1].date;
342
+ const paramsQuery = {
343
+ getType: "loadMore",
344
+ id: JSON.stringify(dataChat.id),
345
+ date: encodeURIComponent(date),
346
+ isUserTech: JSON.stringify(dataChat.currentUser.isUserTech),
347
+ };
348
+ const response = await fetchGET(
349
+ process.env.REACT_APP_TICKETS_CHAT_ENDPOINT,
350
+ paramsQuery
351
+ );
352
+ //programar update en 30s
353
+ setStartUpdate((prev) => prev + 1);
354
+ if (!response.body) {
355
+ return {
356
+ title: response.message,
357
+ message: response.errorDetail,
358
+ };
359
+ }
360
+ // success
361
+ console.log(response.body);
362
+ // actualizar la lista de los users
363
+ updateAllUsers(response.body.users);
364
+ // actualizar los items del chat
365
+ let newSingleChat = { ...singleChat };
366
+ newSingleChat.items = addOldItemsChat(
367
+ newSingleChat.items,
368
+ response.body.items
369
+ );
370
+ newSingleChat.enabledLoadMore = response.body.items.length === 50;
371
+ setSingleChat(newSingleChat);
372
+ };
373
+
374
+ /*=======================================================================
375
+ PETICION GET UPDATE_LATEST SEGUN EL TIPO DE CHAT
376
+ ======================================================================= */
377
+ const getUpdateLatestMerchantProduct = async () => {
378
+ console.log(lastUpdateDate);
379
+ const paramsQuery = {
380
+ getType: "updateLatest",
381
+ id: JSON.stringify(dataChat.id),
382
+ version: JSON.stringify(dataChat.version),
383
+ date: encodeURIComponent(lastUpdateDate),
384
+ };
385
+ const response = await fetchGET(
386
+ process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
387
+ paramsQuery
388
+ );
389
+ if (!response.body) {
390
+ console.log("ERROR updateLatest:", {
391
+ message: response.message,
392
+ errorDetail: response.errorDetail,
393
+ });
394
+ return;
395
+ }
396
+ // success
397
+ console.log(response.body);
398
+ setLastUpdateDate(response.body.data.lastUpdateDate);
399
+ // actualizar la lista de los users
400
+ updateAllUsers(response.body.users);
401
+ // actualizar los items del chat
402
+ let newSingleChat = { ...singleChat };
403
+ newSingleChat.items = addNewItemsChat(
404
+ newSingleChat.items,
405
+ response.body.items
406
+ );
407
+ setSingleChat(newSingleChat);
408
+ };
409
+
410
+ const getUpdateLatestOrderProduct = async () => {
411
+ console.log(lastUpdateDate);
412
+ const paramsQuery = {
413
+ getType: "updateLatest",
414
+ id: JSON.stringify(dataChat.id),
415
+ orderId: JSON.stringify(dataChat.orderId),
416
+ retailerId: JSON.stringify(dataChat.retailerId),
417
+ version: JSON.stringify(currentArticle.version),
418
+ status: currentArticle.status,
419
+ currentCompanyId: JSON.stringify(currentUser.companyId),
420
+ othersCompanyId: encodeURIComponent(
421
+ JSON.stringify(Object.keys(companies))
422
+ ),
423
+ date: encodeURIComponent(lastUpdateDate),
424
+ };
425
+ const response = await fetchGET(
426
+ process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
427
+ paramsQuery
428
+ );
429
+ if (!response.body) {
430
+ console.log("ERROR update: ", {
431
+ message: response.message,
432
+ errorDetail: response.errorDetail,
433
+ });
434
+ return;
435
+ }
436
+ // success
437
+ console.log(response.body);
438
+
439
+ // cuando cambie la lista de chats por un cambio de version o estatus
440
+ if (response.body.data.status) {
441
+ setIsLoading(true);
442
+ setTimeout(() => {
443
+ setLastUpdateDate(response.body.data.lastUpdateDate);
444
+ setCurrentArticle({
445
+ status: response.body.data.status,
446
+ version: response.body.data.version,
447
+ });
448
+ setAllUsers(response.body.users);
449
+ const companiesList = response.body.companies;
450
+ const companiesIdList = Object.keys(companiesList);
451
+ let companyActive;
452
+ // encontrar el chat inicial a cargar y si se debe permitir cargar mas
453
+ for (const companyId of companiesIdList) {
454
+ if (companiesList[companyId].items.length < 50) {
455
+ companiesList[companyId].enabledLoadMore = false;
456
+ } else {
457
+ companiesList[companyId].enabledLoadMore = true;
458
+ }
459
+
460
+ if (companiesList[companyId].statusChat === "current") {
461
+ companyActive = Number(companyId);
462
+ }
463
+ }
464
+ if (!companyActive && companiesIdList.length) {
465
+ companyActive = Number(companiesIdList[0]);
466
+ }
467
+ //console.log("new companies: ", companiesList);
468
+ //console.log("new companyActive: ", companyActive);
469
+ setCompanies(companiesList);
470
+ if (companyActive) setActiveCompanyId(companyActive);
471
+ setErrorChat({ existError: false });
472
+ setIsLoading(false);
473
+ }, 2000);
474
+ }
475
+ // cuando se hizo un update de los mismos chats
476
+ else {
477
+ setLastUpdateDate(response.body.data.lastUpdateDate);
478
+ // actualizar la lista de los users
479
+ updateAllUsers(response.body.users);
480
+ // actualizar los items de los chats
481
+ let companiesList = { ...companies };
482
+ Object.keys(response.body.companies).forEach((companyId) => {
483
+ companiesList[companyId].items = addNewItemsChat(
484
+ companiesList[companyId].items,
485
+ response.body.companies[companyId].items
486
+ );
487
+ });
488
+ //console.log("new items companies: ", companiesList);
489
+ setCompanies(companiesList);
490
+ }
491
+ };
492
+
493
+ const getUpdateLatestTicket = async () => {
494
+ console.log("======== UPDATE chat =======");
495
+ console.log("lastUpdate:", lastUpdateDate);
496
+ const paramsQuery = {
497
+ getType: "updateLatest",
498
+ id: JSON.stringify(dataChat.id),
499
+ date: encodeURIComponent(lastUpdateDate),
500
+ isUserTech: JSON.stringify(dataChat.currentUser.isUserTech),
501
+ };
502
+ const response = await fetchGET(
503
+ process.env.REACT_APP_TICKETS_CHAT_ENDPOINT,
504
+ paramsQuery
505
+ );
506
+ //programar update en 30s
507
+ setStartUpdate((prev) => prev + 1);
508
+ if (!response.body) {
509
+ if (errorUpdate.startDate) {
510
+ setErrorUpdate((prev) => ({
511
+ ...prev,
512
+ lastDate: new Date(),
513
+ }));
514
+ } else {
515
+ setErrorUpdate((prev) => ({
516
+ startDate: new Date(),
517
+ }));
518
+ }
519
+ console.log("ERROR updateLatest:", {
520
+ message: response.message,
521
+ errorDetail: response.errorDetail,
522
+ });
523
+ return;
524
+ }
525
+ // limpiar error update
526
+ if (errorUpdate.startDate) {
527
+ setErrorUpdate({});
528
+ }
529
+ // success
530
+ console.log(response.body);
531
+ setLastUpdateDate(response.body.data.lastUpdateDate);
532
+ // actualizar la lista de los users
533
+ updateAllUsers(response.body.users);
534
+ // actualizar los items del chat
535
+ let newSingleChat = { ...singleChat };
536
+ newSingleChat.items = addNewItemsChat(
537
+ newSingleChat.items,
538
+ response.body.items
539
+ );
540
+ newSingleChat.statusChat = response.body.data.statusChat;
541
+ setSingleChat(newSingleChat);
542
+ };
543
+
544
+ /*=======================================================================
545
+ FUNCION QUE EJECUTA EL MICROSERVICIO CREATE-ITEM
546
+ Este metodo recibe los items que queremos agregar al chat.
547
+ requiere:
548
+ => items: [ { type , value } , ... ]
549
+ NOTA: si se quiere agregar un mensaje mandar un array con un object
550
+ example: [ {
551
+ type: "message" ,
552
+ value: "mi mensaje"
553
+ } ]
554
+ ======================================================================= */
555
+ const createItemsChat = async (items = []) => {
556
+ if (items.length === 0) {
557
+ return {
558
+ message:
559
+ "No se especifico ningun mensaje, imagen o archivo nuevo " +
560
+ "que se quiera enviar al chat",
561
+ errorDetail: "Reporta esto a TI",
562
+ };
563
+ }
564
+ for (const item of items) {
565
+ if (!["message", "img", "file"].includes(item.type)) {
566
+ return {
567
+ message:
568
+ "Uno de los elementos que se quiere enviar al chat " +
569
+ `no es un tipo valido "${item.type}"`,
570
+ errorDetail: "Reporta esto a TI",
571
+ };
572
+ }
573
+ if (isStringEmpty(item.value)) {
574
+ return {
575
+ message:
576
+ "Uno de los elementos que se quiere enviar al chat " +
577
+ `contiene un valor vacio`,
578
+ errorDetail: "Reporta esto a TI",
579
+ };
580
+ }
581
+ }
582
+ console.log("======= create items ========");
583
+ console.log("items a enviar:", items);
584
+ let errorCreate;
585
+ stopUpdate(); // finalizamos el temporizador
586
+
587
+ // enviar items a la BD
588
+ if (chatType === "merchant_product") {
589
+ errorCreate = await createItemsMerchantProduct(items);
590
+ } else if (chatType === "order_product") {
591
+ errorCreate = await createItemsOrderProduct(items);
592
+ } else errorCreate = await createItemsTicket(items);
593
+
594
+ // actualizar chat para que aparezcan los items enviados
595
+ if (chatType === "merchant_product") {
596
+ await getUpdateLatestMerchantProduct();
597
+ } else if (chatType === "order_product") {
598
+ await getUpdateLatestOrderProduct();
599
+ } else await getUpdateLatestTicket();
600
+
601
+ // cuando no se pudieron guardar los items
602
+ if (errorCreate) {
603
+ return errorCreate;
604
+ }
605
+ };
606
+
607
+ const createItemsMerchantProduct = async (items = []) => {
608
+ console.log("create items merchants");
609
+ const paramsBody = {
610
+ id: JSON.stringify(dataChat.id),
611
+ version: JSON.stringify(dataChat.version),
612
+ userId: JSON.stringify(currentUser.id),
613
+ items: JSON.stringify(items),
614
+ };
615
+ const response = await fetchPOST(
616
+ process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
617
+ paramsBody
618
+ );
619
+ if (!response.body) {
620
+ return {
621
+ message: response.message,
622
+ errorDetail: response.errorDetail,
623
+ };
624
+ }
625
+ };
626
+
627
+ const createItemsOrderProduct = async (items = []) => {
628
+ console.log("create items order");
629
+ const paramsBody = {
630
+ id: JSON.stringify(dataChat.id),
631
+ version: JSON.stringify(currentArticle.version),
632
+ userId: JSON.stringify(currentUser.id),
633
+ items: JSON.stringify(items),
634
+ orderId: JSON.stringify(dataChat.orderId),
635
+ sentCompanyId: JSON.stringify(currentUser.companyId),
636
+ receivedCompanyId: JSON.stringify(activeCompanyId),
637
+ };
638
+ console.log(paramsBody);
639
+ const response = await fetchPOST(
640
+ process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT,
641
+ paramsBody
642
+ );
643
+ if (!response.body) {
644
+ return {
645
+ message: response.message,
646
+ errorDetail: response.errorDetail,
647
+ };
648
+ }
649
+ };
650
+
651
+ const createItemsTicket = async (items = []) => {
652
+ const paramsBody = {
653
+ id: JSON.stringify(dataChat.id),
654
+ userId: JSON.stringify(dataChat.currentUser.id),
655
+ items: JSON.stringify(items),
656
+ };
657
+ const response = await fetchPOST(
658
+ process.env.REACT_APP_TICKETS_CHAT_ENDPOINT,
659
+ paramsBody
660
+ );
661
+ if (!response.body) {
662
+ return {
663
+ message: response.message,
664
+ errorDetail: response.errorDetail,
665
+ };
666
+ }
667
+ };
668
+
669
+ /*=======================================================================
670
+ SECCION DE FUNCIONES
671
+ ======================================================================= */
672
+ const isSingleChat = () => {
673
+ if (chatType === "merchant_product" || chatType === "ticket") {
674
+ return true;
675
+ }
676
+ if (companies && Object.keys(companies).length < 2) return true;
677
+ else return false;
678
+ };
679
+
680
+ const getChatCompany = () => {
681
+ if (chatType === "merchant_product" || chatType === "ticket") {
682
+ return undefined;
683
+ }
684
+ if (companies && companies[activeCompanyId]) {
685
+ return {
686
+ ...companies[activeCompanyId],
687
+ id: activeCompanyId,
688
+ };
689
+ }
690
+ return undefined;
691
+ };
692
+
693
+ const addOldItemsChat = (currentItems = [], newItems = []) => {
694
+ let items = currentItems.slice();
695
+ let itemsId = {};
696
+ items.forEach((item) => {
697
+ itemsId[item.id] = true;
698
+ });
699
+ newItems.forEach((item) => {
700
+ if (!itemsId[item.id]) {
701
+ items.push(item);
702
+ itemsId[item.id] = true;
703
+ }
704
+ });
705
+ //console.log("newItems: ", items);
706
+ return items;
707
+ };
708
+
709
+ const addNewItemsChat = (currentItems = [], newItems = []) => {
710
+ let items = currentItems.slice();
711
+ let itemsId = {};
712
+ items.forEach((item) => {
713
+ itemsId[item.id] = true;
714
+ });
715
+ for (let i = newItems.length - 1; i >= 0; i--) {
716
+ if (!itemsId[newItems[i].id]) {
717
+ items.unshift(newItems[i]);
718
+ itemsId[newItems[i].id] = true;
719
+ }
720
+ }
721
+ //console.log("newItems: ", items);
722
+ return items;
723
+ };
724
+
725
+ const updateAllUsers = (newUsers = {}) => {
726
+ let currentUsers = { ...allUsers };
727
+ Object.keys(newUsers).forEach((userId) => {
728
+ if (!currentUsers[userId]) {
729
+ currentUsers[userId] = newUsers[userId];
730
+ }
731
+ });
732
+ //console.log("newUsers: ", currentUsers);
733
+ setAllUsers(currentUsers);
734
+ };
735
+
736
+ const stopUpdate = () => {
737
+ if (processUpdateID !== undefined) {
738
+ clearTimeout(processUpdateID);
739
+ setProcessUpdateID(undefined);
740
+ }
741
+ };
742
+
743
+ const renderBodyChat = () => {
744
+ if (isLoading) {
745
+ return <Loading />;
746
+ }
747
+ if (errorChat.existError) {
748
+ return (
749
+ <NotFound
750
+ code={errorChat.code}
751
+ message={errorChat.message}
752
+ details={errorChat.errorDetail}
753
+ />
754
+ );
755
+ }
756
+ // cuando se quiere ver la lista de chats
757
+ if (showChatsList) {
758
+ return (
759
+ <ChatLists
760
+ companies={companies}
761
+ currentCompanyId={currentUser?.companyId}
762
+ onClickCompany={(companyIdSelected) => {
763
+ setActiveCompanyId(Number(companyIdSelected));
764
+ setShowChatsList(false);
765
+ }}
766
+ />
767
+ );
768
+ }
769
+ // mostrar chat?
770
+ let items;
771
+ let enabledLoadMore;
772
+ if (chatType === "merchant_product" || chatType === "ticket") {
773
+ items = singleChat.items;
774
+ enabledLoadMore = singleChat.enabledLoadMore;
775
+ }
776
+ // ORDER_PRODUCT
777
+ else if (companies) {
778
+ // caso 0 chats
779
+ if (Object.keys(companies).length === 0) {
780
+ return (
781
+ <div className="container-chatEmpty">
782
+ <CustomIcon
783
+ className="icon-chat"
784
+ transparent
785
+ size={35}
786
+ icon={IconChat}
787
+ type={"gray"}
788
+ />
789
+ <label>
790
+ De acuerdo al estatus del producto, tu compañia no tiene
791
+ disponible ningun chat abierto o cerrado
792
+ </label>
793
+ </div>
794
+ );
795
+ }
796
+ // caso 1 o mas chats
797
+ if (companies[activeCompanyId]) {
798
+ items = companies[activeCompanyId].items;
799
+ enabledLoadMore = companies[activeCompanyId].enabledLoadMore;
800
+ }
801
+ }
802
+ if (items) {
803
+ let containerItems = null;
804
+ if (items.length) {
805
+ containerItems = (
806
+ <ContainerItems
807
+ items={items}
808
+ users={allUsers}
809
+ showBtnLoadMore={enabledLoadMore}
810
+ chatType={chatType}
811
+ activeCompanyId={activeCompanyId}
812
+ currentUser={
813
+ ["merchant_product", "order_product"].includes(chatType)
814
+ ? currentUser
815
+ : dataChat.currentUser
816
+ }
817
+ onClickBtnLoadMore={
818
+ chatType === "merchant_product"
819
+ ? getLoadMoreMerchantProduct
820
+ : chatType === "order_product"
821
+ ? getLoadMoreOrderProduct
822
+ : getLoadMoreTicket
823
+ }
824
+ />
825
+ );
826
+ } else {
827
+ containerItems = (
828
+ <div className="container-chatEmpty">
829
+ <CustomIcon
830
+ className="icon-chat"
831
+ size={35}
832
+ icon={IconChat}
833
+ type={"gray"}
834
+ transparent
835
+ />
836
+ <label>Este chat no tiene mensajes</label>
837
+ </div>
838
+ );
839
+ }
840
+ return (
841
+ <>
842
+ {containerItems}
843
+ <Footer
844
+ chatType={chatType}
845
+ dataChat={
846
+ chatType === "merchant_product"
847
+ ? { id: dataChat.id, version: dataChat.version }
848
+ : chatType === "order_product"
849
+ ? { id: dataChat.id, version: currentArticle.version }
850
+ : chatType === "ticket"
851
+ ? { id: dataChat.id }
852
+ : undefined
853
+ }
854
+ chatCompany={getChatCompany()}
855
+ statusChat={
856
+ chatType === "order_product"
857
+ ? getChatCompany()?.statusChat
858
+ : chatType === "ticket"
859
+ ? singleChat.statusChat
860
+ : undefined
861
+ }
862
+ messageDisabled={
863
+ chatType === "order_product"
864
+ ? `La conversación con ${getChatCompany()?.name} ha finalizado`
865
+ : chatType === "ticket"
866
+ ? "Ticket cerrado"
867
+ : `La conversación ha finalizado`
868
+ }
869
+ createItemsChat={createItemsChat}
870
+ errorUpdate={errorUpdate}
871
+ />
872
+ </>
873
+ );
874
+ }
875
+ return <Loading />;
876
+ };
877
+
878
+ return (
879
+ <>
880
+ <Container>
881
+ {/* header */}
882
+ {(chatContainerType !== "fixed" || !isSingleChat()) && (
883
+ <Header
884
+ showBtnClose={showBtnClose}
885
+ onClickBtnClose={onClickBtnClose}
886
+ showChatsList={showChatsList}
887
+ chatCompany={getChatCompany()}
888
+ multipleCompanies={!isSingleChat()}
889
+ onClickBtnChooseChat={() => {
890
+ setShowChatsList(true);
891
+ }}
892
+ />
893
+ )}
894
+
895
+ {/* body */}
896
+ {renderBodyChat()}
897
+ </Container>
898
+ </>
899
+ );
900
+ };