contentoh-components-library 21.5.70 → 21.5.72

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.
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.Default = void 0;
7
+
8
+ var _ = require(".");
9
+
10
+ var _default = {
11
+ component: _.RetailerSelector,
12
+ parameters: {
13
+ layout: "centered"
14
+ }
15
+ };
16
+ exports.default = _default;
17
+ var Default = {};
18
+ exports.Default = Default;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RetailerSelector = void 0;
7
+
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+
10
+ var RetailerSelector = function RetailerSelector() {
11
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
12
+ children: "RetailerSelector Component"
13
+ });
14
+ };
15
+
16
+ exports.RetailerSelector = RetailerSelector;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.useProviderProductEdition = exports.ProviderProductEditionProvider = void 0;
9
9
 
10
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectWithoutProperties"));
11
+
10
12
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
13
 
12
14
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
@@ -35,6 +37,8 @@ var _utils = require("../utils");
35
37
 
36
38
  var _jsxRuntime = require("react/jsx-runtime");
37
39
 
40
+ var _excluded = ["src"],
41
+ _excluded2 = ["src"];
38
42
  var S3_BUCKET = process.env.REACT_APP_IMAGES_BUCKET;
39
43
  var REGION = "us-east-1";
40
44
 
@@ -306,9 +310,9 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
306
310
 
307
311
  var updateImages = /*#__PURE__*/function () {
308
312
  var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(token) {
309
- var _state$product7, _state$images_values, _state$product8, _state$product9, _data$articleData, _data$updateImages;
313
+ var _state$images_values, _state$product7, _state$product8, _state$product9, _data$articleData, _data$updateImages;
310
314
 
311
- var updatedImages, data, valid, promiseArray, res;
315
+ var updatedImages, attrForImgs, generalAttrs, retailerKey, retailerAttrs, mergedAttrs, data, valid, promiseArray, res;
312
316
  return _regenerator.default.wrap(function _callee3$(_context3) {
313
317
  while (1) {
314
318
  switch (_context3.prev = _context3.next) {
@@ -322,14 +326,33 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
322
326
 
323
327
  case 2:
324
328
  updatedImages = state.updated_images_values;
329
+ attrForImgs = ((_state$images_values = state.images_values) === null || _state$images_values === void 0 ? void 0 : _state$images_values.attrForImgs) || {};
330
+ generalAttrs = attrForImgs.general || [];
331
+ retailerKey = Object.keys(attrForImgs).find(function (key) {
332
+ return key !== "general";
333
+ });
334
+ retailerAttrs = retailerKey ? attrForImgs[retailerKey] : [];
335
+ mergedAttrs = retailerAttrs.map(function (retailerAttr) {
336
+ var generalAttr = generalAttrs.find(function (g) {
337
+ return g.id === retailerAttr.id;
338
+ });
339
+
340
+ if (generalAttr && generalAttr.value !== retailerAttr.value) {
341
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, retailerAttr), {}, {
342
+ value: generalAttr.value
343
+ });
344
+ }
345
+
346
+ return retailerAttr;
347
+ });
325
348
  data = {
326
349
  articleId: (_state$product7 = state.product) === null || _state$product7 === void 0 ? void 0 : _state$product7.id_article,
327
- 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) {
328
- var _e$, _e$0$value, _e$2;
350
+ attrReqImgs: mergedAttrs.map(function (e) {
351
+ var _e$value;
329
352
 
330
353
  return {
331
- attrId: (_e$ = e[0]) === null || _e$ === void 0 ? void 0 : _e$.id,
332
- 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 : ""
354
+ attrId: e.id,
355
+ value: (_e$value = e.value) !== null && _e$value !== void 0 ? _e$value : ""
333
356
  };
334
357
  }),
335
358
  articleData: state.images_values.values.filter(function (e) {
@@ -350,7 +373,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
350
373
  });
351
374
 
352
375
  if (!valid) {
353
- _context3.next = 31;
376
+ _context3.next = 38;
354
377
  break;
355
378
  }
356
379
 
@@ -369,7 +392,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
369
392
  isApproved: true
370
393
  });
371
394
  });
372
- _context3.prev = 11;
395
+ _context3.prev = 16;
373
396
  promiseArray = data.articleData.map(function (e) {
374
397
  var file = Buffer.from(e.src.replace(/^data:image\/\w+;base64,/, ""), "base64");
375
398
  var params = {
@@ -380,11 +403,22 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
380
403
  };
381
404
  return myBucket.putObject(params).promise();
382
405
  });
383
- _context3.next = 15;
406
+ _context3.next = 20;
384
407
  return Promise.all(promiseArray);
385
408
 
386
- case 15:
387
- _context3.next = 17;
409
+ case 20:
410
+ // Eliminar el buffer base64 antes de enviar al endpoint para evitar error 413
411
+ data.articleData = data.articleData.map(function (_ref5) {
412
+ var src = _ref5.src,
413
+ rest = (0, _objectWithoutProperties2.default)(_ref5, _excluded);
414
+ return rest;
415
+ });
416
+ data.updateImages = data.updateImages.map(function (_ref6) {
417
+ var src = _ref6.src,
418
+ rest = (0, _objectWithoutProperties2.default)(_ref6, _excluded2);
419
+ return rest;
420
+ });
421
+ _context3.next = 24;
388
422
  return _axios.default.put(process.env.REACT_APP_ARTICLE_DATA_ENDPOINT, data, {
389
423
  params: {
390
424
  image: true,
@@ -395,7 +429,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
395
429
  }
396
430
  });
397
431
 
398
- case 17:
432
+ case 24:
399
433
  res = _context3.sent;
400
434
 
401
435
  if (res.data.statusCode === 200) {
@@ -416,12 +450,12 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
416
450
  });
417
451
  }
418
452
 
419
- _context3.next = 26;
453
+ _context3.next = 33;
420
454
  break;
421
455
 
422
- case 21:
423
- _context3.prev = 21;
424
- _context3.t0 = _context3["catch"](11);
456
+ case 28:
457
+ _context3.prev = 28;
458
+ _context3.t0 = _context3["catch"](16);
425
459
  console.log(_context3.t0);
426
460
  dispatch({
427
461
  type: "SET_ERRORS",
@@ -437,19 +471,19 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
437
471
  }
438
472
  });
439
473
 
440
- case 26:
441
- _context3.prev = 26;
474
+ case 33:
475
+ _context3.prev = 33;
442
476
  dispatch({
443
477
  type: "SET_SAVING",
444
478
  payload: false
445
479
  });
446
- return _context3.finish(26);
480
+ return _context3.finish(33);
447
481
 
448
- case 29:
449
- _context3.next = 32;
482
+ case 36:
483
+ _context3.next = 39;
450
484
  break;
451
485
 
452
- case 31:
486
+ case 38:
453
487
  dispatch({
454
488
  type: "SET_MODAL",
455
489
  payload: {
@@ -460,12 +494,12 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
460
494
  }
461
495
  });
462
496
 
463
- case 32:
497
+ case 39:
464
498
  case "end":
465
499
  return _context3.stop();
466
500
  }
467
501
  }
468
- }, _callee3, null, [[11, 21, 26, 29]]);
502
+ }, _callee3, null, [[16, 28, 33, 36]]);
469
503
  }));
470
504
 
471
505
  return function updateImages(_x3) {
@@ -473,15 +507,130 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
473
507
  };
474
508
  }();
475
509
 
510
+ var saveImageAttrs = /*#__PURE__*/function () {
511
+ var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(token) {
512
+ var _state$images_values$, _state$images_values2, _state$images_values3, _state$product10, _state$product11, _state$product12;
513
+
514
+ var activeImage, attrForImgs, data, _state$product13, _state$product14, res;
515
+
516
+ return _regenerator.default.wrap(function _callee4$(_context4) {
517
+ while (1) {
518
+ switch (_context4.prev = _context4.next) {
519
+ case 0:
520
+ if (!(state.updated_attr_for_imgs.length === 0)) {
521
+ _context4.next = 2;
522
+ break;
523
+ }
524
+
525
+ return _context4.abrupt("return");
526
+
527
+ case 2:
528
+ dispatch({
529
+ type: "SET_SAVING",
530
+ payload: true
531
+ });
532
+ activeImage = state.images_values.values[state.current_image];
533
+ 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$ : [];
534
+ data = {
535
+ articleId: (_state$product10 = state.product) === null || _state$product10 === void 0 ? void 0 : _state$product10.id_article,
536
+ attrReqImgs: attrForImgs.map(function (e) {
537
+ var _e$value2;
538
+
539
+ return {
540
+ attrId: e.id,
541
+ value: (_e$value2 = e.value) !== null && _e$value2 !== void 0 ? _e$value2 : "-"
542
+ };
543
+ }),
544
+ articleData: [],
545
+ updateImages: activeImage ? [activeImage] : []
546
+ };
547
+
548
+ 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) {
549
+ 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);
550
+ }
551
+
552
+ _context4.prev = 7;
553
+ _context4.next = 10;
554
+ return _axios.default.put(process.env.REACT_APP_ARTICLE_DATA_ENDPOINT, data, {
555
+ params: {
556
+ image: true,
557
+ version: state.product.version
558
+ },
559
+ headers: {
560
+ Authorization: token
561
+ }
562
+ });
563
+
564
+ case 10:
565
+ res = _context4.sent;
566
+
567
+ if (res.data.statusCode === 200) {
568
+ dispatch({
569
+ type: "SET_UPDATED_ATTR_FOR_IMGS",
570
+ payload: []
571
+ });
572
+ dispatch({
573
+ type: "SET_MODAL",
574
+ payload: {
575
+ show: true,
576
+ title: "",
577
+ message: "Atributos de imagen guardados con éxito",
578
+ image: _genericModalCheck.default
579
+ }
580
+ });
581
+ }
582
+
583
+ _context4.next = 19;
584
+ break;
585
+
586
+ case 14:
587
+ _context4.prev = 14;
588
+ _context4.t0 = _context4["catch"](7);
589
+ console.log(_context4.t0);
590
+ dispatch({
591
+ type: "SET_ERRORS",
592
+ payload: [].concat((0, _toConsumableArray2.default)(state.errors), [_context4.t0])
593
+ });
594
+ dispatch({
595
+ type: "SET_MODAL",
596
+ payload: {
597
+ show: true,
598
+ title: "Error",
599
+ message: "Hubo un error al guardar los atributos de imagen",
600
+ image: _errorModal.default
601
+ }
602
+ });
603
+
604
+ case 19:
605
+ _context4.prev = 19;
606
+ dispatch({
607
+ type: "SET_SAVING",
608
+ payload: false
609
+ });
610
+ return _context4.finish(19);
611
+
612
+ case 22:
613
+ case "end":
614
+ return _context4.stop();
615
+ }
616
+ }
617
+ }, _callee4, null, [[7, 14, 19, 22]]);
618
+ }));
619
+
620
+ return function saveImageAttrs(_x4) {
621
+ return _ref7.apply(this, arguments);
622
+ };
623
+ }();
624
+
476
625
  var handleOnDownloadImages = function handleOnDownloadImages() {
477
- var _state$product10, _state$product11, _state$product11$arti, _state$images_values2, _state$images_values3;
626
+ var _state$product15, _state$product16, _state$product16$arti, _state$images_values4, _state$images_values5;
478
627
 
479
- var upc = ((_state$product10 = state.product) === null || _state$product10 === void 0 ? void 0 : _state$product10.upc) || ((_state$product11 = state.product) === null || _state$product11 === void 0 ? void 0 : (_state$product11$arti = _state$product11.article) === null || _state$product11$arti === void 0 ? void 0 : _state$product11$arti.upc);
628
+ 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);
480
629
  state.selected_images.length > 0 ? state.selected_images.forEach(function (e) {
481
630
  if (e.id) {
482
631
  saveAs("https://".concat(process.env.REACT_APP_IMAGES_BUCKET, ".s3.amazonaws.com/").concat(e.srcDB), "".concat(upc, "_").concat(e.name, ".").concat(e.ext));
483
632
  }
484
- }) : (_state$images_values2 = state.images_values) === null || _state$images_values2 === void 0 ? void 0 : (_state$images_values3 = _state$images_values2.values) === null || _state$images_values3 === void 0 ? void 0 : _state$images_values3.forEach(function (e) {
633
+ }) : (_state$images_values4 = state.images_values) === null || _state$images_values4 === void 0 ? void 0 : (_state$images_values5 = _state$images_values4.values) === null || _state$images_values5 === void 0 ? void 0 : _state$images_values5.forEach(function (e) {
485
634
  if (e.id) {
486
635
  saveAs("https://".concat(process.env.REACT_APP_IMAGES_BUCKET, ".s3.amazonaws.com/").concat(e.srcDB), "".concat(upc, "_").concat(e.name, ".").concat(e.ext));
487
636
  }
@@ -489,12 +638,12 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
489
638
  };
490
639
 
491
640
  var deleteImages = /*#__PURE__*/function () {
492
- var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(token) {
493
- var imgsInBack, _state$product12, data;
641
+ var _ref8 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(token) {
642
+ var imgsInBack, _state$product17, data;
494
643
 
495
- return _regenerator.default.wrap(function _callee4$(_context4) {
644
+ return _regenerator.default.wrap(function _callee5$(_context5) {
496
645
  while (1) {
497
- switch (_context4.prev = _context4.next) {
646
+ switch (_context5.prev = _context5.next) {
498
647
  case 0:
499
648
  dispatch({
500
649
  type: "SET_SAVING",
@@ -506,16 +655,16 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
506
655
  }); // Hacer el request al backend si hay imágenes que eliminar
507
656
 
508
657
  if (!(imgsInBack.length > 0)) {
509
- _context4.next = 18;
658
+ _context5.next = 18;
510
659
  break;
511
660
  }
512
661
 
513
662
  data = {
514
- articleId: (_state$product12 = state.product) === null || _state$product12 === void 0 ? void 0 : _state$product12.id_article,
663
+ articleId: (_state$product17 = state.product) === null || _state$product17 === void 0 ? void 0 : _state$product17.id_article,
515
664
  deleteImages: imgsInBack
516
665
  };
517
- _context4.prev = 4;
518
- _context4.next = 7;
666
+ _context5.prev = 4;
667
+ _context5.next = 7;
519
668
  return _axios.default.put(process.env.REACT_APP_ARTICLE_DATA_ENDPOINT, data, {
520
669
  params: {
521
670
  image: true,
@@ -537,13 +686,13 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
537
686
  image: _genericModalCheck.default
538
687
  }
539
688
  });
540
- _context4.next = 15;
689
+ _context5.next = 15;
541
690
  break;
542
691
 
543
692
  case 10:
544
- _context4.prev = 10;
545
- _context4.t0 = _context4["catch"](4);
546
- console.log(_context4.t0);
693
+ _context5.prev = 10;
694
+ _context5.t0 = _context5["catch"](4);
695
+ console.log(_context5.t0);
547
696
  dispatch({
548
697
  type: "SET_MODAL",
549
698
  payload: {
@@ -553,15 +702,15 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
553
702
  image: _errorModal.default
554
703
  }
555
704
  });
556
- return _context4.abrupt("return");
705
+ return _context5.abrupt("return");
557
706
 
558
707
  case 15:
559
- _context4.prev = 15;
708
+ _context5.prev = 15;
560
709
  dispatch({
561
710
  type: "SET_SAVING",
562
711
  payload: false
563
712
  });
564
- return _context4.finish(15);
713
+ return _context5.finish(15);
565
714
 
566
715
  case 18:
567
716
  // Actualizar el estado eliminando las imágenes seleccionadas
@@ -578,36 +727,36 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
578
727
 
579
728
  case 20:
580
729
  case "end":
581
- return _context4.stop();
730
+ return _context5.stop();
582
731
  }
583
732
  }
584
- }, _callee4, null, [[4, 10, 15, 18]]);
733
+ }, _callee5, null, [[4, 10, 15, 18]]);
585
734
  }));
586
735
 
587
- return function deleteImages(_x4) {
588
- return _ref5.apply(this, arguments);
736
+ return function deleteImages(_x5) {
737
+ return _ref8.apply(this, arguments);
589
738
  };
590
739
  }();
591
740
 
592
741
  var createComment = /*#__PURE__*/function () {
593
- var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(body, token) {
594
- var _state$product13, _state$product14, _state$product15;
742
+ var _ref9 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(body, token) {
743
+ var _state$product18, _state$product19, _state$product20;
595
744
 
596
745
  var concept, data;
597
- return _regenerator.default.wrap(function _callee5$(_context5) {
746
+ return _regenerator.default.wrap(function _callee6$(_context6) {
598
747
  while (1) {
599
- switch (_context5.prev = _context5.next) {
748
+ switch (_context6.prev = _context6.next) {
600
749
  case 0:
601
750
  concept = (0, _utils.getConceptByTab)(state.active_tab);
602
751
  data = {
603
- articleId: (_state$product13 = state.product) === null || _state$product13 === void 0 ? void 0 : _state$product13.id_article,
604
- orderId: ((_state$product14 = state.product) === null || _state$product14 === void 0 ? void 0 : _state$product14.orderId) || ((_state$product15 = state.product) === null || _state$product15 === void 0 ? void 0 : _state$product15.id_order),
752
+ articleId: (_state$product18 = state.product) === null || _state$product18 === void 0 ? void 0 : _state$product18.id_article,
753
+ 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),
605
754
  message: body,
606
755
  concept: concept,
607
756
  version: state.product.version
608
757
  };
609
- _context5.prev = 2;
610
- _context5.next = 5;
758
+ _context6.prev = 2;
759
+ _context6.next = 5;
611
760
  return _axios.default.post("".concat(process.env.REACT_APP_COMMENTS_ENDPOINT), data, {
612
761
  headers: {
613
762
  Authorization: token
@@ -615,24 +764,24 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
615
764
  });
616
765
 
617
766
  case 5:
618
- _context5.next = 10;
767
+ _context6.next = 10;
619
768
  break;
620
769
 
621
770
  case 7:
622
- _context5.prev = 7;
623
- _context5.t0 = _context5["catch"](2);
624
- console.log("Error creating comment:", _context5.t0);
771
+ _context6.prev = 7;
772
+ _context6.t0 = _context6["catch"](2);
773
+ console.log("Error creating comment:", _context6.t0);
625
774
 
626
775
  case 10:
627
776
  case "end":
628
- return _context5.stop();
777
+ return _context6.stop();
629
778
  }
630
779
  }
631
- }, _callee5, null, [[2, 7]]);
780
+ }, _callee6, null, [[2, 7]]);
632
781
  }));
633
782
 
634
- return function createComment(_x5, _x6) {
635
- return _ref6.apply(this, arguments);
783
+ return function createComment(_x6, _x7) {
784
+ return _ref9.apply(this, arguments);
636
785
  };
637
786
  }();
638
787
 
@@ -642,6 +791,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
642
791
  saveDatasheets: saveDatasheets,
643
792
  saveDescriptions: saveDescriptions,
644
793
  updateImages: updateImages,
794
+ saveImageAttrs: saveImageAttrs,
645
795
  deleteImages: deleteImages,
646
796
  handleOnDownloadImages: handleOnDownloadImages,
647
797
  createComment: createComment
@@ -54,7 +54,8 @@ var ACTIVE_STATE_ACTIONS = {
54
54
  DELETE_IMAGES: "DELETE_IMAGES",
55
55
  TOGGLE_CHECK_ALL_IMAGES: "TOGGLE_CHECK_ALL_IMAGES",
56
56
  TOGGLE_CHECKBOX_IMAGE: "TOGGLE_CHECKBOX_IMAGE",
57
- SET_MISSING_REQUIRED_FIELDS: "SET_MISSING_REQUIRED_FIELDS"
57
+ SET_MISSING_REQUIRED_FIELDS: "SET_MISSING_REQUIRED_FIELDS",
58
+ CHANGE_ATTR_VALUE: "CHANGE_ATTR_VALUE"
58
59
  };
59
60
  exports.ACTIVE_STATE_ACTIONS = ACTIVE_STATE_ACTIONS;
60
61
 
@@ -268,6 +269,67 @@ var activeStateReducer = function activeStateReducer(state, action) {
268
269
  });
269
270
  }
270
271
 
272
+ case ACTIVE_STATE_ACTIONS.CHANGE_ATTR_VALUE:
273
+ {
274
+ var _state$images_values;
275
+
276
+ var _action$payload2 = action.payload,
277
+ id = _action$payload2.id,
278
+ _value = _action$payload2.value;
279
+ var attrForImgs = (_state$images_values = state.images_values) === null || _state$images_values === void 0 ? void 0 : _state$images_values.attrForImgs;
280
+ if (!(attrForImgs !== null && attrForImgs !== void 0 && attrForImgs.general)) return state;
281
+ var attrIndex = attrForImgs.general.findIndex(function (f) {
282
+ return f.id === id;
283
+ });
284
+ if (attrIndex === -1) return state;
285
+ var originalAttr = attrForImgs.general[attrIndex];
286
+ var updatedGeneral = attrForImgs.general.map(function (attr, i) {
287
+ return i === attrIndex ? (0, _objectSpread4.default)((0, _objectSpread4.default)({}, attr), {}, {
288
+ value: _value
289
+ }) : attr;
290
+ }); // Tracking de cambios en updated_attr_for_imgs
291
+
292
+ var existingIndex = state.updated_attr_for_imgs.findIndex(function (attr) {
293
+ return attr.attrId === id;
294
+ });
295
+ var newUpdatedAttrForImgs;
296
+
297
+ if (existingIndex === -1) {
298
+ // Agregar nuevo cambio con valor original
299
+ newUpdatedAttrForImgs = [].concat((0, _toConsumableArray2.default)(state.updated_attr_for_imgs), [{
300
+ attrId: id,
301
+ value: _value,
302
+ originalValue: originalAttr.value
303
+ }]);
304
+ } else {
305
+ // Actualizar valor existente
306
+ var updated = state.updated_attr_for_imgs.map(function (attr, i) {
307
+ return i === existingIndex ? (0, _objectSpread4.default)((0, _objectSpread4.default)({}, attr), {}, {
308
+ value: _value
309
+ }) : attr;
310
+ }); // Si el valor vuelve al original, eliminarlo del tracking
311
+
312
+ var _originalValue = updated[existingIndex].originalValue;
313
+
314
+ if (String(_value) === String(_originalValue)) {
315
+ newUpdatedAttrForImgs = updated.filter(function (_, i) {
316
+ return i !== existingIndex;
317
+ });
318
+ } else {
319
+ newUpdatedAttrForImgs = updated;
320
+ }
321
+ }
322
+
323
+ return (0, _objectSpread4.default)((0, _objectSpread4.default)({}, state), {}, {
324
+ images_values: (0, _objectSpread4.default)((0, _objectSpread4.default)({}, state.images_values), {}, {
325
+ attrForImgs: (0, _objectSpread4.default)((0, _objectSpread4.default)({}, attrForImgs), {}, {
326
+ general: updatedGeneral
327
+ })
328
+ }),
329
+ updated_attr_for_imgs: newUpdatedAttrForImgs
330
+ });
331
+ }
332
+
271
333
  default:
272
334
  {
273
335
  return null;
@@ -12,13 +12,15 @@ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/
12
12
  var inputsInitialState = {
13
13
  updated_datasheets_inputs: [],
14
14
  updated_descriptions_inputs: [],
15
- updated_images_values: []
15
+ updated_images_values: [],
16
+ updated_attr_for_imgs: []
16
17
  };
17
18
  exports.inputsInitialState = inputsInitialState;
18
19
  var INPUTS_ACTIONS = {
19
20
  SET_UPDATED_DATASHEETS_INPUTS: "SET_UPDATED_DATASHEETS_INPUTS",
20
21
  SET_UPDATED_DESCRIPTIONS_INPUTS: "SET_UPDATED_DESCRIPTIONS_INPUTS",
21
22
  SET_UPDATED_IMAGES_VALUES: "SET_UPDATED_IMAGES_VALUES",
23
+ SET_UPDATED_ATTR_FOR_IMGS: "SET_UPDATED_ATTR_FOR_IMGS",
22
24
  UPDATE_DESCRIPTIONS_INPUTS: "UPDATE_DESCRIPTIONS_INPUTS",
23
25
  UPDATE_DATASHEETS_INPUTS: "UPDATE_DATASHEETS_INPUTS"
24
26
  };
@@ -47,6 +49,13 @@ var inputsReducer = function inputsReducer(state, action) {
47
49
  });
48
50
  }
49
51
 
52
+ case INPUTS_ACTIONS.SET_UPDATED_ATTR_FOR_IMGS:
53
+ {
54
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, state), {}, {
55
+ updated_attr_for_imgs: action.payload
56
+ });
57
+ }
58
+
50
59
  case INPUTS_ACTIONS.UPDATE_DESCRIPTIONS_INPUTS:
51
60
  {
52
61
  var _state$descriptions_i;
@@ -11,6 +11,8 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
11
11
 
12
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
13
13
 
14
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/typeof"));
15
+
14
16
  var _objectSpread5 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
15
17
 
16
18
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
@@ -106,6 +108,7 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
106
108
  saveDatasheets = _useProviderProductEd.saveDatasheets,
107
109
  saveDescriptions = _useProviderProductEd.saveDescriptions,
108
110
  updateImages = _useProviderProductEd.updateImages,
111
+ saveImageAttrs = _useProviderProductEd.saveImageAttrs,
109
112
  deleteImages = _useProviderProductEd.deleteImages,
110
113
  handleOnDownloadImages = _useProviderProductEd.handleOnDownloadImages,
111
114
  createComment = _useProviderProductEd.createComment;
@@ -654,10 +657,17 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
654
657
  }, [state.active_retailer, state.product]);
655
658
 
656
659
  var handleOnChangeCurrentImage = function handleOnChangeCurrentImage(index) {
657
- dispatch({
658
- type: "SET_CURRENT_IMAGE",
659
- payload: index
660
- });
660
+ if (typeof index === "number") {
661
+ dispatch({
662
+ type: "SET_CURRENT_IMAGE",
663
+ payload: index
664
+ });
665
+ } else if ((0, _typeof2.default)(index) === "object") {
666
+ dispatch({
667
+ type: "CHANGE_ATTR_VALUE",
668
+ payload: index
669
+ });
670
+ }
661
671
  };
662
672
 
663
673
  var handleOnShowModalGallery = function handleOnShowModalGallery() {
@@ -767,7 +777,7 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
767
777
  var _state$product5, _state$product5$servi;
768
778
 
769
779
  if (((_state$product5 = state.product) === null || _state$product5 === void 0 ? void 0 : (_state$product5$servi = _state$product5.services) === null || _state$product5$servi === void 0 ? void 0 : _state$product5$servi.images) === 1) {
770
- updateImages();
780
+ saveImageAttrs(token);
771
781
  }
772
782
  };
773
783
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentoh-components-library",
3
- "version": "21.5.70",
3
+ "version": "21.5.72",
4
4
  "dependencies": {
5
5
  "@aws-amplify/auth": "^4.5.3",
6
6
  "@aws-amplify/datastore": "^3.11.0",
@@ -0,0 +1,10 @@
1
+ import { RetailerSelector } from ".";
2
+
3
+ export default {
4
+ component: RetailerSelector,
5
+ parameters: {
6
+ layout: "centered",
7
+ },
8
+ };
9
+
10
+ export const Default = {};
@@ -0,0 +1,3 @@
1
+ export const RetailerSelector = () => {
2
+ return <div>RetailerSelector Component</div>;
3
+ };
@@ -231,14 +231,27 @@ export const ProviderProductEditionProvider = ({ children }) => {
231
231
  if (state.updated_images_values.length === 0) return;
232
232
  const updatedImages = state.updated_images_values;
233
233
 
234
+ const attrForImgs = state.images_values?.attrForImgs || {};
235
+ const generalAttrs = attrForImgs.general || [];
236
+ const retailerKey = Object.keys(attrForImgs).find(
237
+ (key) => key !== "general",
238
+ );
239
+ const retailerAttrs = retailerKey ? attrForImgs[retailerKey] : [];
240
+
241
+ const mergedAttrs = retailerAttrs.map((retailerAttr) => {
242
+ const generalAttr = generalAttrs.find((g) => g.id === retailerAttr.id);
243
+ if (generalAttr && generalAttr.value !== retailerAttr.value) {
244
+ return { ...retailerAttr, value: generalAttr.value };
245
+ }
246
+ return retailerAttr;
247
+ });
248
+
234
249
  const data = {
235
250
  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
- })),
251
+ attrReqImgs: mergedAttrs.map((e) => ({
252
+ attrId: e.id,
253
+ value: e.value ?? "",
254
+ })),
242
255
  articleData: state.images_values.values.filter((e) => !e.id),
243
256
  updateImages: state.images_values.values.filter((e) => e.id),
244
257
  };
@@ -282,6 +295,10 @@ export const ProviderProductEditionProvider = ({ children }) => {
282
295
 
283
296
  await Promise.all(promiseArray);
284
297
 
298
+ // Eliminar el buffer base64 antes de enviar al endpoint para evitar error 413
299
+ data.articleData = data.articleData.map(({ src, ...rest }) => rest);
300
+ data.updateImages = data.updateImages.map(({ src, ...rest }) => rest);
301
+
285
302
  const res = await axios.put(
286
303
  process.env.REACT_APP_ARTICLE_DATA_ENDPOINT,
287
304
  data,
@@ -302,7 +319,6 @@ export const ProviderProductEditionProvider = ({ children }) => {
302
319
  type: "SET_UPDATED_IMAGES_VALUES",
303
320
  payload: [],
304
321
  });
305
-
306
322
  // Mostrar modal de éxito
307
323
  dispatch({
308
324
  type: "SET_MODAL",
@@ -346,6 +362,80 @@ export const ProviderProductEditionProvider = ({ children }) => {
346
362
  }
347
363
  };
348
364
 
365
+ const saveImageAttrs = async (token) => {
366
+ if (state.updated_attr_for_imgs.length === 0) return;
367
+
368
+ dispatch({ type: "SET_SAVING", payload: true });
369
+
370
+ const activeImage = state.images_values.values[state.current_image];
371
+
372
+ const attrForImgs = state.images_values?.attrForImgs?.general ?? [];
373
+
374
+ const data = {
375
+ articleId: state.product?.id_article,
376
+ attrReqImgs: attrForImgs.map((e) => ({
377
+ attrId: e.id,
378
+ value: e.value ?? "-",
379
+ })),
380
+ articleData: [],
381
+ updateImages: activeImage ? [activeImage] : [],
382
+ };
383
+
384
+ if (state.product?.orderId || state.product?.id_order) {
385
+ data.orderId = state.product?.orderId || state.product?.id_order;
386
+ }
387
+
388
+ try {
389
+ const res = await axios.put(
390
+ process.env.REACT_APP_ARTICLE_DATA_ENDPOINT,
391
+ data,
392
+ {
393
+ params: {
394
+ image: true,
395
+ version: state.product.version,
396
+ },
397
+ headers: {
398
+ Authorization: token,
399
+ },
400
+ },
401
+ );
402
+
403
+ if (res.data.statusCode === 200) {
404
+ dispatch({
405
+ type: "SET_UPDATED_ATTR_FOR_IMGS",
406
+ payload: [],
407
+ });
408
+
409
+ dispatch({
410
+ type: "SET_MODAL",
411
+ payload: {
412
+ show: true,
413
+ title: "",
414
+ message: "Atributos de imagen guardados con éxito",
415
+ image: successIcon,
416
+ },
417
+ });
418
+ }
419
+ } catch (error) {
420
+ console.log(error);
421
+ dispatch({
422
+ type: "SET_ERRORS",
423
+ payload: [...state.errors, error],
424
+ });
425
+ dispatch({
426
+ type: "SET_MODAL",
427
+ payload: {
428
+ show: true,
429
+ title: "Error",
430
+ message: "Hubo un error al guardar los atributos de imagen",
431
+ image: errorIcon,
432
+ },
433
+ });
434
+ } finally {
435
+ dispatch({ type: "SET_SAVING", payload: false });
436
+ }
437
+ };
438
+
349
439
  const handleOnDownloadImages = () => {
350
440
  const upc = state.product?.upc || state.product?.article?.upc;
351
441
  state.selected_images.length > 0
@@ -453,6 +543,7 @@ export const ProviderProductEditionProvider = ({ children }) => {
453
543
  saveDatasheets,
454
544
  saveDescriptions,
455
545
  updateImages,
546
+ saveImageAttrs,
456
547
  deleteImages,
457
548
  handleOnDownloadImages,
458
549
  createComment,
@@ -37,6 +37,7 @@ export const ACTIVE_STATE_ACTIONS = {
37
37
  TOGGLE_CHECK_ALL_IMAGES: "TOGGLE_CHECK_ALL_IMAGES",
38
38
  TOGGLE_CHECKBOX_IMAGE: "TOGGLE_CHECKBOX_IMAGE",
39
39
  SET_MISSING_REQUIRED_FIELDS: "SET_MISSING_REQUIRED_FIELDS",
40
+ CHANGE_ATTR_VALUE: "CHANGE_ATTR_VALUE",
40
41
  };
41
42
 
42
43
  export const activeStateReducer = (state, action) => {
@@ -141,7 +142,7 @@ export const activeStateReducer = (state, action) => {
141
142
 
142
143
  // Paso 3. Buscar si ya existe dentro de updated_images_values
143
144
  const existingUpdatedIndex = state.updated_images_values.findIndex(
144
- (img) => img.id === imageToUpdate.id
145
+ (img) => img.id === imageToUpdate.id,
145
146
  );
146
147
 
147
148
  // Paso 4. Actualizar el valor en images_values
@@ -152,7 +153,7 @@ export const activeStateReducer = (state, action) => {
152
153
  [attribute]: value,
153
154
  ...(attribute === "image_id" && { imageID: value }),
154
155
  }
155
- : img
156
+ : img,
156
157
  );
157
158
 
158
159
  // Paso 5. Actualizar updated_images_values
@@ -180,7 +181,7 @@ export const activeStateReducer = (state, action) => {
180
181
  } else {
181
182
  // Si existe, actualizar su newValue
182
183
  newUpdatedImagesValues = state.updated_images_values.map((img, i) =>
183
- i === existingUpdatedIndex ? { ...img, newValue: value } : img
184
+ i === existingUpdatedIndex ? { ...img, newValue: value } : img,
184
185
  );
185
186
 
186
187
  // Verificar si el nuevo valor es igual al valor original
@@ -202,7 +203,7 @@ export const activeStateReducer = (state, action) => {
202
203
  // Si el nuevo valor es igual al original, eliminar la imagen de updated_images_values
203
204
  if (isOriginalValue) {
204
205
  newUpdatedImagesValues = state.updated_images_values.filter(
205
- (_, i) => i !== existingUpdatedIndex
206
+ (_, i) => i !== existingUpdatedIndex,
206
207
  );
207
208
  }
208
209
  }
@@ -238,7 +239,7 @@ export const activeStateReducer = (state, action) => {
238
239
  const selectedIdentifier = selected.image_id || selected.id;
239
240
  return imageIdentifier === selectedIdentifier;
240
241
  });
241
- }
242
+ },
242
243
  );
243
244
 
244
245
  return {
@@ -282,6 +283,60 @@ export const activeStateReducer = (state, action) => {
282
283
  };
283
284
  }
284
285
 
286
+ case ACTIVE_STATE_ACTIONS.CHANGE_ATTR_VALUE: {
287
+ const { id, value } = action.payload;
288
+ const attrForImgs = state.images_values?.attrForImgs;
289
+
290
+ if (!attrForImgs?.general) return state;
291
+
292
+ const attrIndex = attrForImgs.general.findIndex((f) => f.id === id);
293
+ if (attrIndex === -1) return state;
294
+
295
+ const originalAttr = attrForImgs.general[attrIndex];
296
+
297
+ const updatedGeneral = attrForImgs.general.map((attr, i) =>
298
+ i === attrIndex ? { ...attr, value } : attr,
299
+ );
300
+
301
+ // Tracking de cambios en updated_attr_for_imgs
302
+ const existingIndex = state.updated_attr_for_imgs.findIndex(
303
+ (attr) => attr.attrId === id,
304
+ );
305
+
306
+ let newUpdatedAttrForImgs;
307
+ if (existingIndex === -1) {
308
+ // Agregar nuevo cambio con valor original
309
+ newUpdatedAttrForImgs = [
310
+ ...state.updated_attr_for_imgs,
311
+ { attrId: id, value, originalValue: originalAttr.value },
312
+ ];
313
+ } else {
314
+ // Actualizar valor existente
315
+ const updated = state.updated_attr_for_imgs.map((attr, i) =>
316
+ i === existingIndex ? { ...attr, value } : attr,
317
+ );
318
+ // Si el valor vuelve al original, eliminarlo del tracking
319
+ const originalValue = updated[existingIndex].originalValue;
320
+ if (String(value) === String(originalValue)) {
321
+ newUpdatedAttrForImgs = updated.filter((_, i) => i !== existingIndex);
322
+ } else {
323
+ newUpdatedAttrForImgs = updated;
324
+ }
325
+ }
326
+
327
+ return {
328
+ ...state,
329
+ images_values: {
330
+ ...state.images_values,
331
+ attrForImgs: {
332
+ ...attrForImgs,
333
+ general: updatedGeneral,
334
+ },
335
+ },
336
+ updated_attr_for_imgs: newUpdatedAttrForImgs,
337
+ };
338
+ }
339
+
285
340
  default: {
286
341
  return null;
287
342
  }
@@ -2,12 +2,14 @@ export const inputsInitialState = {
2
2
  updated_datasheets_inputs: [],
3
3
  updated_descriptions_inputs: [],
4
4
  updated_images_values: [],
5
+ updated_attr_for_imgs: [],
5
6
  };
6
7
 
7
8
  export const INPUTS_ACTIONS = {
8
9
  SET_UPDATED_DATASHEETS_INPUTS: "SET_UPDATED_DATASHEETS_INPUTS",
9
10
  SET_UPDATED_DESCRIPTIONS_INPUTS: "SET_UPDATED_DESCRIPTIONS_INPUTS",
10
11
  SET_UPDATED_IMAGES_VALUES: "SET_UPDATED_IMAGES_VALUES",
12
+ SET_UPDATED_ATTR_FOR_IMGS: "SET_UPDATED_ATTR_FOR_IMGS",
11
13
  UPDATE_DESCRIPTIONS_INPUTS: "UPDATE_DESCRIPTIONS_INPUTS",
12
14
  UPDATE_DATASHEETS_INPUTS: "UPDATE_DATASHEETS_INPUTS",
13
15
  };
@@ -35,6 +37,13 @@ export const inputsReducer = (state, action) => {
35
37
  };
36
38
  }
37
39
 
40
+ case INPUTS_ACTIONS.SET_UPDATED_ATTR_FOR_IMGS: {
41
+ return {
42
+ ...state,
43
+ updated_attr_for_imgs: action.payload,
44
+ };
45
+ }
46
+
38
47
  case INPUTS_ACTIONS.UPDATE_DESCRIPTIONS_INPUTS: {
39
48
  // Validar que la posicion [0] de descriptions_inputs corresponda al retailer actual
40
49
  const retailerId = state.active_retailer.id_retailer;
@@ -75,6 +75,7 @@ const RetailerProductEditionView = ({
75
75
  saveDatasheets,
76
76
  saveDescriptions,
77
77
  updateImages,
78
+ saveImageAttrs,
78
79
  deleteImages,
79
80
  handleOnDownloadImages,
80
81
  createComment,
@@ -468,7 +469,11 @@ const RetailerProductEditionView = ({
468
469
  }, [state.active_retailer, state.product]);
469
470
 
470
471
  const handleOnChangeCurrentImage = (index) => {
471
- dispatch({ type: "SET_CURRENT_IMAGE", payload: index });
472
+ if (typeof index === "number") {
473
+ dispatch({ type: "SET_CURRENT_IMAGE", payload: index });
474
+ } else if (typeof index === "object") {
475
+ dispatch({ type: "CHANGE_ATTR_VALUE", payload: index });
476
+ }
472
477
  };
473
478
 
474
479
  const handleOnShowModalGallery = () => {
@@ -586,7 +591,7 @@ const RetailerProductEditionView = ({
586
591
 
587
592
  const handleOnClickSaveImages = () => {
588
593
  if (state.product?.services?.images === 1) {
589
- updateImages();
594
+ saveImageAttrs(token);
590
595
  }
591
596
  };
592
597