contentoh-components-library 21.3.17 → 21.3.19

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