contentoh-components-library 21.6.55 → 21.6.57
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.
- package/.claude/launch.json +14 -0
- package/.env.test +1 -0
- package/dist/ai/prompts/attribute.prompt.js +28 -0
- package/dist/ai/prompts/description.prompt.js +33 -0
- package/dist/ai/schemas/attribute.schema.js +35 -0
- package/dist/ai/schemas/description.schema.js +27 -0
- package/dist/components/atoms/AsignationOption/index.js +1 -0
- package/dist/components/atoms/AsignationOption/styles.js +1 -1
- package/dist/components/atoms/AssetPreview/AssetPreview.stories.js +118 -0
- package/dist/components/atoms/AssetPreview/index.js +150 -0
- package/dist/components/atoms/AssetPreview/styles.js +28 -0
- package/dist/components/atoms/IconFile/index.js +85 -2
- package/dist/components/atoms/IconFile/styles.js +1 -1
- package/dist/components/atoms/ProductImage/ProductImage.stories.js +70 -2
- package/dist/components/atoms/ProductImage/index.js +100 -27
- package/dist/components/atoms/ProductImage/styles.js +3 -1
- package/dist/components/molecules/EditionActiveImage/index.js +4 -2
- package/dist/components/molecules/GalleryAssetElement/GalleryAssetElement.stories.js +147 -0
- package/dist/components/molecules/GalleryAssetElement/index.js +178 -0
- package/dist/components/molecules/GalleryAssetElement/styles.js +26 -0
- package/dist/components/molecules/GalleryElement/index.js +13 -4
- package/dist/components/molecules/GalleryHeader/index.js +96 -24
- package/dist/components/molecules/GalleryHeader/styles.js +4 -1
- package/dist/components/molecules/GalleryTrayTabs/GalleryTrayTabs.stories.js +56 -0
- package/dist/components/molecules/GalleryTrayTabs/index.js +60 -0
- package/dist/components/molecules/GalleryTrayTabs/styles.js +20 -0
- package/dist/components/molecules/ImageSelector/index.js +1 -0
- package/dist/components/molecules/RetailerSelector/RetailerSelector.stories.js +23 -2
- package/dist/components/molecules/RetailerSelector/index.js +7 -2
- package/dist/components/molecules/RetailerSelectorv2/index.js +6 -2
- package/dist/components/organisms/DigitalAssetsTray/DigitalAssetsTray.stories.js +235 -0
- package/dist/components/organisms/DigitalAssetsTray/index.js +219 -0
- package/dist/components/organisms/DigitalAssetsTray/styles.js +22 -0
- package/dist/components/organisms/ImagePreviewer/index.js +1 -0
- package/dist/components/organisms/ProductImageModal/index.js +3 -2
- package/dist/components/pages/CreatorsProductEdition/CreatorsProductEditionView.js +905 -0
- package/dist/components/pages/CreatorsProductEdition/constants.js +19 -0
- package/dist/components/pages/CreatorsProductEdition/hooks/useCreatorsProductEdition.js +2967 -0
- package/dist/components/pages/CreatorsProductEdition/index.js +33 -0
- package/dist/components/pages/CreatorsProductEdition/mocks/api.fixtures.js +537 -0
- package/dist/components/pages/CreatorsProductEdition/mocks/mockApi.js +251 -0
- package/dist/components/pages/CreatorsProductEdition/sections/CommentBox.js +311 -0
- package/dist/components/pages/CreatorsProductEdition/sections/ImagePanel.js +421 -0
- package/dist/components/pages/CreatorsProductEdition/sections/ImagesSection.js +473 -0
- package/dist/components/pages/CreatorsProductEdition/sections/ProductHeader.js +379 -0
- package/dist/components/pages/CreatorsProductEdition/sections/ProductMedia.js +138 -0
- package/dist/components/pages/CreatorsProductEdition/sections/RetailerMenu.js +162 -0
- package/dist/components/pages/CreatorsProductEdition/sections/ServiceActions.js +542 -0
- package/dist/components/pages/CreatorsProductEdition/sections/StatusChip.js +50 -0
- package/dist/components/pages/CreatorsProductEdition/sections/TabsBar.js +247 -0
- package/dist/components/pages/CreatorsProductEdition/sections/VariantsPanel.js +389 -0
- package/dist/components/pages/CreatorsProductEdition/sections/tokens.js +90 -0
- package/dist/components/pages/CreatorsProductEdition/stories/CreatorsProductEdition.stories.js +168 -0
- package/dist/components/pages/CreatorsProductEdition/stories/CreatorsProductEditionAPI.stories.js +74 -0
- package/dist/components/pages/CreatorsProductEdition/styles.js +46 -0
- package/dist/components/pages/RetailerProductEdition/context/provider-product-edition.context.js +330 -15
- package/dist/components/pages/RetailerProductEdition/context/provider-product-edition.reducer.js +12 -2
- package/dist/components/pages/RetailerProductEdition/index.js +606 -425
- package/dist/components/pages/RetailerProductEdition/stories/ImageEditor.stories.js +1 -0
- package/dist/global-files/data.js +16 -3
- package/dist/global-files/digital-assets/assetTypes.js +517 -0
- package/dist/global-files/digital-assets/assets.actions.js +64 -0
- package/dist/global-files/digital-assets/assets.adapter.js +304 -0
- package/dist/global-files/digital-assets/assets.mock.js +136 -0
- package/dist/global-files/digital-assets/assets.reducer.js +220 -0
- package/dist/global-files/digital-assets/uploadAssets.js +202 -0
- package/dist/global-files/digital-assets/useDigitalAssets.js +535 -0
- package/dist/index.js +142 -90
- package/docs/activos-digitales.md +273 -0
- package/package.json +1 -1
- package/src/components/atoms/AsignationOption/index.js +1 -1
- package/src/components/atoms/AsignationOption/styles.js +9 -0
- package/src/components/atoms/AssetPreview/AssetPreview.stories.js +78 -0
- package/src/components/atoms/AssetPreview/index.js +119 -0
- package/src/components/atoms/AssetPreview/styles.js +190 -0
- package/src/components/atoms/IconFile/index.js +28 -1
- package/src/components/atoms/IconFile/styles.js +8 -0
- package/src/components/atoms/ProductImage/ProductImage.stories.js +38 -0
- package/src/components/atoms/ProductImage/index.js +95 -20
- package/src/components/atoms/ProductImage/styles.js +92 -7
- package/src/components/molecules/EditionActiveImage/index.js +2 -2
- package/src/components/molecules/GalleryAssetElement/GalleryAssetElement.stories.js +102 -0
- package/src/components/molecules/GalleryAssetElement/index.js +162 -0
- package/src/components/molecules/GalleryAssetElement/styles.js +163 -0
- package/src/components/molecules/GalleryElement/index.js +9 -0
- package/src/components/molecules/GalleryHeader/index.js +65 -13
- package/src/components/molecules/GalleryHeader/styles.js +2 -1
- package/src/components/molecules/GalleryTrayTabs/GalleryTrayTabs.stories.js +32 -0
- package/src/components/molecules/GalleryTrayTabs/index.js +41 -0
- package/src/components/molecules/GalleryTrayTabs/styles.js +52 -0
- package/src/components/molecules/ImageSelector/index.js +1 -0
- package/src/components/molecules/RetailerSelector/RetailerSelector.stories.js +15 -1
- package/src/components/molecules/RetailerSelector/index.js +8 -1
- package/src/components/molecules/RetailerSelectorv2/index.js +7 -1
- package/src/components/organisms/DigitalAssetsTray/DigitalAssetsTray.stories.js +164 -0
- package/src/components/organisms/DigitalAssetsTray/index.js +193 -0
- package/src/components/organisms/DigitalAssetsTray/styles.js +183 -0
- package/src/components/organisms/ImagePreviewer/index.js +1 -0
- package/src/components/organisms/ProductImageModal/index.js +1 -0
- package/src/components/pages/RetailerProductEdition/context/provider-product-edition.context.jsx +201 -0
- package/src/components/pages/RetailerProductEdition/context/provider-product-edition.reducer.js +12 -0
- package/src/components/pages/RetailerProductEdition/index.js +356 -139
- package/src/components/pages/RetailerProductEdition/stories/ImageEditor.stories.js +1 -0
- package/src/global-files/data.js +17 -2
- package/src/global-files/digital-assets/assetTypes.js +451 -0
- package/src/global-files/digital-assets/assets.actions.js +50 -0
- package/src/global-files/digital-assets/assets.adapter.js +229 -0
- package/src/global-files/digital-assets/assets.mock.js +122 -0
- package/src/global-files/digital-assets/assets.reducer.js +197 -0
- package/src/global-files/digital-assets/uploadAssets.js +124 -0
- package/src/global-files/digital-assets/useDigitalAssets.js +340 -0
- package/src/index.js +4 -0
|
@@ -0,0 +1,2967 @@
|
|
|
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.useCreatorsProductEdition = void 0;
|
|
9
|
+
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
+
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
|
|
13
|
+
|
|
14
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/typeof"));
|
|
15
|
+
|
|
16
|
+
var _objectSpread5 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
17
|
+
|
|
18
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
|
|
19
|
+
|
|
20
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator"));
|
|
21
|
+
|
|
22
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
|
|
23
|
+
|
|
24
|
+
var _react = require("react");
|
|
25
|
+
|
|
26
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
27
|
+
|
|
28
|
+
var _reactDropzone = require("react-dropzone");
|
|
29
|
+
|
|
30
|
+
var _fileSaver = require("file-saver");
|
|
31
|
+
|
|
32
|
+
var _providerProductEdition = require("../../RetailerProductEdition/context/provider-product-edition.context");
|
|
33
|
+
|
|
34
|
+
var _product = require("../../RetailerProductEdition/context/reducers/product");
|
|
35
|
+
|
|
36
|
+
var _utils = require("../../RetailerProductEdition/utils");
|
|
37
|
+
|
|
38
|
+
var _generateThumnail = _interopRequireDefault(require("../../RetailerProductEdition/generateThumnail"));
|
|
39
|
+
|
|
40
|
+
var _data = require("../../../../global-files/data");
|
|
41
|
+
|
|
42
|
+
var _customHooks = require("../../../../global-files/customHooks");
|
|
43
|
+
|
|
44
|
+
var _useDigitalAssets = require("../../../../global-files/digital-assets/useDigitalAssets");
|
|
45
|
+
|
|
46
|
+
var _assets = require("../../../../global-files/digital-assets/assets.reducer");
|
|
47
|
+
|
|
48
|
+
var _GalleryTrayTabs = require("../../../molecules/GalleryTrayTabs");
|
|
49
|
+
|
|
50
|
+
var _nonPropagable = require("../../../organisms/PropagateChangesModal/non-propagable");
|
|
51
|
+
|
|
52
|
+
var _api = require("../../../organisms/LinkVariantsModal/api");
|
|
53
|
+
|
|
54
|
+
var _genericModalCheck = _interopRequireDefault(require("../../../../assets/images/genericModal/genericModalCheck.svg"));
|
|
55
|
+
|
|
56
|
+
var _errorModal = _interopRequireDefault(require("../../../../assets/images/genericModal/errorModal.svg"));
|
|
57
|
+
|
|
58
|
+
var _genericModalWarning = _interopRequireDefault(require("../../../../assets/images/genericModal/genericModalWarning.svg"));
|
|
59
|
+
|
|
60
|
+
var _attributesSent = _interopRequireDefault(require("../../../../assets/images/modalsSVGs/attributesSent.svg"));
|
|
61
|
+
|
|
62
|
+
var _descriptionSent = _interopRequireDefault(require("../../../../assets/images/modalsSVGs/descriptionSent.svg"));
|
|
63
|
+
|
|
64
|
+
var _uploadingImages = _interopRequireDefault(require("../../../../assets/images/modalsSVGs/uploadingImages.svg"));
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Lógica de la edición de producto de Creators.
|
|
68
|
+
*
|
|
69
|
+
* COPIA LITERAL de `RetailerProductEdition/index.js` (commit ff06fba), líneas
|
|
70
|
+
* 122-317, 365-2182 y 2309-2320: todo lo que no es JSX. Se copió en vez de
|
|
71
|
+
* compartirse porque la vista actual no se puede tocar. Consecuencia: un fix
|
|
72
|
+
* en RetailerProductEdition hay que portarlo aquí a mano. Para ver qué cambió
|
|
73
|
+
* desde la copia:
|
|
74
|
+
*
|
|
75
|
+
* git diff ff06fba -- src/components/pages/RetailerProductEdition/index.js
|
|
76
|
+
*
|
|
77
|
+
* Lo único que no se copió: `thumbs` (JSX de la galería, vive en la vista) y
|
|
78
|
+
* el skeleton. El botón de "comentario revisado" se dejó fuera a propósito:
|
|
79
|
+
* en el original llama a `commentRevised()`, que no existe.
|
|
80
|
+
*/
|
|
81
|
+
function obtenerDuracionVideoBase64(base64Data) {
|
|
82
|
+
return new Promise(function (resolve, reject) {
|
|
83
|
+
var video = document.createElement("video");
|
|
84
|
+
video.src = base64Data;
|
|
85
|
+
video.addEventListener("loadedmetadata", function () {
|
|
86
|
+
resolve(video.duration);
|
|
87
|
+
});
|
|
88
|
+
video.addEventListener("error", reject);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
var useCreatorsProductEdition = function useCreatorsProductEdition(_ref) {
|
|
93
|
+
var _state$product$id_art, _state$product, _state$product11, _family$variants, _state$product12, _state$product16;
|
|
94
|
+
|
|
95
|
+
var tabsSections = _ref.tabsSections,
|
|
96
|
+
_ref$productSelected = _ref.productSelected,
|
|
97
|
+
productSelected = _ref$productSelected === void 0 ? {} : _ref$productSelected,
|
|
98
|
+
_ref$user = _ref.user,
|
|
99
|
+
user = _ref$user === void 0 ? {} : _ref$user,
|
|
100
|
+
token = _ref.token,
|
|
101
|
+
location = _ref.location,
|
|
102
|
+
_ref$enableDigitalAss = _ref.enableDigitalAssets,
|
|
103
|
+
enableDigitalAssets = _ref$enableDigitalAss === void 0 ? false : _ref$enableDigitalAss;
|
|
104
|
+
|
|
105
|
+
var _useProviderProductEd = (0, _providerProductEdition.useProviderProductEdition)(),
|
|
106
|
+
state = _useProviderProductEd.state,
|
|
107
|
+
dispatch = _useProviderProductEd.dispatch,
|
|
108
|
+
saveDatasheets = _useProviderProductEd.saveDatasheets,
|
|
109
|
+
saveDescriptions = _useProviderProductEd.saveDescriptions,
|
|
110
|
+
updateImages = _useProviderProductEd.updateImages,
|
|
111
|
+
deleteImages = _useProviderProductEd.deleteImages,
|
|
112
|
+
saveAssets = _useProviderProductEd.saveAssets,
|
|
113
|
+
registerUploadedAssets = _useProviderProductEd.registerUploadedAssets,
|
|
114
|
+
handleOnDownloadImages = _useProviderProductEd.handleOnDownloadImages,
|
|
115
|
+
createComment = _useProviderProductEd.createComment;
|
|
116
|
+
|
|
117
|
+
var isRetailer = user === null || user === void 0 ? void 0 : user.is_retailer;
|
|
118
|
+
|
|
119
|
+
var _useCloseModal = (0, _customHooks.useCloseModal)("version-selector"),
|
|
120
|
+
_useCloseModal2 = (0, _slicedToArray2.default)(_useCloseModal, 2),
|
|
121
|
+
showVersionSelector = _useCloseModal2[0],
|
|
122
|
+
setShowVersionSelector = _useCloseModal2[1];
|
|
123
|
+
|
|
124
|
+
var _useState = (0, _react.useState)(null),
|
|
125
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
126
|
+
auditableVersion = _useState2[0],
|
|
127
|
+
setAuditableVersion = _useState2[1];
|
|
128
|
+
|
|
129
|
+
var _useState3 = (0, _react.useState)(0),
|
|
130
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
131
|
+
headerTop = _useState4[0],
|
|
132
|
+
setHeaderTop = _useState4[1];
|
|
133
|
+
|
|
134
|
+
var _useState5 = (0, _react.useState)(false),
|
|
135
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
136
|
+
shotThd = _useState6[0],
|
|
137
|
+
setShotThd = _useState6[1];
|
|
138
|
+
|
|
139
|
+
var _useState7 = (0, _react.useState)(),
|
|
140
|
+
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
|
141
|
+
observation = _useState8[0],
|
|
142
|
+
setObservation = _useState8[1];
|
|
143
|
+
|
|
144
|
+
var _useState9 = (0, _react.useState)(false),
|
|
145
|
+
_useState10 = (0, _slicedToArray2.default)(_useState9, 2),
|
|
146
|
+
showRejectModal = _useState10[0],
|
|
147
|
+
setShowRejectModal = _useState10[1];
|
|
148
|
+
|
|
149
|
+
var _useState11 = (0, _react.useState)(false),
|
|
150
|
+
_useState12 = (0, _slicedToArray2.default)(_useState11, 2),
|
|
151
|
+
isObservationVisible = _useState12[0],
|
|
152
|
+
setObservationVisible = _useState12[1];
|
|
153
|
+
|
|
154
|
+
var _useState13 = (0, _react.useState)(false),
|
|
155
|
+
_useState14 = (0, _slicedToArray2.default)(_useState13, 2),
|
|
156
|
+
imageLayout = _useState14[0],
|
|
157
|
+
setImageLayout = _useState14[1];
|
|
158
|
+
|
|
159
|
+
var _useState15 = (0, _react.useState)(false),
|
|
160
|
+
_useState16 = (0, _slicedToArray2.default)(_useState15, 2),
|
|
161
|
+
crossComment = _useState16[0],
|
|
162
|
+
setCrossComment = _useState16[1];
|
|
163
|
+
|
|
164
|
+
var _useState17 = (0, _react.useState)([]),
|
|
165
|
+
_useState18 = (0, _slicedToArray2.default)(_useState17, 2),
|
|
166
|
+
statusArray = _useState18[0],
|
|
167
|
+
setStatusArray = _useState18[1];
|
|
168
|
+
|
|
169
|
+
var _useState19 = (0, _react.useState)(false),
|
|
170
|
+
_useState20 = (0, _slicedToArray2.default)(_useState19, 2),
|
|
171
|
+
rejectAll = _useState20[0],
|
|
172
|
+
setRejectAll = _useState20[1]; // Padre/hijo: mismo comportamiento que la ficha de la aplicación de clientes.
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
var _useState21 = (0, _react.useState)(false),
|
|
176
|
+
_useState22 = (0, _slicedToArray2.default)(_useState21, 2),
|
|
177
|
+
showLinkVariants = _useState22[0],
|
|
178
|
+
setShowLinkVariants = _useState22[1];
|
|
179
|
+
|
|
180
|
+
var _useState23 = (0, _react.useState)(null),
|
|
181
|
+
_useState24 = (0, _slicedToArray2.default)(_useState23, 2),
|
|
182
|
+
family = _useState24[0],
|
|
183
|
+
setFamily = _useState24[1];
|
|
184
|
+
|
|
185
|
+
var _useState25 = (0, _react.useState)(false),
|
|
186
|
+
_useState26 = (0, _slicedToArray2.default)(_useState25, 2),
|
|
187
|
+
showFamily = _useState26[0],
|
|
188
|
+
setShowFamily = _useState26[1];
|
|
189
|
+
|
|
190
|
+
var _useState27 = (0, _react.useState)(null),
|
|
191
|
+
_useState28 = (0, _slicedToArray2.default)(_useState27, 2),
|
|
192
|
+
loadingVariant = _useState28[0],
|
|
193
|
+
setLoadingVariant = _useState28[1];
|
|
194
|
+
/*
|
|
195
|
+
Agrupación de variantes. Aparte del padre/hijo a propósito: son mecanismos
|
|
196
|
+
independientes y un producto puede tener los dos. Padre/hijo es herencia;
|
|
197
|
+
esto es solo un código compartido.
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
var _useState29 = (0, _react.useState)(null),
|
|
202
|
+
_useState30 = (0, _slicedToArray2.default)(_useState29, 2),
|
|
203
|
+
variantGroup = _useState30[0],
|
|
204
|
+
setVariantGroup = _useState30[1];
|
|
205
|
+
|
|
206
|
+
var _useState31 = (0, _react.useState)(false),
|
|
207
|
+
_useState32 = (0, _slicedToArray2.default)(_useState31, 2),
|
|
208
|
+
showGroup = _useState32[0],
|
|
209
|
+
setShowGroup = _useState32[1];
|
|
210
|
+
|
|
211
|
+
var _useState33 = (0, _react.useState)(false),
|
|
212
|
+
_useState34 = (0, _slicedToArray2.default)(_useState33, 2),
|
|
213
|
+
showGroupModal = _useState34[0],
|
|
214
|
+
setShowGroupModal = _useState34[1]; // Qué vínculo se está por romper, o null si no hay diálogo abierto. Guarda al
|
|
215
|
+
// HIJO, que es quien lleva la relación y lo que pide la acción `unlink`.
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
var _useState35 = (0, _react.useState)(null),
|
|
219
|
+
_useState36 = (0, _slicedToArray2.default)(_useState35, 2),
|
|
220
|
+
porDesvincular = _useState36[0],
|
|
221
|
+
setPorDesvincular = _useState36[1]; // Por qué un salto no se pudo hacer. Vive aparte de `family.error` porque no
|
|
222
|
+
// es un fallo al leer la familia, sino al abrir uno de sus miembros.
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
var _useState37 = (0, _react.useState)(null),
|
|
226
|
+
_useState38 = (0, _slicedToArray2.default)(_useState37, 2),
|
|
227
|
+
avisoFamilia = _useState38[0],
|
|
228
|
+
setAvisoFamilia = _useState38[1];
|
|
229
|
+
|
|
230
|
+
var _useState39 = (0, _react.useState)(null),
|
|
231
|
+
_useState40 = (0, _slicedToArray2.default)(_useState39, 2),
|
|
232
|
+
pendingPropagation = _useState40[0],
|
|
233
|
+
setPendingPropagation = _useState40[1];
|
|
234
|
+
|
|
235
|
+
var _useState41 = (0, _react.useState)(false),
|
|
236
|
+
_useState42 = (0, _slicedToArray2.default)(_useState41, 2),
|
|
237
|
+
preparandoPropagacion = _useState42[0],
|
|
238
|
+
setPreparandoPropagacion = _useState42[1];
|
|
239
|
+
|
|
240
|
+
var _useState43 = (0, _react.useState)([]),
|
|
241
|
+
_useState44 = (0, _slicedToArray2.default)(_useState43, 2),
|
|
242
|
+
auditServices = _useState44[0],
|
|
243
|
+
setAuditServices = _useState44[1];
|
|
244
|
+
|
|
245
|
+
var _useState45 = (0, _react.useState)([]),
|
|
246
|
+
_useState46 = (0, _slicedToArray2.default)(_useState45, 2),
|
|
247
|
+
auditDatasheets = _useState46[0],
|
|
248
|
+
setAuditDatasheets = _useState46[1];
|
|
249
|
+
|
|
250
|
+
var _useState47 = (0, _react.useState)([]),
|
|
251
|
+
_useState48 = (0, _slicedToArray2.default)(_useState47, 2),
|
|
252
|
+
auditDescriptions = _useState48[0],
|
|
253
|
+
setAuditDescriptions = _useState48[1];
|
|
254
|
+
|
|
255
|
+
var _useState49 = (0, _react.useState)(false),
|
|
256
|
+
_useState50 = (0, _slicedToArray2.default)(_useState49, 2),
|
|
257
|
+
showModal = _useState50[0],
|
|
258
|
+
setShowModal = _useState50[1];
|
|
259
|
+
|
|
260
|
+
var _useState51 = (0, _react.useState)(false),
|
|
261
|
+
_useState52 = (0, _slicedToArray2.default)(_useState51, 2),
|
|
262
|
+
compare = _useState52[0],
|
|
263
|
+
setCompare = _useState52[1];
|
|
264
|
+
|
|
265
|
+
var _useDropzone = (0, _reactDropzone.useDropzone)({
|
|
266
|
+
accept: "image/*, video/mp4",
|
|
267
|
+
noKeyboard: true,
|
|
268
|
+
multiple: true,
|
|
269
|
+
noClick: true,
|
|
270
|
+
onDrop: function onDrop(acceptedFiles) {
|
|
271
|
+
acceptedFiles.map(function (file) {
|
|
272
|
+
var reader = new FileReader();
|
|
273
|
+
reader.fileName = file.name;
|
|
274
|
+
|
|
275
|
+
reader.onload = /*#__PURE__*/function () {
|
|
276
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(e) {
|
|
277
|
+
var fileName, fileExtension, fileDataURL, img, duracion;
|
|
278
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
279
|
+
while (1) {
|
|
280
|
+
switch (_context.prev = _context.next) {
|
|
281
|
+
case 0:
|
|
282
|
+
fileName = e.target.fileName;
|
|
283
|
+
fileExtension = fileName.split(".").pop();
|
|
284
|
+
fileDataURL = e.target.result;
|
|
285
|
+
img = new Image();
|
|
286
|
+
|
|
287
|
+
if (!(fileExtension === "mp4")) {
|
|
288
|
+
_context.next = 22;
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
_context.prev = 5;
|
|
293
|
+
_context.next = 8;
|
|
294
|
+
return obtenerDuracionVideoBase64(fileDataURL);
|
|
295
|
+
|
|
296
|
+
case 8:
|
|
297
|
+
duracion = _context.sent;
|
|
298
|
+
|
|
299
|
+
if (!(duracion <= 10 || duracion >= 600)) {
|
|
300
|
+
_context.next = 12;
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
dispatch({
|
|
305
|
+
type: "SET_MODAL",
|
|
306
|
+
payload: {
|
|
307
|
+
show: true,
|
|
308
|
+
title: "Hubo un error al subir el video",
|
|
309
|
+
message: "Los videos deben durar entre 15 segundos y 10 minutos",
|
|
310
|
+
image: _errorModal.default
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
return _context.abrupt("return");
|
|
314
|
+
|
|
315
|
+
case 12:
|
|
316
|
+
_context.next = 14;
|
|
317
|
+
return (0, _generateThumnail.default)(fileDataURL, 2);
|
|
318
|
+
|
|
319
|
+
case 14:
|
|
320
|
+
img.src = _context.sent;
|
|
321
|
+
|
|
322
|
+
img.onload = function () {
|
|
323
|
+
var newImg = {
|
|
324
|
+
src: img.src,
|
|
325
|
+
name: fileName,
|
|
326
|
+
ext: fileExtension,
|
|
327
|
+
width: img.width,
|
|
328
|
+
height: img.height,
|
|
329
|
+
video_src: fileDataURL,
|
|
330
|
+
isApproved: true // VALIDAR QUE SOLO SEA PARA RADIOSHACK
|
|
331
|
+
|
|
332
|
+
};
|
|
333
|
+
dispatch({
|
|
334
|
+
type: "ADD_IMAGE_VALUE",
|
|
335
|
+
payload: newImg
|
|
336
|
+
});
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
_context.next = 21;
|
|
340
|
+
break;
|
|
341
|
+
|
|
342
|
+
case 18:
|
|
343
|
+
_context.prev = 18;
|
|
344
|
+
_context.t0 = _context["catch"](5);
|
|
345
|
+
console.error("Error al obtener la duración del video:", _context.t0);
|
|
346
|
+
|
|
347
|
+
case 21:
|
|
348
|
+
return _context.abrupt("return");
|
|
349
|
+
|
|
350
|
+
case 22:
|
|
351
|
+
img.src = fileDataURL;
|
|
352
|
+
|
|
353
|
+
img.onload = function () {
|
|
354
|
+
var width = img.width;
|
|
355
|
+
var height = img.height;
|
|
356
|
+
var newImg = {
|
|
357
|
+
src: fileDataURL,
|
|
358
|
+
name: fileName,
|
|
359
|
+
ext: fileExtension,
|
|
360
|
+
width: width,
|
|
361
|
+
height: height,
|
|
362
|
+
video_src: "",
|
|
363
|
+
isApproved: true // VALIDAR QUE SOLO SEA PARA RADIOSHACK
|
|
364
|
+
|
|
365
|
+
};
|
|
366
|
+
dispatch({
|
|
367
|
+
type: "ADD_IMAGE_VALUE",
|
|
368
|
+
payload: newImg
|
|
369
|
+
});
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
case 24:
|
|
373
|
+
case "end":
|
|
374
|
+
return _context.stop();
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}, _callee, null, [[5, 18]]);
|
|
378
|
+
}));
|
|
379
|
+
|
|
380
|
+
return function (_x) {
|
|
381
|
+
return _ref2.apply(this, arguments);
|
|
382
|
+
};
|
|
383
|
+
}();
|
|
384
|
+
|
|
385
|
+
reader.onerror = function (error) {
|
|
386
|
+
console.log("dropzoneError: ", error);
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
reader.readAsDataURL(file);
|
|
390
|
+
return file;
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
}),
|
|
394
|
+
getRootProps = _useDropzone.getRootProps,
|
|
395
|
+
getInputProps = _useDropzone.getInputProps,
|
|
396
|
+
isDragActive = _useDropzone.isDragActive,
|
|
397
|
+
open = _useDropzone.open;
|
|
398
|
+
|
|
399
|
+
var _useState53 = (0, _react.useState)(false),
|
|
400
|
+
_useState54 = (0, _slicedToArray2.default)(_useState53, 2),
|
|
401
|
+
openChangeStatusModal = _useState54[0],
|
|
402
|
+
setOpenChangeStatusModal = _useState54[1];
|
|
403
|
+
/*
|
|
404
|
+
Bandeja de activos digitales. La lista vive en el reducer de la ficha
|
|
405
|
+
(`state.assets_values`), igual que las imágenes, para que el guardado del
|
|
406
|
+
contexto pueda leerla. El hook solo aporta validación y ciclo de vida.
|
|
407
|
+
Sigue vacía porque todavía no hay de dónde leerla: cuando exista el endpoint
|
|
408
|
+
se llama a `replaceAll` desde `loadData` y el resto de la pantalla no cambia.
|
|
409
|
+
*/
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
var _useState55 = (0, _react.useState)([]),
|
|
413
|
+
_useState56 = (0, _slicedToArray2.default)(_useState55, 2),
|
|
414
|
+
assetNotices = _useState56[0],
|
|
415
|
+
setAssetNotices = _useState56[1];
|
|
416
|
+
|
|
417
|
+
var digitalAssets = (0, _useDigitalAssets.useDigitalAssets)({
|
|
418
|
+
assets: state.assets_values,
|
|
419
|
+
dispatch: dispatch,
|
|
420
|
+
notices: assetNotices,
|
|
421
|
+
setNotices: setAssetNotices,
|
|
422
|
+
// Con los dos, la subida a S3 arranca sola al soltar los archivos. Sin
|
|
423
|
+
// ellos —en Storybook, por ejemplo— la bandeja funciona igual pero no sube.
|
|
424
|
+
articleId: (_state$product$id_art = (_state$product = state.product) === null || _state$product === void 0 ? void 0 : _state$product.id_article) !== null && _state$product$id_art !== void 0 ? _state$product$id_art : null,
|
|
425
|
+
token: token,
|
|
426
|
+
// Al terminar la subida el activo queda registrado solo, sin esperar al
|
|
427
|
+
// botón de guardar: con la barra llena, nadie supone que falta un paso.
|
|
428
|
+
onUploaded: function onUploaded(uploaded) {
|
|
429
|
+
return registerUploadedAssets(token, uploaded);
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
var _useState57 = (0, _react.useState)(_GalleryTrayTabs.TRAYS.IMAGES),
|
|
434
|
+
_useState58 = (0, _slicedToArray2.default)(_useState57, 2),
|
|
435
|
+
activeTray = _useState58[0],
|
|
436
|
+
setActiveTray = _useState58[1];
|
|
437
|
+
|
|
438
|
+
var currentTray = enableDigitalAssets ? activeTray : _GalleryTrayTabs.TRAYS.IMAGES;
|
|
439
|
+
/*
|
|
440
|
+
De qué artículo se cargaron ya los activos.
|
|
441
|
+
`loadData` se vuelve a ejecutar cada vez que cambia la cadena activa, pero los
|
|
442
|
+
activos son generales: no dependen de la cadena ni de la versión, así que la
|
|
443
|
+
respuesta sería idéntica. Volver a cargarlos borraría los archivos que el
|
|
444
|
+
usuario acaba de soltar y todavía no guarda —sin aviso y sin forma de
|
|
445
|
+
recuperarlos—. Por eso se cargan una sola vez por artículo.
|
|
446
|
+
*/
|
|
447
|
+
|
|
448
|
+
var assetsLoadedFor = (0, _react.useRef)(null);
|
|
449
|
+
|
|
450
|
+
var handleOnSetSelectedAssets = function handleOnSetSelectedAssets(assets) {
|
|
451
|
+
return dispatch({
|
|
452
|
+
type: "SET_SELECTED_ASSETS",
|
|
453
|
+
payload: assets
|
|
454
|
+
});
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
var handleOnSetAllAssetsChecked = function handleOnSetAllAssetsChecked(isChecked) {
|
|
458
|
+
return dispatch({
|
|
459
|
+
type: "TOGGLE_CHECK_ALL_ASSETS",
|
|
460
|
+
payload: isChecked
|
|
461
|
+
});
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
var initializeProduct = /*#__PURE__*/function () {
|
|
465
|
+
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
466
|
+
var product, productNormalized, users, id_article, response, parseData;
|
|
467
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
468
|
+
while (1) {
|
|
469
|
+
switch (_context2.prev = _context2.next) {
|
|
470
|
+
case 0:
|
|
471
|
+
_context2.prev = 0;
|
|
472
|
+
product = productSelected ? productSelected : JSON.parse(sessionStorage.getItem("productSelected"));
|
|
473
|
+
productNormalized = (0, _utils.normalizeProduct)(product);
|
|
474
|
+
console.log({
|
|
475
|
+
productNormalized: productNormalized
|
|
476
|
+
});
|
|
477
|
+
dispatch({
|
|
478
|
+
type: "SET_PRODUCT",
|
|
479
|
+
payload: productNormalized
|
|
480
|
+
});
|
|
481
|
+
dispatch({
|
|
482
|
+
type: "SET_ACTIVE_RETAILER",
|
|
483
|
+
payload: productNormalized.categoryRetailerInOrder[0]
|
|
484
|
+
});
|
|
485
|
+
setShotThd([58, 59, 60, 61].includes(productNormalized.categoryRetailerInOrder[0].id_retailer)); // Los estatus evaluables salen del rol UNIDO a la asignación. Solo por
|
|
486
|
+
// rol, quien produce y además audita no tenía 'AC' en la lista y el
|
|
487
|
+
// envío se quedaba sin nada que mandar.
|
|
488
|
+
|
|
489
|
+
setStatusArray((0, _utils.getStatusArrayForUser)(user, productNormalized)); // Cargar usuarios y asignaciones
|
|
490
|
+
|
|
491
|
+
_context2.next = 10;
|
|
492
|
+
return (0, _data.fetchUsers)(token);
|
|
493
|
+
|
|
494
|
+
case 10:
|
|
495
|
+
users = _context2.sent;
|
|
496
|
+
|
|
497
|
+
if (users.length > 0) {
|
|
498
|
+
dispatch({
|
|
499
|
+
type: "SET_COLLABORATOR_ASSIGNATIONS",
|
|
500
|
+
payload: (0, _utils.buildCollaboratorAssignations)(productNormalized, users)
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
id_article = productNormalized.id_article;
|
|
505
|
+
|
|
506
|
+
if (!id_article) {
|
|
507
|
+
_context2.next = 22;
|
|
508
|
+
break;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
_context2.prev = 14;
|
|
512
|
+
_context2.next = 17;
|
|
513
|
+
return (0, _utils.getAuditVersion)(id_article, setAuditableVersion, token);
|
|
514
|
+
|
|
515
|
+
case 17:
|
|
516
|
+
_context2.next = 22;
|
|
517
|
+
break;
|
|
518
|
+
|
|
519
|
+
case 19:
|
|
520
|
+
_context2.prev = 19;
|
|
521
|
+
_context2.t0 = _context2["catch"](14);
|
|
522
|
+
console.warn("No se pudo obtener la versión auditable:", _context2.t0.message);
|
|
523
|
+
|
|
524
|
+
case 22:
|
|
525
|
+
if (!(id_article && productNormalized.id_order)) {
|
|
526
|
+
_context2.next = 28;
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
_context2.next = 25;
|
|
531
|
+
return _axios.default.get(process.env.REACT_APP_READ_OBSERVATION, {
|
|
532
|
+
params: {
|
|
533
|
+
articleId: id_article,
|
|
534
|
+
orderId: productNormalized.id_order
|
|
535
|
+
},
|
|
536
|
+
headers: {
|
|
537
|
+
Authorization: sessionStorage.getItem("jwt")
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
case 25:
|
|
542
|
+
response = _context2.sent;
|
|
543
|
+
parseData = JSON.parse(response.data.body).data[0];
|
|
544
|
+
setObservation(parseData.observations);
|
|
545
|
+
|
|
546
|
+
case 28:
|
|
547
|
+
_context2.next = 33;
|
|
548
|
+
break;
|
|
549
|
+
|
|
550
|
+
case 30:
|
|
551
|
+
_context2.prev = 30;
|
|
552
|
+
_context2.t1 = _context2["catch"](0);
|
|
553
|
+
console.log("Error setting product data: ", _context2.t1);
|
|
554
|
+
|
|
555
|
+
case 33:
|
|
556
|
+
case "end":
|
|
557
|
+
return _context2.stop();
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}, _callee2, null, [[0, 30], [14, 19]]);
|
|
561
|
+
}));
|
|
562
|
+
|
|
563
|
+
return function initializeProduct() {
|
|
564
|
+
return _ref3.apply(this, arguments);
|
|
565
|
+
};
|
|
566
|
+
}(); // Setter del producto y carga inicial (optimizado para evitar cascada)
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
(0, _react.useEffect)(function () {
|
|
570
|
+
initializeProduct();
|
|
571
|
+
}, []);
|
|
572
|
+
|
|
573
|
+
var loadAuditableData = /*#__PURE__*/function () {
|
|
574
|
+
var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
|
|
575
|
+
var _state$product2, _state$product3, _state$product4;
|
|
576
|
+
|
|
577
|
+
var auditServices;
|
|
578
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
579
|
+
while (1) {
|
|
580
|
+
switch (_context3.prev = _context3.next) {
|
|
581
|
+
case 0:
|
|
582
|
+
_context3.next = 2;
|
|
583
|
+
return (0, _data.getRetailerServices)((_state$product2 = state.product) === null || _state$product2 === void 0 ? void 0 : _state$product2.id_article, (_state$product3 = state.product) === null || _state$product3 === void 0 ? void 0 : _state$product3.categoryName, parseInt((_state$product4 = state.product) === null || _state$product4 === void 0 ? void 0 : _state$product4.id_category), auditableVersion.version, token);
|
|
584
|
+
|
|
585
|
+
case 2:
|
|
586
|
+
auditServices = _context3.sent;
|
|
587
|
+
|
|
588
|
+
if (Array.isArray(auditServices)) {
|
|
589
|
+
_context3.next = 5;
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
return _context3.abrupt("return");
|
|
594
|
+
|
|
595
|
+
case 5:
|
|
596
|
+
(0, _utils.getInputsData)(auditServices, {
|
|
597
|
+
id: state.active_retailer.id_retailer
|
|
598
|
+
}, setAuditDatasheets, setAuditDescriptions);
|
|
599
|
+
setAuditServices(auditServices);
|
|
600
|
+
|
|
601
|
+
case 7:
|
|
602
|
+
case "end":
|
|
603
|
+
return _context3.stop();
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}, _callee3);
|
|
607
|
+
}));
|
|
608
|
+
|
|
609
|
+
return function loadAuditableData() {
|
|
610
|
+
return _ref4.apply(this, arguments);
|
|
611
|
+
};
|
|
612
|
+
}();
|
|
613
|
+
|
|
614
|
+
(0, _react.useEffect)(function () {
|
|
615
|
+
if (auditableVersion) {
|
|
616
|
+
loadAuditableData();
|
|
617
|
+
}
|
|
618
|
+
}, [auditableVersion]);
|
|
619
|
+
|
|
620
|
+
var loadData = /*#__PURE__*/function () {
|
|
621
|
+
var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
|
|
622
|
+
var enableLoading,
|
|
623
|
+
versionSelected,
|
|
624
|
+
_services$,
|
|
625
|
+
_retailerDatasheets$d,
|
|
626
|
+
_state$active_retaile2,
|
|
627
|
+
_services$0$inputs,
|
|
628
|
+
_services$2,
|
|
629
|
+
_state$product5,
|
|
630
|
+
id_article,
|
|
631
|
+
version,
|
|
632
|
+
id_order,
|
|
633
|
+
_state$active_retaile,
|
|
634
|
+
category,
|
|
635
|
+
id_category,
|
|
636
|
+
id_retailer,
|
|
637
|
+
data,
|
|
638
|
+
headers,
|
|
639
|
+
_yield$Promise$all,
|
|
640
|
+
_yield$Promise$all2,
|
|
641
|
+
services,
|
|
642
|
+
percentagesRes,
|
|
643
|
+
servicesDataRes,
|
|
644
|
+
commentsResponse,
|
|
645
|
+
percentages,
|
|
646
|
+
_JSON$parse$0$relatio,
|
|
647
|
+
_JSON$parse,
|
|
648
|
+
_JSON$parse$,
|
|
649
|
+
_percentagesRes$,
|
|
650
|
+
commentsMap,
|
|
651
|
+
orderMap,
|
|
652
|
+
orderedValues,
|
|
653
|
+
retailerDatasheets,
|
|
654
|
+
datasheetsActiveRetailer,
|
|
655
|
+
descriptionsActiveRetailer,
|
|
656
|
+
activeRetailerId,
|
|
657
|
+
filteredValues,
|
|
658
|
+
_args4 = arguments;
|
|
659
|
+
|
|
660
|
+
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
661
|
+
while (1) {
|
|
662
|
+
switch (_context4.prev = _context4.next) {
|
|
663
|
+
case 0:
|
|
664
|
+
enableLoading = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : true;
|
|
665
|
+
versionSelected = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : null;
|
|
666
|
+
_context4.prev = 2;
|
|
667
|
+
if (enableLoading) dispatch({
|
|
668
|
+
type: "SET_LOADING",
|
|
669
|
+
payload: true
|
|
670
|
+
});
|
|
671
|
+
dispatch({
|
|
672
|
+
type: "SET_ERRORS",
|
|
673
|
+
payload: []
|
|
674
|
+
});
|
|
675
|
+
_state$product5 = state.product, id_article = _state$product5.id_article, version = _state$product5.version, id_order = _state$product5.id_order;
|
|
676
|
+
_state$active_retaile = state.active_retailer, category = _state$active_retaile.category, id_category = _state$active_retaile.id_category, id_retailer = _state$active_retaile.id_retailer; // Payloads y headers
|
|
677
|
+
|
|
678
|
+
data = [{
|
|
679
|
+
id_article: id_article,
|
|
680
|
+
version: versionSelected ? versionSelected : version,
|
|
681
|
+
relations: [{
|
|
682
|
+
id_retailer: id_retailer,
|
|
683
|
+
id_category: id_category
|
|
684
|
+
}]
|
|
685
|
+
}];
|
|
686
|
+
headers = {
|
|
687
|
+
Authorization: token
|
|
688
|
+
};
|
|
689
|
+
_context4.next = 11;
|
|
690
|
+
return Promise.all([(0, _data.getRetailerServices)(id_article, category, id_category, versionSelected !== null && versionSelected !== void 0 ? versionSelected : version, token, id_retailer), (0, _data.getPercentage)({
|
|
691
|
+
data: data,
|
|
692
|
+
headers: headers
|
|
693
|
+
}), (0, _data.getServicesData)({
|
|
694
|
+
articleId: id_article,
|
|
695
|
+
orderId: id_order,
|
|
696
|
+
end: true,
|
|
697
|
+
token: token
|
|
698
|
+
}), // Obtener comentarios en paralelo
|
|
699
|
+
Promise.all([_axios.default.get(process.env.REACT_APP_COMMENTS_ENDPOINT, {
|
|
700
|
+
params: {
|
|
701
|
+
articleId: id_article,
|
|
702
|
+
concept: "description",
|
|
703
|
+
orderIdColab: id_order,
|
|
704
|
+
version: versionSelected !== null && versionSelected !== void 0 ? versionSelected : version
|
|
705
|
+
}
|
|
706
|
+
}), _axios.default.get(process.env.REACT_APP_COMMENTS_ENDPOINT, {
|
|
707
|
+
params: {
|
|
708
|
+
articleId: id_article,
|
|
709
|
+
concept: "datasheet",
|
|
710
|
+
orderIdColab: id_order,
|
|
711
|
+
version: versionSelected !== null && versionSelected !== void 0 ? versionSelected : version
|
|
712
|
+
}
|
|
713
|
+
}), _axios.default.get(process.env.REACT_APP_COMMENTS_ENDPOINT, {
|
|
714
|
+
params: {
|
|
715
|
+
articleId: id_article,
|
|
716
|
+
concept: "images",
|
|
717
|
+
orderIdColab: id_order,
|
|
718
|
+
version: versionSelected !== null && versionSelected !== void 0 ? versionSelected : version
|
|
719
|
+
}
|
|
720
|
+
})])]);
|
|
721
|
+
|
|
722
|
+
case 11:
|
|
723
|
+
_yield$Promise$all = _context4.sent;
|
|
724
|
+
_yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 4);
|
|
725
|
+
services = _yield$Promise$all2[0];
|
|
726
|
+
percentagesRes = _yield$Promise$all2[1];
|
|
727
|
+
servicesDataRes = _yield$Promise$all2[2];
|
|
728
|
+
commentsResponse = _yield$Promise$all2[3];
|
|
729
|
+
|
|
730
|
+
if (!(!Array.isArray(services) || services.length < 3 || !services[2])) {
|
|
731
|
+
_context4.next = 19;
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
throw new Error("No se pudieron cargar los servicios del producto. Inténtalo de nuevo.");
|
|
736
|
+
|
|
737
|
+
case 19:
|
|
738
|
+
dispatch({
|
|
739
|
+
type: "SET_RETAILER_STATUS",
|
|
740
|
+
payload: servicesDataRes.map(function (service) {
|
|
741
|
+
return {
|
|
742
|
+
retailer_id: service === null || service === void 0 ? void 0 : service.id_retailer,
|
|
743
|
+
service: service === null || service === void 0 ? void 0 : service.service,
|
|
744
|
+
status: service === null || service === void 0 ? void 0 : service.status,
|
|
745
|
+
task_user_group_id: service === null || service === void 0 ? void 0 : service.task_user_group_id
|
|
746
|
+
};
|
|
747
|
+
})
|
|
748
|
+
}); // Extraer relaciones del response. getPercentage se traga sus errores y
|
|
749
|
+
// devuelve undefined (p. ej. si CORS bloquea el endpoint), así que el
|
|
750
|
+
// JSON.parse va protegido para no tumbar toda la carga.
|
|
751
|
+
|
|
752
|
+
percentages = [];
|
|
753
|
+
|
|
754
|
+
try {
|
|
755
|
+
percentages = (_JSON$parse$0$relatio = (_JSON$parse = JSON.parse(percentagesRes === null || percentagesRes === void 0 ? void 0 : (_percentagesRes$ = percentagesRes[0]) === null || _percentagesRes$ === void 0 ? void 0 : _percentagesRes$.body)) === null || _JSON$parse === void 0 ? void 0 : (_JSON$parse$ = _JSON$parse[0]) === null || _JSON$parse$ === void 0 ? void 0 : _JSON$parse$.relations) !== null && _JSON$parse$0$relatio !== void 0 ? _JSON$parse$0$relatio : [];
|
|
756
|
+
} catch (e) {
|
|
757
|
+
console.warn("No se pudieron parsear los porcentajes:", e.message);
|
|
758
|
+
} // Procesar comentarios
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
commentsMap = {};
|
|
762
|
+
commentsResponse.forEach(function (commentRes) {
|
|
763
|
+
var _commentRes$data;
|
|
764
|
+
|
|
765
|
+
var commentData = JSON.parse(commentRes === null || commentRes === void 0 ? void 0 : (_commentRes$data = commentRes.data) === null || _commentRes$data === void 0 ? void 0 : _commentRes$data.body).data[0];
|
|
766
|
+
|
|
767
|
+
if (commentData) {
|
|
768
|
+
var tab = (0, _utils.translateConcept)(commentData.concept);
|
|
769
|
+
commentsMap[tab] = commentData;
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
dispatch({
|
|
773
|
+
type: "SET_COMMENTS",
|
|
774
|
+
payload: commentsMap
|
|
775
|
+
});
|
|
776
|
+
console.log("services", services); // Ordenamiento de imágenes
|
|
777
|
+
|
|
778
|
+
orderMap = services[2].inputsByRetailer.flat().reduce(function (acc, item) {
|
|
779
|
+
acc[item.id_image] = item.order;
|
|
780
|
+
return acc;
|
|
781
|
+
}, {});
|
|
782
|
+
orderedValues = (0, _toConsumableArray2.default)(services[2].values).sort(function (a, b) {
|
|
783
|
+
var _orderMap$a$image_id, _orderMap$b$image_id;
|
|
784
|
+
|
|
785
|
+
var orderA = (_orderMap$a$image_id = orderMap[a.image_id]) !== null && _orderMap$a$image_id !== void 0 ? _orderMap$a$image_id : Number.MAX_SAFE_INTEGER;
|
|
786
|
+
var orderB = (_orderMap$b$image_id = orderMap[b.image_id]) !== null && _orderMap$b$image_id !== void 0 ? _orderMap$b$image_id : Number.MAX_SAFE_INTEGER;
|
|
787
|
+
return orderA - orderB;
|
|
788
|
+
}); // Procesamiento de inputs del retailer activo (evita cascada con state.services)
|
|
789
|
+
// El retailer activo puede no traer datasheets; usamos data vacía como fallback
|
|
790
|
+
// para no reventar en Object.values(undefined).
|
|
791
|
+
|
|
792
|
+
retailerDatasheets = (_services$ = services[0]) === null || _services$ === void 0 ? void 0 : _services$[id_retailer];
|
|
793
|
+
datasheetsActiveRetailer = (0, _objectSpread5.default)((0, _objectSpread5.default)({}, retailerDatasheets), {}, {
|
|
794
|
+
data: Object.values((_retailerDatasheets$d = retailerDatasheets === null || retailerDatasheets === void 0 ? void 0 : retailerDatasheets.data) !== null && _retailerDatasheets$d !== void 0 ? _retailerDatasheets$d : {})
|
|
795
|
+
});
|
|
796
|
+
descriptionsActiveRetailer = services[1].filter(function (item) {
|
|
797
|
+
return item.id === id_retailer;
|
|
798
|
+
});
|
|
799
|
+
/**
|
|
800
|
+
* El id del retailer activo viene con dos nombres según de dónde salga:
|
|
801
|
+
* `categoryRetailerInOrder` lo trae como `id_retailer`, mientras que los
|
|
802
|
+
* retailers de `read-data-images` lo traen como `id`. Si se compara solo
|
|
803
|
+
* contra uno, al cambiar de cadena el otro queda `undefined`, la
|
|
804
|
+
* comparación es siempre falsa y `filteredValues` sale vacío — la imagen
|
|
805
|
+
* existe, el backend la devuelve, y aun así no se pinta ninguna.
|
|
806
|
+
*/
|
|
807
|
+
|
|
808
|
+
activeRetailerId = id_retailer !== null && id_retailer !== void 0 ? id_retailer : (_state$active_retaile2 = state.active_retailer) === null || _state$active_retaile2 === void 0 ? void 0 : _state$active_retaile2.id;
|
|
809
|
+
filteredValues = services[2].values.filter(function (value) {
|
|
810
|
+
return services[2].inputsByRetailer.some(function (retailerInput) {
|
|
811
|
+
return retailerInput.some(function (input) {
|
|
812
|
+
return Number(input.id_retailer) === Number(activeRetailerId) && Number(input.id_image) === Number(value.image_id);
|
|
813
|
+
});
|
|
814
|
+
});
|
|
815
|
+
}); // Dispatch consolidado
|
|
816
|
+
|
|
817
|
+
dispatch({
|
|
818
|
+
type: "SET_SERVICES",
|
|
819
|
+
payload: {
|
|
820
|
+
datasheets: services[0],
|
|
821
|
+
descriptions: services[1],
|
|
822
|
+
images: (0, _objectSpread5.default)((0, _objectSpread5.default)({}, services[2]), {}, {
|
|
823
|
+
values: orderedValues
|
|
824
|
+
})
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
dispatch({
|
|
828
|
+
type: "SET_PERCENTAGES",
|
|
829
|
+
payload: percentages
|
|
830
|
+
});
|
|
831
|
+
dispatch({
|
|
832
|
+
type: "SET_ACTIVE_PERCENTAGES",
|
|
833
|
+
payload: percentages.find(function (_ref6) {
|
|
834
|
+
var rId = _ref6.id_retailer;
|
|
835
|
+
return rId === id_retailer;
|
|
836
|
+
})
|
|
837
|
+
});
|
|
838
|
+
dispatch({
|
|
839
|
+
type: "SET_SERVICES_DATA",
|
|
840
|
+
payload: servicesDataRes
|
|
841
|
+
}); // Setear inputs del retailer activo directamente (evita cascada)
|
|
842
|
+
|
|
843
|
+
dispatch({
|
|
844
|
+
type: "SET_DATASHEETS_INPUTS",
|
|
845
|
+
// `services[0]?` por lo mismo que el fallback de arriba: la lectura de
|
|
846
|
+
// fichas puede volver sin datos para esa cadena y categoría. Arriba ya
|
|
847
|
+
// se contemplaba; aquí no, y como este dispatch va ANTES de
|
|
848
|
+
// SET_IMAGES_VALUES, reventar aquí dejaba la ficha cargando para
|
|
849
|
+
// siempre — con las imágenes ya traídas y sin pintar.
|
|
850
|
+
payload: [datasheetsActiveRetailer, (_services$0$inputs = (_services$2 = services[0]) === null || _services$2 === void 0 ? void 0 : _services$2.inputs) !== null && _services$0$inputs !== void 0 ? _services$0$inputs : {}]
|
|
851
|
+
});
|
|
852
|
+
dispatch({
|
|
853
|
+
type: "SET_DESCRIPTIONS_INPUTS",
|
|
854
|
+
payload: descriptionsActiveRetailer
|
|
855
|
+
});
|
|
856
|
+
dispatch({
|
|
857
|
+
type: "SET_IMAGES_VALUES",
|
|
858
|
+
payload: (0, _objectSpread5.default)((0, _objectSpread5.default)({}, services[2]), {}, {
|
|
859
|
+
values: filteredValues
|
|
860
|
+
})
|
|
861
|
+
});
|
|
862
|
+
/*
|
|
863
|
+
Activos digitales. `services[2].assets` todavía no existe en la
|
|
864
|
+
respuesta del backend: hasta que exista, esto no hace nada, y el día que
|
|
865
|
+
llegue la bandeja se llena sola sin tocar nada más.
|
|
866
|
+
*/
|
|
867
|
+
|
|
868
|
+
if (Array.isArray(services[2].assets) && assetsLoadedFor.current !== id_article) {
|
|
869
|
+
assetsLoadedFor.current = id_article;
|
|
870
|
+
digitalAssets.replaceAll(services[2].assets);
|
|
871
|
+
} // Calcular campos requeridos sin valor
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
dispatch({
|
|
875
|
+
type: "SET_MISSING_REQUIRED_FIELDS",
|
|
876
|
+
payload: (0, _utils.calculateRequiredNull)(services, servicesDataRes, id_retailer)
|
|
877
|
+
}); // Auditable
|
|
878
|
+
|
|
879
|
+
if (auditableVersion && id_retailer) {
|
|
880
|
+
loadAuditableData();
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
_context4.next = 49;
|
|
884
|
+
break;
|
|
885
|
+
|
|
886
|
+
case 45:
|
|
887
|
+
_context4.prev = 45;
|
|
888
|
+
_context4.t0 = _context4["catch"](2);
|
|
889
|
+
console.log("Error loading data: ", _context4.t0);
|
|
890
|
+
dispatch({
|
|
891
|
+
type: "SET_ERRORS",
|
|
892
|
+
payload: [_context4.t0.message]
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
case 49:
|
|
896
|
+
_context4.prev = 49;
|
|
897
|
+
dispatch({
|
|
898
|
+
type: "SET_LOADING",
|
|
899
|
+
payload: false
|
|
900
|
+
});
|
|
901
|
+
return _context4.finish(49);
|
|
902
|
+
|
|
903
|
+
case 52:
|
|
904
|
+
case "end":
|
|
905
|
+
return _context4.stop();
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
}, _callee4, null, [[2, 45, 49, 52]]);
|
|
909
|
+
}));
|
|
910
|
+
|
|
911
|
+
return function loadData() {
|
|
912
|
+
return _ref5.apply(this, arguments);
|
|
913
|
+
};
|
|
914
|
+
}();
|
|
915
|
+
|
|
916
|
+
(0, _react.useEffect)(function () {
|
|
917
|
+
if (state.active_retailer) {
|
|
918
|
+
loadData();
|
|
919
|
+
}
|
|
920
|
+
}, [state.active_retailer]);
|
|
921
|
+
|
|
922
|
+
var handleOnChangeCurrentImage = function handleOnChangeCurrentImage(index) {
|
|
923
|
+
if (typeof index === "number") {
|
|
924
|
+
dispatch({
|
|
925
|
+
type: "SET_CURRENT_IMAGE",
|
|
926
|
+
payload: index
|
|
927
|
+
});
|
|
928
|
+
} else if ((0, _typeof2.default)(index) === "object") {
|
|
929
|
+
dispatch({
|
|
930
|
+
type: "CHANGE_ATTR_VALUE",
|
|
931
|
+
payload: index
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
|
|
936
|
+
var handleOnShowModalGallery = function handleOnShowModalGallery() {
|
|
937
|
+
dispatch({
|
|
938
|
+
type: "SET_ACTIVE_TAB",
|
|
939
|
+
payload: "Imágenes"
|
|
940
|
+
});
|
|
941
|
+
setShowModal(true);
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
var handleOnChangeActiveRetailer = function handleOnChangeActiveRetailer(retailer) {
|
|
945
|
+
dispatch({
|
|
946
|
+
type: "SET_ACTIVE_RETAILER",
|
|
947
|
+
payload: retailer
|
|
948
|
+
});
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
var handleOnChangeActiveTab = function handleOnChangeActiveTab(tab) {
|
|
952
|
+
dispatch({
|
|
953
|
+
type: "SET_ACTIVE_TAB",
|
|
954
|
+
payload: tab
|
|
955
|
+
});
|
|
956
|
+
};
|
|
957
|
+
|
|
958
|
+
var handleOnToggleImageLayout = function handleOnToggleImageLayout() {
|
|
959
|
+
setImageLayout(!imageLayout);
|
|
960
|
+
};
|
|
961
|
+
|
|
962
|
+
var handleOnToggleObservation = function handleOnToggleObservation() {
|
|
963
|
+
setObservationVisible(!isObservationVisible);
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
var handleOnHideObservation = function handleOnHideObservation() {
|
|
967
|
+
setObservationVisible(false);
|
|
968
|
+
};
|
|
969
|
+
|
|
970
|
+
var isAuditorAssigned = function isAuditorAssigned() {
|
|
971
|
+
var _state$product6;
|
|
972
|
+
|
|
973
|
+
return ((_state$product6 = state.product) === null || _state$product6 === void 0 ? void 0 : _state$product6.id_auditor) === (user === null || user === void 0 ? void 0 : user.id_user);
|
|
974
|
+
};
|
|
975
|
+
/**
|
|
976
|
+
* ¿Ocupo este slot EN ESTE producto?
|
|
977
|
+
*
|
|
978
|
+
* La calidad en la que actúas sale de la ASIGNACIÓN, no del rol. Con la
|
|
979
|
+
* estructura nueva de Creators, quien produce un servicio también lo valida:
|
|
980
|
+
* un especialista de textos puede ser el auditor del mismo producto y tiene
|
|
981
|
+
* que recorrer las dos fases, AS -> AC como especialista y AC -> AA como QA.
|
|
982
|
+
*/
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
var isAssignedAs = function isAssignedAs(rol, concept) {
|
|
986
|
+
var _state$product7;
|
|
987
|
+
|
|
988
|
+
var assigned = (_state$product7 = state.product) === null || _state$product7 === void 0 ? void 0 : _state$product7["id_".concat(concept, "_").concat(rol)];
|
|
989
|
+
return !!assigned && assigned === (user === null || user === void 0 ? void 0 : user.id_user);
|
|
990
|
+
};
|
|
991
|
+
|
|
992
|
+
var isUserAssignedToService = function isUserAssignedToService(tab, rol) {
|
|
993
|
+
var concept = (0, _utils.getConceptByTab)(state.active_tab);
|
|
994
|
+
var allowedRoles = [1, 4, 5, 6, 7, 8];
|
|
995
|
+
var validUser = allowedRoles.includes(user === null || user === void 0 ? void 0 : user.id_role);
|
|
996
|
+
var isAdmin = user.id_role === 1;
|
|
997
|
+
if (isAdmin) return true; // Sin `rol` explícito se prueba por asignación, no por rol. Antes se
|
|
998
|
+
// infería del `id_role`: un rol 6 caía en `id_<concept>_undefined` —columna
|
|
999
|
+
// inexistente, siempre falso— y un rol 7 solo podía ser especialista, nunca
|
|
1000
|
+
// auditor. Es el mismo defecto que se corrigió en el backend.
|
|
1001
|
+
|
|
1002
|
+
var isAssigned = rol ? isAssignedAs(rol, concept) : isAssignedAs("especialist", concept) || isAssignedAs("facilitator", concept);
|
|
1003
|
+
return isAssigned && validUser;
|
|
1004
|
+
};
|
|
1005
|
+
|
|
1006
|
+
var canShowSingleEvaluationButtons = function canShowSingleEvaluationButtons(action) {
|
|
1007
|
+
var _state$services_data, _state$services_data$, _state$services_data$2;
|
|
1008
|
+
|
|
1009
|
+
var concept = (0, _utils.getConceptByTab)(action || state.active_tab);
|
|
1010
|
+
var retailerStatus = (_state$services_data = state.services_data) === null || _state$services_data === void 0 ? void 0 : (_state$services_data$ = _state$services_data.find(function (srv) {
|
|
1011
|
+
var _state$active_retaile3;
|
|
1012
|
+
|
|
1013
|
+
return srv.id_retailer === ((_state$active_retaile3 = state.active_retailer) === null || _state$active_retaile3 === void 0 ? void 0 : _state$active_retaile3.id_retailer) && srv.service === concept;
|
|
1014
|
+
})) === null || _state$services_data$ === void 0 ? void 0 : (_state$services_data$2 = _state$services_data$.status) === null || _state$services_data$2 === void 0 ? void 0 : _state$services_data$2.replace(/.*\//, ""); // Se SUMA la vía por asignación a la que ya había por rol; no la
|
|
1015
|
+
// reemplaza. Así los coordinadores y el administrador conservan su acceso
|
|
1016
|
+
// tal cual, y el especialista que además es auditor alcanza la segunda fase.
|
|
1017
|
+
|
|
1018
|
+
var canEvaluateAsFacilitator = retailerStatus === "IE" && ([1, 4, 5].includes(user.id_role) || isAssignedAs("facilitator", concept));
|
|
1019
|
+
var canEvaluateAsAuditor = ["AC", "RP", "RCA", "SAC"].includes(retailerStatus) && ([1, 6].includes(user.id_role) || isAuditorAssigned()); // Los roles 7 y 8 también pueden validar/rechazar lo que está en AC.
|
|
1020
|
+
|
|
1021
|
+
var canEvaluateAC = retailerStatus === "AC" && [7, 8].includes(user.id_role);
|
|
1022
|
+
return canEvaluateAsFacilitator || canEvaluateAsAuditor || canEvaluateAC;
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
var canShowBulkEvaluationButtons = function canShowBulkEvaluationButtons() {
|
|
1026
|
+
var concepts = (0, _utils.getConceptsByRole)(user.id_role);
|
|
1027
|
+
var services = state.services_data.filter(function (_ref7) {
|
|
1028
|
+
var service = _ref7.service;
|
|
1029
|
+
return concepts.includes(service);
|
|
1030
|
+
});
|
|
1031
|
+
var canEvaluateAsFacilitator = services.every(function (srv) {
|
|
1032
|
+
var _srv$status;
|
|
1033
|
+
|
|
1034
|
+
return (srv === null || srv === void 0 ? void 0 : (_srv$status = srv.status) === null || _srv$status === void 0 ? void 0 : _srv$status.replace(/.*\//, "")) === "IE";
|
|
1035
|
+
}) && ([1, 4, 5].includes(user.id_role) || services.some(function (_ref8) {
|
|
1036
|
+
var service = _ref8.service;
|
|
1037
|
+
return isAssignedAs("facilitator", service);
|
|
1038
|
+
}));
|
|
1039
|
+
var canEvaluateAsAuditor = state.services_data.every(function (srv) {
|
|
1040
|
+
var _srv$status2;
|
|
1041
|
+
|
|
1042
|
+
return ["AC", "RP", "RCA"].includes(srv === null || srv === void 0 ? void 0 : (_srv$status2 = srv.status) === null || _srv$status2 === void 0 ? void 0 : _srv$status2.replace(/.*\//, ""));
|
|
1043
|
+
}) && ([1, 6].includes(user.id_role) || isAuditorAssigned());
|
|
1044
|
+
var canEvaluateAC = services.length > 0 && services.every(function (srv) {
|
|
1045
|
+
var _srv$status3;
|
|
1046
|
+
|
|
1047
|
+
return (srv === null || srv === void 0 ? void 0 : (_srv$status3 = srv.status) === null || _srv$status3 === void 0 ? void 0 : _srv$status3.replace(/.*\//, "")) === "AC";
|
|
1048
|
+
}) && [7, 8].includes(user.id_role);
|
|
1049
|
+
return canEvaluateAsFacilitator || canEvaluateAsAuditor || canEvaluateAC;
|
|
1050
|
+
};
|
|
1051
|
+
|
|
1052
|
+
var getStatusByCurrentServiceAndRetailer = function getStatusByCurrentServiceAndRetailer() {
|
|
1053
|
+
var _statusByRetailer$fil;
|
|
1054
|
+
|
|
1055
|
+
var statusByRetailer = state.product.statusByRetailer;
|
|
1056
|
+
if (!statusByRetailer) return "-";
|
|
1057
|
+
var currentService = (0, _utils.getConceptByTab)(state.active_tab);
|
|
1058
|
+
var currentRetailer = state.active_retailer.id_retailer;
|
|
1059
|
+
var currentStatus = ((_statusByRetailer$fil = statusByRetailer.filter(function (item) {
|
|
1060
|
+
return item.retailer_id === currentRetailer && item.service === currentService;
|
|
1061
|
+
})[0]) === null || _statusByRetailer$fil === void 0 ? void 0 : _statusByRetailer$fil.status) || "-";
|
|
1062
|
+
return currentStatus;
|
|
1063
|
+
};
|
|
1064
|
+
/*
|
|
1065
|
+
Guarda los activos y recarga si algo se escribió.
|
|
1066
|
+
La recarga no es opcional: un activo recién creado sigue en memoria con su
|
|
1067
|
+
id temporal y sin el id de la base. Sin volver a leer, el siguiente guardado
|
|
1068
|
+
lo mandaría otra vez como nuevo y se duplicaría. Poner el ref en `null` es
|
|
1069
|
+
lo que permite que `loadData` lo vuelva a traer —normalmente los activos se
|
|
1070
|
+
cargan una sola vez por artículo—.
|
|
1071
|
+
*/
|
|
1072
|
+
|
|
1073
|
+
|
|
1074
|
+
var handleOnSaveAssets = /*#__PURE__*/function () {
|
|
1075
|
+
var _ref9 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
|
|
1076
|
+
var guardado;
|
|
1077
|
+
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
1078
|
+
while (1) {
|
|
1079
|
+
switch (_context5.prev = _context5.next) {
|
|
1080
|
+
case 0:
|
|
1081
|
+
_context5.next = 2;
|
|
1082
|
+
return saveAssets(token);
|
|
1083
|
+
|
|
1084
|
+
case 2:
|
|
1085
|
+
guardado = _context5.sent;
|
|
1086
|
+
|
|
1087
|
+
if (guardado) {
|
|
1088
|
+
_context5.next = 5;
|
|
1089
|
+
break;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
return _context5.abrupt("return");
|
|
1093
|
+
|
|
1094
|
+
case 5:
|
|
1095
|
+
assetsLoadedFor.current = null;
|
|
1096
|
+
_context5.next = 8;
|
|
1097
|
+
return loadData(false);
|
|
1098
|
+
|
|
1099
|
+
case 8:
|
|
1100
|
+
case "end":
|
|
1101
|
+
return _context5.stop();
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
}, _callee5);
|
|
1105
|
+
}));
|
|
1106
|
+
|
|
1107
|
+
return function handleOnSaveAssets() {
|
|
1108
|
+
return _ref9.apply(this, arguments);
|
|
1109
|
+
};
|
|
1110
|
+
}();
|
|
1111
|
+
|
|
1112
|
+
var handleOnClickSaveImages = /*#__PURE__*/function () {
|
|
1113
|
+
var _ref10 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6() {
|
|
1114
|
+
var _state$product8, _state$product8$servi;
|
|
1115
|
+
|
|
1116
|
+
return _regenerator.default.wrap(function _callee6$(_context6) {
|
|
1117
|
+
while (1) {
|
|
1118
|
+
switch (_context6.prev = _context6.next) {
|
|
1119
|
+
case 0:
|
|
1120
|
+
if (!(currentTray === _GalleryTrayTabs.TRAYS.ASSETS)) {
|
|
1121
|
+
_context6.next = 4;
|
|
1122
|
+
break;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
_context6.next = 3;
|
|
1126
|
+
return handleOnSaveAssets();
|
|
1127
|
+
|
|
1128
|
+
case 3:
|
|
1129
|
+
return _context6.abrupt("return");
|
|
1130
|
+
|
|
1131
|
+
case 4:
|
|
1132
|
+
if (!(((_state$product8 = state.product) === null || _state$product8 === void 0 ? void 0 : (_state$product8$servi = _state$product8.services) === null || _state$product8$servi === void 0 ? void 0 : _state$product8$servi.images) === 1)) {
|
|
1133
|
+
_context6.next = 9;
|
|
1134
|
+
break;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
_context6.next = 7;
|
|
1138
|
+
return updateImages(token);
|
|
1139
|
+
|
|
1140
|
+
case 7:
|
|
1141
|
+
_context6.next = 9;
|
|
1142
|
+
return loadData(false);
|
|
1143
|
+
|
|
1144
|
+
case 9:
|
|
1145
|
+
case "end":
|
|
1146
|
+
return _context6.stop();
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
}, _callee6);
|
|
1150
|
+
}));
|
|
1151
|
+
|
|
1152
|
+
return function handleOnClickSaveImages() {
|
|
1153
|
+
return _ref10.apply(this, arguments);
|
|
1154
|
+
};
|
|
1155
|
+
}();
|
|
1156
|
+
/*
|
|
1157
|
+
Trae la familia: los hijos del producto, o sus hermanos si el abierto es
|
|
1158
|
+
una de ellas. Se pide al abrir la sección y no al montar la pantalla: la
|
|
1159
|
+
mayoría de los productos no son familia.
|
|
1160
|
+
*/
|
|
1161
|
+
|
|
1162
|
+
|
|
1163
|
+
var loadFamily = /*#__PURE__*/function () {
|
|
1164
|
+
var _ref11 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7() {
|
|
1165
|
+
var forzar,
|
|
1166
|
+
_state$product9,
|
|
1167
|
+
res,
|
|
1168
|
+
data,
|
|
1169
|
+
_args7 = arguments;
|
|
1170
|
+
|
|
1171
|
+
return _regenerator.default.wrap(function _callee7$(_context7) {
|
|
1172
|
+
while (1) {
|
|
1173
|
+
switch (_context7.prev = _context7.next) {
|
|
1174
|
+
case 0:
|
|
1175
|
+
forzar = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : false;
|
|
1176
|
+
|
|
1177
|
+
if (!(family && !forzar)) {
|
|
1178
|
+
_context7.next = 3;
|
|
1179
|
+
break;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
return _context7.abrupt("return", family);
|
|
1183
|
+
|
|
1184
|
+
case 3:
|
|
1185
|
+
_context7.prev = 3;
|
|
1186
|
+
_context7.next = 6;
|
|
1187
|
+
return _axios.default.post("".concat(process.env.REACT_APP_VARIANTS_ENDPOINT, "/family"), {
|
|
1188
|
+
articleId: (_state$product9 = state.product) === null || _state$product9 === void 0 ? void 0 : _state$product9.id_article
|
|
1189
|
+
}, {
|
|
1190
|
+
headers: {
|
|
1191
|
+
Authorization: token
|
|
1192
|
+
}
|
|
1193
|
+
});
|
|
1194
|
+
|
|
1195
|
+
case 6:
|
|
1196
|
+
res = _context7.sent;
|
|
1197
|
+
data = (0, _api.readPayload)(res);
|
|
1198
|
+
setFamily(data);
|
|
1199
|
+
return _context7.abrupt("return", data);
|
|
1200
|
+
|
|
1201
|
+
case 12:
|
|
1202
|
+
_context7.prev = 12;
|
|
1203
|
+
_context7.t0 = _context7["catch"](3);
|
|
1204
|
+
console.error("loadFamily: ", _context7.t0);
|
|
1205
|
+
setFamily({
|
|
1206
|
+
variants: [],
|
|
1207
|
+
parent: null,
|
|
1208
|
+
error: true
|
|
1209
|
+
});
|
|
1210
|
+
return _context7.abrupt("return", null);
|
|
1211
|
+
|
|
1212
|
+
case 17:
|
|
1213
|
+
case "end":
|
|
1214
|
+
return _context7.stop();
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
}, _callee7, null, [[3, 12]]);
|
|
1218
|
+
}));
|
|
1219
|
+
|
|
1220
|
+
return function loadFamily() {
|
|
1221
|
+
return _ref11.apply(this, arguments);
|
|
1222
|
+
};
|
|
1223
|
+
}();
|
|
1224
|
+
/*
|
|
1225
|
+
En Creators el parentesco se pregunta, no viene con el producto.
|
|
1226
|
+
Su listado sale del endpoint de reportes, que no trae `variantsCount` ni
|
|
1227
|
+
`parentArticleId`: esas columnas se agregaron a las vistas pero DynamoDB no
|
|
1228
|
+
las tiene hasta que se corra el recorrido de datos. Y aunque las tuviera,
|
|
1229
|
+
dependería de lo actualizado que esté ese recorrido.
|
|
1230
|
+
Preguntar a `family` cuesta una llamada por ficha y da el dato de la base, no
|
|
1231
|
+
de una copia. Además aplica el alcance del perfil (§5.1): al equipo interno le
|
|
1232
|
+
devuelve los productos solicitados a ContentOh, que es justo lo que puede
|
|
1233
|
+
tocar.
|
|
1234
|
+
*/
|
|
1235
|
+
|
|
1236
|
+
|
|
1237
|
+
(0, _react.useEffect)(function () {
|
|
1238
|
+
var _state$product10;
|
|
1239
|
+
|
|
1240
|
+
if (!((_state$product10 = state.product) !== null && _state$product10 !== void 0 && _state$product10.id_article)) return;
|
|
1241
|
+
loadFamily(true); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1242
|
+
}, [(_state$product11 = state.product) === null || _state$product11 === void 0 ? void 0 : _state$product11.id_article]); // El conteo sale de la familia recién consultada, no del producto.
|
|
1243
|
+
|
|
1244
|
+
var hijosDelProducto = family !== null && family !== void 0 && family.error ? 0 : ((_family$variants = family === null || family === void 0 ? void 0 : family.variants) !== null && _family$variants !== void 0 ? _family$variants : []).filter(function (v) {
|
|
1245
|
+
return !v.isCurrent;
|
|
1246
|
+
}).length;
|
|
1247
|
+
var esHijoDeOtro = family !== null && family !== void 0 && family.error ? !!((_state$product12 = state.product) !== null && _state$product12 !== void 0 && _state$product12.parentArticleId) : !!(family !== null && family !== void 0 && family.parent);
|
|
1248
|
+
/*
|
|
1249
|
+
Un hijo no se agrupa como variante (decisión de producto, 2026-09-25).
|
|
1250
|
+
Agrupar declara «estos son el mismo producto en otra presentación», y un
|
|
1251
|
+
hijo ya declaró de dónde deriva. El servidor lo rechaza con
|
|
1252
|
+
VARIANT_GROUP_NOT_FOR_CHILD, así que ofrecer el botón sería ofrecer algo
|
|
1253
|
+
que siempre falla.
|
|
1254
|
+
Se apoya en `esHijoDeOtro` y no en `state.product` porque en esta pantalla
|
|
1255
|
+
el producto sale de sessionStorage: la señal buena es la familia recién
|
|
1256
|
+
consultada, con el producto solo como respaldo si esa consulta falló.
|
|
1257
|
+
*/
|
|
1258
|
+
|
|
1259
|
+
var puedeAgruparse = !esHijoDeOtro;
|
|
1260
|
+
/*
|
|
1261
|
+
Abre otro producto de la familia.
|
|
1262
|
+
Cambiar la URL no basta: esta pantalla no lee el producto de la ruta sino de
|
|
1263
|
+
sessionStorage —el router hace JSON.parse(sessionStorage.productSelected) y
|
|
1264
|
+
se lo pasa como prop—, así que navegar sin precargar dejaría la URL nueva
|
|
1265
|
+
mostrando el producto anterior. Por eso primero se trae el destino y se
|
|
1266
|
+
escriben las tres llaves que el listado escribe al hacer clic en una fila
|
|
1267
|
+
(productSelected, version, productEdit), y solo entonces se navega.
|
|
1268
|
+
Se pide a /ordered-services y no a read-articles-v2, que es lo que usa la
|
|
1269
|
+
aplicación de clientes: aquel filtra por la compañía del usuario y el equipo
|
|
1270
|
+
interno es de ContentOh trabajando productos de sus clientes, así que ahí no
|
|
1271
|
+
devolvería nada. /ordered-services es el mismo endpoint del listado de esta
|
|
1272
|
+
aplicación, así que el objeto llega con la forma exacta que normalizeProduct
|
|
1273
|
+
espera —con `article` anidado, `statusByRetailer` y `categoryRetailer`—.
|
|
1274
|
+
Un producto de la familia puede no estar en ninguna orden de trabajo: la
|
|
1275
|
+
relación padre/hijo vive en `article` y no exige haber pasado por ContentOh.
|
|
1276
|
+
En ese caso no hay nada que abrir aquí, y se dice en vez de navegar a una
|
|
1277
|
+
pantalla que mostraría el producto equivocado.
|
|
1278
|
+
*/
|
|
1279
|
+
|
|
1280
|
+
/*
|
|
1281
|
+
Después de desvincular, esta ficha cambia de forma: si se soltó de su padre
|
|
1282
|
+
vuelve a poder ligar, y si soltó a un hijo pierde uno de la cuenta. En esta
|
|
1283
|
+
pantalla el bloque de parentesco se decide con `family`, así que hay que
|
|
1284
|
+
repreguntarla —vaciarla lo haría desaparecer, que es el error que ya se
|
|
1285
|
+
cometió una vez aquí—.
|
|
1286
|
+
*/
|
|
1287
|
+
|
|
1288
|
+
var handleOnUnlinked = function handleOnUnlinked(result) {
|
|
1289
|
+
var _state$product$varian, _state$product13, _updatedProduct$varia;
|
|
1290
|
+
|
|
1291
|
+
if (!result) return;
|
|
1292
|
+
var updatedProduct = result.mode === "self" ? (0, _objectSpread5.default)((0, _objectSpread5.default)({}, state.product), {}, {
|
|
1293
|
+
parentArticleId: null,
|
|
1294
|
+
variantsCount: 0
|
|
1295
|
+
}) : (0, _objectSpread5.default)((0, _objectSpread5.default)({}, state.product), {}, {
|
|
1296
|
+
variantsCount: Math.max(((_state$product$varian = (_state$product13 = state.product) === null || _state$product13 === void 0 ? void 0 : _state$product13.variantsCount) !== null && _state$product$varian !== void 0 ? _state$product$varian : 1) - 1, 0)
|
|
1297
|
+
});
|
|
1298
|
+
dispatch({
|
|
1299
|
+
type: "SET_PRODUCT",
|
|
1300
|
+
payload: updatedProduct
|
|
1301
|
+
}); // Se PARCHEA lo guardado: ahí vive el producto con la forma del listado
|
|
1302
|
+
// —`article` anidado, servicios, cadenas— y escribir encima la versión
|
|
1303
|
+
// aplanada de esta pantalla lo dejaría mutilado en el siguiente F5.
|
|
1304
|
+
|
|
1305
|
+
try {
|
|
1306
|
+
var _sessionStorage$getIt;
|
|
1307
|
+
|
|
1308
|
+
var guardado = JSON.parse((_sessionStorage$getIt = sessionStorage.getItem("productSelected")) !== null && _sessionStorage$getIt !== void 0 ? _sessionStorage$getIt : "null");
|
|
1309
|
+
|
|
1310
|
+
if (guardado) {
|
|
1311
|
+
var _updatedProduct$paren;
|
|
1312
|
+
|
|
1313
|
+
sessionStorage.setItem("productSelected", JSON.stringify((0, _objectSpread5.default)((0, _objectSpread5.default)({}, guardado), {}, {
|
|
1314
|
+
variantsCount: updatedProduct.variantsCount,
|
|
1315
|
+
parentArticleId: (_updatedProduct$paren = updatedProduct.parentArticleId) !== null && _updatedProduct$paren !== void 0 ? _updatedProduct$paren : null
|
|
1316
|
+
})));
|
|
1317
|
+
}
|
|
1318
|
+
} catch (error) {
|
|
1319
|
+
console.error("unlinkVariant/sessionStorage: ", error);
|
|
1320
|
+
}
|
|
1321
|
+
/*
|
|
1322
|
+
Si ya no queda familia, se cierra el desplegable: su botón desaparece con
|
|
1323
|
+
el vínculo, y dejarlo abierto pinta una caja que dice «no tiene hijos» y
|
|
1324
|
+
que nadie puede cerrar.
|
|
1325
|
+
*/
|
|
1326
|
+
|
|
1327
|
+
|
|
1328
|
+
if (!updatedProduct.parentArticleId && ((_updatedProduct$varia = updatedProduct.variantsCount) !== null && _updatedProduct$varia !== void 0 ? _updatedProduct$varia : 0) === 0) {
|
|
1329
|
+
setShowFamily(false);
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
loadFamily(true); // Al desvincular el servidor pone `is_overridden = 0` en todas las
|
|
1333
|
+
// versiones, así que los chips de herencia tienen que dejar de dibujarse.
|
|
1334
|
+
// Sin `enableLoading` para no parpadear el esqueleto encima de una pantalla
|
|
1335
|
+
// que ya está pintada.
|
|
1336
|
+
|
|
1337
|
+
loadData(false);
|
|
1338
|
+
};
|
|
1339
|
+
/*
|
|
1340
|
+
Trae el grupo de variantes y sus miembros.
|
|
1341
|
+
Al montar, no al abrir el desplegable: `variant_group` no lo devuelve el
|
|
1342
|
+
endpoint del listado, así que sin esta llamada la ficha no sabe si el
|
|
1343
|
+
producto está agrupado.
|
|
1344
|
+
*/
|
|
1345
|
+
|
|
1346
|
+
|
|
1347
|
+
var loadVariantGroup = /*#__PURE__*/function () {
|
|
1348
|
+
var _ref12 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8() {
|
|
1349
|
+
var forzar,
|
|
1350
|
+
_state$product14,
|
|
1351
|
+
res,
|
|
1352
|
+
data,
|
|
1353
|
+
_args8 = arguments;
|
|
1354
|
+
|
|
1355
|
+
return _regenerator.default.wrap(function _callee8$(_context8) {
|
|
1356
|
+
while (1) {
|
|
1357
|
+
switch (_context8.prev = _context8.next) {
|
|
1358
|
+
case 0:
|
|
1359
|
+
forzar = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : false;
|
|
1360
|
+
|
|
1361
|
+
if (!(variantGroup && !forzar)) {
|
|
1362
|
+
_context8.next = 3;
|
|
1363
|
+
break;
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
return _context8.abrupt("return", variantGroup);
|
|
1367
|
+
|
|
1368
|
+
case 3:
|
|
1369
|
+
_context8.prev = 3;
|
|
1370
|
+
_context8.next = 6;
|
|
1371
|
+
return _axios.default.post("".concat(process.env.REACT_APP_VARIANTS_ENDPOINT, "/group"), {
|
|
1372
|
+
articleId: (_state$product14 = state.product) === null || _state$product14 === void 0 ? void 0 : _state$product14.id_article
|
|
1373
|
+
}, {
|
|
1374
|
+
headers: {
|
|
1375
|
+
Authorization: token
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
|
|
1379
|
+
case 6:
|
|
1380
|
+
res = _context8.sent;
|
|
1381
|
+
data = (0, _api.readPayload)(res);
|
|
1382
|
+
setVariantGroup(data);
|
|
1383
|
+
return _context8.abrupt("return", data);
|
|
1384
|
+
|
|
1385
|
+
case 12:
|
|
1386
|
+
_context8.prev = 12;
|
|
1387
|
+
_context8.t0 = _context8["catch"](3);
|
|
1388
|
+
console.error("loadVariantGroup: ", _context8.t0);
|
|
1389
|
+
setVariantGroup({
|
|
1390
|
+
group: null,
|
|
1391
|
+
members: [],
|
|
1392
|
+
error: true
|
|
1393
|
+
});
|
|
1394
|
+
return _context8.abrupt("return", null);
|
|
1395
|
+
|
|
1396
|
+
case 17:
|
|
1397
|
+
case "end":
|
|
1398
|
+
return _context8.stop();
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
}, _callee8, null, [[3, 12]]);
|
|
1402
|
+
}));
|
|
1403
|
+
|
|
1404
|
+
return function loadVariantGroup() {
|
|
1405
|
+
return _ref12.apply(this, arguments);
|
|
1406
|
+
};
|
|
1407
|
+
}();
|
|
1408
|
+
|
|
1409
|
+
(0, _react.useEffect)(function () {
|
|
1410
|
+
var _state$product15;
|
|
1411
|
+
|
|
1412
|
+
if (!((_state$product15 = state.product) !== null && _state$product15 !== void 0 && _state$product15.id_article)) return;
|
|
1413
|
+
loadVariantGroup(true); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1414
|
+
}, [(_state$product16 = state.product) === null || _state$product16 === void 0 ? void 0 : _state$product16.id_article]);
|
|
1415
|
+
|
|
1416
|
+
var handleOnLeaveGroup = /*#__PURE__*/function () {
|
|
1417
|
+
var _ref13 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9() {
|
|
1418
|
+
var _state$product17, res;
|
|
1419
|
+
|
|
1420
|
+
return _regenerator.default.wrap(function _callee9$(_context9) {
|
|
1421
|
+
while (1) {
|
|
1422
|
+
switch (_context9.prev = _context9.next) {
|
|
1423
|
+
case 0:
|
|
1424
|
+
_context9.prev = 0;
|
|
1425
|
+
_context9.next = 3;
|
|
1426
|
+
return _axios.default.post("".concat(process.env.REACT_APP_VARIANTS_ENDPOINT, "/leave"), {
|
|
1427
|
+
articleId: (_state$product17 = state.product) === null || _state$product17 === void 0 ? void 0 : _state$product17.id_article
|
|
1428
|
+
}, {
|
|
1429
|
+
headers: {
|
|
1430
|
+
Authorization: token
|
|
1431
|
+
}
|
|
1432
|
+
});
|
|
1433
|
+
|
|
1434
|
+
case 3:
|
|
1435
|
+
res = _context9.sent;
|
|
1436
|
+
setVariantGroup((0, _api.readPayload)(res));
|
|
1437
|
+
setShowGroup(false);
|
|
1438
|
+
_context9.next = 12;
|
|
1439
|
+
break;
|
|
1440
|
+
|
|
1441
|
+
case 8:
|
|
1442
|
+
_context9.prev = 8;
|
|
1443
|
+
_context9.t0 = _context9["catch"](0);
|
|
1444
|
+
console.error("leaveVariantGroup: ", _context9.t0);
|
|
1445
|
+
dispatch({
|
|
1446
|
+
type: "SET_MODAL",
|
|
1447
|
+
payload: {
|
|
1448
|
+
show: true,
|
|
1449
|
+
title: "Variantes",
|
|
1450
|
+
message: "No se pudo quitar el producto del grupo. Intenta de nuevo.",
|
|
1451
|
+
image: _genericModalWarning.default,
|
|
1452
|
+
buttons: [{
|
|
1453
|
+
text: "Entendido",
|
|
1454
|
+
buttonType: "general-white-button",
|
|
1455
|
+
action: function action() {
|
|
1456
|
+
return dispatch({
|
|
1457
|
+
type: "SET_MODAL",
|
|
1458
|
+
payload: {
|
|
1459
|
+
show: false
|
|
1460
|
+
}
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
}]
|
|
1464
|
+
}
|
|
1465
|
+
});
|
|
1466
|
+
|
|
1467
|
+
case 12:
|
|
1468
|
+
case "end":
|
|
1469
|
+
return _context9.stop();
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
}, _callee9, null, [[0, 8]]);
|
|
1473
|
+
}));
|
|
1474
|
+
|
|
1475
|
+
return function handleOnLeaveGroup() {
|
|
1476
|
+
return _ref13.apply(this, arguments);
|
|
1477
|
+
};
|
|
1478
|
+
}();
|
|
1479
|
+
|
|
1480
|
+
var openFamilyMember = /*#__PURE__*/function () {
|
|
1481
|
+
var _ref14 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(articleId) {
|
|
1482
|
+
var _readPayload, res, _ref15, data, encontrado;
|
|
1483
|
+
|
|
1484
|
+
return _regenerator.default.wrap(function _callee10$(_context10) {
|
|
1485
|
+
while (1) {
|
|
1486
|
+
switch (_context10.prev = _context10.next) {
|
|
1487
|
+
case 0:
|
|
1488
|
+
setLoadingVariant(articleId);
|
|
1489
|
+
setAvisoFamilia(null);
|
|
1490
|
+
_context10.prev = 2;
|
|
1491
|
+
_context10.next = 5;
|
|
1492
|
+
return _axios.default.get("".concat(process.env.REACT_APP_ORDERED_SERVICES_ENDPOINT), {
|
|
1493
|
+
params: {
|
|
1494
|
+
filterByIdArticle: articleId,
|
|
1495
|
+
includeFilters: false
|
|
1496
|
+
},
|
|
1497
|
+
headers: {
|
|
1498
|
+
Authorization: token
|
|
1499
|
+
}
|
|
1500
|
+
});
|
|
1501
|
+
|
|
1502
|
+
case 5:
|
|
1503
|
+
res = _context10.sent;
|
|
1504
|
+
// read-order-services responde { total, data: [...] }. La vista trae una
|
|
1505
|
+
// fila por orden, así que puede haber varias del mismo artículo; llegan
|
|
1506
|
+
// ordenadas por order_id DESC y la primera es la orden más reciente.
|
|
1507
|
+
_ref15 = (_readPayload = (0, _api.readPayload)(res)) !== null && _readPayload !== void 0 ? _readPayload : {}, data = _ref15.data;
|
|
1508
|
+
encontrado = (data !== null && data !== void 0 ? data : []).find(function (item) {
|
|
1509
|
+
var _item$article;
|
|
1510
|
+
|
|
1511
|
+
return Number(item === null || item === void 0 ? void 0 : (_item$article = item.article) === null || _item$article === void 0 ? void 0 : _item$article.id_article) === Number(articleId);
|
|
1512
|
+
});
|
|
1513
|
+
|
|
1514
|
+
if (encontrado) {
|
|
1515
|
+
_context10.next = 11;
|
|
1516
|
+
break;
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
setAvisoFamilia("Ese producto no está en ninguna orden de trabajo, así que no se puede abrir desde aquí.");
|
|
1520
|
+
return _context10.abrupt("return");
|
|
1521
|
+
|
|
1522
|
+
case 11:
|
|
1523
|
+
sessionStorage.setItem("productSelected", JSON.stringify(encontrado));
|
|
1524
|
+
sessionStorage.setItem("version", JSON.stringify(encontrado.version));
|
|
1525
|
+
sessionStorage.setItem("productEdit", JSON.stringify({
|
|
1526
|
+
ArticleId: encontrado.article.id_article,
|
|
1527
|
+
categoryId: encontrado.article.id_article,
|
|
1528
|
+
product: [encontrado]
|
|
1529
|
+
}));
|
|
1530
|
+
window.location.assign("/EditProducts");
|
|
1531
|
+
_context10.next = 21;
|
|
1532
|
+
break;
|
|
1533
|
+
|
|
1534
|
+
case 17:
|
|
1535
|
+
_context10.prev = 17;
|
|
1536
|
+
_context10.t0 = _context10["catch"](2);
|
|
1537
|
+
console.error("openFamilyMember: ", _context10.t0);
|
|
1538
|
+
setAvisoFamilia("No se pudo abrir ese producto. Intenta de nuevo.");
|
|
1539
|
+
|
|
1540
|
+
case 21:
|
|
1541
|
+
_context10.prev = 21;
|
|
1542
|
+
setLoadingVariant(null);
|
|
1543
|
+
return _context10.finish(21);
|
|
1544
|
+
|
|
1545
|
+
case 24:
|
|
1546
|
+
case "end":
|
|
1547
|
+
return _context10.stop();
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
}, _callee10, null, [[2, 17, 21, 24]]);
|
|
1551
|
+
}));
|
|
1552
|
+
|
|
1553
|
+
return function openFamilyMember(_x2) {
|
|
1554
|
+
return _ref14.apply(this, arguments);
|
|
1555
|
+
};
|
|
1556
|
+
}();
|
|
1557
|
+
/*
|
|
1558
|
+
Refresca tras ligar, sin recargar la página: el producto sale de
|
|
1559
|
+
sessionStorage, así que un F5 devolvería el mismo objeto y el contador
|
|
1560
|
+
seguiría igual.
|
|
1561
|
+
*/
|
|
1562
|
+
|
|
1563
|
+
|
|
1564
|
+
var handleOnLinkedVariants = function handleOnLinkedVariants(result) {
|
|
1565
|
+
var _state$product$varian2, _state$product18, _result$linked, _result$parentArticle;
|
|
1566
|
+
|
|
1567
|
+
if (!result) return;
|
|
1568
|
+
var updatedProduct = result.mode === "children" ? (0, _objectSpread5.default)((0, _objectSpread5.default)({}, state.product), {}, {
|
|
1569
|
+
variantsCount: ((_state$product$varian2 = (_state$product18 = state.product) === null || _state$product18 === void 0 ? void 0 : _state$product18.variantsCount) !== null && _state$product$varian2 !== void 0 ? _state$product$varian2 : 0) + ((_result$linked = result.linked) !== null && _result$linked !== void 0 ? _result$linked : []).length
|
|
1570
|
+
}) : (0, _objectSpread5.default)((0, _objectSpread5.default)({}, state.product), {}, {
|
|
1571
|
+
parentArticleId: (_result$parentArticle = result.parentArticleId) !== null && _result$parentArticle !== void 0 ? _result$parentArticle : null,
|
|
1572
|
+
variantsCount: 0
|
|
1573
|
+
});
|
|
1574
|
+
dispatch({
|
|
1575
|
+
type: "SET_PRODUCT",
|
|
1576
|
+
payload: updatedProduct
|
|
1577
|
+
});
|
|
1578
|
+
/*
|
|
1579
|
+
En sessionStorage se PARCHEA lo guardado; no se reemplaza.
|
|
1580
|
+
Lo que hay ahí es el producto tal como lo devuelve el listado de esta
|
|
1581
|
+
aplicación: con `article` anidado, `statusByRetailer`, `categoryRetailer`
|
|
1582
|
+
y los servicios. `updatedProduct` es la versión aplanada que usa esta
|
|
1583
|
+
pantalla, y escribirla encima tiraba todo eso: al siguiente F5 la ficha se
|
|
1584
|
+
reconstruía desde un objeto mutilado —sin relaciones de cadena, sin
|
|
1585
|
+
estatus por cadena— aunque en pantalla se viera bien hasta entonces.
|
|
1586
|
+
De ligar solo cambian dos cosas, y son las dos que se copian aquí.
|
|
1587
|
+
*/
|
|
1588
|
+
|
|
1589
|
+
try {
|
|
1590
|
+
var _sessionStorage$getIt2;
|
|
1591
|
+
|
|
1592
|
+
var guardado = JSON.parse((_sessionStorage$getIt2 = sessionStorage.getItem("productSelected")) !== null && _sessionStorage$getIt2 !== void 0 ? _sessionStorage$getIt2 : "null");
|
|
1593
|
+
|
|
1594
|
+
if (guardado) {
|
|
1595
|
+
var _updatedProduct$paren2;
|
|
1596
|
+
|
|
1597
|
+
sessionStorage.setItem("productSelected", JSON.stringify((0, _objectSpread5.default)((0, _objectSpread5.default)({}, guardado), {}, {
|
|
1598
|
+
variantsCount: updatedProduct.variantsCount,
|
|
1599
|
+
parentArticleId: (_updatedProduct$paren2 = updatedProduct.parentArticleId) !== null && _updatedProduct$paren2 !== void 0 ? _updatedProduct$paren2 : null
|
|
1600
|
+
})));
|
|
1601
|
+
}
|
|
1602
|
+
} catch (error) {
|
|
1603
|
+
// Un sessionStorage inaccesible no debe tumbar la pantalla: el estado en
|
|
1604
|
+
// memoria ya quedó bien y es lo que el usuario está viendo.
|
|
1605
|
+
console.error("linkVariants/sessionStorage: ", error);
|
|
1606
|
+
}
|
|
1607
|
+
/*
|
|
1608
|
+
Volver a preguntar, no vaciar.
|
|
1609
|
+
Antes esto hacía `setFamily(null)` para invalidar la caché, y en esta
|
|
1610
|
+
pantalla eso tenía el efecto contrario al buscado: el bloque de parentesco
|
|
1611
|
+
se decide con `esHijoDeOtro`, que sale de `family`, no del producto. Con
|
|
1612
|
+
`family` en null el bloque desaparecía, así que después de ligar la
|
|
1613
|
+
pantalla se quedaba SIN ninguna señal de que el producto ya tenía padre
|
|
1614
|
+
—justo lo que el usuario acababa de hacer—.
|
|
1615
|
+
*/
|
|
1616
|
+
|
|
1617
|
+
|
|
1618
|
+
loadFamily(true);
|
|
1619
|
+
/*
|
|
1620
|
+
Y se recargan los servicios, porque ligar cambia la herencia de cada campo
|
|
1621
|
+
en el servidor: al planchar, lo que era propio pasa a heredado y los chips
|
|
1622
|
+
tienen que decirlo. Sin esto la ficha sigue mostrando el estado anterior
|
|
1623
|
+
hasta que alguien cierra y vuelve a abrir el producto.
|
|
1624
|
+
Sin `enableLoading` para no parpadear el esqueleto encima de una pantalla
|
|
1625
|
+
que ya está pintada.
|
|
1626
|
+
*/
|
|
1627
|
+
|
|
1628
|
+
loadData(false);
|
|
1629
|
+
};
|
|
1630
|
+
/*
|
|
1631
|
+
Acción "Volver a heredar" de los chips. Repinta en sitio con lo que devuelve
|
|
1632
|
+
el endpoint: recargar la ficha se llevaría lo que haya sin guardar.
|
|
1633
|
+
*/
|
|
1634
|
+
|
|
1635
|
+
/*
|
|
1636
|
+
`kind` distingue de qué pestaña salió el chip. Las descripciones viven en
|
|
1637
|
+
`rel_article_description` y la ficha técnica en `article_data`: el endpoint
|
|
1638
|
+
recibe una lista o la otra.
|
|
1639
|
+
*/
|
|
1640
|
+
|
|
1641
|
+
|
|
1642
|
+
var handleOnRestoreInheritance = /*#__PURE__*/function () {
|
|
1643
|
+
var _ref16 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(attributeId) {
|
|
1644
|
+
var _state$product19;
|
|
1645
|
+
|
|
1646
|
+
var kind,
|
|
1647
|
+
esDescripcion,
|
|
1648
|
+
res,
|
|
1649
|
+
data,
|
|
1650
|
+
_args11 = arguments;
|
|
1651
|
+
return _regenerator.default.wrap(function _callee11$(_context11) {
|
|
1652
|
+
while (1) {
|
|
1653
|
+
switch (_context11.prev = _context11.next) {
|
|
1654
|
+
case 0:
|
|
1655
|
+
kind = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : "attribute";
|
|
1656
|
+
|
|
1657
|
+
if (!(!attributeId || !((_state$product19 = state.product) !== null && _state$product19 !== void 0 && _state$product19.id_article))) {
|
|
1658
|
+
_context11.next = 3;
|
|
1659
|
+
break;
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
return _context11.abrupt("return");
|
|
1663
|
+
|
|
1664
|
+
case 3:
|
|
1665
|
+
esDescripcion = kind === "description";
|
|
1666
|
+
_context11.prev = 4;
|
|
1667
|
+
_context11.next = 7;
|
|
1668
|
+
return _axios.default.post("".concat(process.env.REACT_APP_VARIANTS_ENDPOINT, "/restore"), (0, _objectSpread5.default)({
|
|
1669
|
+
articleId: state.product.id_article
|
|
1670
|
+
}, esDescripcion ? {
|
|
1671
|
+
descriptions: [Number(attributeId)]
|
|
1672
|
+
} : {
|
|
1673
|
+
attributes: [Number(attributeId)]
|
|
1674
|
+
}), {
|
|
1675
|
+
headers: {
|
|
1676
|
+
Authorization: token
|
|
1677
|
+
}
|
|
1678
|
+
});
|
|
1679
|
+
|
|
1680
|
+
case 7:
|
|
1681
|
+
res = _context11.sent;
|
|
1682
|
+
data = (0, _api.readPayload)(res);
|
|
1683
|
+
|
|
1684
|
+
if (!esDescripcion) {
|
|
1685
|
+
_context11.next = 12;
|
|
1686
|
+
break;
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
dispatch({
|
|
1690
|
+
type: "UPDATE_DESCRIPTIONS_INPUTS",
|
|
1691
|
+
payload: (data.descriptionValues || []).map(function (item) {
|
|
1692
|
+
return {
|
|
1693
|
+
attributeId: item.id_description,
|
|
1694
|
+
value: item.value,
|
|
1695
|
+
isOverridden: 0
|
|
1696
|
+
};
|
|
1697
|
+
})
|
|
1698
|
+
});
|
|
1699
|
+
return _context11.abrupt("return");
|
|
1700
|
+
|
|
1701
|
+
case 12:
|
|
1702
|
+
dispatch({
|
|
1703
|
+
type: "UPDATE_DATASHEETS_INPUTS",
|
|
1704
|
+
payload: (data.values || []).map(function (item) {
|
|
1705
|
+
return {
|
|
1706
|
+
attributeId: item.id,
|
|
1707
|
+
value: item.value,
|
|
1708
|
+
isOverridden: 0
|
|
1709
|
+
};
|
|
1710
|
+
})
|
|
1711
|
+
});
|
|
1712
|
+
_context11.next = 18;
|
|
1713
|
+
break;
|
|
1714
|
+
|
|
1715
|
+
case 15:
|
|
1716
|
+
_context11.prev = 15;
|
|
1717
|
+
_context11.t0 = _context11["catch"](4);
|
|
1718
|
+
console.error("restoreInheritance: ", _context11.t0);
|
|
1719
|
+
|
|
1720
|
+
case 18:
|
|
1721
|
+
case "end":
|
|
1722
|
+
return _context11.stop();
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
}, _callee11, null, [[4, 15]]);
|
|
1726
|
+
}));
|
|
1727
|
+
|
|
1728
|
+
return function handleOnRestoreInheritance(_x3) {
|
|
1729
|
+
return _ref16.apply(this, arguments);
|
|
1730
|
+
};
|
|
1731
|
+
}();
|
|
1732
|
+
/*
|
|
1733
|
+
Los atributos recién tocados, con el nombre que ve el usuario:
|
|
1734
|
+
`updated_datasheets_inputs` solo trae { attributeId, value }.
|
|
1735
|
+
*/
|
|
1736
|
+
|
|
1737
|
+
|
|
1738
|
+
var cambiosDeFichaTecnica = function cambiosDeFichaTecnica() {
|
|
1739
|
+
var _state$active_retaile4, _state$services$datas, _state$services, _state$services$datas2, _state$updated_datash;
|
|
1740
|
+
|
|
1741
|
+
var retailerId = (_state$active_retaile4 = state.active_retailer) === null || _state$active_retaile4 === void 0 ? void 0 : _state$active_retaile4.id_retailer;
|
|
1742
|
+
var inputs = (_state$services$datas = (_state$services = state.services) === null || _state$services === void 0 ? void 0 : (_state$services$datas2 = _state$services.datasheets) === null || _state$services$datas2 === void 0 ? void 0 : _state$services$datas2.inputs) !== null && _state$services$datas !== void 0 ? _state$services$datas : {};
|
|
1743
|
+
var cambios = ((_state$updated_datash = state.updated_datasheets_inputs) !== null && _state$updated_datash !== void 0 ? _state$updated_datash : []).map(function (item) {
|
|
1744
|
+
var _input$name;
|
|
1745
|
+
|
|
1746
|
+
var input = inputs["".concat(item.attributeId, "_").concat(retailerId)];
|
|
1747
|
+
return {
|
|
1748
|
+
id: Number(item.attributeId),
|
|
1749
|
+
name: (_input$name = input === null || input === void 0 ? void 0 : input.name) !== null && _input$name !== void 0 ? _input$name : "Atributo ".concat(item.attributeId),
|
|
1750
|
+
value: item.value
|
|
1751
|
+
};
|
|
1752
|
+
});
|
|
1753
|
+
/*
|
|
1754
|
+
UPC y SKU se quitan aquí y no dentro del diálogo porque esta lista también
|
|
1755
|
+
decide SI el diálogo se abre. Editar solo el UPC no tiene nada que
|
|
1756
|
+
propagar, así que preguntarlo sería pedirle al usuario una decisión sobre
|
|
1757
|
+
un conjunto vacío.
|
|
1758
|
+
*/
|
|
1759
|
+
|
|
1760
|
+
return (0, _nonPropagable.soloPropagables)(cambios);
|
|
1761
|
+
};
|
|
1762
|
+
/*
|
|
1763
|
+
Lo que se acaba de editar en la pestaña de descripciones.
|
|
1764
|
+
Va aparte de `cambiosDeFichaTecnica` porque son tablas distintas y el
|
|
1765
|
+
endpoint recibe una lista o la otra. Aquí NO se filtran UPC ni SKU: esos son
|
|
1766
|
+
atributos de ficha técnica y no aparecen en esta pestaña.
|
|
1767
|
+
*/
|
|
1768
|
+
|
|
1769
|
+
|
|
1770
|
+
var cambiosDeDescripciones = function cambiosDeDescripciones() {
|
|
1771
|
+
var _state$active_retaile5, _state$services$descr, _state$services2, _state$services2$desc, _state$updated_descri;
|
|
1772
|
+
|
|
1773
|
+
var retailerId = (_state$active_retaile5 = state.active_retailer) === null || _state$active_retaile5 === void 0 ? void 0 : _state$active_retaile5.id_retailer;
|
|
1774
|
+
var inputs = (_state$services$descr = (_state$services2 = state.services) === null || _state$services2 === void 0 ? void 0 : (_state$services2$desc = _state$services2.descriptions) === null || _state$services2$desc === void 0 ? void 0 : _state$services2$desc.inputs) !== null && _state$services$descr !== void 0 ? _state$services$descr : {};
|
|
1775
|
+
return ((_state$updated_descri = state.updated_descriptions_inputs) !== null && _state$updated_descri !== void 0 ? _state$updated_descri : []).map(function (item) {
|
|
1776
|
+
var _input$name2;
|
|
1777
|
+
|
|
1778
|
+
var input = inputs["".concat(item.attributeId, "_").concat(retailerId)];
|
|
1779
|
+
return {
|
|
1780
|
+
id: Number(item.attributeId),
|
|
1781
|
+
name: (_input$name2 = input === null || input === void 0 ? void 0 : input.name) !== null && _input$name2 !== void 0 ? _input$name2 : "Descripci\xF3n ".concat(item.attributeId),
|
|
1782
|
+
value: item.value
|
|
1783
|
+
};
|
|
1784
|
+
});
|
|
1785
|
+
};
|
|
1786
|
+
|
|
1787
|
+
var handleOnClickSave = /*#__PURE__*/function () {
|
|
1788
|
+
var _ref17 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12() {
|
|
1789
|
+
var _variantGroup$members, _familiaDesc$variants, _familiaDesc, cambiosDesc, companerasDesc, familiaDesc, hijosDesc, _familia, _familia$variants, _variantGroup$members2, cambios, familia, esHijo, hijos, companeras;
|
|
1790
|
+
|
|
1791
|
+
return _regenerator.default.wrap(function _callee12$(_context12) {
|
|
1792
|
+
while (1) {
|
|
1793
|
+
switch (_context12.prev = _context12.next) {
|
|
1794
|
+
case 0:
|
|
1795
|
+
if (!(state.saving || preparandoPropagacion)) {
|
|
1796
|
+
_context12.next = 2;
|
|
1797
|
+
break;
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
return _context12.abrupt("return");
|
|
1801
|
+
|
|
1802
|
+
case 2:
|
|
1803
|
+
_context12.t0 = state.active_tab;
|
|
1804
|
+
_context12.next = _context12.t0 === "Descripción" ? 5 : _context12.t0 === "Ficha técnica" ? 27 : _context12.t0 === "Imágenes" ? 53 : 60;
|
|
1805
|
+
break;
|
|
1806
|
+
|
|
1807
|
+
case 5:
|
|
1808
|
+
/*
|
|
1809
|
+
Guardar una descripción en un padre también abre la decisión de
|
|
1810
|
+
propagar. Sin esto, el hijo heredaba la descripción al ligarse y se
|
|
1811
|
+
quedaba con la versión vieja en cuanto el padre la corregía, sin que
|
|
1812
|
+
nadie lo notara.
|
|
1813
|
+
*/
|
|
1814
|
+
cambiosDesc = cambiosDeDescripciones();
|
|
1815
|
+
companerasDesc = ((_variantGroup$members = variantGroup === null || variantGroup === void 0 ? void 0 : variantGroup.members) !== null && _variantGroup$members !== void 0 ? _variantGroup$members : []).filter(function (m) {
|
|
1816
|
+
return !m.isCurrent;
|
|
1817
|
+
});
|
|
1818
|
+
|
|
1819
|
+
if (!(esHijoDeOtro || cambiosDesc.length === 0)) {
|
|
1820
|
+
_context12.next = 11;
|
|
1821
|
+
break;
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
_context12.next = 10;
|
|
1825
|
+
return saveDescriptions(token);
|
|
1826
|
+
|
|
1827
|
+
case 10:
|
|
1828
|
+
return _context12.abrupt("break", 61);
|
|
1829
|
+
|
|
1830
|
+
case 11:
|
|
1831
|
+
setPreparandoPropagacion(true);
|
|
1832
|
+
familiaDesc = null;
|
|
1833
|
+
_context12.prev = 13;
|
|
1834
|
+
_context12.next = 16;
|
|
1835
|
+
return loadFamily(true);
|
|
1836
|
+
|
|
1837
|
+
case 16:
|
|
1838
|
+
familiaDesc = _context12.sent;
|
|
1839
|
+
|
|
1840
|
+
case 17:
|
|
1841
|
+
_context12.prev = 17;
|
|
1842
|
+
setPreparandoPropagacion(false);
|
|
1843
|
+
return _context12.finish(17);
|
|
1844
|
+
|
|
1845
|
+
case 20:
|
|
1846
|
+
hijosDesc = ((_familiaDesc$variants = (_familiaDesc = familiaDesc) === null || _familiaDesc === void 0 ? void 0 : _familiaDesc.variants) !== null && _familiaDesc$variants !== void 0 ? _familiaDesc$variants : []).filter(function (v) {
|
|
1847
|
+
return !v.isCurrent;
|
|
1848
|
+
});
|
|
1849
|
+
|
|
1850
|
+
if (!(hijosDesc.length > 0 || companerasDesc.length > 0)) {
|
|
1851
|
+
_context12.next = 24;
|
|
1852
|
+
break;
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
setPendingPropagation({
|
|
1856
|
+
cambios: cambiosDesc,
|
|
1857
|
+
kind: "description"
|
|
1858
|
+
});
|
|
1859
|
+
return _context12.abrupt("return");
|
|
1860
|
+
|
|
1861
|
+
case 24:
|
|
1862
|
+
_context12.next = 26;
|
|
1863
|
+
return saveDescriptions(token);
|
|
1864
|
+
|
|
1865
|
+
case 26:
|
|
1866
|
+
return _context12.abrupt("break", 61);
|
|
1867
|
+
|
|
1868
|
+
case 27:
|
|
1869
|
+
cambios = cambiosDeFichaTecnica();
|
|
1870
|
+
|
|
1871
|
+
if (!(cambios.length === 0)) {
|
|
1872
|
+
_context12.next = 32;
|
|
1873
|
+
break;
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
_context12.next = 31;
|
|
1877
|
+
return saveDatasheets(token);
|
|
1878
|
+
|
|
1879
|
+
case 31:
|
|
1880
|
+
return _context12.abrupt("break", 61);
|
|
1881
|
+
|
|
1882
|
+
case 32:
|
|
1883
|
+
/*
|
|
1884
|
+
Guardar un padre con hijos abre la decisión de propagar. Sin este paso
|
|
1885
|
+
el cambio se queda solo en el padre y los hijos se van separando de él
|
|
1886
|
+
sin que nadie lo note.
|
|
1887
|
+
Si tiene hijos se resuelve AQUÍ, esperando la respuesta, en vez de
|
|
1888
|
+
mirar la copia en memoria. `family` es una consulta asíncrona: si
|
|
1889
|
+
todavía no llegó, o si falló, `hijosDelProducto` vale 0 — o sea que
|
|
1890
|
+
«todavía no sé» se leía igual que «no tiene hijos», y el padre se
|
|
1891
|
+
guardaba sin ofrecer la propagación. En silencio, que es lo peor: el
|
|
1892
|
+
usuario creía haber bajado el cambio a los hijos.
|
|
1893
|
+
La ficha de la aplicación de clientes no tiene el problema porque ahí
|
|
1894
|
+
`state.product.variantsCount` viene del listado; aquí el producto sale
|
|
1895
|
+
del endpoint de reportes, que no trae el parentesco.
|
|
1896
|
+
*/
|
|
1897
|
+
setPreparandoPropagacion(true);
|
|
1898
|
+
familia = null;
|
|
1899
|
+
_context12.prev = 34;
|
|
1900
|
+
_context12.next = 37;
|
|
1901
|
+
return loadFamily(true);
|
|
1902
|
+
|
|
1903
|
+
case 37:
|
|
1904
|
+
familia = _context12.sent;
|
|
1905
|
+
|
|
1906
|
+
case 38:
|
|
1907
|
+
_context12.prev = 38;
|
|
1908
|
+
setPreparandoPropagacion(false);
|
|
1909
|
+
return _context12.finish(38);
|
|
1910
|
+
|
|
1911
|
+
case 41:
|
|
1912
|
+
if (!(!familia || familia.error)) {
|
|
1913
|
+
_context12.next = 44;
|
|
1914
|
+
break;
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
dispatch({
|
|
1918
|
+
type: "SET_MODAL",
|
|
1919
|
+
payload: {
|
|
1920
|
+
show: true,
|
|
1921
|
+
title: "No se pudo consultar la familia",
|
|
1922
|
+
message: "No pudimos saber si este producto tiene hijos, así que no sabemos si hay que bajarles el cambio. Vuelve a intentar el guardado; si sigue fallando, guarda y revisa los hijos a mano.",
|
|
1923
|
+
image: _genericModalWarning.default,
|
|
1924
|
+
buttons: [{
|
|
1925
|
+
text: "Entendido",
|
|
1926
|
+
buttonType: "general-white-button",
|
|
1927
|
+
action: function action() {
|
|
1928
|
+
return dispatch({
|
|
1929
|
+
type: "SET_MODAL",
|
|
1930
|
+
payload: {
|
|
1931
|
+
show: false
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1934
|
+
}
|
|
1935
|
+
}, {
|
|
1936
|
+
text: "Guardar solo este producto",
|
|
1937
|
+
buttonType: "general-button-default",
|
|
1938
|
+
action: function action() {
|
|
1939
|
+
dispatch({
|
|
1940
|
+
type: "SET_MODAL",
|
|
1941
|
+
payload: {
|
|
1942
|
+
show: false
|
|
1943
|
+
}
|
|
1944
|
+
});
|
|
1945
|
+
saveDatasheets(token);
|
|
1946
|
+
}
|
|
1947
|
+
}]
|
|
1948
|
+
}
|
|
1949
|
+
});
|
|
1950
|
+
return _context12.abrupt("return");
|
|
1951
|
+
|
|
1952
|
+
case 44:
|
|
1953
|
+
/*
|
|
1954
|
+
Un HIJO no propaga a nadie, y hay que decirlo explícitamente.
|
|
1955
|
+
`familia.variants` mira la familia desde el PADRE —eso es lo correcto
|
|
1956
|
+
para navegar entre hermanos— así que desde la ficha de un hijo esa
|
|
1957
|
+
lista son sus HERMANOS. Leerla como «los destinos de este producto»
|
|
1958
|
+
hacía que el diálogo le ofreciera heredar a sus hermanos. El servidor
|
|
1959
|
+
resolvía los destinos por su cuenta y no escribía nada, de modo que el
|
|
1960
|
+
usuario elegía, guardaba, y no pasaba nada: un no-operativo silencioso.
|
|
1961
|
+
*/
|
|
1962
|
+
esHijo = !!((_familia = familia) !== null && _familia !== void 0 && _familia.parent);
|
|
1963
|
+
hijos = esHijo ? [] : ((_familia$variants = familia.variants) !== null && _familia$variants !== void 0 ? _familia$variants : []).filter(function (v) {
|
|
1964
|
+
return !v.isCurrent;
|
|
1965
|
+
});
|
|
1966
|
+
/*
|
|
1967
|
+
También cuentan las compañeras de grupo: un producto puede no tener
|
|
1968
|
+
hijos y aun así pertenecer a un grupo de variantes, y el cambio se les
|
|
1969
|
+
puede copiar igual. Si no se miraran, guardar no ofrecería nada.
|
|
1970
|
+
*/
|
|
1971
|
+
|
|
1972
|
+
companeras = ((_variantGroup$members2 = variantGroup === null || variantGroup === void 0 ? void 0 : variantGroup.members) !== null && _variantGroup$members2 !== void 0 ? _variantGroup$members2 : []).filter(function (m) {
|
|
1973
|
+
return !m.isCurrent;
|
|
1974
|
+
}); // Un hijo tampoco puede estar agrupado desde 2026-09-25, así que para
|
|
1975
|
+
// él no queda ningún destino posible.
|
|
1976
|
+
|
|
1977
|
+
if (!(!esHijo && (hijos.length > 0 || companeras.length > 0))) {
|
|
1978
|
+
_context12.next = 50;
|
|
1979
|
+
break;
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
setPendingPropagation({
|
|
1983
|
+
cambios: cambios,
|
|
1984
|
+
kind: "datasheet"
|
|
1985
|
+
});
|
|
1986
|
+
return _context12.abrupt("return");
|
|
1987
|
+
|
|
1988
|
+
case 50:
|
|
1989
|
+
_context12.next = 52;
|
|
1990
|
+
return saveDatasheets(token);
|
|
1991
|
+
|
|
1992
|
+
case 52:
|
|
1993
|
+
return _context12.abrupt("break", 61);
|
|
1994
|
+
|
|
1995
|
+
case 53:
|
|
1996
|
+
if (!(currentTray === _GalleryTrayTabs.TRAYS.ASSETS)) {
|
|
1997
|
+
_context12.next = 57;
|
|
1998
|
+
break;
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
_context12.next = 56;
|
|
2002
|
+
return handleOnSaveAssets();
|
|
2003
|
+
|
|
2004
|
+
case 56:
|
|
2005
|
+
return _context12.abrupt("return");
|
|
2006
|
+
|
|
2007
|
+
case 57:
|
|
2008
|
+
_context12.next = 59;
|
|
2009
|
+
return updateImages(token);
|
|
2010
|
+
|
|
2011
|
+
case 59:
|
|
2012
|
+
return _context12.abrupt("break", 61);
|
|
2013
|
+
|
|
2014
|
+
case 60:
|
|
2015
|
+
return _context12.abrupt("break", 61);
|
|
2016
|
+
|
|
2017
|
+
case 61:
|
|
2018
|
+
_context12.next = 63;
|
|
2019
|
+
return loadData(false);
|
|
2020
|
+
|
|
2021
|
+
case 63:
|
|
2022
|
+
case "end":
|
|
2023
|
+
return _context12.stop();
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
}, _callee12, null, [[13,, 17, 20], [34,, 38, 41]]);
|
|
2027
|
+
}));
|
|
2028
|
+
|
|
2029
|
+
return function handleOnClickSave() {
|
|
2030
|
+
return _ref17.apply(this, arguments);
|
|
2031
|
+
};
|
|
2032
|
+
}();
|
|
2033
|
+
|
|
2034
|
+
var handleOnSetUpdatedDescriptions = function handleOnSetUpdatedDescriptions(items) {
|
|
2035
|
+
dispatch({
|
|
2036
|
+
type: "SET_UPDATED_DESCRIPTIONS_INPUTS",
|
|
2037
|
+
payload: items
|
|
2038
|
+
});
|
|
2039
|
+
};
|
|
2040
|
+
|
|
2041
|
+
var handleOnSetUpdatedDatasheets = function handleOnSetUpdatedDatasheets(items) {
|
|
2042
|
+
dispatch({
|
|
2043
|
+
type: "SET_UPDATED_DATASHEETS_INPUTS",
|
|
2044
|
+
payload: items
|
|
2045
|
+
});
|
|
2046
|
+
};
|
|
2047
|
+
/*
|
|
2048
|
+
Descarga de activos: los seleccionados, o todos si no hay selección — el
|
|
2049
|
+
mismo criterio que usa la descarga de imágenes.
|
|
2050
|
+
Solo se descarga lo que ya está en S3. Un activo recién soltado vive como
|
|
2051
|
+
referencia al archivo del disco del usuario: "descargarlo" le devolvería el
|
|
2052
|
+
archivo que él mismo acaba de elegir, lo cual no tiene sentido.
|
|
2053
|
+
*/
|
|
2054
|
+
|
|
2055
|
+
|
|
2056
|
+
var handleOnDownloadAssets = function handleOnDownloadAssets() {
|
|
2057
|
+
var seleccion = state.selected_assets.length ? state.selected_assets : state.assets_values;
|
|
2058
|
+
var descargables = seleccion.filter(function (asset) {
|
|
2059
|
+
return asset.id && asset.url;
|
|
2060
|
+
});
|
|
2061
|
+
|
|
2062
|
+
if (descargables.length === 0) {
|
|
2063
|
+
dispatch({
|
|
2064
|
+
type: "SET_MODAL",
|
|
2065
|
+
payload: {
|
|
2066
|
+
show: true,
|
|
2067
|
+
title: "Nada que descargar",
|
|
2068
|
+
message: "Los activos seleccionados todavía no se han guardado. Guárdalos primero.",
|
|
2069
|
+
image: _genericModalWarning.default
|
|
2070
|
+
}
|
|
2071
|
+
});
|
|
2072
|
+
return;
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
descargables.forEach(function (asset) {
|
|
2076
|
+
return (0, _fileSaver.saveAs)(asset.url, asset.name);
|
|
2077
|
+
});
|
|
2078
|
+
};
|
|
2079
|
+
/*
|
|
2080
|
+
Borrado en lote de activos.
|
|
2081
|
+
A diferencia de las imágenes, que se borran contra el backend en el momento,
|
|
2082
|
+
los activos se quitan de la bandeja y su baja viaja en el mismo PUT del
|
|
2083
|
+
guardado (`deleteAssets`). Es lo que permite al usuario deshacerse de un
|
|
2084
|
+
borrado por error: basta con no guardar. El mensaje lo dice, para que nadie
|
|
2085
|
+
se quede pensando que ya se aplicó.
|
|
2086
|
+
*/
|
|
2087
|
+
|
|
2088
|
+
|
|
2089
|
+
var handleOnAskToDeleteAssets = function handleOnAskToDeleteAssets() {
|
|
2090
|
+
if (state.selected_assets.length === 0) {
|
|
2091
|
+
dispatch({
|
|
2092
|
+
type: "SET_MODAL",
|
|
2093
|
+
payload: {
|
|
2094
|
+
show: true,
|
|
2095
|
+
title: "Eliminar activos digitales",
|
|
2096
|
+
message: "No has seleccionado ningún activo para eliminar.",
|
|
2097
|
+
image: _genericModalWarning.default
|
|
2098
|
+
}
|
|
2099
|
+
});
|
|
2100
|
+
return;
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
var seleccionados = state.selected_assets;
|
|
2104
|
+
dispatch({
|
|
2105
|
+
type: "SET_MODAL",
|
|
2106
|
+
payload: {
|
|
2107
|
+
show: true,
|
|
2108
|
+
title: "Eliminar activos digitales",
|
|
2109
|
+
message: "Se quitar\xE1n ".concat(seleccionados.length, " activo(s) de la bandeja. El borrado se aplica al guardar."),
|
|
2110
|
+
image: _genericModalWarning.default,
|
|
2111
|
+
buttons: [{
|
|
2112
|
+
text: "Cancelar",
|
|
2113
|
+
buttonType: "general-white-button",
|
|
2114
|
+
action: function action() {
|
|
2115
|
+
return dispatch({
|
|
2116
|
+
type: "SET_MODAL",
|
|
2117
|
+
payload: {
|
|
2118
|
+
show: false
|
|
2119
|
+
}
|
|
2120
|
+
});
|
|
2121
|
+
}
|
|
2122
|
+
}, {
|
|
2123
|
+
text: "Eliminar",
|
|
2124
|
+
buttonType: "general-button-default",
|
|
2125
|
+
action: function action() {
|
|
2126
|
+
dispatch({
|
|
2127
|
+
type: "SET_MODAL",
|
|
2128
|
+
payload: {
|
|
2129
|
+
show: false
|
|
2130
|
+
}
|
|
2131
|
+
});
|
|
2132
|
+
seleccionados.forEach(function (asset) {
|
|
2133
|
+
return digitalAssets.removeAsset(asset);
|
|
2134
|
+
});
|
|
2135
|
+
}
|
|
2136
|
+
}]
|
|
2137
|
+
}
|
|
2138
|
+
});
|
|
2139
|
+
};
|
|
2140
|
+
|
|
2141
|
+
var handleOnAskToDeleteImages = function handleOnAskToDeleteImages() {
|
|
2142
|
+
if (currentTray === _GalleryTrayTabs.TRAYS.ASSETS) {
|
|
2143
|
+
handleOnAskToDeleteAssets();
|
|
2144
|
+
return;
|
|
2145
|
+
}
|
|
2146
|
+
|
|
2147
|
+
if (state.selected_images.length === 0) {
|
|
2148
|
+
dispatch({
|
|
2149
|
+
type: "SET_MODAL",
|
|
2150
|
+
payload: {
|
|
2151
|
+
show: true,
|
|
2152
|
+
title: "Eliminar imágenes",
|
|
2153
|
+
message: "No has seleccionado ninguna imagen para eliminar.",
|
|
2154
|
+
image: _genericModalWarning.default
|
|
2155
|
+
}
|
|
2156
|
+
});
|
|
2157
|
+
return;
|
|
2158
|
+
}
|
|
2159
|
+
|
|
2160
|
+
dispatch({
|
|
2161
|
+
type: "SET_MODAL",
|
|
2162
|
+
payload: {
|
|
2163
|
+
show: true,
|
|
2164
|
+
title: "Eliminar imágenes",
|
|
2165
|
+
message: "¿Estás seguro de que deseas eliminar las imágenes seleccionadas?",
|
|
2166
|
+
image: _genericModalWarning.default,
|
|
2167
|
+
buttons: [{
|
|
2168
|
+
text: "Cancelar",
|
|
2169
|
+
buttonType: "general-white-button",
|
|
2170
|
+
action: function action() {
|
|
2171
|
+
return dispatch({
|
|
2172
|
+
type: "SET_MODAL",
|
|
2173
|
+
payload: {
|
|
2174
|
+
show: false
|
|
2175
|
+
}
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2178
|
+
}, {
|
|
2179
|
+
text: "Eliminar",
|
|
2180
|
+
buttonType: "general-button-default",
|
|
2181
|
+
action: function action() {
|
|
2182
|
+
dispatch({
|
|
2183
|
+
type: "SET_MODAL",
|
|
2184
|
+
payload: {
|
|
2185
|
+
show: false
|
|
2186
|
+
}
|
|
2187
|
+
});
|
|
2188
|
+
deleteImages(token);
|
|
2189
|
+
}
|
|
2190
|
+
}]
|
|
2191
|
+
}
|
|
2192
|
+
});
|
|
2193
|
+
};
|
|
2194
|
+
|
|
2195
|
+
var handleOnApproveSingleService = /*#__PURE__*/function () {
|
|
2196
|
+
var _ref18 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13() {
|
|
2197
|
+
return _regenerator.default.wrap(function _callee13$(_context13) {
|
|
2198
|
+
while (1) {
|
|
2199
|
+
switch (_context13.prev = _context13.next) {
|
|
2200
|
+
case 0:
|
|
2201
|
+
_context13.next = 2;
|
|
2202
|
+
return sendSingleEvaluation("A");
|
|
2203
|
+
|
|
2204
|
+
case 2:
|
|
2205
|
+
case "end":
|
|
2206
|
+
return _context13.stop();
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
}, _callee13);
|
|
2210
|
+
}));
|
|
2211
|
+
|
|
2212
|
+
return function handleOnApproveSingleService() {
|
|
2213
|
+
return _ref18.apply(this, arguments);
|
|
2214
|
+
};
|
|
2215
|
+
}();
|
|
2216
|
+
|
|
2217
|
+
var handleOnRejectSingleService = function handleOnRejectSingleService() {
|
|
2218
|
+
setShowRejectModal(true);
|
|
2219
|
+
};
|
|
2220
|
+
|
|
2221
|
+
var sendSingleEvaluation = /*#__PURE__*/function () {
|
|
2222
|
+
var _ref19 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee14(result) {
|
|
2223
|
+
var _state$product$id_ord, _state$active_retaile6;
|
|
2224
|
+
|
|
2225
|
+
var concept, articleId, orderId, sectionStatusKey, evalStatus, retailerId, data, res, message, icon, activeTab, newStatuses, serviceStatus, articleStatus, updatedStatusByRetailer, updatedProduct, specialistDone, _objectSpread2, _state$services_data2, _JSON$parse2, newStatus, newOrderStatus, newArticleStatus, _articleStatus, updatedStatusByRetailerForSend, _updatedProduct, updatedServicesData, sessionProduct, _objectSpread3, productInSession, updatedProductInSession;
|
|
2226
|
+
|
|
2227
|
+
return _regenerator.default.wrap(function _callee14$(_context14) {
|
|
2228
|
+
while (1) {
|
|
2229
|
+
switch (_context14.prev = _context14.next) {
|
|
2230
|
+
case 0:
|
|
2231
|
+
if (!state.saving) {
|
|
2232
|
+
_context14.next = 2;
|
|
2233
|
+
break;
|
|
2234
|
+
}
|
|
2235
|
+
|
|
2236
|
+
return _context14.abrupt("return");
|
|
2237
|
+
|
|
2238
|
+
case 2:
|
|
2239
|
+
dispatch({
|
|
2240
|
+
type: "SET_SAVING",
|
|
2241
|
+
payload: true
|
|
2242
|
+
});
|
|
2243
|
+
concept = (0, _utils.getConceptByTab)(state.active_tab);
|
|
2244
|
+
articleId = state.product.id_article;
|
|
2245
|
+
orderId = (_state$product$id_ord = state.product.id_order) !== null && _state$product$id_ord !== void 0 ? _state$product$id_ord : state.product.orderId;
|
|
2246
|
+
sectionStatusKey = "".concat(concept, "_status");
|
|
2247
|
+
evalStatus = state.product[sectionStatusKey];
|
|
2248
|
+
retailerId = (_state$active_retaile6 = state.active_retailer) === null || _state$active_retaile6 === void 0 ? void 0 : _state$active_retaile6.id_retailer;
|
|
2249
|
+
data = {
|
|
2250
|
+
articleId: articleId,
|
|
2251
|
+
orderId: orderId,
|
|
2252
|
+
concept: concept,
|
|
2253
|
+
evalStatus: evalStatus,
|
|
2254
|
+
retailerId: retailerId
|
|
2255
|
+
};
|
|
2256
|
+
activeTab = state.active_tab;
|
|
2257
|
+
_context14.prev = 11;
|
|
2258
|
+
|
|
2259
|
+
if (!result) {
|
|
2260
|
+
_context14.next = 28;
|
|
2261
|
+
break;
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
data.result = result;
|
|
2265
|
+
data.retailerId = retailerId;
|
|
2266
|
+
_context14.next = 17;
|
|
2267
|
+
return _axios.default.put("".concat(process.env.REACT_APP_EVALUATION_ENDPOINT), data, {
|
|
2268
|
+
headers: {
|
|
2269
|
+
Authorization: token
|
|
2270
|
+
}
|
|
2271
|
+
});
|
|
2272
|
+
|
|
2273
|
+
case 17:
|
|
2274
|
+
res = _context14.sent;
|
|
2275
|
+
newStatuses = JSON.parse(res.data.body);
|
|
2276
|
+
serviceStatus = newStatuses.newServiceStatus[articleId]["".concat(concept, "Status")];
|
|
2277
|
+
articleStatus = newStatuses.newArticleStatus[articleId];
|
|
2278
|
+
console.log({
|
|
2279
|
+
newStatuses: newStatuses
|
|
2280
|
+
}); // Actualizar el producto con los nuevos estados
|
|
2281
|
+
|
|
2282
|
+
updatedStatusByRetailer = state.product.statusByRetailer.map(function (item) {
|
|
2283
|
+
return item.retailer_id === retailerId && item.service === concept ? (0, _objectSpread5.default)((0, _objectSpread5.default)({}, item), {}, {
|
|
2284
|
+
status: serviceStatus
|
|
2285
|
+
}) : item;
|
|
2286
|
+
});
|
|
2287
|
+
updatedProduct = (0, _objectSpread5.default)((0, _objectSpread5.default)({}, state.product), {}, {
|
|
2288
|
+
statusByRetailer: updatedStatusByRetailer,
|
|
2289
|
+
status: (0, _product.getMinorStatusFromRetailer)(updatedStatusByRetailer)
|
|
2290
|
+
});
|
|
2291
|
+
dispatch({
|
|
2292
|
+
type: "SET_PRODUCT",
|
|
2293
|
+
payload: updatedProduct
|
|
2294
|
+
}); // Mostrar modal de éxito
|
|
2295
|
+
|
|
2296
|
+
dispatch({
|
|
2297
|
+
type: "SET_MODAL",
|
|
2298
|
+
payload: {
|
|
2299
|
+
show: true,
|
|
2300
|
+
title: "",
|
|
2301
|
+
message: result === "A" ? "Aprobado con éxito" : "Rechazado con éxito",
|
|
2302
|
+
image: _genericModalCheck.default
|
|
2303
|
+
}
|
|
2304
|
+
});
|
|
2305
|
+
_context14.next = 33;
|
|
2306
|
+
break;
|
|
2307
|
+
|
|
2308
|
+
case 28:
|
|
2309
|
+
//Caso del botón "Enviar evaluación"
|
|
2310
|
+
//Se construye el mensaje y se actualiza el estatus
|
|
2311
|
+
specialistDone = ["RC", "RA", "CA"].includes(evalStatus);
|
|
2312
|
+
|
|
2313
|
+
if (specialistDone) {
|
|
2314
|
+
message = "".concat(activeTab, " enviada a facilitador");
|
|
2315
|
+
icon = activeTab === "Descripción" ? _descriptionSent.default : activeTab === "Ficha técnica" ? _attributesSent.default : _uploadingImages.default;
|
|
2316
|
+
} else if (["IE", "AC", "RP", "RCA"].includes(evalStatus)) {
|
|
2317
|
+
message = "Evaluación enviada";
|
|
2318
|
+
icon = _genericModalCheck.default;
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
_context14.next = 32;
|
|
2322
|
+
return _axios.default.put("".concat(process.env.REACT_APP_SEND_EVAL), data, {
|
|
2323
|
+
headers: {
|
|
2324
|
+
Authorization: token
|
|
2325
|
+
}
|
|
2326
|
+
});
|
|
2327
|
+
|
|
2328
|
+
case 32:
|
|
2329
|
+
res = _context14.sent;
|
|
2330
|
+
|
|
2331
|
+
case 33:
|
|
2332
|
+
if (res.data.statusCode === 200) {
|
|
2333
|
+
_JSON$parse2 = JSON.parse(res.data.body), newStatus = _JSON$parse2.newStatus, newOrderStatus = _JSON$parse2.newOrderStatus, newArticleStatus = _JSON$parse2.newArticleStatus;
|
|
2334
|
+
_articleStatus = newArticleStatus[articleId];
|
|
2335
|
+
console.log({
|
|
2336
|
+
newArticleStatus: newArticleStatus
|
|
2337
|
+
}); // const retailers = state.product.categoryRetailer.map((r) => ({
|
|
2338
|
+
// id: r.id_retailer,
|
|
2339
|
+
// name: r.retailerName,
|
|
2340
|
+
// }));
|
|
2341
|
+
// const messageToChat = createMessage(
|
|
2342
|
+
// retailers,
|
|
2343
|
+
// retailerId,
|
|
2344
|
+
// evalStatus,
|
|
2345
|
+
// newStatus,
|
|
2346
|
+
// activeTab,
|
|
2347
|
+
// );
|
|
2348
|
+
// const messageData = {
|
|
2349
|
+
// paramsBody: {
|
|
2350
|
+
// id: articleId,
|
|
2351
|
+
// version: state.product.version,
|
|
2352
|
+
// items: [{ type: "status", value: messageToChat }],
|
|
2353
|
+
// retailerId: retailerId,
|
|
2354
|
+
// status: state.product.status,
|
|
2355
|
+
// },
|
|
2356
|
+
// paramsHeader: { Authorization: token },
|
|
2357
|
+
// };
|
|
2358
|
+
// await sendMessage(messageData);
|
|
2359
|
+
|
|
2360
|
+
updatedStatusByRetailerForSend = state.product.statusByRetailer.map(function (item) {
|
|
2361
|
+
if (item.retailer_id === retailerId && item.service === concept) {
|
|
2362
|
+
return (0, _objectSpread5.default)((0, _objectSpread5.default)({}, item), {}, {
|
|
2363
|
+
status: newStatus
|
|
2364
|
+
});
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
return item;
|
|
2368
|
+
});
|
|
2369
|
+
_updatedProduct = (0, _objectSpread5.default)((0, _objectSpread5.default)({}, state.product), {}, (_objectSpread2 = {}, (0, _defineProperty2.default)(_objectSpread2, "".concat(concept, "_status"), newStatus), (0, _defineProperty2.default)(_objectSpread2, "statusByRetailer", updatedStatusByRetailerForSend), (0, _defineProperty2.default)(_objectSpread2, "status", (0, _product.getMinorStatusFromRetailer)(updatedStatusByRetailerForSend)), _objectSpread2)); //Actualizamos el services_data en el servicio específico del retailer actual
|
|
2370
|
+
|
|
2371
|
+
updatedServicesData = (_state$services_data2 = state.services_data) === null || _state$services_data2 === void 0 ? void 0 : _state$services_data2.map(function (service) {
|
|
2372
|
+
return (0, _objectSpread5.default)((0, _objectSpread5.default)({}, service), {}, {
|
|
2373
|
+
status: (service === null || service === void 0 ? void 0 : service.id_retailer) === retailerId && (service === null || service === void 0 ? void 0 : service.service) === concept ? newStatus : service === null || service === void 0 ? void 0 : service.status
|
|
2374
|
+
});
|
|
2375
|
+
});
|
|
2376
|
+
sessionProduct = sessionStorage.getItem("productSelected");
|
|
2377
|
+
|
|
2378
|
+
if (sessionProduct) {
|
|
2379
|
+
productInSession = JSON.parse(sessionProduct);
|
|
2380
|
+
updatedProductInSession = (0, _objectSpread5.default)((0, _objectSpread5.default)({}, productInSession), {}, (_objectSpread3 = {}, (0, _defineProperty2.default)(_objectSpread3, "".concat(concept, "_status"), newStatus), (0, _defineProperty2.default)(_objectSpread3, "statusByRetailer", state.product.statusByRetailer.map(function (item) {
|
|
2381
|
+
if (item.retailer_id === retailerId && item.service === concept) {
|
|
2382
|
+
return (0, _objectSpread5.default)((0, _objectSpread5.default)({}, item), {}, {
|
|
2383
|
+
status: newStatus
|
|
2384
|
+
});
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2387
|
+
return item;
|
|
2388
|
+
})), _objectSpread3));
|
|
2389
|
+
sessionStorage.setItem("productSelected", JSON.stringify(updatedProductInSession));
|
|
2390
|
+
}
|
|
2391
|
+
|
|
2392
|
+
if (message) {
|
|
2393
|
+
dispatch({
|
|
2394
|
+
type: "SET_MODAL",
|
|
2395
|
+
payload: {
|
|
2396
|
+
show: true,
|
|
2397
|
+
title: "",
|
|
2398
|
+
message: message,
|
|
2399
|
+
image: _genericModalCheck.default
|
|
2400
|
+
}
|
|
2401
|
+
});
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
dispatch({
|
|
2405
|
+
type: "SET_PRODUCT",
|
|
2406
|
+
payload: _updatedProduct
|
|
2407
|
+
});
|
|
2408
|
+
dispatch({
|
|
2409
|
+
type: "SET_SERVICES_DATA",
|
|
2410
|
+
payload: updatedServicesData
|
|
2411
|
+
});
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2414
|
+
_context14.next = 40;
|
|
2415
|
+
break;
|
|
2416
|
+
|
|
2417
|
+
case 36:
|
|
2418
|
+
_context14.prev = 36;
|
|
2419
|
+
_context14.t0 = _context14["catch"](11);
|
|
2420
|
+
console.error("Error sending evaluation:", _context14.t0);
|
|
2421
|
+
dispatch({
|
|
2422
|
+
type: "SET_MODAL",
|
|
2423
|
+
payload: {
|
|
2424
|
+
show: true,
|
|
2425
|
+
title: "Error",
|
|
2426
|
+
message: "Hubo un error al procesar la evaluación",
|
|
2427
|
+
image: _errorModal.default
|
|
2428
|
+
}
|
|
2429
|
+
});
|
|
2430
|
+
|
|
2431
|
+
case 40:
|
|
2432
|
+
_context14.prev = 40;
|
|
2433
|
+
dispatch({
|
|
2434
|
+
type: "SET_SAVING",
|
|
2435
|
+
payload: false
|
|
2436
|
+
});
|
|
2437
|
+
return _context14.finish(40);
|
|
2438
|
+
|
|
2439
|
+
case 43:
|
|
2440
|
+
case "end":
|
|
2441
|
+
return _context14.stop();
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
}, _callee14, null, [[11, 36, 40, 43]]);
|
|
2445
|
+
}));
|
|
2446
|
+
|
|
2447
|
+
return function sendSingleEvaluation(_x4) {
|
|
2448
|
+
return _ref19.apply(this, arguments);
|
|
2449
|
+
};
|
|
2450
|
+
}();
|
|
2451
|
+
|
|
2452
|
+
var handleOnApproveAllServices = /*#__PURE__*/function () {
|
|
2453
|
+
var _ref20 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15() {
|
|
2454
|
+
return _regenerator.default.wrap(function _callee15$(_context15) {
|
|
2455
|
+
while (1) {
|
|
2456
|
+
switch (_context15.prev = _context15.next) {
|
|
2457
|
+
case 0:
|
|
2458
|
+
_context15.next = 2;
|
|
2459
|
+
return sendBulkEvaluation("A");
|
|
2460
|
+
|
|
2461
|
+
case 2:
|
|
2462
|
+
case "end":
|
|
2463
|
+
return _context15.stop();
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
}, _callee15);
|
|
2467
|
+
}));
|
|
2468
|
+
|
|
2469
|
+
return function handleOnApproveAllServices() {
|
|
2470
|
+
return _ref20.apply(this, arguments);
|
|
2471
|
+
};
|
|
2472
|
+
}();
|
|
2473
|
+
|
|
2474
|
+
var handleOnRejectAllServices = function handleOnRejectAllServices() {
|
|
2475
|
+
setRejectAll(true);
|
|
2476
|
+
setShowRejectModal(true);
|
|
2477
|
+
};
|
|
2478
|
+
|
|
2479
|
+
var sendBulkEvaluation = /*#__PURE__*/function () {
|
|
2480
|
+
var _ref21 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16(result) {
|
|
2481
|
+
var _state$services_data3, evaluationArray, conceptArray, status, updatedStatusByRetailer, updatedProduct, updatedServicesData;
|
|
2482
|
+
|
|
2483
|
+
return _regenerator.default.wrap(function _callee16$(_context16) {
|
|
2484
|
+
while (1) {
|
|
2485
|
+
switch (_context16.prev = _context16.next) {
|
|
2486
|
+
case 0:
|
|
2487
|
+
dispatch({
|
|
2488
|
+
type: "SET_SAVING",
|
|
2489
|
+
payload: true
|
|
2490
|
+
});
|
|
2491
|
+
_context16.prev = 1;
|
|
2492
|
+
evaluationArray = [];
|
|
2493
|
+
conceptArray = (0, _utils.getConceptsByRole)(user.id_role);
|
|
2494
|
+
(_state$services_data3 = state.services_data) === null || _state$services_data3 === void 0 ? void 0 : _state$services_data3.forEach(function (ret, idx) {
|
|
2495
|
+
var retailer_service = ret.service,
|
|
2496
|
+
id_retailer = ret.id_retailer,
|
|
2497
|
+
status_retailer_service = ret.status;
|
|
2498
|
+
var lastStatusLevel = status_retailer_service === null || status_retailer_service === void 0 ? void 0 : status_retailer_service.replace(/.*\//, "");
|
|
2499
|
+
|
|
2500
|
+
if (conceptArray.includes(retailer_service) && statusArray !== null && statusArray !== void 0 && statusArray.includes(lastStatusLevel)) {
|
|
2501
|
+
var data = {
|
|
2502
|
+
articleId: state.product.id_article,
|
|
2503
|
+
orderId: state.product.id_order,
|
|
2504
|
+
concept: retailer_service,
|
|
2505
|
+
result: result,
|
|
2506
|
+
evalStatus: status_retailer_service,
|
|
2507
|
+
retailerId: id_retailer
|
|
2508
|
+
};
|
|
2509
|
+
evaluationArray.push(_axios.default.put("".concat(process.env.REACT_APP_EVALUATION_ENDPOINT), data, {
|
|
2510
|
+
headers: {
|
|
2511
|
+
Authorization: token
|
|
2512
|
+
}
|
|
2513
|
+
}));
|
|
2514
|
+
}
|
|
2515
|
+
});
|
|
2516
|
+
_context16.next = 7;
|
|
2517
|
+
return Promise.all(evaluationArray);
|
|
2518
|
+
|
|
2519
|
+
case 7:
|
|
2520
|
+
if (!(evaluationArray.length === 0)) {
|
|
2521
|
+
_context16.next = 10;
|
|
2522
|
+
break;
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
dispatch({
|
|
2526
|
+
type: "SET_MODAL",
|
|
2527
|
+
payload: {
|
|
2528
|
+
show: true,
|
|
2529
|
+
title: "Error",
|
|
2530
|
+
message: "No hay servicios que puedas evaluar en el estatus actual.",
|
|
2531
|
+
image: _errorModal.default
|
|
2532
|
+
}
|
|
2533
|
+
});
|
|
2534
|
+
return _context16.abrupt("return");
|
|
2535
|
+
|
|
2536
|
+
case 10:
|
|
2537
|
+
status = "".concat(result, "A"); // Actualizar el statusByRetailer para todos los retailers y conceptos
|
|
2538
|
+
|
|
2539
|
+
updatedStatusByRetailer = state.product.statusByRetailer.map(function (item) {
|
|
2540
|
+
return conceptArray.includes(item.service) ? (0, _objectSpread5.default)((0, _objectSpread5.default)({}, item), {}, {
|
|
2541
|
+
status: status
|
|
2542
|
+
}) : item;
|
|
2543
|
+
}); // Actualizar el producto con los nuevos estados
|
|
2544
|
+
|
|
2545
|
+
updatedProduct = (0, _objectSpread5.default)((0, _objectSpread5.default)({}, state.product), {}, {
|
|
2546
|
+
article_status: status,
|
|
2547
|
+
status: (0, _product.getMinorStatusFromRetailer)(updatedStatusByRetailer),
|
|
2548
|
+
datasheet_status: state.product.datasheet_status === "NA" ? "NA" : status,
|
|
2549
|
+
description_status: state.product.description_status === "NA" ? "NA" : status,
|
|
2550
|
+
images_status: state.product.images_status === "NA" ? "NA" : status,
|
|
2551
|
+
statusByRetailer: updatedStatusByRetailer
|
|
2552
|
+
});
|
|
2553
|
+
dispatch({
|
|
2554
|
+
type: "SET_PRODUCT",
|
|
2555
|
+
payload: updatedProduct
|
|
2556
|
+
});
|
|
2557
|
+
updatedServicesData = state.services_data.map(function (service) {
|
|
2558
|
+
return conceptArray.includes(service.service) ? (0, _objectSpread5.default)((0, _objectSpread5.default)({}, service), {}, {
|
|
2559
|
+
status: status
|
|
2560
|
+
}) : service;
|
|
2561
|
+
});
|
|
2562
|
+
dispatch({
|
|
2563
|
+
type: "SET_SERVICES_DATA",
|
|
2564
|
+
payload: updatedServicesData
|
|
2565
|
+
}); // sessionStorage.setItem(
|
|
2566
|
+
// "productSelected",
|
|
2567
|
+
// JSON.stringify(updatedProduct),
|
|
2568
|
+
// );
|
|
2569
|
+
// sessionStorage.setItem(
|
|
2570
|
+
// "productEdit",
|
|
2571
|
+
// JSON.stringify({
|
|
2572
|
+
// ArticleId: updatedProduct.id_article,
|
|
2573
|
+
// idCategory: updatedProduct.id_category,
|
|
2574
|
+
// product: updatedProduct,
|
|
2575
|
+
// }),
|
|
2576
|
+
// );
|
|
2577
|
+
// Mostrar modal de éxito
|
|
2578
|
+
|
|
2579
|
+
dispatch({
|
|
2580
|
+
type: "SET_MODAL",
|
|
2581
|
+
payload: {
|
|
2582
|
+
show: true,
|
|
2583
|
+
title: "",
|
|
2584
|
+
message: result === "A" ? "Todos los servicios aprobados con éxito" : "Todos los servicios rechazados con éxito",
|
|
2585
|
+
image: _genericModalCheck.default
|
|
2586
|
+
}
|
|
2587
|
+
});
|
|
2588
|
+
_context16.next = 22;
|
|
2589
|
+
break;
|
|
2590
|
+
|
|
2591
|
+
case 19:
|
|
2592
|
+
_context16.prev = 19;
|
|
2593
|
+
_context16.t0 = _context16["catch"](1);
|
|
2594
|
+
console.error("Error in bulk evaluation:", _context16.t0);
|
|
2595
|
+
|
|
2596
|
+
case 22:
|
|
2597
|
+
_context16.prev = 22;
|
|
2598
|
+
dispatch({
|
|
2599
|
+
type: "SET_SAVING",
|
|
2600
|
+
payload: false
|
|
2601
|
+
});
|
|
2602
|
+
return _context16.finish(22);
|
|
2603
|
+
|
|
2604
|
+
case 25:
|
|
2605
|
+
case "end":
|
|
2606
|
+
return _context16.stop();
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
}, _callee16, null, [[1, 19, 22, 25]]);
|
|
2610
|
+
}));
|
|
2611
|
+
|
|
2612
|
+
return function sendBulkEvaluation(_x5) {
|
|
2613
|
+
return _ref21.apply(this, arguments);
|
|
2614
|
+
};
|
|
2615
|
+
}();
|
|
2616
|
+
|
|
2617
|
+
var handleOnChangeAssignations = /*#__PURE__*/function () {
|
|
2618
|
+
var _ref22 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee17(assignationType, assignationId) {
|
|
2619
|
+
var concept, data, updatedProduct;
|
|
2620
|
+
return _regenerator.default.wrap(function _callee17$(_context17) {
|
|
2621
|
+
while (1) {
|
|
2622
|
+
switch (_context17.prev = _context17.next) {
|
|
2623
|
+
case 0:
|
|
2624
|
+
concept = (0, _utils.getConceptByTab)(state.active_tab);
|
|
2625
|
+
data = {
|
|
2626
|
+
articleList: [{
|
|
2627
|
+
orderId: state.product.id_order,
|
|
2628
|
+
articleId: state.product.id_article
|
|
2629
|
+
}],
|
|
2630
|
+
concept: concept,
|
|
2631
|
+
userId: assignationId
|
|
2632
|
+
};
|
|
2633
|
+
_context17.next = 4;
|
|
2634
|
+
return (0, _axios.default)({
|
|
2635
|
+
method: "post",
|
|
2636
|
+
url: process.env.REACT_APP_ASSIGNATIONS_ENDPOINT,
|
|
2637
|
+
data: data,
|
|
2638
|
+
headers: {
|
|
2639
|
+
Authorization: token
|
|
2640
|
+
}
|
|
2641
|
+
});
|
|
2642
|
+
|
|
2643
|
+
case 4:
|
|
2644
|
+
updatedProduct = (0, _objectSpread5.default)((0, _objectSpread5.default)({}, state.product), {}, (0, _defineProperty2.default)({}, "id_".concat(concept, "_").concat(assignationType), assignationId));
|
|
2645
|
+
dispatch({
|
|
2646
|
+
type: "SET_PRODUCT",
|
|
2647
|
+
payload: updatedProduct
|
|
2648
|
+
});
|
|
2649
|
+
|
|
2650
|
+
case 6:
|
|
2651
|
+
case "end":
|
|
2652
|
+
return _context17.stop();
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
}, _callee17);
|
|
2656
|
+
}));
|
|
2657
|
+
|
|
2658
|
+
return function handleOnChangeAssignations(_x6, _x7) {
|
|
2659
|
+
return _ref22.apply(this, arguments);
|
|
2660
|
+
};
|
|
2661
|
+
}();
|
|
2662
|
+
|
|
2663
|
+
var handleOnSetAssignation = function handleOnSetAssignation() {
|
|
2664
|
+
console.log("handleOnSetAssignation - pendiente de implementar");
|
|
2665
|
+
};
|
|
2666
|
+
|
|
2667
|
+
var handleOnSetImages = function handleOnSetImages() {
|
|
2668
|
+
console.log("handleOnSetImages - pendiente de implementar");
|
|
2669
|
+
};
|
|
2670
|
+
|
|
2671
|
+
var handleOnSetCheckAll = function handleOnSetCheckAll(isChecked) {
|
|
2672
|
+
dispatch({
|
|
2673
|
+
type: "TOGGLE_CHECK_ALL_IMAGES",
|
|
2674
|
+
payload: isChecked
|
|
2675
|
+
});
|
|
2676
|
+
};
|
|
2677
|
+
|
|
2678
|
+
var handleOnSetSelectedImages = function handleOnSetSelectedImages() {
|
|
2679
|
+
/*
|
|
2680
|
+
Esta función no se utiliza actualmente.
|
|
2681
|
+
En la versión anterior se usaban dos funciones distintas para el checkbox
|
|
2682
|
+
"Seleccionar todo":
|
|
2683
|
+
- Una para cambiar el valor booleano del checkbox.
|
|
2684
|
+
- Otra para actualizar el array de imágenes seleccionadas.
|
|
2685
|
+
En la versión actual se unificó la lógica en una sola función,
|
|
2686
|
+
`handleOnSetCheckAll`, que recibe el valor `true` o `false` del checkbox
|
|
2687
|
+
"Seleccionar todo" y, a partir de este, agrega o elimina todas las imágenes
|
|
2688
|
+
del array de imágenes seleccionadas.
|
|
2689
|
+
*/
|
|
2690
|
+
console.log("setSelectedImages");
|
|
2691
|
+
};
|
|
2692
|
+
|
|
2693
|
+
var handleOnSubmitComment = /*#__PURE__*/function () {
|
|
2694
|
+
var _ref23 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee18(e) {
|
|
2695
|
+
var commentText;
|
|
2696
|
+
return _regenerator.default.wrap(function _callee18$(_context18) {
|
|
2697
|
+
while (1) {
|
|
2698
|
+
switch (_context18.prev = _context18.next) {
|
|
2699
|
+
case 0:
|
|
2700
|
+
e.preventDefault();
|
|
2701
|
+
commentText = document.querySelector("#commentary-box .ql-container .ql-editor > p").innerHTML;
|
|
2702
|
+
_context18.prev = 2;
|
|
2703
|
+
_context18.next = 5;
|
|
2704
|
+
return createComment(commentText, token);
|
|
2705
|
+
|
|
2706
|
+
case 5:
|
|
2707
|
+
dispatch({
|
|
2708
|
+
type: "SET_MODAL",
|
|
2709
|
+
payload: {
|
|
2710
|
+
show: true,
|
|
2711
|
+
title: "",
|
|
2712
|
+
message: "Comentario guardado con éxito",
|
|
2713
|
+
image: _genericModalCheck.default
|
|
2714
|
+
}
|
|
2715
|
+
});
|
|
2716
|
+
_context18.next = 12;
|
|
2717
|
+
break;
|
|
2718
|
+
|
|
2719
|
+
case 8:
|
|
2720
|
+
_context18.prev = 8;
|
|
2721
|
+
_context18.t0 = _context18["catch"](2);
|
|
2722
|
+
console.error("Error saving comment:", _context18.t0);
|
|
2723
|
+
dispatch({
|
|
2724
|
+
type: "SET_MODAL",
|
|
2725
|
+
payload: {
|
|
2726
|
+
show: true,
|
|
2727
|
+
title: "Error",
|
|
2728
|
+
message: "Hubo un error al guardar el comentario",
|
|
2729
|
+
image: _errorModal.default
|
|
2730
|
+
}
|
|
2731
|
+
});
|
|
2732
|
+
|
|
2733
|
+
case 12:
|
|
2734
|
+
case "end":
|
|
2735
|
+
return _context18.stop();
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
}, _callee18, null, [[2, 8]]);
|
|
2739
|
+
}));
|
|
2740
|
+
|
|
2741
|
+
return function handleOnSubmitComment(_x8) {
|
|
2742
|
+
return _ref23.apply(this, arguments);
|
|
2743
|
+
};
|
|
2744
|
+
}();
|
|
2745
|
+
|
|
2746
|
+
var handleOnSendEvaluationToFacilitator = function handleOnSendEvaluationToFacilitator() {
|
|
2747
|
+
sendSingleEvaluation();
|
|
2748
|
+
};
|
|
2749
|
+
|
|
2750
|
+
var isEvaluationFinished = function isEvaluationFinished(id_rol, tab, statusArray) {
|
|
2751
|
+
var _servicesByTab$find, _servicesByTab$find$s, _product$, _srv;
|
|
2752
|
+
|
|
2753
|
+
var servicesData = state.services_data;
|
|
2754
|
+
var activeRetailer = state.active_retailer;
|
|
2755
|
+
var product = state.product;
|
|
2756
|
+
var concept = (0, _utils.getConceptByTab)(tab);
|
|
2757
|
+
var servicesByTab = servicesData === null || servicesData === void 0 ? void 0 : servicesData.filter(function (serv) {
|
|
2758
|
+
return serv.service === concept;
|
|
2759
|
+
});
|
|
2760
|
+
var statusBySelectedRetailerService = servicesByTab === null || servicesByTab === void 0 ? void 0 : (_servicesByTab$find = servicesByTab.find(function (serv) {
|
|
2761
|
+
return serv.id_retailer === (activeRetailer === null || activeRetailer === void 0 ? void 0 : activeRetailer.id_retailer);
|
|
2762
|
+
})) === null || _servicesByTab$find === void 0 ? void 0 : (_servicesByTab$find$s = _servicesByTab$find.status) === null || _servicesByTab$find$s === void 0 ? void 0 : _servicesByTab$find$s.replace(/.*\//, "");
|
|
2763
|
+
var currentProducStatus = product === null || product === void 0 ? void 0 : (_product$ = product["".concat(concept, "_status")]) === null || _product$ === void 0 ? void 0 : _product$.replace(/.*\//, "");
|
|
2764
|
+
var unvalidated = ["IE", "CA"].includes(currentProducStatus);
|
|
2765
|
+
var auditorUnvalidated = !["RA", "AA", "ACA", "AP"].includes(currentProducStatus);
|
|
2766
|
+
var result;
|
|
2767
|
+
|
|
2768
|
+
switch (id_rol) {
|
|
2769
|
+
case 7:
|
|
2770
|
+
case 8:
|
|
2771
|
+
// AC se valida/rechaza desde el panel, no se reenvía con "Enviar evaluación".
|
|
2772
|
+
var canSendEvaluation = statusBySelectedRetailerService !== "AC" && statusArray.includes(statusBySelectedRetailerService); // const conditionTwo = statusArray.includes(product?.status);
|
|
2773
|
+
// const conditionThree =
|
|
2774
|
+
// servicesByTab.filter((service) =>
|
|
2775
|
+
// statusArray.includes(service.status?.replace(/.*\//, "")),
|
|
2776
|
+
// ).length === servicesByTab.length;
|
|
2777
|
+
// return (canSendEvaluation && conditionTwo) || conditionThree;
|
|
2778
|
+
|
|
2779
|
+
return canSendEvaluation;
|
|
2780
|
+
|
|
2781
|
+
case 4:
|
|
2782
|
+
case 5:
|
|
2783
|
+
var filteredSrv45 = servicesByTab === null || servicesByTab === void 0 ? void 0 : servicesByTab.filter(function (serv) {
|
|
2784
|
+
return statusArray.includes(serv === null || serv === void 0 ? void 0 : serv.status);
|
|
2785
|
+
});
|
|
2786
|
+
var condition45 = unvalidated && ["CA", "IE"].includes(product === null || product === void 0 ? void 0 : product.status) && (filteredSrv45 === null || filteredSrv45 === void 0 ? void 0 : filteredSrv45.length) === (servicesByTab === null || servicesByTab === void 0 ? void 0 : servicesByTab.length);
|
|
2787
|
+
return condition45;
|
|
2788
|
+
|
|
2789
|
+
case 6:
|
|
2790
|
+
var statusInArray = statusArray.includes(product === null || product === void 0 ? void 0 : product.status);
|
|
2791
|
+
var allSrvValid = (_srv = srv) === null || _srv === void 0 ? void 0 : _srv.every(function (serv) {
|
|
2792
|
+
return ["RA", "AA", "AP", "ACA"].includes(serv === null || serv === void 0 ? void 0 : serv.status);
|
|
2793
|
+
});
|
|
2794
|
+
var condition6 = statusInArray && allSrvValid && auditorUnvalidated;
|
|
2795
|
+
return condition6;
|
|
2796
|
+
|
|
2797
|
+
default:
|
|
2798
|
+
console.log("Default case - returning false");
|
|
2799
|
+
return false;
|
|
2800
|
+
}
|
|
2801
|
+
};
|
|
2802
|
+
|
|
2803
|
+
var handleOnChangeProductVersion = function handleOnChangeProductVersion(version) {
|
|
2804
|
+
console.log("se cambia la version");
|
|
2805
|
+
dispatch({
|
|
2806
|
+
type: "SET_PRODUCT_VERSION",
|
|
2807
|
+
payload: version
|
|
2808
|
+
});
|
|
2809
|
+
loadData(true, version);
|
|
2810
|
+
};
|
|
2811
|
+
|
|
2812
|
+
(0, _react.useEffect)(function () {
|
|
2813
|
+
console.log({
|
|
2814
|
+
stateProduct: state.product
|
|
2815
|
+
});
|
|
2816
|
+
}, [state.product]);
|
|
2817
|
+
|
|
2818
|
+
var handleRetryLoad = function handleRetryLoad() {
|
|
2819
|
+
dispatch({
|
|
2820
|
+
type: "SET_ERRORS",
|
|
2821
|
+
payload: []
|
|
2822
|
+
});
|
|
2823
|
+
|
|
2824
|
+
if (state.active_retailer) {
|
|
2825
|
+
loadData();
|
|
2826
|
+
} else {
|
|
2827
|
+
initializeProduct();
|
|
2828
|
+
}
|
|
2829
|
+
};
|
|
2830
|
+
|
|
2831
|
+
return {
|
|
2832
|
+
isRetailer: isRetailer,
|
|
2833
|
+
digitalAssets: digitalAssets,
|
|
2834
|
+
currentTray: currentTray,
|
|
2835
|
+
assetsLoadedFor: assetsLoadedFor,
|
|
2836
|
+
handleOnSetSelectedAssets: handleOnSetSelectedAssets,
|
|
2837
|
+
handleOnSetAllAssetsChecked: handleOnSetAllAssetsChecked,
|
|
2838
|
+
initializeProduct: initializeProduct,
|
|
2839
|
+
loadAuditableData: loadAuditableData,
|
|
2840
|
+
loadData: loadData,
|
|
2841
|
+
handleOnChangeCurrentImage: handleOnChangeCurrentImage,
|
|
2842
|
+
handleOnShowModalGallery: handleOnShowModalGallery,
|
|
2843
|
+
handleOnChangeActiveRetailer: handleOnChangeActiveRetailer,
|
|
2844
|
+
handleOnChangeActiveTab: handleOnChangeActiveTab,
|
|
2845
|
+
handleOnToggleImageLayout: handleOnToggleImageLayout,
|
|
2846
|
+
handleOnToggleObservation: handleOnToggleObservation,
|
|
2847
|
+
handleOnHideObservation: handleOnHideObservation,
|
|
2848
|
+
isAuditorAssigned: isAuditorAssigned,
|
|
2849
|
+
isAssignedAs: isAssignedAs,
|
|
2850
|
+
isUserAssignedToService: isUserAssignedToService,
|
|
2851
|
+
canShowSingleEvaluationButtons: canShowSingleEvaluationButtons,
|
|
2852
|
+
canShowBulkEvaluationButtons: canShowBulkEvaluationButtons,
|
|
2853
|
+
getStatusByCurrentServiceAndRetailer: getStatusByCurrentServiceAndRetailer,
|
|
2854
|
+
handleOnSaveAssets: handleOnSaveAssets,
|
|
2855
|
+
handleOnClickSaveImages: handleOnClickSaveImages,
|
|
2856
|
+
loadFamily: loadFamily,
|
|
2857
|
+
hijosDelProducto: hijosDelProducto,
|
|
2858
|
+
esHijoDeOtro: esHijoDeOtro,
|
|
2859
|
+
puedeAgruparse: puedeAgruparse,
|
|
2860
|
+
handleOnUnlinked: handleOnUnlinked,
|
|
2861
|
+
loadVariantGroup: loadVariantGroup,
|
|
2862
|
+
handleOnLeaveGroup: handleOnLeaveGroup,
|
|
2863
|
+
openFamilyMember: openFamilyMember,
|
|
2864
|
+
handleOnLinkedVariants: handleOnLinkedVariants,
|
|
2865
|
+
handleOnRestoreInheritance: handleOnRestoreInheritance,
|
|
2866
|
+
cambiosDeFichaTecnica: cambiosDeFichaTecnica,
|
|
2867
|
+
cambiosDeDescripciones: cambiosDeDescripciones,
|
|
2868
|
+
handleOnClickSave: handleOnClickSave,
|
|
2869
|
+
handleOnSetUpdatedDescriptions: handleOnSetUpdatedDescriptions,
|
|
2870
|
+
handleOnSetUpdatedDatasheets: handleOnSetUpdatedDatasheets,
|
|
2871
|
+
handleOnDownloadAssets: handleOnDownloadAssets,
|
|
2872
|
+
handleOnAskToDeleteAssets: handleOnAskToDeleteAssets,
|
|
2873
|
+
handleOnAskToDeleteImages: handleOnAskToDeleteImages,
|
|
2874
|
+
handleOnApproveSingleService: handleOnApproveSingleService,
|
|
2875
|
+
handleOnRejectSingleService: handleOnRejectSingleService,
|
|
2876
|
+
sendSingleEvaluation: sendSingleEvaluation,
|
|
2877
|
+
handleOnApproveAllServices: handleOnApproveAllServices,
|
|
2878
|
+
handleOnRejectAllServices: handleOnRejectAllServices,
|
|
2879
|
+
sendBulkEvaluation: sendBulkEvaluation,
|
|
2880
|
+
handleOnChangeAssignations: handleOnChangeAssignations,
|
|
2881
|
+
handleOnSetAssignation: handleOnSetAssignation,
|
|
2882
|
+
handleOnSetImages: handleOnSetImages,
|
|
2883
|
+
handleOnSetCheckAll: handleOnSetCheckAll,
|
|
2884
|
+
handleOnSetSelectedImages: handleOnSetSelectedImages,
|
|
2885
|
+
handleOnSubmitComment: handleOnSubmitComment,
|
|
2886
|
+
handleOnSendEvaluationToFacilitator: handleOnSendEvaluationToFacilitator,
|
|
2887
|
+
isEvaluationFinished: isEvaluationFinished,
|
|
2888
|
+
handleOnChangeProductVersion: handleOnChangeProductVersion,
|
|
2889
|
+
handleRetryLoad: handleRetryLoad,
|
|
2890
|
+
showVersionSelector: showVersionSelector,
|
|
2891
|
+
setShowVersionSelector: setShowVersionSelector,
|
|
2892
|
+
auditableVersion: auditableVersion,
|
|
2893
|
+
setAuditableVersion: setAuditableVersion,
|
|
2894
|
+
headerTop: headerTop,
|
|
2895
|
+
setHeaderTop: setHeaderTop,
|
|
2896
|
+
shotThd: shotThd,
|
|
2897
|
+
setShotThd: setShotThd,
|
|
2898
|
+
observation: observation,
|
|
2899
|
+
setObservation: setObservation,
|
|
2900
|
+
showRejectModal: showRejectModal,
|
|
2901
|
+
setShowRejectModal: setShowRejectModal,
|
|
2902
|
+
isObservationVisible: isObservationVisible,
|
|
2903
|
+
setObservationVisible: setObservationVisible,
|
|
2904
|
+
imageLayout: imageLayout,
|
|
2905
|
+
setImageLayout: setImageLayout,
|
|
2906
|
+
crossComment: crossComment,
|
|
2907
|
+
setCrossComment: setCrossComment,
|
|
2908
|
+
statusArray: statusArray,
|
|
2909
|
+
setStatusArray: setStatusArray,
|
|
2910
|
+
rejectAll: rejectAll,
|
|
2911
|
+
setRejectAll: setRejectAll,
|
|
2912
|
+
showLinkVariants: showLinkVariants,
|
|
2913
|
+
setShowLinkVariants: setShowLinkVariants,
|
|
2914
|
+
family: family,
|
|
2915
|
+
setFamily: setFamily,
|
|
2916
|
+
showFamily: showFamily,
|
|
2917
|
+
setShowFamily: setShowFamily,
|
|
2918
|
+
loadingVariant: loadingVariant,
|
|
2919
|
+
setLoadingVariant: setLoadingVariant,
|
|
2920
|
+
variantGroup: variantGroup,
|
|
2921
|
+
setVariantGroup: setVariantGroup,
|
|
2922
|
+
showGroup: showGroup,
|
|
2923
|
+
setShowGroup: setShowGroup,
|
|
2924
|
+
showGroupModal: showGroupModal,
|
|
2925
|
+
setShowGroupModal: setShowGroupModal,
|
|
2926
|
+
porDesvincular: porDesvincular,
|
|
2927
|
+
setPorDesvincular: setPorDesvincular,
|
|
2928
|
+
avisoFamilia: avisoFamilia,
|
|
2929
|
+
setAvisoFamilia: setAvisoFamilia,
|
|
2930
|
+
pendingPropagation: pendingPropagation,
|
|
2931
|
+
setPendingPropagation: setPendingPropagation,
|
|
2932
|
+
preparandoPropagacion: preparandoPropagacion,
|
|
2933
|
+
setPreparandoPropagacion: setPreparandoPropagacion,
|
|
2934
|
+
auditServices: auditServices,
|
|
2935
|
+
setAuditServices: setAuditServices,
|
|
2936
|
+
auditDatasheets: auditDatasheets,
|
|
2937
|
+
setAuditDatasheets: setAuditDatasheets,
|
|
2938
|
+
auditDescriptions: auditDescriptions,
|
|
2939
|
+
setAuditDescriptions: setAuditDescriptions,
|
|
2940
|
+
showModal: showModal,
|
|
2941
|
+
setShowModal: setShowModal,
|
|
2942
|
+
compare: compare,
|
|
2943
|
+
setCompare: setCompare,
|
|
2944
|
+
openChangeStatusModal: openChangeStatusModal,
|
|
2945
|
+
setOpenChangeStatusModal: setOpenChangeStatusModal,
|
|
2946
|
+
assetNotices: assetNotices,
|
|
2947
|
+
setAssetNotices: setAssetNotices,
|
|
2948
|
+
activeTray: activeTray,
|
|
2949
|
+
setActiveTray: setActiveTray,
|
|
2950
|
+
state: state,
|
|
2951
|
+
dispatch: dispatch,
|
|
2952
|
+
saveDatasheets: saveDatasheets,
|
|
2953
|
+
saveDescriptions: saveDescriptions,
|
|
2954
|
+
updateImages: updateImages,
|
|
2955
|
+
deleteImages: deleteImages,
|
|
2956
|
+
saveAssets: saveAssets,
|
|
2957
|
+
registerUploadedAssets: registerUploadedAssets,
|
|
2958
|
+
handleOnDownloadImages: handleOnDownloadImages,
|
|
2959
|
+
createComment: createComment,
|
|
2960
|
+
getRootProps: getRootProps,
|
|
2961
|
+
getInputProps: getInputProps,
|
|
2962
|
+
isDragActive: isDragActive,
|
|
2963
|
+
open: open
|
|
2964
|
+
};
|
|
2965
|
+
};
|
|
2966
|
+
|
|
2967
|
+
exports.useCreatorsProductEdition = useCreatorsProductEdition;
|