contentoh-components-library 21.2.104 → 21.2.106

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