contentoh-components-library 21.1.95 → 21.1.98

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.
@@ -162,24 +162,31 @@ var reducerImages = function reducerImages(state, action) {
162
162
 
163
163
  case "orderImages":
164
164
  {
165
- var _inputsByRetailer$act;
166
-
167
165
  var _inputsByRetailer = state.inputsByRetailer,
168
166
  valuesInitial = state.valuesInitial,
169
167
  inputsInitial = state.inputsInitial,
170
168
  inputs = state.inputs;
171
- var orderedImages = [];
172
- var imageIdArray = [];
173
- action.retailerId && ((_inputsByRetailer$act = _inputsByRetailer[action.retailerId]) === null || _inputsByRetailer$act === void 0 ? void 0 : _inputsByRetailer$act.filter(function (input) {
174
- imageIdArray.push(input.id_image);
175
- valuesInitial.forEach(function (value) {
176
- if (value.image_id === input.id_image) orderedImages.push(value);
169
+
170
+ try {
171
+ var _inputsByRetailer$act;
172
+
173
+ var orderedImages = [];
174
+ var imageIdArray = [];
175
+ if (action !== null && action !== void 0 && action.retailerId && !_inputsByRetailer[action.retailerId]) _inputsByRetailer[action.retailerId] = [];
176
+ action.retailerId && ((_inputsByRetailer$act = _inputsByRetailer[action.retailerId]) === null || _inputsByRetailer$act === void 0 ? void 0 : _inputsByRetailer$act.filter(function (input) {
177
+ imageIdArray.push(input.id_image);
178
+ valuesInitial.forEach(function (value) {
179
+ if (value.image_id === input.id_image) orderedImages.push(value);
180
+ });
181
+ }));
182
+ inputs = inputsInitial === null || inputsInitial === void 0 ? void 0 : inputsInitial.filter(function (input) {
183
+ return imageIdArray.includes(input.id);
177
184
  });
178
- }));
179
- inputs = inputsInitial === null || inputsInitial === void 0 ? void 0 : inputsInitial.filter(function (input) {
180
- return imageIdArray.includes(input.id);
181
- });
182
- values = orderedImages.length > 0 ? orderedImages : valuesInitial;
185
+ values = orderedImages.length > 0 ? orderedImages : [];
186
+ } catch (error) {
187
+ console.log(error);
188
+ }
189
+
183
190
  return (0, _objectSpread3.default)((0, _objectSpread3.default)({}, state), {}, {
184
191
  values: values,
185
192
  inputs: inputs
@@ -548,8 +555,10 @@ var ProviderProductEdition = function ProviderProductEdition(_ref) {
548
555
  services = _context2.sent;
549
556
  //Converts the data inside the datasheets object to array
550
557
  setServices(services);
551
- getServices();
558
+ _context2.next = 6;
559
+ return getServices();
552
560
 
561
+ case 6:
553
562
  if (!originProp) {
554
563
  setActiveRetailer(product !== null && product !== void 0 && product.retailers ? product === null || product === void 0 ? void 0 : product.retailers[0] : product === null || product === void 0 ? void 0 : product.retailersAvailable[0]);
555
564
  } // setActiveRetailer(product?.retailers[0]);
@@ -567,7 +576,7 @@ var ProviderProductEdition = function ProviderProductEdition(_ref) {
567
576
  });
568
577
  setLoading(false);
569
578
 
570
- case 10:
579
+ case 11:
571
580
  case "end":
572
581
  return _context2.stop();
573
582
  }
@@ -584,7 +593,7 @@ var ProviderProductEdition = function ProviderProductEdition(_ref) {
584
593
  var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
585
594
  var _product$article4;
586
595
 
587
- var productInOrder, idArticle, _product$id_order, _servicesResponse$dat, servicesResponse, parsedResponse, retailerResponse, retailers, active;
596
+ var productInOrder, idArticle, retailers, active, _product$id_order, _servicesResponse$dat, servicesResponse, parsedResponse, retailerResponse;
588
597
 
589
598
  return _regenerator.default.wrap(function _callee3$(_context3) {
590
599
  while (1) {
@@ -592,29 +601,32 @@ var ProviderProductEdition = function ProviderProductEdition(_ref) {
592
601
  case 0:
593
602
  productInOrder = product.id_order || product.orderId;
594
603
  idArticle = (product === null || product === void 0 ? void 0 : product.id_article) || (product === null || product === void 0 ? void 0 : (_product$article4 = product.article) === null || _product$article4 === void 0 ? void 0 : _product$article4.id_article);
604
+ retailers = product.retailers || product.retailersAvailable;
605
+ active = null;
595
606
 
596
607
  if (!(isRevision() || productInOrder)) {
597
608
  _context3.next = 12;
598
609
  break;
599
610
  }
600
611
 
601
- _context3.next = 5;
612
+ _context3.next = 7;
602
613
  return _axios.default.get("".concat(process.env.REACT_APP_SERVICES_ENDPOINT, "?articleId=").concat(idArticle, "&orderId=").concat((_product$id_order = product === null || product === void 0 ? void 0 : product.id_order) !== null && _product$id_order !== void 0 ? _product$id_order : product.orderId, "&end=true"));
603
614
 
604
- case 5:
615
+ case 7:
605
616
  servicesResponse = _context3.sent;
606
617
  parsedResponse = JSON.parse(servicesResponse === null || servicesResponse === void 0 ? void 0 : (_servicesResponse$dat = servicesResponse.data) === null || _servicesResponse$dat === void 0 ? void 0 : _servicesResponse$dat.body).data;
607
618
  retailerResponse = parsedResponse === null || parsedResponse === void 0 ? void 0 : parsedResponse.map(function (srv) {
608
619
  return srv.id_retailer;
609
620
  });
610
- retailers = product.retailers || product.retailersAvailable;
611
621
  active = retailers === null || retailers === void 0 ? void 0 : retailers.find(function (retailer) {
612
622
  return retailerResponse.includes(retailer.id);
613
623
  });
614
- !activeRetailer.id && setActiveRetailer(active ? active : retailers[0]);
615
624
  setServicesData(parsedResponse);
616
625
 
617
626
  case 12:
627
+ !activeRetailer.id && setActiveRetailer(active ? active : retailers[0]);
628
+
629
+ case 13:
618
630
  case "end":
619
631
  return _context3.stop();
620
632
  }
@@ -700,6 +712,12 @@ var ProviderProductEdition = function ProviderProductEdition(_ref) {
700
712
  retailerId: activeRetailer.id
701
713
  });
702
714
  }, [product, version]);
715
+ (0, _react.useEffect)(function () {
716
+ setImages({
717
+ action: "orderImages",
718
+ retailerId: activeRetailer.id
719
+ });
720
+ }, [activeRetailer]);
703
721
 
704
722
  var loadAssignations = function loadAssignations(currentProduct) {
705
723
  setAssig(product === null || product === void 0 ? void 0 : product.asignations);
@@ -140,24 +140,31 @@ var reducerImages = function reducerImages(state, action) {
140
140
 
141
141
  case "orderImages":
142
142
  {
143
- var _inputsByRetailer$act;
144
-
145
143
  var _inputsByRetailer = state.inputsByRetailer,
146
144
  valuesInitial = state.valuesInitial,
147
145
  inputsInitial = state.inputsInitial,
148
146
  inputs = state.inputs;
149
- var orderedImages = [];
150
- var imageIdArray = [];
151
- action.retailerId && ((_inputsByRetailer$act = _inputsByRetailer[action.retailerId]) === null || _inputsByRetailer$act === void 0 ? void 0 : _inputsByRetailer$act.filter(function (input) {
152
- imageIdArray.push(input.id_image);
153
- valuesInitial.forEach(function (value) {
154
- if (value.image_id === input.id_image) orderedImages.push(value);
147
+
148
+ try {
149
+ var _inputsByRetailer$act;
150
+
151
+ var orderedImages = [];
152
+ var imageIdArray = [];
153
+ if (action !== null && action !== void 0 && action.retailerId && !_inputsByRetailer[action.retailerId]) _inputsByRetailer[action.retailerId] = [];
154
+ action.retailerId && ((_inputsByRetailer$act = _inputsByRetailer[action.retailerId]) === null || _inputsByRetailer$act === void 0 ? void 0 : _inputsByRetailer$act.filter(function (input) {
155
+ imageIdArray.push(input.id_image);
156
+ valuesInitial.forEach(function (value) {
157
+ if (value.image_id === input.id_image) orderedImages.push(value);
158
+ });
159
+ }));
160
+ inputs = inputsInitial === null || inputsInitial === void 0 ? void 0 : inputsInitial.filter(function (input) {
161
+ return imageIdArray.includes(input.id);
155
162
  });
156
- }));
157
- inputs = inputsInitial === null || inputsInitial === void 0 ? void 0 : inputsInitial.filter(function (input) {
158
- return imageIdArray.includes(input.id);
159
- });
160
- values = orderedImages.length > 0 ? orderedImages : valuesInitial;
163
+ values = orderedImages.length > 0 ? orderedImages : [];
164
+ } catch (error) {
165
+ console.log(error);
166
+ }
167
+
161
168
  return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, state), {}, {
162
169
  values: values,
163
170
  inputs: inputs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentoh-components-library",
3
- "version": "21.1.95",
3
+ "version": "21.1.98",
4
4
  "dependencies": {
5
5
  "@aws-amplify/auth": "^4.5.3",
6
6
  "@aws-amplify/datastore": "^3.11.0",
@@ -83,21 +83,27 @@ const reducerImages = (state, action) => {
83
83
  return { ...state, values };
84
84
  case "orderImages": {
85
85
  let { inputsByRetailer, valuesInitial, inputsInitial, inputs } = state;
86
- const orderedImages = [];
87
- const imageIdArray = [];
88
- action.retailerId &&
89
- inputsByRetailer[action.retailerId]?.filter((input) => {
90
- imageIdArray.push(input.id_image);
91
- valuesInitial.forEach((value) => {
92
- if (value.image_id === input.id_image) orderedImages.push(value);
86
+ try {
87
+ const orderedImages = [];
88
+ const imageIdArray = [];
89
+ if (action?.retailerId && !inputsByRetailer[action.retailerId])
90
+ inputsByRetailer[action.retailerId] = [];
91
+ action.retailerId &&
92
+ inputsByRetailer[action.retailerId]?.filter((input) => {
93
+ imageIdArray.push(input.id_image);
94
+ valuesInitial.forEach((value) => {
95
+ if (value.image_id === input.id_image) orderedImages.push(value);
96
+ });
93
97
  });
94
- });
95
98
 
96
- inputs = inputsInitial?.filter((input) =>
97
- imageIdArray.includes(input.id)
98
- );
99
+ inputs = inputsInitial?.filter((input) =>
100
+ imageIdArray.includes(input.id)
101
+ );
99
102
 
100
- values = orderedImages.length > 0 ? orderedImages : valuesInitial;
103
+ values = orderedImages.length > 0 ? orderedImages : [];
104
+ } catch (error) {
105
+ console.log(error);
106
+ }
101
107
  return { ...state, values, inputs };
102
108
  }
103
109
  default:
@@ -263,7 +269,7 @@ export const ProviderProductEdition = ({
263
269
 
264
270
  //Converts the data inside the datasheets object to array
265
271
  setServices(services);
266
- getServices();
272
+ await getServices();
267
273
 
268
274
  if (!originProp) {
269
275
  setActiveRetailer(
@@ -284,6 +290,8 @@ export const ProviderProductEdition = ({
284
290
  const getServices = async () => {
285
291
  const productInOrder = product.id_order || product.orderId;
286
292
  const idArticle = product?.id_article || product?.article?.id_article;
293
+ let retailers = product.retailers || product.retailersAvailable;
294
+ let active = null;
287
295
  if (isRevision() || productInOrder) {
288
296
  const servicesResponse = await axios.get(
289
297
  `${
@@ -294,13 +302,12 @@ export const ProviderProductEdition = ({
294
302
  );
295
303
  const parsedResponse = JSON.parse(servicesResponse?.data?.body).data;
296
304
  const retailerResponse = parsedResponse?.map((srv) => srv.id_retailer);
297
- let retailers = product.retailers || product.retailersAvailable;
298
- let active = retailers?.find((retailer) =>
305
+ active = retailers?.find((retailer) =>
299
306
  retailerResponse.includes(retailer.id)
300
307
  );
301
- !activeRetailer.id && setActiveRetailer(active ? active : retailers[0]);
302
308
  setServicesData(parsedResponse);
303
309
  }
310
+ !activeRetailer.id && setActiveRetailer(active ? active : retailers[0]);
304
311
  };
305
312
 
306
313
  const isRevision = () => {
@@ -351,6 +358,10 @@ export const ProviderProductEdition = ({
351
358
  setImages({ action: "orderImages", retailerId: activeRetailer.id });
352
359
  }, [product, version]);
353
360
 
361
+ useEffect(() => {
362
+ setImages({ action: "orderImages", retailerId: activeRetailer.id });
363
+ }, [activeRetailer]);
364
+
354
365
  const loadAssignations = (currentProduct) => {
355
366
  setAssig(product?.asignations);
356
367
  };
@@ -73,21 +73,27 @@ const reducerImages = (state, action) => {
73
73
  return { ...state, values };
74
74
  case "orderImages": {
75
75
  let { inputsByRetailer, valuesInitial, inputsInitial, inputs } = state;
76
- const orderedImages = [];
77
- const imageIdArray = [];
78
- action.retailerId &&
79
- inputsByRetailer[action.retailerId]?.filter((input) => {
80
- imageIdArray.push(input.id_image);
81
- valuesInitial.forEach((value) => {
82
- if (value.image_id === input.id_image) orderedImages.push(value);
76
+ try {
77
+ const orderedImages = [];
78
+ const imageIdArray = [];
79
+ if (action?.retailerId && !inputsByRetailer[action.retailerId])
80
+ inputsByRetailer[action.retailerId] = [];
81
+ action.retailerId &&
82
+ inputsByRetailer[action.retailerId]?.filter((input) => {
83
+ imageIdArray.push(input.id_image);
84
+ valuesInitial.forEach((value) => {
85
+ if (value.image_id === input.id_image) orderedImages.push(value);
86
+ });
83
87
  });
84
- });
85
88
 
86
- inputs = inputsInitial?.filter((input) =>
87
- imageIdArray.includes(input.id)
88
- );
89
+ inputs = inputsInitial?.filter((input) =>
90
+ imageIdArray.includes(input.id)
91
+ );
89
92
 
90
- values = orderedImages.length > 0 ? orderedImages : valuesInitial;
93
+ values = orderedImages.length > 0 ? orderedImages : [];
94
+ } catch (error) {
95
+ console.log(error);
96
+ }
91
97
  return { ...state, values, inputs };
92
98
  }
93
99
  default: