contentoh-components-library 21.0.96 → 21.0.99

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.
@@ -45,6 +45,11 @@ const reducerImages = (state, action) => {
45
45
  case "changeAttrValue":
46
46
  attrForImgs[action.retailer][action.index].value = action.value;
47
47
  return { ...state, attrForImgs, values };
48
+ case "deleteImage":
49
+ values = values.filter(
50
+ (value) => action.selectedImages.indexOf(value) === -1
51
+ );
52
+ return { ...state, values };
48
53
  default:
49
54
  return state;
50
55
  }
@@ -153,6 +158,8 @@ export const RetailerProductEdition = ({
153
158
  const [retailerStatus, setRetailerStatus] = useState("-");
154
159
  const [statusArray, setStatusArray] = useState([]);
155
160
  const [socketType, setSocketType] = useState(null);
161
+ const [servicesStatus, setServicesStatus] = useState([]);
162
+ const [saving, setSaving] = useState(loading);
156
163
 
157
164
  useEffect(() => {
158
165
  checkAll && setSelectedImages(images.values);
@@ -166,18 +173,15 @@ export const RetailerProductEdition = ({
166
173
  );
167
174
  //Converts the data inside the datasheets object to array
168
175
  setServices(services);
176
+ getServices();
169
177
 
170
178
  //setActiveRetailer(product?.retailers[0]);
171
179
  setImages({
172
180
  action: "init",
173
- init: JSON.parse(sessionStorage.getItem("imagesList")) || services[2],
181
+ init: services[2],
174
182
  });
175
183
  if (services[2]?.values?.length > 0) setActiveImage(0);
176
184
 
177
- setActiveRetailer(
178
- product.retailers ? product.retailers[0] : product.retailersAvailable[0]
179
- );
180
-
181
185
  getPercentage({ data: [product] }).then((res) => setPercentages(res));
182
186
  setLoading(false);
183
187
  };
@@ -234,7 +238,13 @@ export const RetailerProductEdition = ({
234
238
  // getPercentage({ data: [product] }).then((res) =>
235
239
  // setPercentages(res)
236
240
  // );
237
- getServices();
241
+ setActiveRetailer((current) =>
242
+ current.id
243
+ ? current
244
+ : product.retailers
245
+ ? product.retailers[0]
246
+ : product.retailersAvailable[0]
247
+ );
238
248
  getComments();
239
249
  setUserGroups(await fetchUsers(token));
240
250
  let arr = [];
@@ -483,6 +493,7 @@ export const RetailerProductEdition = ({
483
493
  });
484
494
  }
485
495
  if (valid && duplicated?.length === 0) {
496
+ setLoading(true);
486
497
  try {
487
498
  data?.articleData?.forEach((e) => {
488
499
  e.uuid = uuidv4();
@@ -524,7 +535,6 @@ export const RetailerProductEdition = ({
524
535
 
525
536
  useEffect(async () => {
526
537
  if (imagesUploaded) {
527
- setLoading(true);
528
538
  dataImages.articleData = dataImages?.articleData.map((e) => {
529
539
  delete e.src;
530
540
  e.imageID = e.image_id;
@@ -561,6 +571,10 @@ export const RetailerProductEdition = ({
561
571
  product[`${getConcept(tab)}_status`] === "QF" ||
562
572
  product[`${getConcept(tab)}_status`] === "IN_PROGRESS";
563
573
 
574
+ const auditorUnvalidated = !["RA", "AA"].includes(
575
+ product[`${getConcept(tab)}_status`]
576
+ );
577
+
564
578
  switch (userId) {
565
579
  case 7:
566
580
  case 8:
@@ -582,7 +596,8 @@ export const RetailerProductEdition = ({
582
596
  case 6:
583
597
  return (
584
598
  statusArray.includes(product.status) &&
585
- servicesData.every((serv) => ["RA", "AA"].includes(serv.status))
599
+ servicesData.every((serv) => ["RA", "AA"].includes(serv.status)) &&
600
+ auditorUnvalidated
586
601
  );
587
602
  default:
588
603
  break;
@@ -660,7 +675,7 @@ export const RetailerProductEdition = ({
660
675
  Authorization: token,
661
676
  },
662
677
  });
663
- getServices();
678
+ //getServices();
664
679
  } else {
665
680
  const specialistDone =
666
681
  evalStatus === "RF" ||
@@ -723,8 +738,8 @@ export const RetailerProductEdition = ({
723
738
  Authorization: token,
724
739
  },
725
740
  });
726
- getServices();
727
741
  }
742
+ loadData();
728
743
  sessionStorage.setItem("productSelected", JSON.stringify(productTemp));
729
744
  setProduct(productTemp);
730
745
  } catch (error) {
@@ -836,7 +851,22 @@ export const RetailerProductEdition = ({
836
851
  });
837
852
 
838
853
  objetcTemp["Descripción"] = desInputsRequired;
839
- const requiredImages = services[2]?.inputs?.filter((e) => e.required);
854
+
855
+ const retailersRequested = [];
856
+ services[2]?.retailerMandatories?.forEach((retMan) =>
857
+ retMan.forEach((rm) => retailersRequested.push(rm))
858
+ );
859
+ const requiredImages = services[2]?.inputs?.filter(
860
+ (e) =>
861
+ e.required === 1 &&
862
+ retailersRequested.filter(
863
+ (ret) =>
864
+ ret.id_image === e.id &&
865
+ servicesData.filter((srv) => srv.id_retailer === ret.id_retailer)
866
+ .length > 0
867
+ ).length > 0
868
+ );
869
+
840
870
  let requiredCounter = 0;
841
871
  requiredImages?.forEach(
842
872
  (req) =>
@@ -985,7 +1015,6 @@ export const RetailerProductEdition = ({
985
1015
 
986
1016
  const deleteImages = () => {
987
1017
  setLoading(true);
988
- const imagesTemp = images;
989
1018
  const { values } = images;
990
1019
  const imgsInBack = [];
991
1020
 
@@ -997,12 +1026,10 @@ export const RetailerProductEdition = ({
997
1026
  (value) => selectedImages.indexOf(value) === -1
998
1027
  );
999
1028
 
1000
- imagesTemp.values = imgsLeft;
1001
-
1002
1029
  if (imgsInBack.length > 0) {
1003
1030
  const data = {
1004
1031
  articleId: product.article.id_article,
1005
- deleteImages: selectedImages,
1032
+ deleteImages: imgsInBack,
1006
1033
  };
1007
1034
  try {
1008
1035
  axios.put(
@@ -1016,8 +1043,22 @@ export const RetailerProductEdition = ({
1016
1043
  console.log(err);
1017
1044
  }
1018
1045
  }
1019
- sessionStorage.setItem("imagesList", JSON.stringify(imagesTemp));
1020
- loadData();
1046
+
1047
+ setImages({
1048
+ action: "deleteImage",
1049
+ selectedImages,
1050
+ });
1051
+
1052
+ getRequired([
1053
+ services[0],
1054
+ services[1],
1055
+ { ...services[2], values: imgsLeft },
1056
+ ]);
1057
+
1058
+ setTimeout(() => {
1059
+ setLoading(false);
1060
+ }, 500);
1061
+
1021
1062
  setMessage("");
1022
1063
  setComponentsArray([]);
1023
1064
  };
@@ -1093,6 +1134,10 @@ export const RetailerProductEdition = ({
1093
1134
  services.length > 0 && getRequired(services);
1094
1135
  }, [services, servicesData, activeTab]);
1095
1136
 
1137
+ useEffect(() => {
1138
+ setSaving(loading);
1139
+ }, [loading]);
1140
+
1096
1141
  return (
1097
1142
  <Container headerTop={headerTop}>
1098
1143
  <HeaderTop setHeaderTop={setHeaderTop} />
@@ -1123,6 +1168,7 @@ export const RetailerProductEdition = ({
1123
1168
  headerData={product}
1124
1169
  percent={activePercentage}
1125
1170
  activeRetailer={activeRetailer}
1171
+ servicesData={servicesData}
1126
1172
  setActiveRetailer={setActiveRetailer}
1127
1173
  sendToFacilitator={sendToFacilitator}
1128
1174
  approve={() => {
@@ -1146,17 +1192,21 @@ export const RetailerProductEdition = ({
1146
1192
  assig={assig[activeTab]}
1147
1193
  setAssignation={setAssignation}
1148
1194
  isRetailer={isRetailer}
1149
- showSaveButton={true}
1195
+ showSaveButton={userAssigned()}
1150
1196
  onClickSave={() => {
1151
1197
  switch (activeTab) {
1152
1198
  case "Descripción":
1153
- product?.description_status !== "NS" && saveDescriptions();
1199
+ !saving &&
1200
+ product?.description_status !== "NS" &&
1201
+ saveDescriptions();
1154
1202
  break;
1155
1203
  case "Ficha técnica":
1156
- product?.datasheet_status !== "NS" && saveDatasheets();
1204
+ !saving &&
1205
+ product?.datasheet_status !== "NS" &&
1206
+ saveDatasheets();
1157
1207
  break;
1158
1208
  case "Imágenes":
1159
- product?.images_status !== "NS" && updateImages();
1209
+ !saving && product?.images_status !== "NS" && updateImages();
1160
1210
  break;
1161
1211
 
1162
1212
  default:
@@ -194,5 +194,7 @@ export const getNewStatus = (statusArray) => {
194
194
  if (lookupString.includes("AA")) return "AA";
195
195
  if (lookupString.includes("AP")) return "AP";
196
196
  if (lookupString.includes("AC")) return "AC";
197
+ if (lookupString.includes("RECEIVED")) return "RECEIVED";
198
+ if (lookupString.includes("NA")) return "NA";
197
199
  return new Error("Status not found");
198
200
  };