contentoh-components-library 21.5.96 → 21.5.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.
@@ -243,16 +243,24 @@ var ProviderProductEditionView = function ProviderProductEditionView(_ref) {
243
243
  type: "SET_PRODUCT",
244
244
  payload: productNormalized
245
245
  });
246
- dispatch({
247
- type: "SET_ACTIVE_RETAILER",
248
- payload: productNormalized.categoryRetailer[0]
249
- });
250
- var firstRetailerStatus = productNormalized.statusByRetailer[productNormalized.categoryRetailerInOrder[0].id_retailer];
251
- var initialTab = firstRetailerStatus.description ? "Descripción" : firstRetailerStatus.datasheet ? "Ficha técnica" : firstRetailerStatus.images ? "Imágenes" : "Imágenes";
252
- dispatch({
253
- type: "SET_ACTIVE_TAB",
254
- payload: initialTab
255
- });
246
+
247
+ if (productNormalized.categoryRetailerInOrder.length > 0 && productNormalized.statusByRetailer) {
248
+ dispatch({
249
+ type: "SET_ACTIVE_RETAILER",
250
+ payload: productNormalized.categoryRetailerInOrder[0]
251
+ });
252
+ var firstRetailerStatus = productNormalized.statusByRetailer[productNormalized.categoryRetailerInOrder[0].id_retailer];
253
+ var initialTab = firstRetailerStatus.description ? "Descripción" : firstRetailerStatus.datasheet ? "Ficha técnica" : firstRetailerStatus.images ? "Imágenes" : "Imágenes";
254
+ dispatch({
255
+ type: "SET_ACTIVE_TAB",
256
+ payload: initialTab
257
+ });
258
+ } else {
259
+ dispatch({
260
+ type: "SET_ACTIVE_RETAILER",
261
+ payload: productNormalized.categoryRetailer[0]
262
+ });
263
+ }
256
264
  } catch (error) {
257
265
  console.log("Error setting product data: ", error);
258
266
  }
@@ -275,7 +283,7 @@ var ProviderProductEditionView = function ProviderProductEditionView(_ref) {
275
283
 
276
284
  var fetchData = /*#__PURE__*/function () {
277
285
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
278
- var _JSON$parse$0$relatio, _JSON$parse, _JSON$parse$, _percentageRes$, data, headers, _yield$Promise$all, _yield$Promise$all2, services, percentageRes, servicesDataRes, percentages, orderMap, orderedValues, updatedStatusByRetailer;
286
+ var _JSON$parse$0$relatio, _JSON$parse, _JSON$parse$, _percentageRes$, _services$2$inputsByR, _services$2$values, data, headers, _yield$Promise$all, _yield$Promise$all2, services, percentageRes, servicesDataRes, percentages, orderMap, orderedValues, updatedStatusByRetailer;
279
287
 
280
288
  return _regenerator.default.wrap(function _callee2$(_context2) {
281
289
  while (1) {
@@ -315,11 +323,11 @@ var ProviderProductEditionView = function ProviderProductEditionView(_ref) {
315
323
  percentageRes = _yield$Promise$all2[1];
316
324
  servicesDataRes = _yield$Promise$all2[2];
317
325
  percentages = (_JSON$parse$0$relatio = (_JSON$parse = JSON.parse(percentageRes === null || percentageRes === void 0 ? void 0 : (_percentageRes$ = percentageRes[0]) === null || _percentageRes$ === void 0 ? void 0 : _percentageRes$.body)) === null || _JSON$parse === void 0 ? void 0 : (_JSON$parse$ = _JSON$parse[0]) === null || _JSON$parse$ === void 0 ? void 0 : _JSON$parse$.relations) !== null && _JSON$parse$0$relatio !== void 0 ? _JSON$parse$0$relatio : [];
318
- orderMap = services[2].inputsByRetailer.flat().reduce(function (acc, item) {
326
+ orderMap = (_services$2$inputsByR = services[2].inputsByRetailer) !== null && _services$2$inputsByR !== void 0 ? _services$2$inputsByR : [].flat().reduce(function (acc, item) {
319
327
  acc[item.id_image] = item.order;
320
328
  return acc;
321
329
  }, {});
322
- orderedValues = (0, _toConsumableArray2.default)(services[2].values).sort(function (a, b) {
330
+ orderedValues = (0, _toConsumableArray2.default)((_services$2$values = services[2].values) !== null && _services$2$values !== void 0 ? _services$2$values : []).sort(function (a, b) {
323
331
  var _orderMap$a$image_id, _orderMap$b$image_id;
324
332
 
325
333
  var orderA = (_orderMap$a$image_id = orderMap[a.image_id]) !== null && _orderMap$a$image_id !== void 0 ? _orderMap$a$image_id : Number.MAX_SAFE_INTEGER;
@@ -454,30 +462,35 @@ var ProviderProductEditionView = function ProviderProductEditionView(_ref) {
454
462
  var _state$product8;
455
463
 
456
464
  if (!((_state$product8 = state.product) !== null && _state$product8 !== void 0 && _state$product8.statusByRetailer)) return false;
457
- var currentService = (0, _utils.getConceptByTab)(state.active_tab); // const currentStatus = state.product[`${currentService}_status`];
458
465
 
459
- var currentRetailer = state.active_retailer.id_retailer; //Información del servicio de la cadena seleccionada
466
+ try {
467
+ var currentService = (0, _utils.getConceptByTab)(state.active_tab); // const currentStatus = state.product[`${currentService}_status`];
468
+
469
+ var currentRetailer = state.active_retailer.id_retailer; //Información del servicio de la cadena seleccionada
460
470
 
461
- var _state$services_data$ = state.services_data.find(function (service) {
462
- return service.service === currentService && service.id_retailer === currentRetailer;
463
- }),
464
- currentStatus = _state$services_data$.status;
471
+ var _state$services_data$ = state.services_data.find(function (service) {
472
+ return service.service === currentService && service.id_retailer === currentRetailer;
473
+ }),
474
+ currentStatus = _state$services_data$.status;
465
475
 
466
- var originTab = origin[state.active_tab];
467
- var isRetailerUser = (user === null || user === void 0 ? void 0 : user.is_retailer) === 1;
468
- var validStatuses = ["AA", "AP", "R", "CA", "RCA"];
469
- if (!validStatuses.includes(currentStatus)) return false;
470
- var validOrigins = ["RequestWithContentoh", "RequestWithoutContentoh", "Contentoh"];
471
- if (!validOrigins.includes(originTab)) return false; // Retailer: solo AP
476
+ var originTab = origin[state.active_tab];
477
+ var isRetailerUser = (user === null || user === void 0 ? void 0 : user.is_retailer) === 1;
478
+ var validStatuses = ["AA", "AP", "R", "CA", "RCA"];
479
+ if (!validStatuses.includes(currentStatus)) return false;
480
+ var validOrigins = ["RequestWithContentoh", "RequestWithoutContentoh", "Contentoh"];
481
+ if (!validOrigins.includes(originTab)) return false; // Retailer: solo AP
472
482
 
473
- if (isRetailerUser) {
474
- return currentStatus === "AP";
475
- } // No retailer
483
+ if (isRetailerUser) {
484
+ return currentStatus === "AP";
485
+ } // No retailer
476
486
 
477
487
 
478
- var hasNoOrder = !state.product.id_order && !state.product.orderId;
479
- var condition = originTab === "RequestWithoutContentoh" && (["R", "CA"].includes(currentStatus) || currentStatus === "RCA" && hasNoOrder) || ["RequestWithContentoh", "Contentoh"].includes(originTab) && currentStatus === "AA";
480
- return condition;
488
+ var hasNoOrder = !state.product.id_order && !state.product.orderId;
489
+ var condition = originTab === "RequestWithoutContentoh" && (["R", "CA"].includes(currentStatus) || currentStatus === "RCA" && hasNoOrder) || ["RequestWithContentoh", "Contentoh"].includes(originTab) && currentStatus === "AA";
490
+ return condition;
491
+ } catch (error) {
492
+ return false;
493
+ }
481
494
  };
482
495
 
483
496
  var canShowSaveButton = function canShowSaveButton(version_status) {
@@ -495,10 +508,10 @@ var ProviderProductEditionView = function ProviderProductEditionView(_ref) {
495
508
 
496
509
  var getStatusByCurrentServiceAndRetailer = function getStatusByCurrentServiceAndRetailer() {
497
510
  var statusByRetailer = state.product.statusByRetailer;
498
- if (!statusByRetailer) return "-";
511
+ if (!statusByRetailer || Object.keys(statusByRetailer).length === 0) return "-";
499
512
  var currentService = (0, _utils.getConceptByTab)(state.active_tab);
500
513
  var currentRetailer = state.active_retailer.id_retailer;
501
- var currentStatus = statusByRetailer[currentRetailer][currentService] || "ERR";
514
+ var currentStatus = statusByRetailer[currentRetailer][currentService] || "N/S";
502
515
  return currentStatus;
503
516
  };
504
517
 
@@ -819,7 +832,7 @@ var ProviderProductEditionView = function ProviderProductEditionView(_ref) {
819
832
  _context3.prev = 8;
820
833
 
821
834
  if (!result) {
822
- _context3.next = 23;
835
+ _context3.next = 22;
823
836
  break;
824
837
  }
825
838
 
@@ -835,13 +848,7 @@ var ProviderProductEditionView = function ProviderProductEditionView(_ref) {
835
848
  case 14:
836
849
  res = _context3.sent;
837
850
  newStatuses = JSON.parse(res.data.body);
838
- serviceStatus = newStatuses.newServiceStatus[articleId]["".concat(concept, "Status")];
839
- console.log({
840
- product: state.product,
841
- newStatuses: newStatuses,
842
- serviceStatus: serviceStatus,
843
- servicesData: state.services_data
844
- }); // Actualizar el producto con los nuevos estados
851
+ serviceStatus = newStatuses.newServiceStatus[articleId]["".concat(concept, "Status")]; // Actualizar el producto con los nuevos estados
845
852
 
846
853
  updatedProduct = (0, _objectSpread4.default)((0, _objectSpread4.default)({}, state.product), {}, {
847
854
  statusByRetailer: (0, _objectSpread4.default)((0, _objectSpread4.default)({}, state.product.statusByRetailer), {}, (0, _defineProperty2.default)({}, retailerId, (0, _objectSpread4.default)((0, _objectSpread4.default)({}, state.product.statusByRetailer[retailerId]), {}, (0, _defineProperty2.default)({}, concept, (_newStatuses$newStatu = newStatuses === null || newStatuses === void 0 ? void 0 : newStatuses.newStatus) !== null && _newStatuses$newStatu !== void 0 ? _newStatuses$newStatu : serviceStatus))))
@@ -873,12 +880,12 @@ var ProviderProductEditionView = function ProviderProductEditionView(_ref) {
873
880
  }
874
881
  });
875
882
 
876
- case 23:
877
- _context3.next = 29;
883
+ case 22:
884
+ _context3.next = 28;
878
885
  break;
879
886
 
880
- case 25:
881
- _context3.prev = 25;
887
+ case 24:
888
+ _context3.prev = 24;
882
889
  _context3.t0 = _context3["catch"](8);
883
890
  console.error("Error sending evaluation:", _context3.t0);
884
891
  dispatch({
@@ -891,20 +898,20 @@ var ProviderProductEditionView = function ProviderProductEditionView(_ref) {
891
898
  }
892
899
  });
893
900
 
894
- case 29:
895
- _context3.prev = 29;
901
+ case 28:
902
+ _context3.prev = 28;
896
903
  dispatch({
897
904
  type: "SET_SAVING",
898
905
  payload: false
899
906
  });
900
- return _context3.finish(29);
907
+ return _context3.finish(28);
901
908
 
902
- case 32:
909
+ case 31:
903
910
  case "end":
904
911
  return _context3.stop();
905
912
  }
906
913
  }
907
- }, _callee3, null, [[8, 25, 29, 32]]);
914
+ }, _callee3, null, [[8, 24, 28, 31]]);
908
915
  }));
909
916
 
910
917
  return function sendEvaluation(_x2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentoh-components-library",
3
- "version": "21.5.96",
3
+ "version": "21.5.98",
4
4
  "dependencies": {
5
5
  "@aws-amplify/auth": "^4.5.3",
6
6
  "@aws-amplify/datastore": "^3.11.0",
@@ -153,26 +153,35 @@ const ProviderProductEditionView = ({
153
153
  type: "SET_PRODUCT",
154
154
  payload: productNormalized,
155
155
  });
156
- dispatch({
157
- type: "SET_ACTIVE_RETAILER",
158
- payload: productNormalized.categoryRetailer[0],
159
- });
160
-
161
- const firstRetailerStatus =
162
- productNormalized.statusByRetailer[
163
- productNormalized.categoryRetailerInOrder[0].id_retailer
164
- ];
165
- const initialTab = firstRetailerStatus.description
166
- ? "Descripción"
167
- : firstRetailerStatus.datasheet
168
- ? "Ficha técnica"
169
- : firstRetailerStatus.images
170
- ? "Imágenes"
171
- : "Imágenes";
172
- dispatch({
173
- type: "SET_ACTIVE_TAB",
174
- payload: initialTab,
175
- });
156
+ if (
157
+ productNormalized.categoryRetailerInOrder.length > 0 &&
158
+ productNormalized.statusByRetailer
159
+ ) {
160
+ dispatch({
161
+ type: "SET_ACTIVE_RETAILER",
162
+ payload: productNormalized.categoryRetailerInOrder[0],
163
+ });
164
+ const firstRetailerStatus =
165
+ productNormalized.statusByRetailer[
166
+ productNormalized.categoryRetailerInOrder[0].id_retailer
167
+ ];
168
+ const initialTab = firstRetailerStatus.description
169
+ ? "Descripción"
170
+ : firstRetailerStatus.datasheet
171
+ ? "Ficha técnica"
172
+ : firstRetailerStatus.images
173
+ ? "Imágenes"
174
+ : "Imágenes";
175
+ dispatch({
176
+ type: "SET_ACTIVE_TAB",
177
+ payload: initialTab,
178
+ });
179
+ } else {
180
+ dispatch({
181
+ type: "SET_ACTIVE_RETAILER",
182
+ payload: productNormalized.categoryRetailer[0],
183
+ });
184
+ }
176
185
  } catch (error) {
177
186
  console.log("Error setting product data: ", error);
178
187
  }
@@ -216,7 +225,7 @@ const ProviderProductEditionView = ({
216
225
  id_category,
217
226
  version,
218
227
  token,
219
- id_retailer
228
+ id_retailer,
220
229
  ),
221
230
  getPercentage({ data, headers }),
222
231
  getServicesData({
@@ -230,14 +239,14 @@ const ProviderProductEditionView = ({
230
239
  const percentages =
231
240
  JSON.parse(percentageRes?.[0]?.body)?.[0]?.relations ?? [];
232
241
 
233
- const orderMap = services[2].inputsByRetailer
234
- .flat()
235
- .reduce((acc, item) => {
242
+ const orderMap =
243
+ services[2].inputsByRetailer ??
244
+ [].flat().reduce((acc, item) => {
236
245
  acc[item.id_image] = item.order;
237
246
  return acc;
238
247
  }, {});
239
248
 
240
- const orderedValues = [...services[2].values].sort((a, b) => {
249
+ const orderedValues = [...(services[2].values ?? [])].sort((a, b) => {
241
250
  const orderA = orderMap[a.image_id] ?? Number.MAX_SAFE_INTEGER;
242
251
  const orderB = orderMap[b.image_id] ?? Number.MAX_SAFE_INTEGER;
243
252
 
@@ -286,7 +295,7 @@ const ProviderProductEditionView = ({
286
295
  dispatch({
287
296
  type: "SET_ACTIVE_PERCENTAGES",
288
297
  payload: percentages.find(
289
- ({ id_retailer: rId }) => rId === id_retailer
298
+ ({ id_retailer: rId }) => rId === id_retailer,
290
299
  ),
291
300
  });
292
301
  } catch (error) {
@@ -306,7 +315,7 @@ const ProviderProductEditionView = ({
306
315
  state.product?.percentages,
307
316
  state.product?.version,
308
317
  state.active_retailer,
309
- token
318
+ token,
310
319
  ]);
311
320
 
312
321
  // Actualizador de campos del ui para que coincidan con el retailer activo
@@ -368,50 +377,51 @@ const ProviderProductEditionView = ({
368
377
  const canShowValidationButtons = () => {
369
378
  if (!state.product?.statusByRetailer) return false;
370
379
 
371
- const currentService = getConceptByTab(state.active_tab);
372
- // const currentStatus = state.product[`${currentService}_status`];
373
- const currentRetailer = state.active_retailer.id_retailer;
374
-
375
- //Información del servicio de la cadena seleccionada
376
- const { status: currentStatus } = state.services_data.find(
377
- (service) =>
378
- service.service === currentService &&
379
- service.id_retailer === currentRetailer,
380
- );
380
+ try {
381
+ const currentService = getConceptByTab(state.active_tab);
382
+ // const currentStatus = state.product[`${currentService}_status`];
383
+ const currentRetailer = state.active_retailer.id_retailer;
384
+
385
+ //Información del servicio de la cadena seleccionada
386
+ const { status: currentStatus } = state.services_data.find(
387
+ (service) =>
388
+ service.service === currentService &&
389
+ service.id_retailer === currentRetailer,
390
+ );
381
391
 
382
- const originTab = origin[state.active_tab];
383
- const isRetailerUser = user?.is_retailer === 1;
392
+ const originTab = origin[state.active_tab];
393
+ const isRetailerUser = user?.is_retailer === 1;
384
394
 
385
- const validStatuses = ["AA", "AP", "R", "CA", "RCA"];
386
- if (!validStatuses.includes(currentStatus)) return false;
395
+ const validStatuses = ["AA", "AP", "R", "CA", "RCA"];
396
+ if (!validStatuses.includes(currentStatus)) return false;
387
397
 
388
- const validOrigins = [
389
- "RequestWithContentoh",
390
- "RequestWithoutContentoh",
391
- "Contentoh",
392
- ];
398
+ const validOrigins = [
399
+ "RequestWithContentoh",
400
+ "RequestWithoutContentoh",
401
+ "Contentoh",
402
+ ];
393
403
 
394
- if (!validOrigins.includes(originTab)) return false;
404
+ if (!validOrigins.includes(originTab)) return false;
395
405
 
396
- // Retailer: solo AP
397
- if (isRetailerUser) {
398
- return currentStatus === "AP";
399
- }
406
+ // Retailer: solo AP
407
+ if (isRetailerUser) {
408
+ return currentStatus === "AP";
409
+ }
400
410
 
401
- // No retailer
402
- const hasNoOrder = !state.product.id_order && !state.product.orderId;
411
+ // No retailer
412
+ const hasNoOrder = !state.product.id_order && !state.product.orderId;
403
413
 
404
- const condition =
405
- (
406
- originTab === "RequestWithoutContentoh" && (
407
- ["R", "CA"].includes(currentStatus) || (currentStatus === "RCA" && hasNoOrder)
408
- )
409
- ) ||
410
- (
411
- ["RequestWithContentoh", "Contentoh"].includes(originTab) && currentStatus === "AA"
412
- )
414
+ const condition =
415
+ (originTab === "RequestWithoutContentoh" &&
416
+ (["R", "CA"].includes(currentStatus) ||
417
+ (currentStatus === "RCA" && hasNoOrder))) ||
418
+ (["RequestWithContentoh", "Contentoh"].includes(originTab) &&
419
+ currentStatus === "AA");
413
420
 
414
- return condition;
421
+ return condition;
422
+ } catch (error) {
423
+ return false;
424
+ }
415
425
  };
416
426
 
417
427
  const canShowSaveButton = (version_status) => {
@@ -428,13 +438,14 @@ const ProviderProductEditionView = ({
428
438
 
429
439
  const getStatusByCurrentServiceAndRetailer = () => {
430
440
  const { statusByRetailer } = state.product;
431
- if (!statusByRetailer) return "-";
441
+ if (!statusByRetailer || Object.keys(statusByRetailer).length === 0)
442
+ return "-";
432
443
 
433
444
  const currentService = getConceptByTab(state.active_tab);
434
445
  const currentRetailer = state.active_retailer.id_retailer;
435
446
 
436
447
  const currentStatus =
437
- statusByRetailer[currentRetailer][currentService] || "ERR";
448
+ statusByRetailer[currentRetailer][currentService] || "N/S";
438
449
  return currentStatus;
439
450
  };
440
451
 
@@ -444,7 +455,7 @@ const ProviderProductEditionView = ({
444
455
  name: e?.name,
445
456
  required: e?.required,
446
457
  active: state.images_values?.values?.some(
447
- (value) => value?.image_id === e?.id
458
+ (value) => value?.image_id === e?.id,
448
459
  ),
449
460
  }));
450
461
  const imageType = state.images_values?.imageType?.map((e) => ({
@@ -455,7 +466,7 @@ const ProviderProductEditionView = ({
455
466
  (e) => ({
456
467
  value: e?.id,
457
468
  name: e?.name,
458
- })
469
+ }),
459
470
  );
460
471
 
461
472
  return state.images_values?.values?.map((image, index) => (
@@ -711,15 +722,13 @@ const ProviderProductEditionView = ({
711
722
  headers: {
712
723
  Authorization: token,
713
724
  },
714
- }
725
+ },
715
726
  );
716
727
 
717
728
  const newStatuses = JSON.parse(res.data.body);
718
729
  const serviceStatus =
719
730
  newStatuses.newServiceStatus[articleId][`${concept}Status`];
720
731
 
721
- console.log({product: state.product, newStatuses, serviceStatus, servicesData: state.services_data});
722
-
723
732
  // Actualizar el producto con los nuevos estados
724
733
  const updatedProduct = {
725
734
  ...state.product,
@@ -732,9 +741,12 @@ const ProviderProductEditionView = ({
732
741
  },
733
742
  };
734
743
 
735
- const updatedServicesData = state.services_data?.map(service => ({
744
+ const updatedServicesData = state.services_data?.map((service) => ({
736
745
  ...service,
737
- status: service?.id_retailer === retailerId && service?.service === concept ? (newStatuses?.newStatus ?? serviceStatus) : service?.status
746
+ status:
747
+ service?.id_retailer === retailerId && service?.service === concept
748
+ ? newStatuses?.newStatus ?? serviceStatus
749
+ : service?.status,
738
750
  }));
739
751
 
740
752
  dispatch({ type: "SET_SERVICES_DATA", payload: updatedServicesData });
@@ -968,7 +980,7 @@ const ProviderProductEditionView = ({
968
980
  headers: {
969
981
  Authorization: token,
970
982
  },
971
- })
983
+ }),
972
984
  );
973
985
  });
974
986
 
@@ -1013,7 +1025,7 @@ const ProviderProductEditionView = ({
1013
1025
  ArticleId: updatedProduct.id_article,
1014
1026
  idCategory: updatedProduct.id_category,
1015
1027
  product: updatedProduct,
1016
- })
1028
+ }),
1017
1029
  );
1018
1030
 
1019
1031
  // Mostrar modal de éxito
@@ -1079,10 +1091,7 @@ const ProviderProductEditionView = ({
1079
1091
  if (state.loading || !state.services || !state.product) return <Loading />;
1080
1092
 
1081
1093
  return (
1082
- <AiProductEditionProvider
1083
- isCreatorsEdition={false}
1084
- state={state}
1085
- >
1094
+ <AiProductEditionProvider isCreatorsEdition={false} state={state}>
1086
1095
  <Container headerTop={headerTop}>
1087
1096
  {showVersionSelector && (
1088
1097
  <VersionSelector