contentoh-components-library 21.5.71 → 21.5.73

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.
@@ -68,7 +68,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
68
68
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(token) {
69
69
  var _state$product, _state$product2;
70
70
 
71
- var dataObject, _state$product3, res, inputs, filledRequiredCount;
71
+ var dataObject, _state$product3, res, inputs, filledRequiredCount, body, newStatus, _state$product4, productFromLocalStorage, updatedProduct;
72
72
 
73
73
  return _regenerator.default.wrap(function _callee$(_context) {
74
74
  while (1) {
@@ -132,6 +132,32 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
132
132
  filledRequiredCount += 1;
133
133
  }
134
134
  });
135
+ body = JSON.parse(res.data.body);
136
+ newStatus = body === null || body === void 0 ? void 0 : body.newStatus;
137
+
138
+ if (newStatus) {
139
+ productFromLocalStorage = JSON.parse(sessionStorage.getItem("productSelected"));
140
+ updatedProduct = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, productFromLocalStorage || state.product), {}, {
141
+ description_status: newStatus,
142
+ statusByRetailer: ((productFromLocalStorage === null || productFromLocalStorage === void 0 ? void 0 : productFromLocalStorage.statusByRetailer) || ((_state$product4 = state.product) === null || _state$product4 === void 0 ? void 0 : _state$product4.statusByRetailer) || []).map(function (retailerStatus) {
143
+ return retailerStatus.service === "description" ? (0, _objectSpread2.default)((0, _objectSpread2.default)({}, retailerStatus), {}, {
144
+ status: newStatus
145
+ }) : retailerStatus;
146
+ })
147
+ });
148
+ sessionStorage.setItem("productSelected", JSON.stringify(updatedProduct));
149
+ dispatch({
150
+ type: "SET_SERVICES_DATA",
151
+ payload: (state.services_data || []).map(function (srv) {
152
+ var _state$active_retaile;
153
+
154
+ return srv.service === "description" && srv.id_retailer === ((_state$active_retaile = state.active_retailer) === null || _state$active_retaile === void 0 ? void 0 : _state$active_retaile.id_retailer) ? (0, _objectSpread2.default)((0, _objectSpread2.default)({}, srv), {}, {
155
+ status: newStatus
156
+ }) : srv;
157
+ })
158
+ });
159
+ }
160
+
135
161
  dispatch({
136
162
  type: "SET_MISSING_REQUIRED_FIELDS",
137
163
  payload: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, state.missing_required_fields), {}, {
@@ -191,9 +217,9 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
191
217
 
192
218
  var saveDatasheets = /*#__PURE__*/function () {
193
219
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(token) {
194
- var _state$product4, _state$product5;
220
+ var _state$product5, _state$product6;
195
221
 
196
- var dataObject, _state$product6, res, _state$active_retaile, datasheetInputs, retailerId, filledRequiredCount;
222
+ var dataObject, _state$product7, res, _state$active_retaile2, datasheetInputs, retailerId, filledRequiredCount, body, newStatus, _state$product8, productFromLocalStorage, updatedProduct;
197
223
 
198
224
  return _regenerator.default.wrap(function _callee2$(_context2) {
199
225
  while (1) {
@@ -212,12 +238,12 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
212
238
  payload: true
213
239
  });
214
240
  dataObject = {
215
- articleId: (_state$product4 = state.product) === null || _state$product4 === void 0 ? void 0 : _state$product4.id_article,
241
+ articleId: (_state$product5 = state.product) === null || _state$product5 === void 0 ? void 0 : _state$product5.id_article,
216
242
  articleData: state.updated_datasheets_inputs
217
243
  };
218
244
 
219
- if ((_state$product5 = state.product) !== null && _state$product5 !== void 0 && _state$product5.id_order) {
220
- dataObject.orderId = (_state$product6 = state.product) === null || _state$product6 === void 0 ? void 0 : _state$product6.id_order;
245
+ if ((_state$product6 = state.product) !== null && _state$product6 !== void 0 && _state$product6.id_order) {
246
+ dataObject.orderId = (_state$product7 = state.product) === null || _state$product7 === void 0 ? void 0 : _state$product7.id_order;
221
247
  }
222
248
 
223
249
  _context2.prev = 5;
@@ -247,7 +273,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
247
273
  }); // Contar cuántos campos requeridos que antes estaban vacíos ahora tienen valor
248
274
 
249
275
  datasheetInputs = state.datasheets_inputs[1];
250
- retailerId = (_state$active_retaile = state.active_retailer) === null || _state$active_retaile === void 0 ? void 0 : _state$active_retaile.id_retailer;
276
+ retailerId = (_state$active_retaile2 = state.active_retailer) === null || _state$active_retaile2 === void 0 ? void 0 : _state$active_retaile2.id_retailer;
251
277
  filledRequiredCount = 0;
252
278
  state.updated_datasheets_inputs.forEach(function (updatedInput) {
253
279
  var key = "".concat(updatedInput.attributeId, "_").concat(retailerId);
@@ -257,6 +283,32 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
257
283
  filledRequiredCount += 1;
258
284
  }
259
285
  });
286
+ body = JSON.parse(res.data.body);
287
+ newStatus = body === null || body === void 0 ? void 0 : body.newStatus;
288
+
289
+ if (newStatus) {
290
+ productFromLocalStorage = JSON.parse(sessionStorage.getItem("productSelected"));
291
+ updatedProduct = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, productFromLocalStorage || state.product), {}, {
292
+ datasheet_status: newStatus,
293
+ statusByRetailer: ((productFromLocalStorage === null || productFromLocalStorage === void 0 ? void 0 : productFromLocalStorage.statusByRetailer) || ((_state$product8 = state.product) === null || _state$product8 === void 0 ? void 0 : _state$product8.statusByRetailer) || []).map(function (retailerStatus) {
294
+ return retailerStatus.service === "datasheet" ? (0, _objectSpread2.default)((0, _objectSpread2.default)({}, retailerStatus), {}, {
295
+ status: newStatus
296
+ }) : retailerStatus;
297
+ })
298
+ });
299
+ sessionStorage.setItem("productSelected", JSON.stringify(updatedProduct));
300
+ dispatch({
301
+ type: "SET_SERVICES_DATA",
302
+ payload: (state.services_data || []).map(function (srv) {
303
+ var _state$active_retaile3;
304
+
305
+ return srv.service === "datasheet" && srv.id_retailer === ((_state$active_retaile3 = state.active_retailer) === null || _state$active_retaile3 === void 0 ? void 0 : _state$active_retaile3.id_retailer) ? (0, _objectSpread2.default)((0, _objectSpread2.default)({}, srv), {}, {
306
+ status: newStatus
307
+ }) : srv;
308
+ })
309
+ });
310
+ }
311
+
260
312
  dispatch({
261
313
  type: "SET_MISSING_REQUIRED_FIELDS",
262
314
  payload: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, state.missing_required_fields), {}, {
@@ -310,9 +362,10 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
310
362
 
311
363
  var updateImages = /*#__PURE__*/function () {
312
364
  var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(token) {
313
- var _state$product7, _state$images_values, _state$product8, _state$product9, _data$articleData, _data$updateImages;
365
+ var _state$images_values, _state$product9, _state$product10, _state$product11, _data$articleData, _data$updateImages;
366
+
367
+ var updatedImages, attrForImgs, generalAttrs, retailerKey, retailerAttrs, mergedAttrs, data, valid, promiseArray, res, imageBody, newStatus, _state$product12, productFromLocalStorage, updatedProduct;
314
368
 
315
- var updatedImages, data, valid, promiseArray, res;
316
369
  return _regenerator.default.wrap(function _callee3$(_context3) {
317
370
  while (1) {
318
371
  switch (_context3.prev = _context3.next) {
@@ -326,14 +379,33 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
326
379
 
327
380
  case 2:
328
381
  updatedImages = state.updated_images_values;
382
+ attrForImgs = ((_state$images_values = state.images_values) === null || _state$images_values === void 0 ? void 0 : _state$images_values.attrForImgs) || {};
383
+ generalAttrs = attrForImgs.general || [];
384
+ retailerKey = Object.keys(attrForImgs).find(function (key) {
385
+ return key !== "general";
386
+ });
387
+ retailerAttrs = retailerKey ? attrForImgs[retailerKey] : [];
388
+ mergedAttrs = retailerAttrs.map(function (retailerAttr) {
389
+ var generalAttr = generalAttrs.find(function (g) {
390
+ return g.id === retailerAttr.id;
391
+ });
392
+
393
+ if (generalAttr && generalAttr.value !== retailerAttr.value) {
394
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, retailerAttr), {}, {
395
+ value: generalAttr.value
396
+ });
397
+ }
398
+
399
+ return retailerAttr;
400
+ });
329
401
  data = {
330
- articleId: (_state$product7 = state.product) === null || _state$product7 === void 0 ? void 0 : _state$product7.id_article,
331
- attrReqImgs: Object.values((_state$images_values = state.images_values) === null || _state$images_values === void 0 ? void 0 : _state$images_values.attrForImgs).slice(0, -1).map(function (e) {
332
- var _e$, _e$0$value, _e$2;
402
+ articleId: (_state$product9 = state.product) === null || _state$product9 === void 0 ? void 0 : _state$product9.id_article,
403
+ attrReqImgs: mergedAttrs.map(function (e) {
404
+ var _e$value;
333
405
 
334
406
  return {
335
- attrId: (_e$ = e[0]) === null || _e$ === void 0 ? void 0 : _e$.id,
336
- value: (_e$0$value = (_e$2 = e[0]) === null || _e$2 === void 0 ? void 0 : _e$2.value) !== null && _e$0$value !== void 0 ? _e$0$value : ""
407
+ attrId: e.id,
408
+ value: (_e$value = e.value) !== null && _e$value !== void 0 ? _e$value : ""
337
409
  };
338
410
  }),
339
411
  articleData: state.images_values.values.filter(function (e) {
@@ -343,7 +415,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
343
415
  return e.id;
344
416
  })
345
417
  };
346
- if ((_state$product8 = state.product) !== null && _state$product8 !== void 0 && _state$product8.orderId) data["orderId"] = (_state$product9 = state.product) === null || _state$product9 === void 0 ? void 0 : _state$product9.orderId;
418
+ if ((_state$product10 = state.product) !== null && _state$product10 !== void 0 && _state$product10.orderId) data["orderId"] = (_state$product11 = state.product) === null || _state$product11 === void 0 ? void 0 : _state$product11.orderId;
347
419
  valid = (data === null || data === void 0 ? void 0 : (_data$articleData = data.articleData) === null || _data$articleData === void 0 ? void 0 : _data$articleData.every(function (e) {
348
420
  return e === null || e === void 0 ? void 0 : e.image_id;
349
421
  })) && (data === null || data === void 0 ? void 0 : (_data$updateImages = data.updateImages) === null || _data$updateImages === void 0 ? void 0 : _data$updateImages.every(function (e) {
@@ -354,7 +426,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
354
426
  });
355
427
 
356
428
  if (!valid) {
357
- _context3.next = 33;
429
+ _context3.next = 38;
358
430
  break;
359
431
  }
360
432
 
@@ -373,7 +445,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
373
445
  isApproved: true
374
446
  });
375
447
  });
376
- _context3.prev = 11;
448
+ _context3.prev = 16;
377
449
  promiseArray = data.articleData.map(function (e) {
378
450
  var file = Buffer.from(e.src.replace(/^data:image\/\w+;base64,/, ""), "base64");
379
451
  var params = {
@@ -384,10 +456,10 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
384
456
  };
385
457
  return myBucket.putObject(params).promise();
386
458
  });
387
- _context3.next = 15;
459
+ _context3.next = 20;
388
460
  return Promise.all(promiseArray);
389
461
 
390
- case 15:
462
+ case 20:
391
463
  // Eliminar el buffer base64 antes de enviar al endpoint para evitar error 413
392
464
  data.articleData = data.articleData.map(function (_ref5) {
393
465
  var src = _ref5.src,
@@ -399,7 +471,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
399
471
  rest = (0, _objectWithoutProperties2.default)(_ref6, _excluded2);
400
472
  return rest;
401
473
  });
402
- _context3.next = 19;
474
+ _context3.next = 24;
403
475
  return _axios.default.put(process.env.REACT_APP_ARTICLE_DATA_ENDPOINT, data, {
404
476
  params: {
405
477
  image: true,
@@ -410,7 +482,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
410
482
  }
411
483
  });
412
484
 
413
- case 19:
485
+ case 24:
414
486
  res = _context3.sent;
415
487
 
416
488
  if (res.data.statusCode === 200) {
@@ -419,10 +491,32 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
419
491
  type: "SET_UPDATED_IMAGES_VALUES",
420
492
  payload: []
421
493
  });
422
- dispatch({
423
- type: "SET_UPDATED_ATTR_FOR_IMGS",
424
- payload: []
425
- }); // Mostrar modal de éxito
494
+ imageBody = JSON.parse(res.data.body);
495
+ newStatus = imageBody === null || imageBody === void 0 ? void 0 : imageBody.newStatus;
496
+
497
+ if (newStatus) {
498
+ productFromLocalStorage = JSON.parse(sessionStorage.getItem("productSelected"));
499
+ updatedProduct = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, productFromLocalStorage || state.product), {}, {
500
+ images_status: newStatus,
501
+ statusByRetailer: ((productFromLocalStorage === null || productFromLocalStorage === void 0 ? void 0 : productFromLocalStorage.statusByRetailer) || ((_state$product12 = state.product) === null || _state$product12 === void 0 ? void 0 : _state$product12.statusByRetailer) || []).map(function (retailerStatus) {
502
+ return retailerStatus.service === "images" ? (0, _objectSpread2.default)((0, _objectSpread2.default)({}, retailerStatus), {}, {
503
+ status: newStatus
504
+ }) : retailerStatus;
505
+ })
506
+ });
507
+ sessionStorage.setItem("productSelected", JSON.stringify(updatedProduct));
508
+ dispatch({
509
+ type: "SET_SERVICES_DATA",
510
+ payload: (state.services_data || []).map(function (srv) {
511
+ var _state$active_retaile4;
512
+
513
+ return srv.service === "images" && srv.id_retailer === ((_state$active_retaile4 = state.active_retailer) === null || _state$active_retaile4 === void 0 ? void 0 : _state$active_retaile4.id_retailer) ? (0, _objectSpread2.default)((0, _objectSpread2.default)({}, srv), {}, {
514
+ status: newStatus
515
+ }) : srv;
516
+ })
517
+ });
518
+ } // Mostrar modal de éxito
519
+
426
520
 
427
521
  dispatch({
428
522
  type: "SET_MODAL",
@@ -435,12 +529,12 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
435
529
  });
436
530
  }
437
531
 
438
- _context3.next = 28;
532
+ _context3.next = 33;
439
533
  break;
440
534
 
441
- case 23:
442
- _context3.prev = 23;
443
- _context3.t0 = _context3["catch"](11);
535
+ case 28:
536
+ _context3.prev = 28;
537
+ _context3.t0 = _context3["catch"](16);
444
538
  console.log(_context3.t0);
445
539
  dispatch({
446
540
  type: "SET_ERRORS",
@@ -456,19 +550,19 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
456
550
  }
457
551
  });
458
552
 
459
- case 28:
460
- _context3.prev = 28;
553
+ case 33:
554
+ _context3.prev = 33;
461
555
  dispatch({
462
556
  type: "SET_SAVING",
463
557
  payload: false
464
558
  });
465
- return _context3.finish(28);
559
+ return _context3.finish(33);
466
560
 
467
- case 31:
468
- _context3.next = 34;
561
+ case 36:
562
+ _context3.next = 39;
469
563
  break;
470
564
 
471
- case 33:
565
+ case 38:
472
566
  dispatch({
473
567
  type: "SET_MODAL",
474
568
  payload: {
@@ -479,12 +573,12 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
479
573
  }
480
574
  });
481
575
 
482
- case 34:
576
+ case 39:
483
577
  case "end":
484
578
  return _context3.stop();
485
579
  }
486
580
  }
487
- }, _callee3, null, [[11, 23, 28, 31]]);
581
+ }, _callee3, null, [[16, 28, 33, 36]]);
488
582
  }));
489
583
 
490
584
  return function updateImages(_x3) {
@@ -494,9 +588,9 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
494
588
 
495
589
  var saveImageAttrs = /*#__PURE__*/function () {
496
590
  var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(token) {
497
- var _state$images_values$, _state$images_values2, _state$images_values3, _state$product10, _state$product11, _state$product12;
591
+ var _state$images_values$, _state$images_values2, _state$images_values3, _state$product13, _state$product14, _state$product15;
498
592
 
499
- var activeImage, attrForImgs, data, _state$product13, _state$product14, res;
593
+ var activeImage, attrForImgs, data, _state$product16, _state$product17, res, attrBody, newStatus, _state$product18, productFromLocalStorage, updatedProduct;
500
594
 
501
595
  return _regenerator.default.wrap(function _callee4$(_context4) {
502
596
  while (1) {
@@ -517,21 +611,21 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
517
611
  activeImage = state.images_values.values[state.current_image];
518
612
  attrForImgs = (_state$images_values$ = (_state$images_values2 = state.images_values) === null || _state$images_values2 === void 0 ? void 0 : (_state$images_values3 = _state$images_values2.attrForImgs) === null || _state$images_values3 === void 0 ? void 0 : _state$images_values3.general) !== null && _state$images_values$ !== void 0 ? _state$images_values$ : [];
519
613
  data = {
520
- articleId: (_state$product10 = state.product) === null || _state$product10 === void 0 ? void 0 : _state$product10.id_article,
614
+ articleId: (_state$product13 = state.product) === null || _state$product13 === void 0 ? void 0 : _state$product13.id_article,
521
615
  attrReqImgs: attrForImgs.map(function (e) {
522
- var _e$value;
616
+ var _e$value2;
523
617
 
524
618
  return {
525
619
  attrId: e.id,
526
- value: (_e$value = e.value) !== null && _e$value !== void 0 ? _e$value : "-"
620
+ value: (_e$value2 = e.value) !== null && _e$value2 !== void 0 ? _e$value2 : "-"
527
621
  };
528
622
  }),
529
623
  articleData: [],
530
624
  updateImages: activeImage ? [activeImage] : []
531
625
  };
532
626
 
533
- if ((_state$product11 = state.product) !== null && _state$product11 !== void 0 && _state$product11.orderId || (_state$product12 = state.product) !== null && _state$product12 !== void 0 && _state$product12.id_order) {
534
- data.orderId = ((_state$product13 = state.product) === null || _state$product13 === void 0 ? void 0 : _state$product13.orderId) || ((_state$product14 = state.product) === null || _state$product14 === void 0 ? void 0 : _state$product14.id_order);
627
+ if ((_state$product14 = state.product) !== null && _state$product14 !== void 0 && _state$product14.orderId || (_state$product15 = state.product) !== null && _state$product15 !== void 0 && _state$product15.id_order) {
628
+ data.orderId = ((_state$product16 = state.product) === null || _state$product16 === void 0 ? void 0 : _state$product16.orderId) || ((_state$product17 = state.product) === null || _state$product17 === void 0 ? void 0 : _state$product17.id_order);
535
629
  }
536
630
 
537
631
  _context4.prev = 7;
@@ -554,6 +648,32 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
554
648
  type: "SET_UPDATED_ATTR_FOR_IMGS",
555
649
  payload: []
556
650
  });
651
+ attrBody = JSON.parse(res.data.body);
652
+ newStatus = attrBody === null || attrBody === void 0 ? void 0 : attrBody.newStatus;
653
+
654
+ if (newStatus) {
655
+ productFromLocalStorage = JSON.parse(sessionStorage.getItem("productSelected"));
656
+ updatedProduct = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, productFromLocalStorage || state.product), {}, {
657
+ images_status: newStatus,
658
+ statusByRetailer: ((productFromLocalStorage === null || productFromLocalStorage === void 0 ? void 0 : productFromLocalStorage.statusByRetailer) || ((_state$product18 = state.product) === null || _state$product18 === void 0 ? void 0 : _state$product18.statusByRetailer) || []).map(function (retailerStatus) {
659
+ return retailerStatus.service === "images" ? (0, _objectSpread2.default)((0, _objectSpread2.default)({}, retailerStatus), {}, {
660
+ status: newStatus
661
+ }) : retailerStatus;
662
+ })
663
+ });
664
+ sessionStorage.setItem("productSelected", JSON.stringify(updatedProduct));
665
+ dispatch({
666
+ type: "SET_SERVICES_DATA",
667
+ payload: (state.services_data || []).map(function (srv) {
668
+ var _state$active_retaile5;
669
+
670
+ return srv.service === "images" && srv.id_retailer === ((_state$active_retaile5 = state.active_retailer) === null || _state$active_retaile5 === void 0 ? void 0 : _state$active_retaile5.id_retailer) ? (0, _objectSpread2.default)((0, _objectSpread2.default)({}, srv), {}, {
671
+ status: newStatus
672
+ }) : srv;
673
+ })
674
+ });
675
+ }
676
+
557
677
  dispatch({
558
678
  type: "SET_MODAL",
559
679
  payload: {
@@ -608,9 +728,9 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
608
728
  }();
609
729
 
610
730
  var handleOnDownloadImages = function handleOnDownloadImages() {
611
- var _state$product15, _state$product16, _state$product16$arti, _state$images_values4, _state$images_values5;
731
+ var _state$product19, _state$product20, _state$product20$arti, _state$images_values4, _state$images_values5;
612
732
 
613
- var upc = ((_state$product15 = state.product) === null || _state$product15 === void 0 ? void 0 : _state$product15.upc) || ((_state$product16 = state.product) === null || _state$product16 === void 0 ? void 0 : (_state$product16$arti = _state$product16.article) === null || _state$product16$arti === void 0 ? void 0 : _state$product16$arti.upc);
733
+ var upc = ((_state$product19 = state.product) === null || _state$product19 === void 0 ? void 0 : _state$product19.upc) || ((_state$product20 = state.product) === null || _state$product20 === void 0 ? void 0 : (_state$product20$arti = _state$product20.article) === null || _state$product20$arti === void 0 ? void 0 : _state$product20$arti.upc);
614
734
  state.selected_images.length > 0 ? state.selected_images.forEach(function (e) {
615
735
  if (e.id) {
616
736
  saveAs("https://".concat(process.env.REACT_APP_IMAGES_BUCKET, ".s3.amazonaws.com/").concat(e.srcDB), "".concat(upc, "_").concat(e.name, ".").concat(e.ext));
@@ -624,7 +744,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
624
744
 
625
745
  var deleteImages = /*#__PURE__*/function () {
626
746
  var _ref8 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(token) {
627
- var imgsInBack, _state$product17, data;
747
+ var imgsInBack, _state$product21, data;
628
748
 
629
749
  return _regenerator.default.wrap(function _callee5$(_context5) {
630
750
  while (1) {
@@ -645,7 +765,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
645
765
  }
646
766
 
647
767
  data = {
648
- articleId: (_state$product17 = state.product) === null || _state$product17 === void 0 ? void 0 : _state$product17.id_article,
768
+ articleId: (_state$product21 = state.product) === null || _state$product21 === void 0 ? void 0 : _state$product21.id_article,
649
769
  deleteImages: imgsInBack
650
770
  };
651
771
  _context5.prev = 4;
@@ -725,7 +845,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
725
845
 
726
846
  var createComment = /*#__PURE__*/function () {
727
847
  var _ref9 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(body, token) {
728
- var _state$product18, _state$product19, _state$product20;
848
+ var _state$product22, _state$product23, _state$product24;
729
849
 
730
850
  var concept, data;
731
851
  return _regenerator.default.wrap(function _callee6$(_context6) {
@@ -734,8 +854,8 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
734
854
  case 0:
735
855
  concept = (0, _utils.getConceptByTab)(state.active_tab);
736
856
  data = {
737
- articleId: (_state$product18 = state.product) === null || _state$product18 === void 0 ? void 0 : _state$product18.id_article,
738
- orderId: ((_state$product19 = state.product) === null || _state$product19 === void 0 ? void 0 : _state$product19.orderId) || ((_state$product20 = state.product) === null || _state$product20 === void 0 ? void 0 : _state$product20.id_order),
857
+ articleId: (_state$product22 = state.product) === null || _state$product22 === void 0 ? void 0 : _state$product22.id_article,
858
+ orderId: ((_state$product23 = state.product) === null || _state$product23 === void 0 ? void 0 : _state$product23.orderId) || ((_state$product24 = state.product) === null || _state$product24 === void 0 ? void 0 : _state$product24.id_order),
739
859
  message: body,
740
860
  concept: concept,
741
861
  version: state.product.version
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentoh-components-library",
3
- "version": "21.5.71",
3
+ "version": "21.5.73",
4
4
  "dependencies": {
5
5
  "@aws-amplify/auth": "^4.5.3",
6
6
  "@aws-amplify/datastore": "^3.11.0",
@@ -95,6 +95,44 @@ export const ProviderProductEditionProvider = ({ children }) => {
95
95
  }
96
96
  });
97
97
 
98
+ const body = JSON.parse(res.data.body);
99
+ const newStatus = body?.newStatus;
100
+
101
+ if (newStatus) {
102
+ const productFromLocalStorage = JSON.parse(
103
+ sessionStorage.getItem("productSelected"),
104
+ );
105
+
106
+ const updatedProduct = {
107
+ ...(productFromLocalStorage || state.product),
108
+ description_status: newStatus,
109
+ statusByRetailer: (
110
+ productFromLocalStorage?.statusByRetailer ||
111
+ state.product?.statusByRetailer ||
112
+ []
113
+ ).map((retailerStatus) =>
114
+ retailerStatus.service === "description"
115
+ ? { ...retailerStatus, status: newStatus }
116
+ : retailerStatus,
117
+ ),
118
+ };
119
+
120
+ sessionStorage.setItem(
121
+ "productSelected",
122
+ JSON.stringify(updatedProduct),
123
+ );
124
+
125
+ dispatch({
126
+ type: "SET_SERVICES_DATA",
127
+ payload: (state.services_data || []).map((srv) =>
128
+ srv.service === "description" &&
129
+ srv.id_retailer === state.active_retailer?.id_retailer
130
+ ? { ...srv, status: newStatus }
131
+ : srv,
132
+ ),
133
+ });
134
+ }
135
+
98
136
  dispatch({
99
137
  type: "SET_MISSING_REQUIRED_FIELDS",
100
138
  payload: {
@@ -195,6 +233,44 @@ export const ProviderProductEditionProvider = ({ children }) => {
195
233
  }
196
234
  });
197
235
 
236
+ const body = JSON.parse(res.data.body);
237
+ const newStatus = body?.newStatus;
238
+
239
+ if (newStatus) {
240
+ const productFromLocalStorage = JSON.parse(
241
+ sessionStorage.getItem("productSelected"),
242
+ );
243
+
244
+ const updatedProduct = {
245
+ ...(productFromLocalStorage || state.product),
246
+ datasheet_status: newStatus,
247
+ statusByRetailer: (
248
+ productFromLocalStorage?.statusByRetailer ||
249
+ state.product?.statusByRetailer ||
250
+ []
251
+ ).map((retailerStatus) =>
252
+ retailerStatus.service === "datasheet"
253
+ ? { ...retailerStatus, status: newStatus }
254
+ : retailerStatus,
255
+ ),
256
+ };
257
+
258
+ sessionStorage.setItem(
259
+ "productSelected",
260
+ JSON.stringify(updatedProduct),
261
+ );
262
+
263
+ dispatch({
264
+ type: "SET_SERVICES_DATA",
265
+ payload: (state.services_data || []).map((srv) =>
266
+ srv.service === "datasheet" &&
267
+ srv.id_retailer === state.active_retailer?.id_retailer
268
+ ? { ...srv, status: newStatus }
269
+ : srv,
270
+ ),
271
+ });
272
+ }
273
+
198
274
  dispatch({
199
275
  type: "SET_MISSING_REQUIRED_FIELDS",
200
276
  payload: {
@@ -231,14 +307,27 @@ export const ProviderProductEditionProvider = ({ children }) => {
231
307
  if (state.updated_images_values.length === 0) return;
232
308
  const updatedImages = state.updated_images_values;
233
309
 
310
+ const attrForImgs = state.images_values?.attrForImgs || {};
311
+ const generalAttrs = attrForImgs.general || [];
312
+ const retailerKey = Object.keys(attrForImgs).find(
313
+ (key) => key !== "general",
314
+ );
315
+ const retailerAttrs = retailerKey ? attrForImgs[retailerKey] : [];
316
+
317
+ const mergedAttrs = retailerAttrs.map((retailerAttr) => {
318
+ const generalAttr = generalAttrs.find((g) => g.id === retailerAttr.id);
319
+ if (generalAttr && generalAttr.value !== retailerAttr.value) {
320
+ return { ...retailerAttr, value: generalAttr.value };
321
+ }
322
+ return retailerAttr;
323
+ });
324
+
234
325
  const data = {
235
326
  articleId: state.product?.id_article,
236
- attrReqImgs: Object.values(state.images_values?.attrForImgs)
237
- .slice(0, -1)
238
- .map((e) => ({
239
- attrId: e[0]?.id,
240
- value: e[0]?.value ?? "",
241
- })),
327
+ attrReqImgs: mergedAttrs.map((e) => ({
328
+ attrId: e.id,
329
+ value: e.value ?? "",
330
+ })),
242
331
  articleData: state.images_values.values.filter((e) => !e.id),
243
332
  updateImages: state.images_values.values.filter((e) => e.id),
244
333
  };
@@ -306,10 +395,44 @@ export const ProviderProductEditionProvider = ({ children }) => {
306
395
  type: "SET_UPDATED_IMAGES_VALUES",
307
396
  payload: [],
308
397
  });
309
- dispatch({
310
- type: "SET_UPDATED_ATTR_FOR_IMGS",
311
- payload: [],
312
- });
398
+
399
+ const imageBody = JSON.parse(res.data.body);
400
+ const newStatus = imageBody?.newStatus;
401
+
402
+ if (newStatus) {
403
+ const productFromLocalStorage = JSON.parse(
404
+ sessionStorage.getItem("productSelected"),
405
+ );
406
+
407
+ const updatedProduct = {
408
+ ...(productFromLocalStorage || state.product),
409
+ images_status: newStatus,
410
+ statusByRetailer: (
411
+ productFromLocalStorage?.statusByRetailer ||
412
+ state.product?.statusByRetailer ||
413
+ []
414
+ ).map((retailerStatus) =>
415
+ retailerStatus.service === "images"
416
+ ? { ...retailerStatus, status: newStatus }
417
+ : retailerStatus,
418
+ ),
419
+ };
420
+
421
+ sessionStorage.setItem(
422
+ "productSelected",
423
+ JSON.stringify(updatedProduct),
424
+ );
425
+
426
+ dispatch({
427
+ type: "SET_SERVICES_DATA",
428
+ payload: (state.services_data || []).map((srv) =>
429
+ srv.service === "images" &&
430
+ srv.id_retailer === state.active_retailer?.id_retailer
431
+ ? { ...srv, status: newStatus }
432
+ : srv,
433
+ ),
434
+ });
435
+ }
313
436
 
314
437
  // Mostrar modal de éxito
315
438
  dispatch({
@@ -398,6 +521,44 @@ export const ProviderProductEditionProvider = ({ children }) => {
398
521
  payload: [],
399
522
  });
400
523
 
524
+ const attrBody = JSON.parse(res.data.body);
525
+ const newStatus = attrBody?.newStatus;
526
+
527
+ if (newStatus) {
528
+ const productFromLocalStorage = JSON.parse(
529
+ sessionStorage.getItem("productSelected"),
530
+ );
531
+
532
+ const updatedProduct = {
533
+ ...(productFromLocalStorage || state.product),
534
+ images_status: newStatus,
535
+ statusByRetailer: (
536
+ productFromLocalStorage?.statusByRetailer ||
537
+ state.product?.statusByRetailer ||
538
+ []
539
+ ).map((retailerStatus) =>
540
+ retailerStatus.service === "images"
541
+ ? { ...retailerStatus, status: newStatus }
542
+ : retailerStatus,
543
+ ),
544
+ };
545
+
546
+ sessionStorage.setItem(
547
+ "productSelected",
548
+ JSON.stringify(updatedProduct),
549
+ );
550
+
551
+ dispatch({
552
+ type: "SET_SERVICES_DATA",
553
+ payload: (state.services_data || []).map((srv) =>
554
+ srv.service === "images" &&
555
+ srv.id_retailer === state.active_retailer?.id_retailer
556
+ ? { ...srv, status: newStatus }
557
+ : srv,
558
+ ),
559
+ });
560
+ }
561
+
401
562
  dispatch({
402
563
  type: "SET_MODAL",
403
564
  payload: {