contentoh-components-library 21.3.19 → 21.3.20

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 (196) hide show
  1. package/.env.development +5 -0
  2. package/dist/assets/images/customSelect/starIcon.svg +14 -0
  3. package/dist/assets/images/defaultImages/Spinner.gif +0 -0
  4. package/dist/assets/images/defaultImages/notFound.svg +124 -0
  5. package/dist/assets/images/generalButton/closeIcon.svg +2 -2
  6. package/dist/assets/sounds/newMessage.mp3 +0 -0
  7. package/dist/components/atoms/ButtonFileChooser/ButtonFileChooser.stories.js +72 -0
  8. package/dist/components/atoms/ButtonFileChooser/index.js +110 -0
  9. package/dist/components/atoms/ButtonFileChooser/styles.js +20 -0
  10. package/dist/components/atoms/ButtonV2/ButtonV2.stories.js +66 -0
  11. package/dist/components/atoms/ButtonV2/index.js +110 -0
  12. package/dist/components/atoms/ButtonV2/styles.js +53 -0
  13. package/dist/components/atoms/CustomIcon/CustomIcon.stories.js +50 -0
  14. package/dist/components/atoms/CustomIcon/index.js +40 -0
  15. package/dist/components/atoms/CustomIcon/styles.js +33 -0
  16. package/dist/components/atoms/IconFile/IconFile.stories.js +48 -0
  17. package/dist/components/atoms/IconFile/index.js +249 -0
  18. package/dist/components/atoms/IconFile/styles.js +23 -0
  19. package/dist/components/atoms/Image/Image.stories.js +73 -0
  20. package/dist/components/atoms/Image/index.js +76 -0
  21. package/dist/components/atoms/Image/styles.js +43 -0
  22. package/dist/components/atoms/ImageLink/ImageLink.stories.js +63 -0
  23. package/dist/components/atoms/ImageLink/index.js +77 -0
  24. package/dist/components/atoms/ImageLink/styles.js +40 -0
  25. package/dist/components/atoms/ImagePreview/ImagePreview.stories.js +70 -0
  26. package/dist/components/atoms/ImagePreview/index.js +208 -0
  27. package/dist/components/atoms/ImagePreview/styles.js +44 -0
  28. package/dist/components/atoms/InputText/InputText.stories.js +60 -0
  29. package/dist/components/atoms/InputText/index.js +66 -0
  30. package/dist/components/atoms/InputText/styles.js +32 -0
  31. package/dist/components/atoms/NotFound/NotFound.stories.js +36 -0
  32. package/dist/components/atoms/NotFound/index.js +75 -0
  33. package/dist/components/atoms/NotFound/styles.js +20 -0
  34. package/dist/components/atoms/ProgressBar/index.js +36 -6
  35. package/dist/components/atoms/ProgressBar/styles.js +11 -3
  36. package/dist/components/atoms/SelectItemV2/SelectItemV2.stories.js +45 -0
  37. package/dist/components/atoms/SelectItemV2/index.js +57 -0
  38. package/dist/components/atoms/SelectItemV2/styles.js +30 -0
  39. package/dist/components/atoms/Tooltip/Tooltip.stories.js +66 -0
  40. package/dist/components/atoms/Tooltip/index.js +72 -0
  41. package/dist/components/atoms/Tooltip/styles.js +20 -0
  42. package/dist/components/molecules/ButtonDownloadFile/DownloadFile.stories.js +66 -0
  43. package/dist/components/molecules/ButtonDownloadFile/index.js +179 -0
  44. package/dist/components/molecules/ButtonDownloadFile/styles.js +23 -0
  45. package/dist/components/molecules/CustomSelect/CustomSelect.stories.js +21 -22
  46. package/dist/components/molecules/CustomSelect/SelectItem.js +10 -1
  47. package/dist/components/molecules/Dropdown/Dropdown.stories.js +98 -0
  48. package/dist/components/molecules/Dropdown/index.js +150 -0
  49. package/dist/components/molecules/Dropdown/styles.js +26 -0
  50. package/dist/components/molecules/HeaderTop/index.js +23 -6
  51. package/dist/components/molecules/HeaderTop/styles.js +1 -1
  52. package/dist/components/molecules/ImageTooltip/ImageTooltip.stories.js +82 -0
  53. package/dist/components/molecules/ImageTooltip/index.js +85 -0
  54. package/dist/components/molecules/ImageTooltip/styles.js +33 -0
  55. package/dist/components/molecules/ProductNameHeader/index.js +6 -4
  56. package/dist/components/molecules/SelectV2/SelectV2.stories.js +120 -0
  57. package/dist/components/molecules/SelectV2/index.js +306 -0
  58. package/dist/components/molecules/SelectV2/styles.js +42 -0
  59. package/dist/components/molecules/SelectV2/test.js +94 -0
  60. package/dist/components/molecules/SelectV2/test.stories.js +27 -0
  61. package/dist/components/organisms/Chat/Chat.stories.js +160 -0
  62. package/dist/components/organisms/Chat/ChatLists/ChatLists.stories.js +83 -0
  63. package/dist/components/organisms/Chat/ChatLists/index.js +160 -0
  64. package/dist/components/organisms/Chat/ChatLists/styles.js +29 -0
  65. package/dist/components/organisms/Chat/ContainerItems/ContainerItems.stories.js +176 -0
  66. package/dist/components/organisms/Chat/ContainerItems/index.js +537 -0
  67. package/dist/components/organisms/Chat/ContainerItems/styles.js +20 -0
  68. package/dist/components/organisms/Chat/ContentChat/ContentChat.stories.js +142 -0
  69. package/dist/components/organisms/Chat/ContentChat/index.js +1466 -0
  70. package/dist/components/organisms/Chat/ContentChat/styles.js +20 -0
  71. package/dist/components/organisms/Chat/Footer/Footer.stories.js +43 -0
  72. package/dist/components/organisms/Chat/Footer/index.js +976 -0
  73. package/dist/components/organisms/Chat/Footer/styles.js +32 -0
  74. package/dist/components/organisms/Chat/Header/Header.stories.js +96 -0
  75. package/dist/components/organisms/Chat/Header/index.js +83 -0
  76. package/dist/components/organisms/Chat/Header/styles.js +20 -0
  77. package/dist/components/organisms/Chat/index.js +253 -0
  78. package/dist/components/organisms/Chat/styles.js +29 -0
  79. package/dist/components/organisms/FullProductNameHeader/index.js +1 -0
  80. package/dist/components/organisms/Modal/Modal.stories.js +66 -0
  81. package/dist/components/organisms/Modal/index.js +95 -0
  82. package/dist/components/organisms/Modal/styles.js +20 -0
  83. package/dist/components/organisms/RangeCalendar/RangeCalendar.stories.js +33 -0
  84. package/dist/components/organisms/RangeCalendar/index.js +149 -0
  85. package/dist/components/organisms/RangeCalendar/styles.js +27 -0
  86. package/dist/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +65 -50
  87. package/dist/components/pages/ProviderProductEdition/index.js +15 -11
  88. package/dist/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +36 -44
  89. package/dist/components/pages/RetailerProductEdition/index.js +13 -12
  90. package/dist/global-files/data.js +18 -23
  91. package/dist/global-files/fonts.css +6 -0
  92. package/dist/global-files/handle_http.js +381 -0
  93. package/dist/global-files/handle_userTech.js +20 -0
  94. package/dist/global-files/utils.js +514 -0
  95. package/dist/global-files/variables.js +2 -0
  96. package/dist/index.js +267 -46
  97. package/package.json +13 -1
  98. package/src/assets/images/customSelect/starIcon.svg +14 -0
  99. package/src/assets/images/defaultImages/Spinner.gif +0 -0
  100. package/src/assets/images/defaultImages/notFound.svg +124 -0
  101. package/src/assets/images/generalButton/closeIcon.svg +2 -2
  102. package/src/assets/sounds/newMessage.mp3 +0 -0
  103. package/src/components/atoms/ButtonFileChooser/ButtonFileChooser.stories.js +47 -0
  104. package/src/components/atoms/ButtonFileChooser/index.js +68 -0
  105. package/src/components/atoms/ButtonFileChooser/styles.js +4 -0
  106. package/src/components/atoms/ButtonV2/ButtonV2.stories.js +53 -0
  107. package/src/components/atoms/ButtonV2/index.js +85 -0
  108. package/src/components/atoms/ButtonV2/styles.js +217 -0
  109. package/src/components/atoms/CustomIcon/CustomIcon.stories.js +36 -0
  110. package/src/components/atoms/CustomIcon/index.js +41 -0
  111. package/src/components/atoms/CustomIcon/styles.js +85 -0
  112. package/src/components/atoms/IconFile/IconFile.stories.js +35 -0
  113. package/src/components/atoms/IconFile/index.js +119 -0
  114. package/src/components/atoms/IconFile/styles.js +67 -0
  115. package/src/components/atoms/Image/Image.stories.js +51 -0
  116. package/src/components/atoms/Image/index.js +55 -0
  117. package/src/components/atoms/Image/styles.js +34 -0
  118. package/src/components/atoms/ImageLink/ImageLink.stories.js +43 -0
  119. package/src/components/atoms/ImageLink/index.js +57 -0
  120. package/src/components/atoms/ImageLink/styles.js +30 -0
  121. package/src/components/atoms/ImagePreview/ImagePreview.stories.js +52 -0
  122. package/src/components/atoms/ImagePreview/index.js +178 -0
  123. package/src/components/atoms/ImagePreview/styles.js +77 -0
  124. package/src/components/atoms/InputText/InputText.stories.js +39 -0
  125. package/src/components/atoms/InputText/index.js +61 -0
  126. package/src/components/atoms/InputText/styles.js +89 -0
  127. package/src/components/atoms/NotFound/NotFound.stories.js +19 -0
  128. package/src/components/atoms/NotFound/index.js +52 -0
  129. package/src/components/atoms/NotFound/styles.js +55 -0
  130. package/src/components/atoms/ProgressBar/index.js +40 -5
  131. package/src/components/atoms/ProgressBar/styles.js +24 -0
  132. package/src/components/atoms/SelectItemV2/SelectItemV2.stories.js +26 -0
  133. package/src/components/atoms/SelectItemV2/index.js +61 -0
  134. package/src/components/atoms/SelectItemV2/styles.js +90 -0
  135. package/src/components/atoms/Tooltip/Tooltip.stories.js +51 -0
  136. package/src/components/atoms/Tooltip/index.js +59 -0
  137. package/src/components/atoms/Tooltip/styles.js +42 -0
  138. package/src/components/molecules/ButtonDownloadFile/DownloadFile.stories.js +54 -0
  139. package/src/components/molecules/ButtonDownloadFile/index.js +109 -0
  140. package/src/components/molecules/ButtonDownloadFile/styles.js +66 -0
  141. package/src/components/molecules/CustomSelect/CustomSelect.stories.js +20 -12
  142. package/src/components/molecules/CustomSelect/SelectItem.js +7 -0
  143. package/src/components/molecules/Dropdown/Dropdown.stories.js +103 -0
  144. package/src/components/molecules/Dropdown/index.js +150 -0
  145. package/src/components/molecules/Dropdown/styles.js +75 -0
  146. package/src/components/molecules/HeaderTop/index.js +29 -8
  147. package/src/components/molecules/HeaderTop/styles.js +4 -0
  148. package/src/components/molecules/ImageTooltip/ImageTooltip.stories.js +68 -0
  149. package/src/components/molecules/ImageTooltip/index.js +63 -0
  150. package/src/components/molecules/ImageTooltip/styles.js +18 -0
  151. package/src/components/molecules/ProductNameHeader/index.js +7 -2
  152. package/src/components/molecules/SelectV2/SelectV2.stories.js +115 -0
  153. package/src/components/molecules/SelectV2/index.js +357 -0
  154. package/src/components/molecules/SelectV2/styles.js +105 -0
  155. package/src/components/molecules/SelectV2/test.js +60 -0
  156. package/src/components/molecules/SelectV2/test.stories.js +10 -0
  157. package/src/components/organisms/Chat/Chat.stories.js +147 -0
  158. package/src/components/organisms/Chat/ChatLists/ChatLists.stories.js +65 -0
  159. package/src/components/organisms/Chat/ChatLists/Rotoplas.jpeg +0 -0
  160. package/src/components/organisms/Chat/ChatLists/THD.png +0 -0
  161. package/src/components/organisms/Chat/ChatLists/index.js +141 -0
  162. package/src/components/organisms/Chat/ChatLists/styles.js +162 -0
  163. package/src/components/organisms/Chat/ContainerItems/ContainerItems.stories.js +142 -0
  164. package/src/components/organisms/Chat/ContainerItems/index.js +512 -0
  165. package/src/components/organisms/Chat/ContainerItems/styles.js +328 -0
  166. package/src/components/organisms/Chat/ContentChat/ContentChat.stories.js +102 -0
  167. package/src/components/organisms/Chat/ContentChat/Rotoplas.jpeg +0 -0
  168. package/src/components/organisms/Chat/ContentChat/THD.png +0 -0
  169. package/src/components/organisms/Chat/ContentChat/index.js +919 -0
  170. package/src/components/organisms/Chat/ContentChat/styles.js +41 -0
  171. package/src/components/organisms/Chat/Footer/Footer.stories.js +22 -0
  172. package/src/components/organisms/Chat/Footer/index.js +661 -0
  173. package/src/components/organisms/Chat/Footer/styles.js +286 -0
  174. package/src/components/organisms/Chat/Header/Header.stories.js +66 -0
  175. package/src/components/organisms/Chat/Header/index.js +93 -0
  176. package/src/components/organisms/Chat/Header/styles.js +49 -0
  177. package/src/components/organisms/Chat/index.js +235 -0
  178. package/src/components/organisms/Chat/styles.js +42 -0
  179. package/src/components/organisms/FullProductNameHeader/index.js +1 -0
  180. package/src/components/organisms/Modal/Modal.stories.js +55 -0
  181. package/src/components/organisms/Modal/index.js +97 -0
  182. package/src/components/organisms/Modal/styles.js +103 -0
  183. package/src/components/organisms/RangeCalendar/RangeCalendar.stories.js +16 -0
  184. package/src/components/organisms/RangeCalendar/index.js +121 -0
  185. package/src/components/organisms/RangeCalendar/styles.js +883 -0
  186. package/src/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +67 -49
  187. package/src/components/pages/ProviderProductEdition/index.js +16 -9
  188. package/src/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +36 -46
  189. package/src/components/pages/RetailerProductEdition/index.js +14 -10
  190. package/src/global-files/data.js +18 -23
  191. package/src/global-files/fonts.css +6 -0
  192. package/src/global-files/handle_http.js +225 -0
  193. package/src/global-files/handle_userTech.js +7 -0
  194. package/src/global-files/utils.js +330 -0
  195. package/src/global-files/variables.js +2 -0
  196. package/src/index.js +17 -0
@@ -0,0 +1,1466 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.ContentChat = void 0;
9
+
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/createForOfIteratorHelper"));
13
+
14
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
15
+
16
+ var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
17
+
18
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator"));
19
+
20
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
21
+
22
+ var _reactHowler = _interopRequireDefault(require("react-howler"));
23
+
24
+ var _styles = require("./styles");
25
+
26
+ var _react = require("react");
27
+
28
+ var _NotFound = require("../../../atoms/NotFound");
29
+
30
+ var _Header = require("../Header");
31
+
32
+ var _freeSolidSvgIcons = require("@fortawesome/free-solid-svg-icons");
33
+
34
+ var _Loading = require("../../../atoms/Loading");
35
+
36
+ var _ContainerItems = require("../ContainerItems");
37
+
38
+ var _Footer = require("../Footer");
39
+
40
+ var _ChatLists = require("../ChatLists");
41
+
42
+ var _CustomIcon = require("../../../atoms/CustomIcon");
43
+
44
+ var _handle_http = require("../../../../global-files/handle_http");
45
+
46
+ var _utils = require("../../../../global-files/utils");
47
+
48
+ var _newMessage = _interopRequireDefault(require("../../../../assets/sounds/newMessage.mp3"));
49
+
50
+ var _jsxRuntime = require("react/jsx-runtime");
51
+
52
+ var ContentChat = function ContentChat(props) {
53
+ var chatType = props.chatType,
54
+ chatContainerType = props.chatContainerType,
55
+ dataChat = props.dataChat,
56
+ showBtnClose = props.showBtnClose,
57
+ onClickBtnClose = props.onClickBtnClose,
58
+ showPopUpChat = props.showPopUpChat;
59
+
60
+ var _useState = (0, _react.useState)({}),
61
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
62
+ companies = _useState2[0],
63
+ setCompanies = _useState2[1];
64
+ /* {
65
+ companyId: {
66
+ name: string,
67
+ statusChat: string => current | open | closed
68
+ items: [{..}] ,
69
+ enabledLoadMore: boolean
70
+ },
71
+ ...
72
+ } chat orderProduct */
73
+
74
+
75
+ var _useState3 = (0, _react.useState)({
76
+ items: undefined,
77
+ enabledLoadMore: false,
78
+ statusChat: undefined
79
+ }),
80
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
81
+ singleChat = _useState4[0],
82
+ setSingleChat = _useState4[1]; // chat merchantProduct o ticket
83
+
84
+
85
+ var _useState5 = (0, _react.useState)(),
86
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
87
+ activeCompanyId = _useState6[0],
88
+ setActiveCompanyId = _useState6[1]; // number
89
+
90
+
91
+ var _useState7 = (0, _react.useState)({}),
92
+ _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
93
+ allUsers = _useState8[0],
94
+ setAllUsers = _useState8[1]; // {...}
95
+
96
+
97
+ var _useState9 = (0, _react.useState)({
98
+ id: undefined,
99
+ companyId: undefined
100
+ }),
101
+ _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
102
+ currentUser = _useState10[0],
103
+ setCurrentUser = _useState10[1];
104
+
105
+ var _useState11 = (0, _react.useState)({
106
+ status: undefined,
107
+ version: undefined
108
+ }),
109
+ _useState12 = (0, _slicedToArray2.default)(_useState11, 2),
110
+ currentArticle = _useState12[0],
111
+ setCurrentArticle = _useState12[1];
112
+
113
+ var _useState13 = (0, _react.useState)(),
114
+ _useState14 = (0, _slicedToArray2.default)(_useState13, 2),
115
+ lastUpdateDate = _useState14[0],
116
+ setLastUpdateDate = _useState14[1]; // string
117
+
118
+
119
+ var _useState15 = (0, _react.useState)(true),
120
+ _useState16 = (0, _slicedToArray2.default)(_useState15, 2),
121
+ isLoading = _useState16[0],
122
+ setIsLoading = _useState16[1]; // boolean
123
+
124
+
125
+ var _useState17 = (0, _react.useState)(false),
126
+ _useState18 = (0, _slicedToArray2.default)(_useState17, 2),
127
+ showChatsList = _useState18[0],
128
+ setShowChatsList = _useState18[1]; // boolean
129
+
130
+
131
+ var _useState19 = (0, _react.useState)(),
132
+ _useState20 = (0, _slicedToArray2.default)(_useState19, 2),
133
+ processUpdateID = _useState20[0],
134
+ setProcessUpdateID = _useState20[1]; // number
135
+
136
+
137
+ var _useState21 = (0, _react.useState)(0),
138
+ _useState22 = (0, _slicedToArray2.default)(_useState21, 2),
139
+ startUpdate = _useState22[0],
140
+ setStartUpdate = _useState22[1]; // number
141
+
142
+
143
+ var _useState23 = (0, _react.useState)(0),
144
+ _useState24 = (0, _slicedToArray2.default)(_useState23, 2),
145
+ runUpdate = _useState24[0],
146
+ setRunUpdate = _useState24[1]; // number
147
+
148
+
149
+ var _useState25 = (0, _react.useState)({
150
+ existError: false,
151
+ code: undefined,
152
+ message: undefined,
153
+ errorDetail: undefined
154
+ }),
155
+ _useState26 = (0, _slicedToArray2.default)(_useState25, 2),
156
+ errorChat = _useState26[0],
157
+ setErrorChat = _useState26[1];
158
+
159
+ var _useState27 = (0, _react.useState)({
160
+ startDate: undefined,
161
+ // Date()
162
+ lastDate: undefined // Date()
163
+
164
+ }),
165
+ _useState28 = (0, _slicedToArray2.default)(_useState27, 2),
166
+ errorUpdate = _useState28[0],
167
+ setErrorUpdate = _useState28[1];
168
+
169
+ var _useState29 = (0, _react.useState)(false),
170
+ _useState30 = (0, _slicedToArray2.default)(_useState29, 2),
171
+ playSound = _useState30[0],
172
+ setPlaySound = _useState30[1]; // matar update al desmontar el componente del chat
173
+
174
+
175
+ (0, _react.useEffect)(function () {
176
+ return function () {
177
+ if (processUpdateID !== undefined) clearTimeout(processUpdateID);
178
+ };
179
+ }, []); // al cargar el componente
180
+
181
+ (0, _react.useEffect)(function () {
182
+ if (dataChat) {
183
+ stopUpdate();
184
+
185
+ if (dataChat.code) {
186
+ setErrorChat({
187
+ existError: true,
188
+ code: dataChat.code,
189
+ message: dataChat.message,
190
+ errorDetail: dataChat.errorDetail
191
+ });
192
+ setIsLoading(false);
193
+ return;
194
+ }
195
+
196
+ if (chatType === "merchant_product") getInitialMerchantProduct();else if (chatType === "order_product") getInitialOrderProduct();else getInitialTicket();
197
+ }
198
+ }, [dataChat, showPopUpChat]); // comenzar temporizador del update de 20s
199
+
200
+ (0, _react.useEffect)(function () {
201
+ //return; -- descomentarizar para hacer pruebas sin update
202
+ if (startUpdate == 0) return;
203
+ var processID = setTimeout(function () {
204
+ setRunUpdate(function (prev) {
205
+ return prev + 1;
206
+ });
207
+ }, 5000);
208
+ setProcessUpdateID(processID);
209
+ return function () {
210
+ return clearTimeout(processID);
211
+ };
212
+ }, [startUpdate]); // ejecutar update
213
+
214
+ (0, _react.useEffect)(function () {
215
+ // if (runUpdate == 0) return;
216
+ if (chatType === "merchant_product") {
217
+ if (singleChat.items) getUpdateLatestMerchantProduct();else getInitialMerchantProduct();
218
+ } else if (chatType === "order_product") {
219
+ if (companies) getUpdateLatestOrderProduct();else getInitialOrderProduct();
220
+ } else {
221
+ if (singleChat.items) getUpdateLatestTicket(true);else getInitialTicket();
222
+ }
223
+ }, [runUpdate]);
224
+ /*=======================================================================
225
+ PETICION GET INICIAL SEGUN EL TIPO DE CHAT
226
+ ======================================================================= */
227
+
228
+ var getInitialMerchantProduct = /*#__PURE__*/function () {
229
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
230
+ var paramsQuery, paramsHeaders, response;
231
+ return _regenerator.default.wrap(function _callee$(_context) {
232
+ while (1) {
233
+ switch (_context.prev = _context.next) {
234
+ case 0:
235
+ paramsQuery = {
236
+ getType: "initial",
237
+ id: JSON.stringify(dataChat.id),
238
+ version: JSON.stringify(dataChat.version)
239
+ };
240
+ paramsHeaders = {
241
+ Authorization: dataChat.userToken
242
+ };
243
+ _context.next = 4;
244
+ return (0, _handle_http.fetchGET)(process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT, paramsQuery, paramsHeaders);
245
+
246
+ case 4:
247
+ response = _context.sent;
248
+
249
+ if (response.body) {
250
+ _context.next = 9;
251
+ break;
252
+ }
253
+
254
+ setErrorChat({
255
+ existError: true,
256
+ code: 400,
257
+ message: response.message,
258
+ errorDetail: response.errorDetail
259
+ });
260
+ setIsLoading(false);
261
+ return _context.abrupt("return");
262
+
263
+ case 9:
264
+ // success
265
+ setCurrentUser({
266
+ id: response.body.data.currentUserId,
267
+ companyId: response.body.data.currentCompanyId
268
+ });
269
+ setLastUpdateDate(response.body.data.lastUpdateDate);
270
+ setAllUsers(response.body.users);
271
+ setSingleChat({
272
+ items: response.body.items,
273
+ enabledLoadMore: response.body.items.length === 50
274
+ });
275
+ setErrorChat({
276
+ existError: false
277
+ });
278
+ setIsLoading(false);
279
+
280
+ case 15:
281
+ case "end":
282
+ return _context.stop();
283
+ }
284
+ }
285
+ }, _callee);
286
+ }));
287
+
288
+ return function getInitialMerchantProduct() {
289
+ return _ref.apply(this, arguments);
290
+ };
291
+ }();
292
+
293
+ var getInitialOrderProduct = /*#__PURE__*/function () {
294
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
295
+ var paramsQuery, paramsHeaders, response, companiesList, companiesIdList, companyActive, _i, _companiesIdList, companyId;
296
+
297
+ return _regenerator.default.wrap(function _callee2$(_context2) {
298
+ while (1) {
299
+ switch (_context2.prev = _context2.next) {
300
+ case 0:
301
+ clearTimeout(processUpdateID); // finalizamos el temporizador
302
+
303
+ paramsQuery = {
304
+ getType: "initial",
305
+ id: JSON.stringify(dataChat.id),
306
+ orderId: JSON.stringify(dataChat.orderId),
307
+ retailerId: JSON.stringify(dataChat.retailerId)
308
+ };
309
+ paramsHeaders = {
310
+ Authorization: dataChat.userToken
311
+ };
312
+ _context2.next = 5;
313
+ return (0, _handle_http.fetchGET)(process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT, paramsQuery, paramsHeaders);
314
+
315
+ case 5:
316
+ response = _context2.sent;
317
+ setStartUpdate(function (prev) {
318
+ return prev + 1;
319
+ }); // TEMPORAL
320
+
321
+ if (response.body) {
322
+ _context2.next = 11;
323
+ break;
324
+ }
325
+
326
+ setErrorChat({
327
+ existError: true,
328
+ code: 400,
329
+ message: response.message,
330
+ errorDetail: response.errorDetail
331
+ });
332
+ setIsLoading(false);
333
+ return _context2.abrupt("return");
334
+
335
+ case 11:
336
+ // success
337
+ setCurrentUser({
338
+ id: response.body.data.currentUserId,
339
+ companyId: response.body.data.currentCompanyId
340
+ });
341
+ setLastUpdateDate(response.body.data.lastUpdateDate);
342
+ setCurrentArticle({
343
+ status: response.body.data.status,
344
+ version: response.body.data.version
345
+ });
346
+ setAllUsers(response.body.users);
347
+ companiesList = response.body.companies;
348
+ companiesIdList = Object.keys(companiesList);
349
+
350
+ // encontrar el chat inicial a cargar y si se debe permitir cargar mas
351
+ for (_i = 0, _companiesIdList = companiesIdList; _i < _companiesIdList.length; _i++) {
352
+ companyId = _companiesIdList[_i];
353
+
354
+ if (companiesList[companyId].items.length < 50) {
355
+ companiesList[companyId].enabledLoadMore = false;
356
+ } else {
357
+ companiesList[companyId].enabledLoadMore = true;
358
+ }
359
+
360
+ if (companiesList[companyId].statusChat === "current") {
361
+ companyActive = Number(companyId);
362
+ }
363
+ }
364
+
365
+ if (!companyActive && companiesIdList.length) {
366
+ companyActive = Number(companiesIdList[0]);
367
+ }
368
+
369
+ setCompanies(companiesList);
370
+ if (companyActive) setActiveCompanyId(companyActive);
371
+ setErrorChat({
372
+ existError: false
373
+ });
374
+ setIsLoading(false);
375
+
376
+ case 23:
377
+ case "end":
378
+ return _context2.stop();
379
+ }
380
+ }
381
+ }, _callee2);
382
+ }));
383
+
384
+ return function getInitialOrderProduct() {
385
+ return _ref2.apply(this, arguments);
386
+ };
387
+ }();
388
+
389
+ var getInitialTicket = /*#__PURE__*/function () {
390
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
391
+ var _dataChat$currentUser, _dataChat$currentUser2, _dataChat$currentUser3, _dataChat$currentUser4;
392
+
393
+ var dataUser, paramsQuery, response;
394
+ return _regenerator.default.wrap(function _callee3$(_context3) {
395
+ while (1) {
396
+ switch (_context3.prev = _context3.next) {
397
+ case 0:
398
+ stopUpdate(); // finalizamos el temporizador
399
+
400
+ dataUser = {
401
+ id: (_dataChat$currentUser = dataChat.currentUser) === null || _dataChat$currentUser === void 0 ? void 0 : _dataChat$currentUser.id,
402
+ companyId: (_dataChat$currentUser2 = dataChat.currentUser) === null || _dataChat$currentUser2 === void 0 ? void 0 : _dataChat$currentUser2.companyId,
403
+ isUserTech: (_dataChat$currentUser3 = dataChat.currentUser) === null || _dataChat$currentUser3 === void 0 ? void 0 : _dataChat$currentUser3.isUserTech
404
+ };
405
+ paramsQuery = {
406
+ id: JSON.stringify(dataChat.id),
407
+ getType: "initial",
408
+ currentUser: (0, _utils.encodeUriJson)(dataUser),
409
+ currentItemsFront: (0, _utils.encodeUriJson)(getItemsIdSingleChat())
410
+ };
411
+ _context3.next = 5;
412
+ return (0, _handle_http.fetchGET)(process.env.REACT_APP_TICKETS_CHAT_ENDPOINT, paramsQuery, {
413
+ Authorization: (_dataChat$currentUser4 = dataChat.currentUser) === null || _dataChat$currentUser4 === void 0 ? void 0 : _dataChat$currentUser4.token
414
+ });
415
+
416
+ case 5:
417
+ response = _context3.sent;
418
+ // programar update en 20s
419
+ setStartUpdate(function (prev) {
420
+ return prev + 1;
421
+ });
422
+
423
+ if (response.body) {
424
+ _context3.next = 11;
425
+ break;
426
+ }
427
+
428
+ setErrorChat({
429
+ existError: true,
430
+ code: 400,
431
+ message: response.message,
432
+ errorDetail: response.errorDetail
433
+ });
434
+ setIsLoading(false);
435
+ return _context3.abrupt("return");
436
+
437
+ case 11:
438
+ // success
439
+ setLastUpdateDate(response.body.data.lastUpdateDate);
440
+ setAllUsers(response.body.users);
441
+ setSingleChat({
442
+ items: response.body.items,
443
+ enabledLoadMore: response.body.items.length === 50,
444
+ statusChat: dataChat.statusChat
445
+ });
446
+ setErrorChat({
447
+ existError: false
448
+ });
449
+ setIsLoading(false);
450
+
451
+ case 16:
452
+ case "end":
453
+ return _context3.stop();
454
+ }
455
+ }
456
+ }, _callee3);
457
+ }));
458
+
459
+ return function getInitialTicket() {
460
+ return _ref3.apply(this, arguments);
461
+ };
462
+ }();
463
+ /*=======================================================================
464
+ PETICION GET LOAD_MORE SEGUN EL TIPO DE CHAT
465
+ ======================================================================= */
466
+
467
+
468
+ var getLoadMoreMerchantProduct = /*#__PURE__*/function () {
469
+ var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
470
+ var date, paramsQuery, response, newSingleChat;
471
+ return _regenerator.default.wrap(function _callee4$(_context4) {
472
+ while (1) {
473
+ switch (_context4.prev = _context4.next) {
474
+ case 0:
475
+ clearTimeout(processUpdateID); // finalizamos el temporizador
476
+
477
+ date = singleChat.items[singleChat.items.length - 1].date;
478
+ paramsQuery = {
479
+ getType: "loadMore",
480
+ id: JSON.stringify(dataChat.id),
481
+ version: JSON.stringify(dataChat.version),
482
+ date: encodeURIComponent(date)
483
+ };
484
+ _context4.next = 5;
485
+ return (0, _handle_http.fetchGET)(process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT, paramsQuery);
486
+
487
+ case 5:
488
+ response = _context4.sent;
489
+
490
+ if (response.body) {
491
+ _context4.next = 8;
492
+ break;
493
+ }
494
+
495
+ return _context4.abrupt("return", {
496
+ title: response.message,
497
+ message: response.errorDetail
498
+ });
499
+
500
+ case 8:
501
+ // success
502
+ // actualizar la lista de los users
503
+ updateAllUsers(response.body.users); // actualizar los items del chat
504
+
505
+ newSingleChat = (0, _objectSpread3.default)({}, singleChat);
506
+ newSingleChat.items = addOldItemsChat(newSingleChat.items, response.body.items);
507
+ newSingleChat.enabledLoadMore = response.body.items.length === 50;
508
+ setSingleChat(newSingleChat);
509
+
510
+ case 13:
511
+ case "end":
512
+ return _context4.stop();
513
+ }
514
+ }
515
+ }, _callee4);
516
+ }));
517
+
518
+ return function getLoadMoreMerchantProduct() {
519
+ return _ref4.apply(this, arguments);
520
+ };
521
+ }();
522
+
523
+ var getLoadMoreOrderProduct = /*#__PURE__*/function () {
524
+ var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
525
+ var company, date, paramsQuery, response;
526
+ return _regenerator.default.wrap(function _callee5$(_context5) {
527
+ while (1) {
528
+ switch (_context5.prev = _context5.next) {
529
+ case 0:
530
+ clearTimeout(processUpdateID); // finalizamos el temporizador
531
+
532
+ company = companies[activeCompanyId];
533
+ date = company.items[company.items.length - 1].date;
534
+ paramsQuery = {
535
+ getType: "loadMore",
536
+ id: JSON.stringify(dataChat.id),
537
+ orderId: JSON.stringify(dataChat.orderId),
538
+ version: JSON.stringify(currentArticle.version),
539
+ currentCompanyId: JSON.stringify(currentUser.companyId),
540
+ date: encodeURIComponent(date),
541
+ othersCompanyId: JSON.stringify([activeCompanyId])
542
+ };
543
+ _context5.next = 6;
544
+ return (0, _handle_http.fetchGET)(process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT, paramsQuery);
545
+
546
+ case 6:
547
+ response = _context5.sent;
548
+
549
+ if (response.body) {
550
+ _context5.next = 9;
551
+ break;
552
+ }
553
+
554
+ return _context5.abrupt("return", {
555
+ title: response.message,
556
+ message: response.errorDetail
557
+ });
558
+
559
+ case 9:
560
+ // success
561
+ // actualizar la lista de los users
562
+ updateAllUsers(response.body.users); // actualizar los items del chat y la lista de users
563
+
564
+ company.items = addOldItemsChat(company.items, response.body.items);
565
+ company.enabledLoadMore = response.body.items.length === 50;
566
+ setCompanies(function (prev) {
567
+ return (0, _objectSpread3.default)((0, _objectSpread3.default)({}, prev), {}, (0, _defineProperty2.default)({}, activeCompanyId, company));
568
+ });
569
+
570
+ case 13:
571
+ case "end":
572
+ return _context5.stop();
573
+ }
574
+ }
575
+ }, _callee5);
576
+ }));
577
+
578
+ return function getLoadMoreOrderProduct() {
579
+ return _ref5.apply(this, arguments);
580
+ };
581
+ }(); // este GET obtiene la lista de compañoas con las que se puede chatear
582
+
583
+
584
+ var getLoadMoreTicket = /*#__PURE__*/function () {
585
+ var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6() {
586
+ var _dataChat$currentUser5, _dataChat$currentUser6, _dataChat$currentUser7, _dataChat$currentUser8;
587
+
588
+ var date, dataUser, paramsQuery, response, newSingleChat;
589
+ return _regenerator.default.wrap(function _callee6$(_context6) {
590
+ while (1) {
591
+ switch (_context6.prev = _context6.next) {
592
+ case 0:
593
+ stopUpdate(); // finalizamos el temporizador
594
+
595
+ date = singleChat.items[singleChat.items.length - 1].date;
596
+ dataUser = {
597
+ id: (_dataChat$currentUser5 = dataChat.currentUser) === null || _dataChat$currentUser5 === void 0 ? void 0 : _dataChat$currentUser5.id,
598
+ companyId: (_dataChat$currentUser6 = dataChat.currentUser) === null || _dataChat$currentUser6 === void 0 ? void 0 : _dataChat$currentUser6.companyId,
599
+ isUserTech: (_dataChat$currentUser7 = dataChat.currentUser) === null || _dataChat$currentUser7 === void 0 ? void 0 : _dataChat$currentUser7.isUserTech
600
+ };
601
+ paramsQuery = {
602
+ id: JSON.stringify(dataChat.id),
603
+ getType: "loadMore",
604
+ date: encodeURIComponent(date),
605
+ currentUser: (0, _utils.encodeUriJson)(dataUser),
606
+ currentItemsFront: (0, _utils.encodeUriJson)(getItemsIdSingleChat())
607
+ };
608
+ _context6.next = 6;
609
+ return (0, _handle_http.fetchGET)(process.env.REACT_APP_TICKETS_CHAT_ENDPOINT, paramsQuery, {
610
+ Authorization: (_dataChat$currentUser8 = dataChat.currentUser) === null || _dataChat$currentUser8 === void 0 ? void 0 : _dataChat$currentUser8.token
611
+ });
612
+
613
+ case 6:
614
+ response = _context6.sent;
615
+ //programar update en 20s
616
+ setStartUpdate(function (prev) {
617
+ return prev + 1;
618
+ });
619
+
620
+ if (response.body) {
621
+ _context6.next = 10;
622
+ break;
623
+ }
624
+
625
+ return _context6.abrupt("return", {
626
+ title: response.message,
627
+ message: response.errorDetail
628
+ });
629
+
630
+ case 10:
631
+ // success
632
+ // actualizar la lista de los users
633
+ updateAllUsers(response.body.users); // actualizar los items del chat
634
+
635
+ newSingleChat = (0, _objectSpread3.default)({}, singleChat);
636
+ newSingleChat.items = addOldItemsChat(newSingleChat.items, response.body.items);
637
+ newSingleChat.enabledLoadMore = response.body.items.length === 50;
638
+ setSingleChat(newSingleChat);
639
+
640
+ case 15:
641
+ case "end":
642
+ return _context6.stop();
643
+ }
644
+ }
645
+ }, _callee6);
646
+ }));
647
+
648
+ return function getLoadMoreTicket() {
649
+ return _ref6.apply(this, arguments);
650
+ };
651
+ }();
652
+ /*=======================================================================
653
+ PETICION GET UPDATE_LATEST SEGUN EL TIPO DE CHAT
654
+ ======================================================================= */
655
+
656
+
657
+ var getUpdateLatestMerchantProduct = /*#__PURE__*/function () {
658
+ var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7() {
659
+ var paramsQuery, response, newSingleChat;
660
+ return _regenerator.default.wrap(function _callee7$(_context7) {
661
+ while (1) {
662
+ switch (_context7.prev = _context7.next) {
663
+ case 0:
664
+ paramsQuery = {
665
+ getType: "updateLatest",
666
+ id: JSON.stringify(dataChat.id),
667
+ version: JSON.stringify(dataChat.version),
668
+ date: encodeURIComponent(lastUpdateDate)
669
+ };
670
+ _context7.next = 3;
671
+ return (0, _handle_http.fetchGET)(process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT, paramsQuery);
672
+
673
+ case 3:
674
+ response = _context7.sent;
675
+
676
+ if (response.body) {
677
+ _context7.next = 7;
678
+ break;
679
+ }
680
+
681
+ console.log("ERROR updateLatest:", {
682
+ message: response.message,
683
+ errorDetail: response.errorDetail
684
+ });
685
+ return _context7.abrupt("return");
686
+
687
+ case 7:
688
+ // success
689
+ setLastUpdateDate(response.body.data.lastUpdateDate); // actualizar la lista de los users
690
+
691
+ updateAllUsers(response.body.users); // actualizar los items del chat
692
+
693
+ newSingleChat = (0, _objectSpread3.default)({}, singleChat);
694
+ newSingleChat.items = addNewItemsChat(newSingleChat.items, response.body.items);
695
+ setSingleChat(newSingleChat);
696
+
697
+ case 12:
698
+ case "end":
699
+ return _context7.stop();
700
+ }
701
+ }
702
+ }, _callee7);
703
+ }));
704
+
705
+ return function getUpdateLatestMerchantProduct() {
706
+ return _ref7.apply(this, arguments);
707
+ };
708
+ }();
709
+
710
+ var getUpdateLatestOrderProduct = /*#__PURE__*/function () {
711
+ var _ref8 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8() {
712
+ var paramsQuery, response, companiesList;
713
+ return _regenerator.default.wrap(function _callee8$(_context8) {
714
+ while (1) {
715
+ switch (_context8.prev = _context8.next) {
716
+ case 0:
717
+ paramsQuery = {
718
+ getType: "updateLatest",
719
+ id: JSON.stringify(dataChat.id),
720
+ orderId: JSON.stringify(dataChat.orderId),
721
+ retailerId: JSON.stringify(dataChat.retailerId),
722
+ version: JSON.stringify(currentArticle.version),
723
+ status: currentArticle.status,
724
+ currentCompanyId: JSON.stringify(currentUser.companyId),
725
+ othersCompanyId: encodeURIComponent(JSON.stringify(Object.keys(companies))),
726
+ date: encodeURIComponent(lastUpdateDate)
727
+ };
728
+ _context8.next = 3;
729
+ return (0, _handle_http.fetchGET)(process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT, paramsQuery);
730
+
731
+ case 3:
732
+ response = _context8.sent;
733
+
734
+ if (response.body) {
735
+ _context8.next = 7;
736
+ break;
737
+ }
738
+
739
+ console.log("ERROR update: ", {
740
+ message: response.message,
741
+ errorDetail: response.errorDetail
742
+ });
743
+ return _context8.abrupt("return");
744
+
745
+ case 7:
746
+ // success
747
+ // cuando cambie la lista de chats por un cambio de version o estatus
748
+ if (response.body.data.status) {
749
+ setIsLoading(true);
750
+ setTimeout(function () {
751
+ setLastUpdateDate(response.body.data.lastUpdateDate);
752
+ setCurrentArticle({
753
+ status: response.body.data.status,
754
+ version: response.body.data.version
755
+ });
756
+ setAllUsers(response.body.users);
757
+ var companiesList = response.body.companies;
758
+ var companiesIdList = Object.keys(companiesList);
759
+ var companyActive; // encontrar el chat inicial a cargar y si se debe permitir cargar mas
760
+
761
+ for (var _i2 = 0, _companiesIdList2 = companiesIdList; _i2 < _companiesIdList2.length; _i2++) {
762
+ var companyId = _companiesIdList2[_i2];
763
+
764
+ if (companiesList[companyId].items.length < 50) {
765
+ companiesList[companyId].enabledLoadMore = false;
766
+ } else {
767
+ companiesList[companyId].enabledLoadMore = true;
768
+ }
769
+
770
+ if (companiesList[companyId].statusChat === "current") {
771
+ companyActive = Number(companyId);
772
+ }
773
+ }
774
+
775
+ if (!companyActive && companiesIdList.length) {
776
+ companyActive = Number(companiesIdList[0]);
777
+ }
778
+
779
+ setCompanies(companiesList);
780
+ if (companyActive) setActiveCompanyId(companyActive);
781
+ setErrorChat({
782
+ existError: false
783
+ });
784
+ setIsLoading(false);
785
+ }, 2000);
786
+ } // cuando se hizo un update de los mismos chats
787
+ else {
788
+ setLastUpdateDate(response.body.data.lastUpdateDate); // actualizar la lista de los users
789
+
790
+ updateAllUsers(response.body.users); // actualizar los items de los chats
791
+
792
+ companiesList = (0, _objectSpread3.default)({}, companies);
793
+ Object.keys(response.body.companies).forEach(function (companyId) {
794
+ companiesList[companyId].items = addNewItemsChat(companiesList[companyId].items, response.body.companies[companyId].items);
795
+ });
796
+ setCompanies(companiesList);
797
+ }
798
+
799
+ case 8:
800
+ case "end":
801
+ return _context8.stop();
802
+ }
803
+ }
804
+ }, _callee8);
805
+ }));
806
+
807
+ return function getUpdateLatestOrderProduct() {
808
+ return _ref8.apply(this, arguments);
809
+ };
810
+ }();
811
+
812
+ var getUpdateLatestTicket = /*#__PURE__*/function () {
813
+ var _ref9 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9() {
814
+ var _dataChat$currentUser9, _dataChat$currentUser10, _dataChat$currentUser11, _dataChat$currentUser12;
815
+
816
+ var fromUpdate,
817
+ dataUser,
818
+ paramsQuery,
819
+ response,
820
+ newSingleChat,
821
+ _args9 = arguments;
822
+ return _regenerator.default.wrap(function _callee9$(_context9) {
823
+ while (1) {
824
+ switch (_context9.prev = _context9.next) {
825
+ case 0:
826
+ fromUpdate = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : false;
827
+ dataUser = {
828
+ id: (_dataChat$currentUser9 = dataChat.currentUser) === null || _dataChat$currentUser9 === void 0 ? void 0 : _dataChat$currentUser9.id,
829
+ companyId: (_dataChat$currentUser10 = dataChat.currentUser) === null || _dataChat$currentUser10 === void 0 ? void 0 : _dataChat$currentUser10.companyId,
830
+ isUserTech: (_dataChat$currentUser11 = dataChat.currentUser) === null || _dataChat$currentUser11 === void 0 ? void 0 : _dataChat$currentUser11.isUserTech
831
+ };
832
+ paramsQuery = {
833
+ id: JSON.stringify(dataChat.id),
834
+ getType: "updateLatest",
835
+ date: encodeURIComponent(lastUpdateDate),
836
+ currentUser: (0, _utils.encodeUriJson)(dataUser),
837
+ currentItemsFront: (0, _utils.encodeUriJson)(getItemsIdSingleChat())
838
+ };
839
+ _context9.next = 5;
840
+ return (0, _handle_http.fetchGET)(process.env.REACT_APP_TICKETS_CHAT_ENDPOINT, paramsQuery, {
841
+ Authorization: (_dataChat$currentUser12 = dataChat.currentUser) === null || _dataChat$currentUser12 === void 0 ? void 0 : _dataChat$currentUser12.token
842
+ });
843
+
844
+ case 5:
845
+ response = _context9.sent;
846
+ //programar update en 20s
847
+ setStartUpdate(function (prev) {
848
+ return prev + 1;
849
+ });
850
+
851
+ if (response.body) {
852
+ _context9.next = 11;
853
+ break;
854
+ }
855
+
856
+ if (errorUpdate.startDate) {
857
+ setErrorUpdate(function (prev) {
858
+ return (0, _objectSpread3.default)((0, _objectSpread3.default)({}, prev), {}, {
859
+ lastDate: new Date()
860
+ });
861
+ });
862
+ } else {
863
+ setErrorUpdate(function (prev) {
864
+ return {
865
+ startDate: new Date()
866
+ };
867
+ });
868
+ }
869
+
870
+ console.log("ERROR updateLatest:", {
871
+ message: response.message,
872
+ errorDetail: response.errorDetail
873
+ });
874
+ return _context9.abrupt("return");
875
+
876
+ case 11:
877
+ // limpiar error update
878
+ if (errorUpdate.startDate) {
879
+ setErrorUpdate({});
880
+ } // success
881
+
882
+
883
+ setLastUpdateDate(response.body.data.lastUpdateDate); // actualizar la lista de los users
884
+
885
+ updateAllUsers(response.body.users); // actualizar los items del chat
886
+
887
+ if (!(response.body.items.length === 0)) {
888
+ _context9.next = 16;
889
+ break;
890
+ }
891
+
892
+ return _context9.abrupt("return");
893
+
894
+ case 16:
895
+ newSingleChat = (0, _objectSpread3.default)({}, singleChat);
896
+ newSingleChat.items = addNewItemsChat(newSingleChat.items, response.body.items, fromUpdate);
897
+ newSingleChat.statusChat = response.body.data.statusChat;
898
+ setSingleChat(newSingleChat);
899
+
900
+ case 20:
901
+ case "end":
902
+ return _context9.stop();
903
+ }
904
+ }
905
+ }, _callee9);
906
+ }));
907
+
908
+ return function getUpdateLatestTicket() {
909
+ return _ref9.apply(this, arguments);
910
+ };
911
+ }();
912
+ /*=======================================================================
913
+ FUNCION QUE EJECUTA EL MICROSERVICIO CREATE-ITEM
914
+ Este metodo recibe los items que queremos agregar al chat.
915
+ requiere:
916
+ => items: [ { type , value } , ... ]
917
+ NOTA: si se quiere agregar un mensaje mandar un array con un object
918
+ example: [ {
919
+ type: "message" ,
920
+ value: "mi mensaje"
921
+ } ]
922
+ ======================================================================= */
923
+
924
+
925
+ var createItemsChat = /*#__PURE__*/function () {
926
+ var _ref10 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10() {
927
+ var items,
928
+ _iterator,
929
+ _step,
930
+ item,
931
+ errorCreate,
932
+ _args10 = arguments;
933
+
934
+ return _regenerator.default.wrap(function _callee10$(_context10) {
935
+ while (1) {
936
+ switch (_context10.prev = _context10.next) {
937
+ case 0:
938
+ items = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : [];
939
+
940
+ if (!(items.length === 0)) {
941
+ _context10.next = 3;
942
+ break;
943
+ }
944
+
945
+ return _context10.abrupt("return", {
946
+ message: "No se especifico ningun mensaje, imagen o archivo nuevo " + "que se quiera enviar al chat",
947
+ errorDetail: "Reporta esto a TI"
948
+ });
949
+
950
+ case 3:
951
+ _iterator = (0, _createForOfIteratorHelper2.default)(items);
952
+ _context10.prev = 4;
953
+
954
+ _iterator.s();
955
+
956
+ case 6:
957
+ if ((_step = _iterator.n()).done) {
958
+ _context10.next = 14;
959
+ break;
960
+ }
961
+
962
+ item = _step.value;
963
+
964
+ if (["message", "img", "file"].includes(item.type)) {
965
+ _context10.next = 10;
966
+ break;
967
+ }
968
+
969
+ return _context10.abrupt("return", {
970
+ message: "Uno de los elementos que se quiere enviar al chat " + "no es un tipo valido \"".concat(item.type, "\""),
971
+ errorDetail: "Reporta esto a TI"
972
+ });
973
+
974
+ case 10:
975
+ if (!(0, _utils.isStringEmpty)(item.value)) {
976
+ _context10.next = 12;
977
+ break;
978
+ }
979
+
980
+ return _context10.abrupt("return", {
981
+ message: "Uno de los elementos que se quiere enviar al chat " + "contiene un valor vacio",
982
+ errorDetail: "Reporta esto a TI"
983
+ });
984
+
985
+ case 12:
986
+ _context10.next = 6;
987
+ break;
988
+
989
+ case 14:
990
+ _context10.next = 19;
991
+ break;
992
+
993
+ case 16:
994
+ _context10.prev = 16;
995
+ _context10.t0 = _context10["catch"](4);
996
+
997
+ _iterator.e(_context10.t0);
998
+
999
+ case 19:
1000
+ _context10.prev = 19;
1001
+
1002
+ _iterator.f();
1003
+
1004
+ return _context10.finish(19);
1005
+
1006
+ case 22:
1007
+ stopUpdate(); // finalizamos el temporizador
1008
+ // enviar items a la BD
1009
+
1010
+ if (!(chatType === "merchant_product")) {
1011
+ _context10.next = 29;
1012
+ break;
1013
+ }
1014
+
1015
+ _context10.next = 26;
1016
+ return createItemsMerchantProduct(items);
1017
+
1018
+ case 26:
1019
+ errorCreate = _context10.sent;
1020
+ _context10.next = 38;
1021
+ break;
1022
+
1023
+ case 29:
1024
+ if (!(chatType === "order_product")) {
1025
+ _context10.next = 35;
1026
+ break;
1027
+ }
1028
+
1029
+ _context10.next = 32;
1030
+ return createItemsOrderProduct(items);
1031
+
1032
+ case 32:
1033
+ errorCreate = _context10.sent;
1034
+ _context10.next = 38;
1035
+ break;
1036
+
1037
+ case 35:
1038
+ _context10.next = 37;
1039
+ return createItemsTicket(items);
1040
+
1041
+ case 37:
1042
+ errorCreate = _context10.sent;
1043
+
1044
+ case 38:
1045
+ if (!(chatType === "merchant_product")) {
1046
+ _context10.next = 43;
1047
+ break;
1048
+ }
1049
+
1050
+ _context10.next = 41;
1051
+ return getUpdateLatestMerchantProduct();
1052
+
1053
+ case 41:
1054
+ _context10.next = 50;
1055
+ break;
1056
+
1057
+ case 43:
1058
+ if (!(chatType === "order_product")) {
1059
+ _context10.next = 48;
1060
+ break;
1061
+ }
1062
+
1063
+ _context10.next = 46;
1064
+ return getUpdateLatestOrderProduct();
1065
+
1066
+ case 46:
1067
+ _context10.next = 50;
1068
+ break;
1069
+
1070
+ case 48:
1071
+ _context10.next = 50;
1072
+ return getUpdateLatestTicket();
1073
+
1074
+ case 50:
1075
+ if (!errorCreate) {
1076
+ _context10.next = 52;
1077
+ break;
1078
+ }
1079
+
1080
+ return _context10.abrupt("return", errorCreate);
1081
+
1082
+ case 52:
1083
+ case "end":
1084
+ return _context10.stop();
1085
+ }
1086
+ }
1087
+ }, _callee10, null, [[4, 16, 19, 22]]);
1088
+ }));
1089
+
1090
+ return function createItemsChat() {
1091
+ return _ref10.apply(this, arguments);
1092
+ };
1093
+ }();
1094
+
1095
+ var createItemsMerchantProduct = /*#__PURE__*/function () {
1096
+ var _ref11 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11() {
1097
+ var items,
1098
+ paramsBody,
1099
+ response,
1100
+ _args11 = arguments;
1101
+ return _regenerator.default.wrap(function _callee11$(_context11) {
1102
+ while (1) {
1103
+ switch (_context11.prev = _context11.next) {
1104
+ case 0:
1105
+ items = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : [];
1106
+ paramsBody = {
1107
+ id: JSON.stringify(dataChat.id),
1108
+ version: JSON.stringify(dataChat.version),
1109
+ userId: JSON.stringify(currentUser.id),
1110
+ items: JSON.stringify(items)
1111
+ };
1112
+ _context11.next = 4;
1113
+ return (0, _handle_http.fetchPOST)(process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT, paramsBody);
1114
+
1115
+ case 4:
1116
+ response = _context11.sent;
1117
+
1118
+ if (response.body) {
1119
+ _context11.next = 7;
1120
+ break;
1121
+ }
1122
+
1123
+ return _context11.abrupt("return", {
1124
+ message: response.message,
1125
+ errorDetail: response.errorDetail
1126
+ });
1127
+
1128
+ case 7:
1129
+ case "end":
1130
+ return _context11.stop();
1131
+ }
1132
+ }
1133
+ }, _callee11);
1134
+ }));
1135
+
1136
+ return function createItemsMerchantProduct() {
1137
+ return _ref11.apply(this, arguments);
1138
+ };
1139
+ }();
1140
+
1141
+ var createItemsOrderProduct = /*#__PURE__*/function () {
1142
+ var _ref12 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12() {
1143
+ var items,
1144
+ paramsBody,
1145
+ response,
1146
+ _args12 = arguments;
1147
+ return _regenerator.default.wrap(function _callee12$(_context12) {
1148
+ while (1) {
1149
+ switch (_context12.prev = _context12.next) {
1150
+ case 0:
1151
+ items = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : [];
1152
+ paramsBody = {
1153
+ id: JSON.stringify(dataChat.id),
1154
+ version: JSON.stringify(currentArticle.version),
1155
+ userId: JSON.stringify(currentUser.id),
1156
+ items: JSON.stringify(items),
1157
+ orderId: JSON.stringify(dataChat.orderId),
1158
+ sentCompanyId: JSON.stringify(currentUser.companyId),
1159
+ receivedCompanyId: JSON.stringify(activeCompanyId)
1160
+ };
1161
+ _context12.next = 4;
1162
+ return (0, _handle_http.fetchPOST)(process.env.REACT_APP_PRODUCTS_CHAT_ENDPOINT, paramsBody);
1163
+
1164
+ case 4:
1165
+ response = _context12.sent;
1166
+
1167
+ if (response.body) {
1168
+ _context12.next = 7;
1169
+ break;
1170
+ }
1171
+
1172
+ return _context12.abrupt("return", {
1173
+ message: response.message,
1174
+ errorDetail: response.errorDetail
1175
+ });
1176
+
1177
+ case 7:
1178
+ case "end":
1179
+ return _context12.stop();
1180
+ }
1181
+ }
1182
+ }, _callee12);
1183
+ }));
1184
+
1185
+ return function createItemsOrderProduct() {
1186
+ return _ref12.apply(this, arguments);
1187
+ };
1188
+ }();
1189
+
1190
+ var createItemsTicket = /*#__PURE__*/function () {
1191
+ var _ref13 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13() {
1192
+ var items,
1193
+ paramsBody,
1194
+ response,
1195
+ _args13 = arguments;
1196
+ return _regenerator.default.wrap(function _callee13$(_context13) {
1197
+ while (1) {
1198
+ switch (_context13.prev = _context13.next) {
1199
+ case 0:
1200
+ items = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : [];
1201
+ paramsBody = {
1202
+ id: JSON.stringify(dataChat.id),
1203
+ userId: JSON.stringify(dataChat.currentUser.id),
1204
+ items: JSON.stringify(items)
1205
+ };
1206
+ _context13.next = 4;
1207
+ return (0, _handle_http.fetchPOST)(process.env.REACT_APP_TICKETS_CHAT_ENDPOINT, paramsBody);
1208
+
1209
+ case 4:
1210
+ response = _context13.sent;
1211
+
1212
+ if (response.body) {
1213
+ _context13.next = 7;
1214
+ break;
1215
+ }
1216
+
1217
+ return _context13.abrupt("return", {
1218
+ message: response.message,
1219
+ errorDetail: response.errorDetail
1220
+ });
1221
+
1222
+ case 7:
1223
+ case "end":
1224
+ return _context13.stop();
1225
+ }
1226
+ }
1227
+ }, _callee13);
1228
+ }));
1229
+
1230
+ return function createItemsTicket() {
1231
+ return _ref13.apply(this, arguments);
1232
+ };
1233
+ }();
1234
+ /*=======================================================================
1235
+ SECCION DE FUNCIONES
1236
+ ======================================================================= */
1237
+
1238
+
1239
+ var isSingleChat = function isSingleChat() {
1240
+ if (chatType === "merchant_product" || chatType === "ticket") {
1241
+ return true;
1242
+ }
1243
+
1244
+ if (companies && Object.keys(companies).length < 2) return true;else return false;
1245
+ };
1246
+
1247
+ var getItemsIdSingleChat = function getItemsIdSingleChat() {
1248
+ var itemsId = {};
1249
+
1250
+ if (Array.isArray(singleChat.items)) {
1251
+ singleChat.items.forEach(function (item) {
1252
+ if ((0, _utils.isValidNaturalNumber)(item.id)) itemsId[item.id] = true;
1253
+ });
1254
+ }
1255
+
1256
+ return itemsId;
1257
+ };
1258
+
1259
+ var getChatCompany = function getChatCompany() {
1260
+ if (chatType === "merchant_product" || chatType === "ticket") {
1261
+ return undefined;
1262
+ }
1263
+
1264
+ if (companies && companies[activeCompanyId]) {
1265
+ return (0, _objectSpread3.default)((0, _objectSpread3.default)({}, companies[activeCompanyId]), {}, {
1266
+ id: activeCompanyId
1267
+ });
1268
+ }
1269
+
1270
+ return undefined;
1271
+ };
1272
+
1273
+ var addOldItemsChat = function addOldItemsChat() {
1274
+ var currentItems = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1275
+ var newItems = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
1276
+ var items = currentItems.slice();
1277
+ var itemsId = {};
1278
+ items.forEach(function (item) {
1279
+ itemsId[item.id] = true;
1280
+ });
1281
+ newItems.forEach(function (item) {
1282
+ if (!itemsId[item.id]) {
1283
+ items.push(item);
1284
+ itemsId[item.id] = true;
1285
+ }
1286
+ });
1287
+ return items;
1288
+ };
1289
+
1290
+ var addNewItemsChat = function addNewItemsChat() {
1291
+ var currentItems = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1292
+ var newItems = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
1293
+ var fromUpdate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1294
+ var itemsId = {};
1295
+ currentItems.forEach(function (item) {
1296
+ itemsId[item.id] = item;
1297
+ });
1298
+ var thereAreNewItems = false;
1299
+ newItems.forEach(function (newitem) {
1300
+ if (!itemsId[newitem.id]) {
1301
+ itemsId[newitem.id] = newitem;
1302
+ thereAreNewItems = true;
1303
+ }
1304
+ });
1305
+
1306
+ if (thereAreNewItems && fromUpdate) {
1307
+ setPlaySound(true);
1308
+ setTimeout(function () {
1309
+ setPlaySound(false);
1310
+ }, 5000);
1311
+ }
1312
+
1313
+ return Object.values(itemsId).sort(function (a, b) {
1314
+ if (a.id < b.id) return 1;
1315
+ if (a.id > b.id) return -1;
1316
+ return 0;
1317
+ });
1318
+ };
1319
+
1320
+ var updateAllUsers = function updateAllUsers() {
1321
+ var newUsers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1322
+ var currentUsers = (0, _objectSpread3.default)({}, allUsers);
1323
+ Object.keys(newUsers).forEach(function (userId) {
1324
+ if (!currentUsers[userId]) {
1325
+ currentUsers[userId] = newUsers[userId];
1326
+ }
1327
+ });
1328
+ setAllUsers(currentUsers);
1329
+ };
1330
+
1331
+ var stopUpdate = function stopUpdate() {
1332
+ if (processUpdateID !== undefined) {
1333
+ clearTimeout(processUpdateID);
1334
+ setProcessUpdateID(undefined);
1335
+ }
1336
+ };
1337
+
1338
+ var renderBodyChat = function renderBodyChat() {
1339
+ if (isLoading) return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Loading.Loading, {});
1340
+
1341
+ if (errorChat.existError) {
1342
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_NotFound.NotFound, {
1343
+ code: errorChat.code,
1344
+ message: errorChat.message,
1345
+ details: errorChat.errorDetail
1346
+ });
1347
+ } // cuando se quiere ver la lista de chats
1348
+
1349
+
1350
+ if (showChatsList) {
1351
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChatLists.ChatLists, {
1352
+ companies: companies,
1353
+ currentCompanyId: currentUser === null || currentUser === void 0 ? void 0 : currentUser.companyId,
1354
+ onClickCompany: function onClickCompany(companyIdSelected) {
1355
+ setActiveCompanyId(Number(companyIdSelected));
1356
+ setShowChatsList(false);
1357
+ }
1358
+ });
1359
+ } // mostrar chat?
1360
+
1361
+
1362
+ var items;
1363
+ var enabledLoadMore;
1364
+
1365
+ if (["merchant_product", "ticket"].includes(chatType)) {
1366
+ items = singleChat.items;
1367
+ enabledLoadMore = singleChat.enabledLoadMore;
1368
+ } // ORDER_PRODUCT
1369
+ else if (companies) {
1370
+ // caso 0 chats
1371
+ if (Object.keys(companies).length === 0) {
1372
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
1373
+ className: "container-chatEmpty",
1374
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomIcon.CustomIcon, {
1375
+ className: "icon-chat",
1376
+ transparent: true,
1377
+ size: 35,
1378
+ icon: _freeSolidSvgIcons.faComments,
1379
+ type: "gray"
1380
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
1381
+ children: "De acuerdo al estatus del producto, tu compa\xF1ia no tiene disponible ningun chat abierto o cerrado"
1382
+ })]
1383
+ });
1384
+ } // caso 1 o mas chats
1385
+
1386
+
1387
+ if (companies[activeCompanyId]) {
1388
+ items = companies[activeCompanyId].items;
1389
+ enabledLoadMore = companies[activeCompanyId].enabledLoadMore;
1390
+ }
1391
+ }
1392
+
1393
+ if (items) {
1394
+ var _getChatCompany, _getChatCompany2;
1395
+
1396
+ var containerItems = null;
1397
+
1398
+ if (items.length) {
1399
+ containerItems = /*#__PURE__*/(0, _jsxRuntime.jsx)(_ContainerItems.ContainerItems, {
1400
+ items: items,
1401
+ users: allUsers,
1402
+ showBtnLoadMore: enabledLoadMore,
1403
+ chatType: chatType,
1404
+ activeCompanyId: activeCompanyId,
1405
+ currentUser: ["merchant_product", "order_product"].includes(chatType) ? currentUser : dataChat.currentUser,
1406
+ onClickBtnLoadMore: chatType === "merchant_product" ? getLoadMoreMerchantProduct : chatType === "order_product" ? getLoadMoreOrderProduct : getLoadMoreTicket
1407
+ });
1408
+ } else {
1409
+ containerItems = /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
1410
+ className: "container-chatEmpty",
1411
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_CustomIcon.CustomIcon, {
1412
+ className: "icon-chat",
1413
+ size: 35,
1414
+ icon: _freeSolidSvgIcons.faComments,
1415
+ type: "gray",
1416
+ transparent: true
1417
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
1418
+ children: "Este chat no tiene mensajes"
1419
+ })]
1420
+ });
1421
+ }
1422
+
1423
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1424
+ children: [containerItems, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Footer.Footer, {
1425
+ chatType: chatType,
1426
+ dataChat: chatType === "merchant_product" ? {
1427
+ id: dataChat.id,
1428
+ version: dataChat.version
1429
+ } : chatType === "order_product" ? {
1430
+ id: dataChat.id,
1431
+ version: currentArticle.version
1432
+ } : chatType === "ticket" ? {
1433
+ id: dataChat.id
1434
+ } : undefined,
1435
+ chatCompany: getChatCompany(),
1436
+ statusChat: chatType === "order_product" ? (_getChatCompany = getChatCompany()) === null || _getChatCompany === void 0 ? void 0 : _getChatCompany.statusChat : chatType === "ticket" ? singleChat.statusChat : undefined,
1437
+ messageDisabled: chatType === "order_product" ? "La conversaci\xF3n con ".concat((_getChatCompany2 = getChatCompany()) === null || _getChatCompany2 === void 0 ? void 0 : _getChatCompany2.name, " ha finalizado") : chatType === "ticket" ? "Ticket cerrado" : "La conversaci\xF3n ha finalizado",
1438
+ createItemsChat: createItemsChat,
1439
+ errorUpdate: errorUpdate
1440
+ })]
1441
+ });
1442
+ }
1443
+
1444
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Loading.Loading, {});
1445
+ };
1446
+
1447
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1448
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Container, {
1449
+ children: [(chatContainerType !== "fixed" || !isSingleChat()) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Header.Header, {
1450
+ showBtnClose: showBtnClose,
1451
+ onClickBtnClose: onClickBtnClose,
1452
+ showChatsList: showChatsList,
1453
+ chatCompany: getChatCompany(),
1454
+ multipleCompanies: !isSingleChat(),
1455
+ onClickBtnChooseChat: function onClickBtnChooseChat() {
1456
+ setShowChatsList(true);
1457
+ }
1458
+ }), renderBodyChat()]
1459
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactHowler.default, {
1460
+ src: _newMessage.default,
1461
+ playing: playSound
1462
+ })]
1463
+ });
1464
+ };
1465
+
1466
+ exports.ContentChat = ContentChat;