contentoh-components-library 21.5.70 → 21.5.71

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
 
@@ -350,7 +354,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
350
354
  });
351
355
 
352
356
  if (!valid) {
353
- _context3.next = 31;
357
+ _context3.next = 33;
354
358
  break;
355
359
  }
356
360
 
@@ -384,7 +388,18 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
384
388
  return Promise.all(promiseArray);
385
389
 
386
390
  case 15:
387
- _context3.next = 17;
391
+ // Eliminar el buffer base64 antes de enviar al endpoint para evitar error 413
392
+ data.articleData = data.articleData.map(function (_ref5) {
393
+ var src = _ref5.src,
394
+ rest = (0, _objectWithoutProperties2.default)(_ref5, _excluded);
395
+ return rest;
396
+ });
397
+ data.updateImages = data.updateImages.map(function (_ref6) {
398
+ var src = _ref6.src,
399
+ rest = (0, _objectWithoutProperties2.default)(_ref6, _excluded2);
400
+ return rest;
401
+ });
402
+ _context3.next = 19;
388
403
  return _axios.default.put(process.env.REACT_APP_ARTICLE_DATA_ENDPOINT, data, {
389
404
  params: {
390
405
  image: true,
@@ -395,7 +410,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
395
410
  }
396
411
  });
397
412
 
398
- case 17:
413
+ case 19:
399
414
  res = _context3.sent;
400
415
 
401
416
  if (res.data.statusCode === 200) {
@@ -403,6 +418,10 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
403
418
  dispatch({
404
419
  type: "SET_UPDATED_IMAGES_VALUES",
405
420
  payload: []
421
+ });
422
+ dispatch({
423
+ type: "SET_UPDATED_ATTR_FOR_IMGS",
424
+ payload: []
406
425
  }); // Mostrar modal de éxito
407
426
 
408
427
  dispatch({
@@ -416,11 +435,11 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
416
435
  });
417
436
  }
418
437
 
419
- _context3.next = 26;
438
+ _context3.next = 28;
420
439
  break;
421
440
 
422
- case 21:
423
- _context3.prev = 21;
441
+ case 23:
442
+ _context3.prev = 23;
424
443
  _context3.t0 = _context3["catch"](11);
425
444
  console.log(_context3.t0);
426
445
  dispatch({
@@ -437,19 +456,19 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
437
456
  }
438
457
  });
439
458
 
440
- case 26:
441
- _context3.prev = 26;
459
+ case 28:
460
+ _context3.prev = 28;
442
461
  dispatch({
443
462
  type: "SET_SAVING",
444
463
  payload: false
445
464
  });
446
- return _context3.finish(26);
465
+ return _context3.finish(28);
447
466
 
448
- case 29:
449
- _context3.next = 32;
467
+ case 31:
468
+ _context3.next = 34;
450
469
  break;
451
470
 
452
- case 31:
471
+ case 33:
453
472
  dispatch({
454
473
  type: "SET_MODAL",
455
474
  payload: {
@@ -460,12 +479,12 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
460
479
  }
461
480
  });
462
481
 
463
- case 32:
482
+ case 34:
464
483
  case "end":
465
484
  return _context3.stop();
466
485
  }
467
486
  }
468
- }, _callee3, null, [[11, 21, 26, 29]]);
487
+ }, _callee3, null, [[11, 23, 28, 31]]);
469
488
  }));
470
489
 
471
490
  return function updateImages(_x3) {
@@ -473,15 +492,130 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
473
492
  };
474
493
  }();
475
494
 
495
+ var saveImageAttrs = /*#__PURE__*/function () {
496
+ 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;
498
+
499
+ var activeImage, attrForImgs, data, _state$product13, _state$product14, res;
500
+
501
+ return _regenerator.default.wrap(function _callee4$(_context4) {
502
+ while (1) {
503
+ switch (_context4.prev = _context4.next) {
504
+ case 0:
505
+ if (!(state.updated_attr_for_imgs.length === 0)) {
506
+ _context4.next = 2;
507
+ break;
508
+ }
509
+
510
+ return _context4.abrupt("return");
511
+
512
+ case 2:
513
+ dispatch({
514
+ type: "SET_SAVING",
515
+ payload: true
516
+ });
517
+ activeImage = state.images_values.values[state.current_image];
518
+ 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
+ data = {
520
+ articleId: (_state$product10 = state.product) === null || _state$product10 === void 0 ? void 0 : _state$product10.id_article,
521
+ attrReqImgs: attrForImgs.map(function (e) {
522
+ var _e$value;
523
+
524
+ return {
525
+ attrId: e.id,
526
+ value: (_e$value = e.value) !== null && _e$value !== void 0 ? _e$value : "-"
527
+ };
528
+ }),
529
+ articleData: [],
530
+ updateImages: activeImage ? [activeImage] : []
531
+ };
532
+
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);
535
+ }
536
+
537
+ _context4.prev = 7;
538
+ _context4.next = 10;
539
+ return _axios.default.put(process.env.REACT_APP_ARTICLE_DATA_ENDPOINT, data, {
540
+ params: {
541
+ image: true,
542
+ version: state.product.version
543
+ },
544
+ headers: {
545
+ Authorization: token
546
+ }
547
+ });
548
+
549
+ case 10:
550
+ res = _context4.sent;
551
+
552
+ if (res.data.statusCode === 200) {
553
+ dispatch({
554
+ type: "SET_UPDATED_ATTR_FOR_IMGS",
555
+ payload: []
556
+ });
557
+ dispatch({
558
+ type: "SET_MODAL",
559
+ payload: {
560
+ show: true,
561
+ title: "",
562
+ message: "Atributos de imagen guardados con éxito",
563
+ image: _genericModalCheck.default
564
+ }
565
+ });
566
+ }
567
+
568
+ _context4.next = 19;
569
+ break;
570
+
571
+ case 14:
572
+ _context4.prev = 14;
573
+ _context4.t0 = _context4["catch"](7);
574
+ console.log(_context4.t0);
575
+ dispatch({
576
+ type: "SET_ERRORS",
577
+ payload: [].concat((0, _toConsumableArray2.default)(state.errors), [_context4.t0])
578
+ });
579
+ dispatch({
580
+ type: "SET_MODAL",
581
+ payload: {
582
+ show: true,
583
+ title: "Error",
584
+ message: "Hubo un error al guardar los atributos de imagen",
585
+ image: _errorModal.default
586
+ }
587
+ });
588
+
589
+ case 19:
590
+ _context4.prev = 19;
591
+ dispatch({
592
+ type: "SET_SAVING",
593
+ payload: false
594
+ });
595
+ return _context4.finish(19);
596
+
597
+ case 22:
598
+ case "end":
599
+ return _context4.stop();
600
+ }
601
+ }
602
+ }, _callee4, null, [[7, 14, 19, 22]]);
603
+ }));
604
+
605
+ return function saveImageAttrs(_x4) {
606
+ return _ref7.apply(this, arguments);
607
+ };
608
+ }();
609
+
476
610
  var handleOnDownloadImages = function handleOnDownloadImages() {
477
- var _state$product10, _state$product11, _state$product11$arti, _state$images_values2, _state$images_values3;
611
+ var _state$product15, _state$product16, _state$product16$arti, _state$images_values4, _state$images_values5;
478
612
 
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);
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);
480
614
  state.selected_images.length > 0 ? state.selected_images.forEach(function (e) {
481
615
  if (e.id) {
482
616
  saveAs("https://".concat(process.env.REACT_APP_IMAGES_BUCKET, ".s3.amazonaws.com/").concat(e.srcDB), "".concat(upc, "_").concat(e.name, ".").concat(e.ext));
483
617
  }
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) {
618
+ }) : (_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
619
  if (e.id) {
486
620
  saveAs("https://".concat(process.env.REACT_APP_IMAGES_BUCKET, ".s3.amazonaws.com/").concat(e.srcDB), "".concat(upc, "_").concat(e.name, ".").concat(e.ext));
487
621
  }
@@ -489,12 +623,12 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
489
623
  };
490
624
 
491
625
  var deleteImages = /*#__PURE__*/function () {
492
- var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(token) {
493
- var imgsInBack, _state$product12, data;
626
+ var _ref8 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(token) {
627
+ var imgsInBack, _state$product17, data;
494
628
 
495
- return _regenerator.default.wrap(function _callee4$(_context4) {
629
+ return _regenerator.default.wrap(function _callee5$(_context5) {
496
630
  while (1) {
497
- switch (_context4.prev = _context4.next) {
631
+ switch (_context5.prev = _context5.next) {
498
632
  case 0:
499
633
  dispatch({
500
634
  type: "SET_SAVING",
@@ -506,16 +640,16 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
506
640
  }); // Hacer el request al backend si hay imágenes que eliminar
507
641
 
508
642
  if (!(imgsInBack.length > 0)) {
509
- _context4.next = 18;
643
+ _context5.next = 18;
510
644
  break;
511
645
  }
512
646
 
513
647
  data = {
514
- articleId: (_state$product12 = state.product) === null || _state$product12 === void 0 ? void 0 : _state$product12.id_article,
648
+ articleId: (_state$product17 = state.product) === null || _state$product17 === void 0 ? void 0 : _state$product17.id_article,
515
649
  deleteImages: imgsInBack
516
650
  };
517
- _context4.prev = 4;
518
- _context4.next = 7;
651
+ _context5.prev = 4;
652
+ _context5.next = 7;
519
653
  return _axios.default.put(process.env.REACT_APP_ARTICLE_DATA_ENDPOINT, data, {
520
654
  params: {
521
655
  image: true,
@@ -537,13 +671,13 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
537
671
  image: _genericModalCheck.default
538
672
  }
539
673
  });
540
- _context4.next = 15;
674
+ _context5.next = 15;
541
675
  break;
542
676
 
543
677
  case 10:
544
- _context4.prev = 10;
545
- _context4.t0 = _context4["catch"](4);
546
- console.log(_context4.t0);
678
+ _context5.prev = 10;
679
+ _context5.t0 = _context5["catch"](4);
680
+ console.log(_context5.t0);
547
681
  dispatch({
548
682
  type: "SET_MODAL",
549
683
  payload: {
@@ -553,15 +687,15 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
553
687
  image: _errorModal.default
554
688
  }
555
689
  });
556
- return _context4.abrupt("return");
690
+ return _context5.abrupt("return");
557
691
 
558
692
  case 15:
559
- _context4.prev = 15;
693
+ _context5.prev = 15;
560
694
  dispatch({
561
695
  type: "SET_SAVING",
562
696
  payload: false
563
697
  });
564
- return _context4.finish(15);
698
+ return _context5.finish(15);
565
699
 
566
700
  case 18:
567
701
  // Actualizar el estado eliminando las imágenes seleccionadas
@@ -578,36 +712,36 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
578
712
 
579
713
  case 20:
580
714
  case "end":
581
- return _context4.stop();
715
+ return _context5.stop();
582
716
  }
583
717
  }
584
- }, _callee4, null, [[4, 10, 15, 18]]);
718
+ }, _callee5, null, [[4, 10, 15, 18]]);
585
719
  }));
586
720
 
587
- return function deleteImages(_x4) {
588
- return _ref5.apply(this, arguments);
721
+ return function deleteImages(_x5) {
722
+ return _ref8.apply(this, arguments);
589
723
  };
590
724
  }();
591
725
 
592
726
  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;
727
+ var _ref9 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(body, token) {
728
+ var _state$product18, _state$product19, _state$product20;
595
729
 
596
730
  var concept, data;
597
- return _regenerator.default.wrap(function _callee5$(_context5) {
731
+ return _regenerator.default.wrap(function _callee6$(_context6) {
598
732
  while (1) {
599
- switch (_context5.prev = _context5.next) {
733
+ switch (_context6.prev = _context6.next) {
600
734
  case 0:
601
735
  concept = (0, _utils.getConceptByTab)(state.active_tab);
602
736
  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),
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),
605
739
  message: body,
606
740
  concept: concept,
607
741
  version: state.product.version
608
742
  };
609
- _context5.prev = 2;
610
- _context5.next = 5;
743
+ _context6.prev = 2;
744
+ _context6.next = 5;
611
745
  return _axios.default.post("".concat(process.env.REACT_APP_COMMENTS_ENDPOINT), data, {
612
746
  headers: {
613
747
  Authorization: token
@@ -615,24 +749,24 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
615
749
  });
616
750
 
617
751
  case 5:
618
- _context5.next = 10;
752
+ _context6.next = 10;
619
753
  break;
620
754
 
621
755
  case 7:
622
- _context5.prev = 7;
623
- _context5.t0 = _context5["catch"](2);
624
- console.log("Error creating comment:", _context5.t0);
756
+ _context6.prev = 7;
757
+ _context6.t0 = _context6["catch"](2);
758
+ console.log("Error creating comment:", _context6.t0);
625
759
 
626
760
  case 10:
627
761
  case "end":
628
- return _context5.stop();
762
+ return _context6.stop();
629
763
  }
630
764
  }
631
- }, _callee5, null, [[2, 7]]);
765
+ }, _callee6, null, [[2, 7]]);
632
766
  }));
633
767
 
634
- return function createComment(_x5, _x6) {
635
- return _ref6.apply(this, arguments);
768
+ return function createComment(_x6, _x7) {
769
+ return _ref9.apply(this, arguments);
636
770
  };
637
771
  }();
638
772
 
@@ -642,6 +776,7 @@ var ProviderProductEditionProvider = function ProviderProductEditionProvider(_re
642
776
  saveDatasheets: saveDatasheets,
643
777
  saveDescriptions: saveDescriptions,
644
778
  updateImages: updateImages,
779
+ saveImageAttrs: saveImageAttrs,
645
780
  deleteImages: deleteImages,
646
781
  handleOnDownloadImages: handleOnDownloadImages,
647
782
  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.71",
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
+ };
@@ -282,6 +282,10 @@ export const ProviderProductEditionProvider = ({ children }) => {
282
282
 
283
283
  await Promise.all(promiseArray);
284
284
 
285
+ // Eliminar el buffer base64 antes de enviar al endpoint para evitar error 413
286
+ data.articleData = data.articleData.map(({ src, ...rest }) => rest);
287
+ data.updateImages = data.updateImages.map(({ src, ...rest }) => rest);
288
+
285
289
  const res = await axios.put(
286
290
  process.env.REACT_APP_ARTICLE_DATA_ENDPOINT,
287
291
  data,
@@ -302,6 +306,10 @@ export const ProviderProductEditionProvider = ({ children }) => {
302
306
  type: "SET_UPDATED_IMAGES_VALUES",
303
307
  payload: [],
304
308
  });
309
+ dispatch({
310
+ type: "SET_UPDATED_ATTR_FOR_IMGS",
311
+ payload: [],
312
+ });
305
313
 
306
314
  // Mostrar modal de éxito
307
315
  dispatch({
@@ -346,6 +354,80 @@ export const ProviderProductEditionProvider = ({ children }) => {
346
354
  }
347
355
  };
348
356
 
357
+ const saveImageAttrs = async (token) => {
358
+ if (state.updated_attr_for_imgs.length === 0) return;
359
+
360
+ dispatch({ type: "SET_SAVING", payload: true });
361
+
362
+ const activeImage = state.images_values.values[state.current_image];
363
+
364
+ const attrForImgs = state.images_values?.attrForImgs?.general ?? [];
365
+
366
+ const data = {
367
+ articleId: state.product?.id_article,
368
+ attrReqImgs: attrForImgs.map((e) => ({
369
+ attrId: e.id,
370
+ value: e.value ?? "-",
371
+ })),
372
+ articleData: [],
373
+ updateImages: activeImage ? [activeImage] : [],
374
+ };
375
+
376
+ if (state.product?.orderId || state.product?.id_order) {
377
+ data.orderId = state.product?.orderId || state.product?.id_order;
378
+ }
379
+
380
+ try {
381
+ const res = await axios.put(
382
+ process.env.REACT_APP_ARTICLE_DATA_ENDPOINT,
383
+ data,
384
+ {
385
+ params: {
386
+ image: true,
387
+ version: state.product.version,
388
+ },
389
+ headers: {
390
+ Authorization: token,
391
+ },
392
+ },
393
+ );
394
+
395
+ if (res.data.statusCode === 200) {
396
+ dispatch({
397
+ type: "SET_UPDATED_ATTR_FOR_IMGS",
398
+ payload: [],
399
+ });
400
+
401
+ dispatch({
402
+ type: "SET_MODAL",
403
+ payload: {
404
+ show: true,
405
+ title: "",
406
+ message: "Atributos de imagen guardados con éxito",
407
+ image: successIcon,
408
+ },
409
+ });
410
+ }
411
+ } catch (error) {
412
+ console.log(error);
413
+ dispatch({
414
+ type: "SET_ERRORS",
415
+ payload: [...state.errors, error],
416
+ });
417
+ dispatch({
418
+ type: "SET_MODAL",
419
+ payload: {
420
+ show: true,
421
+ title: "Error",
422
+ message: "Hubo un error al guardar los atributos de imagen",
423
+ image: errorIcon,
424
+ },
425
+ });
426
+ } finally {
427
+ dispatch({ type: "SET_SAVING", payload: false });
428
+ }
429
+ };
430
+
349
431
  const handleOnDownloadImages = () => {
350
432
  const upc = state.product?.upc || state.product?.article?.upc;
351
433
  state.selected_images.length > 0
@@ -453,6 +535,7 @@ export const ProviderProductEditionProvider = ({ children }) => {
453
535
  saveDatasheets,
454
536
  saveDescriptions,
455
537
  updateImages,
538
+ saveImageAttrs,
456
539
  deleteImages,
457
540
  handleOnDownloadImages,
458
541
  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