contentoh-components-library 21.1.53 → 21.1.56

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.
@@ -208,6 +208,9 @@ export const ProviderProductEdition = ({
208
208
  const [modalViewTextArea, setModalViewTextArea] = useState(false);
209
209
  const [socketType, setSocketType] = useState(null);
210
210
  const [saving, setSaving] = useState(loading);
211
+ const [retailerStatus, setRetailerStatus] = useState(
212
+ product.statusByRetailer
213
+ );
211
214
 
212
215
  useEffect(() => {
213
216
  checkAll && setSelectedImages(images.values);
@@ -233,11 +236,8 @@ export const ProviderProductEdition = ({
233
236
  );
234
237
  }
235
238
 
236
- //setActiveRetailer(product?.retailers[0]);
237
- setImages({
238
- action: "init",
239
- init: services[2],
240
- });
239
+ // setActiveRetailer(product?.retailers[0]);
240
+ setImages({ action: "init", init: services[2] });
241
241
  if (services[2]?.values?.length > 0) setActiveImage(0);
242
242
 
243
243
  getPercentage({ data: [product] }).then((res) => setPercentages(res));
@@ -256,10 +256,11 @@ export const ProviderProductEdition = ({
256
256
  }&end=true`
257
257
  );
258
258
  const parsedResponse = JSON.parse(servicesResponse?.data?.body).data;
259
+ const retailerResponse = parsedResponse?.map((srv) => srv.id_retailer);
259
260
  let retailers = product.retailers || product.retailersAvailable;
260
- let active = retailers?.filter((retailer) =>
261
- parsedResponse?.map((srv) => srv.id_retailer).includes(retailer.id)
262
- )[0];
261
+ let active = retailers?.find((retailer) =>
262
+ retailerResponse.includes(retailer.id)
263
+ );
263
264
  !activeRetailer.id && setActiveRetailer(active ? active : retailers[0]);
264
265
  setServicesData(parsedResponse);
265
266
  }
@@ -280,15 +281,15 @@ export const ProviderProductEdition = ({
280
281
  if (revision && currentService === "AP") return true;
281
282
  } else {
282
283
  const { product } = productEdit;
283
- if (
284
- orgn === "Contentoh" ||
285
- (["RECEIVED", "IN_PROGRESS"].includes(currentService) &&
286
- orgn === "RequestWithoutContentoh") ||
287
- (currentService === "AA" && orgn === "RequestWithContentoh") ||
288
- (currentService === "RC" &&
289
- orgn === "RequestWithoutContentoh" &&
290
- (!product.id_order || !product.orderId))
291
- )
284
+ const isRequestWithoutContentoh =
285
+ orgn === "RequestWithoutContentoh" &&
286
+ (["R", "CA"].includes(currentService) ||
287
+ (currentService === "RCA" &&
288
+ (!product.id_order || !product.orderId)));
289
+ const isRequestWithContentoh =
290
+ orgn === "RequestWithContentoh" && currentService === "AA";
291
+ const isContentoh = orgn === "Contentoh" && currentService === "AA";
292
+ if (isContentoh || isRequestWithoutContentoh || isRequestWithContentoh)
292
293
  return true;
293
294
  }
294
295
  }
@@ -305,26 +306,26 @@ export const ProviderProductEdition = ({
305
306
  setInCart(arr.some((e) => e.articleId === product.id_article));
306
307
  };
307
308
 
308
- useEffect(async () => {
309
+ useEffect(() => {
309
310
  sessionStorage.setItem("user", JSON.stringify(user));
310
311
  loadData();
311
312
  getCart();
312
- setUserGroups(await fetchUsers(token));
313
+ fetchUsers(token).then((res) => setUserGroups(res));
313
314
  let arr = [];
315
+ // ?? Que sentido tiene verificar los roles de colaborador en la app de proveedor
314
316
  switch (user.id_role) {
315
317
  case 7:
316
318
  case 8:
317
- arr = ["IN_PROGRESS", "RF", "RA"];
319
+ arr = ["CA", "RC", "RA"];
318
320
  break;
319
321
  case 4:
320
322
  case 5:
321
- arr = ["RF", "AF", "AA", "AP", "AC"];
323
+ arr = ["RC", "AC", "AA", "AP", "ACA"];
322
324
  break;
323
325
  case 6:
324
- arr = ["RP", "RC", "AF"];
326
+ arr = ["RP", "RCA", "AC"];
325
327
  break;
326
328
  default:
327
- arr = [];
328
329
  break;
329
330
  }
330
331
  setStatusArray(arr);
@@ -342,9 +343,9 @@ export const ProviderProductEdition = ({
342
343
  const productTemp = product;
343
344
  const retailers = productTemp?.retailersAvailable || productTemp?.retailers;
344
345
  retailers?.forEach((retailer) => {
345
- retailer["percentage"] = percentages?.filter(
346
+ retailer["percentage"] = percentages?.find(
346
347
  (percent) => retailer?.id === percent?.id_retailer
347
- )[0]?.percentage;
348
+ )?.percentage;
348
349
  });
349
350
 
350
351
  setProduct(productTemp);
@@ -420,7 +421,7 @@ export const ProviderProductEdition = ({
420
421
  };
421
422
  if (product?.orderId) dataObject["orderId"] = product?.orderId;
422
423
  try {
423
- await axios.put(
424
+ const res = await axios.put(
424
425
  `${process.env.REACT_APP_ARTICLE_DATA_ENDPOINT}?description=true&version=${version}`,
425
426
  dataObject,
426
427
  {
@@ -429,8 +430,10 @@ export const ProviderProductEdition = ({
429
430
  },
430
431
  }
431
432
  );
432
- setMessage("Descripciones guardadas con éxito");
433
- loadData();
433
+ if (res.data.statusCode === 200) {
434
+ setMessage("Descripciones guardadas con éxito");
435
+ await loadData();
436
+ }
434
437
  } catch (error) {
435
438
  console.log(error);
436
439
  }
@@ -453,8 +456,10 @@ export const ProviderProductEdition = ({
453
456
  },
454
457
  }
455
458
  );
456
- setMessage("Fichas técnicas guardadas");
457
- loadData();
459
+ if (res.data.statusCode === 200) {
460
+ setMessage("Fichas técnicas guardadas");
461
+ await loadData();
462
+ }
458
463
  } catch (error) {
459
464
  console.log(error);
460
465
  }
@@ -552,7 +557,7 @@ export const ProviderProductEdition = ({
552
557
  return e;
553
558
  });
554
559
  try {
555
- await axios.put(
560
+ const res = await axios.put(
556
561
  `${process.env.REACT_APP_ARTICLE_DATA_ENDPOINT}?image=true&version=${version}`,
557
562
  dataImages,
558
563
  {
@@ -561,9 +566,11 @@ export const ProviderProductEdition = ({
561
566
  },
562
567
  }
563
568
  );
564
- setMessage("Imágenes guardadas con éxito");
565
- sessionStorage.removeItem("imagesList");
566
- loadData();
569
+ if (res.data.statusCode === 200) {
570
+ setMessage("Imágenes guardadas con éxito");
571
+ sessionStorage.removeItem("imagesList");
572
+ await loadData();
573
+ }
567
574
  } catch (error) {
568
575
  console.log(error);
569
576
  }
@@ -665,12 +672,12 @@ export const ProviderProductEdition = ({
665
672
  },
666
673
  ],
667
674
  concept: concept,
668
- [`${assignationType}Id`]: assignationId,
675
+ userId: assignationId,
669
676
  };
670
- axios({
677
+ await axios({
671
678
  method: "post",
672
679
  url: process.env.REACT_APP_ASSIGNATIONS_ENDPOINT,
673
- data: data,
680
+ data,
674
681
  headers: {
675
682
  Authorization: token,
676
683
  },
@@ -688,7 +695,7 @@ export const ProviderProductEdition = ({
688
695
  serv = serv.filter((f) => f.id_retailer === activeRetailer.id);
689
696
  }
690
697
  const statusArray =
691
- user.is_retailer === 1 ? ["AC", "RC"] : ["AP", "RP", "AC"];
698
+ user.is_retailer === 1 ? ["ACA", "RCA"] : ["AP", "RP", "ACA"];
692
699
  return (
693
700
  serv.length > 0 && serv.every((item) => statusArray.includes(item.status))
694
701
  );
@@ -787,18 +794,11 @@ export const ProviderProductEdition = ({
787
794
  }
788
795
  };
789
796
 
790
- const getSectionStatus = () => {
791
- const concept = getConcept(activeTab);
792
- return ["AA", "AP", "R", "CA", "RCA"].includes(
793
- productEdit.product[`${concept}_status`]
794
- );
795
- };
796
-
797
797
  const confirmStatusComplete = () => {
798
798
  const { datasheet_status, description_status, images_status } = product;
799
799
  const completionStates =
800
800
  user.is_retailer === 1
801
- ? ["AC", "Evaluated", "NS"]
801
+ ? ["ACA", "Evaluated", "NS"]
802
802
  : ["AP", "Evaluated", "NS"];
803
803
  const dsEvaluated = completionStates.includes(datasheet_status);
804
804
  const descsEvaluated = completionStates.includes(description_status);
@@ -868,13 +868,11 @@ export const ProviderProductEdition = ({
868
868
  setProduct(productTemp);
869
869
  sessionStorage.setItem("productSelected", JSON.stringify(productTemp));
870
870
  setOrigin((prev) => ({ ...prev, [concept]: status }));
871
- await loadData();
872
871
  }
873
872
  } catch (err) {
874
873
  console.log(err);
875
874
  }
876
875
  loadData();
877
- showSurvey && showSurvey(confirmStatusComplete());
878
876
  };
879
877
 
880
878
  const validateAll = async (result) => {
@@ -920,13 +918,24 @@ export const ProviderProductEdition = ({
920
918
 
921
919
  await Promise.all(sendAll);
922
920
  const productTemp = product;
923
- productTemp.article_status = `${result}C`;
921
+ productTemp.article_status = `${result}CA`;
924
922
  productTemp.datasheet_status =
925
- productTemp.datasheet_status === "NA" ? "NA" : `${result}C`;
923
+ productTemp.datasheet_status === "NA" ? "NA" : `${result}CA`;
926
924
  productTemp.description_status =
927
- productTemp.description_status === "NA" ? "NA" : `${result}C`;
925
+ productTemp.description_status === "NA" ? "NA" : `${result}CA`;
928
926
  productTemp.images_status =
929
- productTemp.images_status === "NA" ? "NA" : `${result}C`;
927
+ productTemp.images_status === "NA" ? "NA" : `${result}CA`;
928
+
929
+ const retailerStatusCopy = { ...retailerStatus };
930
+ Object.keys(retailerStatusCopy).forEach((key) => {
931
+ conceptArray.forEach((concept) => {
932
+ if (retailerStatusCopy[key][concept]) {
933
+ retailerStatusCopy[key][concept] = `${result}CA`;
934
+ }
935
+ });
936
+ });
937
+ setRetailerStatus(retailerStatusCopy);
938
+ productTemp.statusByRetailer = retailerStatusCopy;
930
939
  setProduct(productTemp);
931
940
  sessionStorage.setItem("productSelected", JSON.stringify(productTemp));
932
941
  setProductEdit({
@@ -943,7 +952,7 @@ export const ProviderProductEdition = ({
943
952
  })
944
953
  );
945
954
 
946
- loadData();
955
+ await loadData();
947
956
  } catch (error) {
948
957
  console.log(error);
949
958
  }
@@ -964,7 +973,7 @@ export const ProviderProductEdition = ({
964
973
  },
965
974
  });
966
975
  const prod = productEdit;
967
- const statusComplete = user.is_retailer ? `${result}C` : `${result}P`;
976
+ const statusComplete = user.is_retailer ? `${result}CA` : `${result}P`;
968
977
  prod.product.datasheet_status = statusComplete;
969
978
  prod.product.description_status = statusComplete;
970
979
  prod.product.images_status = statusComplete;
@@ -973,17 +982,22 @@ export const ProviderProductEdition = ({
973
982
  sessionStorage.setItem("productEdit", JSON.stringify(prod));
974
983
  setProduct(prod);
975
984
  setShowGenericModal && setShowGenericModal(false);
976
- loadData();
985
+ await loadData();
986
+ };
987
+
988
+ const getSectionStatus = () => {
989
+ const concept = getConcept(activeTab);
990
+ return ["AA", "AP", "R", "CA", "RCA"].includes(
991
+ productEdit.product[`${concept}_status`]
992
+ );
977
993
  };
978
994
 
979
995
  const enableActions = (versionStatus) => {
980
996
  try {
981
- const userIsRetailer = user.is_retailer;
982
-
983
- if (userIsRetailer) return false;
997
+ if (user.is_retailer) return false;
984
998
 
985
999
  if (versionStatus) {
986
- return ["AP", "AC", "RC", null].includes(versionStatus);
1000
+ return ["AP", "ACA", "RCA", null].includes(versionStatus);
987
1001
  }
988
1002
  return true;
989
1003
  } catch (err) {
@@ -1073,23 +1087,21 @@ export const ProviderProductEdition = ({
1073
1087
  },
1074
1088
  }));
1075
1089
  setShowGenericModal(true);
1076
- } else {
1077
- if (user.is_retailer) {
1078
- if (product.id_order || product.orderId) {
1079
- validateAll("A");
1080
- } else {
1081
- setDataGenericModal((prev) => ({
1082
- ...prev,
1083
- button2: {
1084
- name: "Continuar",
1085
- action: () => evaluationToRetailer("A"),
1086
- },
1087
- }));
1088
- setShowGenericModal(true);
1089
- }
1090
- } else {
1090
+ } else if (user.is_retailer) {
1091
+ if (product.id_order || product.orderId) {
1091
1092
  validateAll("A");
1093
+ } else {
1094
+ setDataGenericModal((prev) => ({
1095
+ ...prev,
1096
+ button2: {
1097
+ name: "Continuar",
1098
+ action: () => evaluationToRetailer("A"),
1099
+ },
1100
+ }));
1101
+ setShowGenericModal(true);
1092
1102
  }
1103
+ } else {
1104
+ validateAll("A");
1093
1105
  }
1094
1106
  }}
1095
1107
  rejectAll={() => {
@@ -1099,25 +1111,23 @@ export const ProviderProductEdition = ({
1099
1111
  (!product.id_order || !product.orderId)
1100
1112
  ) {
1101
1113
  return;
1102
- } else {
1103
- if (user.is_retailer) {
1104
- if (product.id_order || product.orderId) {
1105
- validateAll("R");
1106
- setModalViewError(true);
1107
- } else {
1108
- setDataGenericModal((prev) => ({
1109
- ...prev,
1110
- button2: {
1111
- name: "Continuar",
1112
- action: () => evaluationToRetailer("R"),
1113
- },
1114
- }));
1115
- setShowGenericModal(true);
1116
- }
1117
- } else {
1114
+ } else if (user.is_retailer) {
1115
+ if (product.id_order || product.orderId) {
1118
1116
  validateAll("R");
1119
1117
  setModalViewError(true);
1118
+ } else {
1119
+ setDataGenericModal((prev) => ({
1120
+ ...prev,
1121
+ button2: {
1122
+ name: "Continuar",
1123
+ action: () => evaluationToRetailer("R"),
1124
+ },
1125
+ }));
1126
+ setShowGenericModal(true);
1120
1127
  }
1128
+ } else {
1129
+ validateAll("R");
1130
+ setModalViewError(true);
1121
1131
  }
1122
1132
  }}
1123
1133
  approve={() => {
@@ -1134,23 +1144,21 @@ export const ProviderProductEdition = ({
1134
1144
  },
1135
1145
  }));
1136
1146
  setShowGenericModal(true);
1137
- } else {
1138
- if (user.is_retailer) {
1139
- if (product.id_order || product.orderId) {
1140
- sendEvaluation("A");
1141
- } else {
1142
- setDataGenericModal((prev) => ({
1143
- ...prev,
1144
- button2: {
1145
- name: "Continuar",
1146
- action: () => evaluationToRetailer("A"),
1147
- },
1148
- }));
1149
- setShowGenericModal(true);
1150
- }
1151
- } else {
1147
+ } else if (user.is_retailer) {
1148
+ if (product.id_order || product.orderId) {
1152
1149
  sendEvaluation("A");
1150
+ } else {
1151
+ setDataGenericModal((prev) => ({
1152
+ ...prev,
1153
+ button2: {
1154
+ name: "Continuar",
1155
+ action: () => evaluationToRetailer("A"),
1156
+ },
1157
+ }));
1158
+ setShowGenericModal(true);
1153
1159
  }
1160
+ } else {
1161
+ sendEvaluation("A");
1154
1162
  }
1155
1163
  }}
1156
1164
  reject={() => {
@@ -1160,33 +1168,33 @@ export const ProviderProductEdition = ({
1160
1168
  (!product.id_order || !product.orderId)
1161
1169
  ) {
1162
1170
  return;
1163
- } else {
1164
- if (user.is_retailer) {
1165
- if (product.id_order || product.orderId) {
1166
- sendEvaluation("R");
1167
- setModalViewError(true);
1168
- } else {
1169
- setDataGenericModal((prev) => ({
1170
- ...prev,
1171
- button2: {
1172
- name: "Continuar",
1173
- action: () => evaluationToRetailer("R"),
1174
- },
1175
- }));
1176
- setShowGenericModal(true);
1177
- }
1178
- } else {
1171
+ } else if (user.is_retailer) {
1172
+ if (product.id_order || product.orderId) {
1179
1173
  sendEvaluation("R");
1180
1174
  setModalViewError(true);
1175
+ } else {
1176
+ setDataGenericModal((prev) => ({
1177
+ ...prev,
1178
+ button2: {
1179
+ name: "Continuar",
1180
+ action: () => evaluationToRetailer("R"),
1181
+ },
1182
+ }));
1183
+ setShowGenericModal(true);
1181
1184
  }
1185
+ } else {
1186
+ sendEvaluation("R");
1187
+ setModalViewError(true);
1182
1188
  }
1183
1189
  }}
1184
1190
  />
1185
1191
  <FullTabsMenu
1186
1192
  tabsSections={tabsSections}
1187
1193
  status={
1188
- product[`${getConcept(activeTab)}_status`] ||
1189
- product?.version_status
1194
+ activeRetailer.id
1195
+ ? retailerStatus[activeRetailer?.id][getConcept(activeTab)] ||
1196
+ "NS"
1197
+ : "-"
1190
1198
  }
1191
1199
  activeTab={activeTab}
1192
1200
  setActiveTab={setActiveTab}
@@ -1329,56 +1337,44 @@ export const ProviderProductEdition = ({
1329
1337
  />
1330
1338
  </div>
1331
1339
  )}
1332
- <Button
1333
- buttonType={
1334
- evaluationComplete(activeTab) &&
1335
- (productEdit.product.id_order || productEdit.product.orderId)
1336
- ? "general-green-button"
1337
- : "general-button-disabled"
1338
- }
1339
- label={"Enviar evaluación"}
1340
- onClick={() => {
1341
- //setModalSent(true);
1342
- sendEvaluation();
1343
- setMessage(`¡Evaluación de ${activeTab} completada!`);
1344
- }}
1345
- />
1346
1340
  </div>
1347
- ) : revision ? null : (
1348
- <div className="required-inputs-message">
1349
- <div>
1350
- <p>
1351
- Los atributos son requeridos por las plataformas de las
1352
- cadenas, es muy importante completar los campos requeridos ya
1353
- que pueden rechazar el producto por falta de información.
1354
- </p>
1341
+ ) : (
1342
+ !revision && (
1343
+ <div className="required-inputs-message">
1344
+ <div>
1345
+ <p>
1346
+ Los atributos son requeridos por las plataformas de las
1347
+ cadenas, es muy importante completar los campos requeridos
1348
+ ya que pueden rechazar el producto por falta de información.
1349
+ </p>
1350
+ </div>
1351
+ {inCart ? (
1352
+ <button type="button">
1353
+ <Link to="/checkout">
1354
+ <p>Articulo en carrito</p>
1355
+ <p>Ir a checkout</p>
1356
+ </Link>
1357
+ </button>
1358
+ ) : (
1359
+ <>
1360
+ <SliderToolTip
1361
+ infoIcon={InfoIcon}
1362
+ slidefront={slidefront}
1363
+ iconSize={"big-image"}
1364
+ slidePosition={"top-slide"}
1365
+ />
1366
+ <Button
1367
+ onClick={() => {
1368
+ setShowContentohRequestModal &&
1369
+ setShowContentohRequestModal(true);
1370
+ }}
1371
+ buttonType="general-default-button"
1372
+ label="Enviar a Content-oh!"
1373
+ />
1374
+ </>
1375
+ )}
1355
1376
  </div>
1356
- {inCart ? (
1357
- <button type="button">
1358
- <Link to="/checkout">
1359
- <p>Articulo en carrito</p>
1360
- <p>Ir a checkout</p>
1361
- </Link>
1362
- </button>
1363
- ) : (
1364
- <>
1365
- <SliderToolTip
1366
- infoIcon={InfoIcon}
1367
- slidefront={slidefront}
1368
- iconSize={"big-image"}
1369
- slidePosition={"top-slide"}
1370
- ></SliderToolTip>
1371
- <Button
1372
- onClick={() => {
1373
- setShowContentohRequestModal &&
1374
- setShowContentohRequestModal(true);
1375
- }}
1376
- buttonType="general-default-button"
1377
- label="Enviar a Content-oh!"
1378
- />
1379
- </>
1380
- )}
1381
- </div>
1377
+ )
1382
1378
  )}
1383
1379
  </div>
1384
1380
  </div>