contentoh-components-library 21.5.78 → 21.5.81
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.
- package/dist/ai/utils/compare-strings.js +43 -0
- package/dist/components/atoms/GeneralInput/index.js +64 -36
- package/dist/components/atoms/GeneralInput/styles.js +1 -1
- package/dist/components/atoms/InputFormatter/index.js +45 -21
- package/dist/components/atoms/InputFormatter/styles.js +1 -1
- package/dist/components/molecules/StatusAsignationInfo/index.js +11 -1
- package/dist/components/molecules/TagAndInput/index.js +110 -29
- package/dist/components/molecules/TagAndInput/styles.js +2 -2
- package/dist/components/organisms/InputGroup/index.js +22 -18
- package/dist/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +92 -785
- package/dist/components/pages/RetailerProductEdition/context/provider-product-edition.context.js +59 -260
- package/dist/components/pages/RetailerProductEdition/context/reducers/product.js +3 -41
- package/dist/components/pages/RetailerProductEdition/index.js +191 -123
- package/dist/contexts/AiProductEdition.js +179 -155
- package/package.json +1 -1
- package/src/ai/utils/compare-strings.js +43 -0
- package/src/components/atoms/GeneralInput/index.js +63 -42
- package/src/components/atoms/GeneralInput/styles.js +7 -0
- package/src/components/atoms/InputFormatter/index.js +51 -23
- package/src/components/atoms/InputFormatter/styles.js +62 -10
- package/src/components/molecules/StatusAsignationInfo/index.js +9 -1
- package/src/components/molecules/TagAndInput/index.js +113 -28
- package/src/components/molecules/TagAndInput/styles.js +48 -17
- package/src/components/organisms/FullTabsMenu/index.js +1 -1
- package/src/components/organisms/InputGroup/index.js +4 -0
- package/src/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +111 -832
- package/src/components/pages/RetailerProductEdition/context/provider-product-edition.context.jsx +3 -221
- package/src/components/pages/RetailerProductEdition/context/reducers/product.js +3 -43
- package/src/components/pages/RetailerProductEdition/index.js +17 -15
- package/src/contexts/AiProductEdition.jsx +138 -96
- package/src/ai/prompts/attribute.prompt.js +0 -46
- package/src/ai/prompts/description.prompt.js +0 -52
- package/src/ai/schemas/attribute.schema.js +0 -23
- package/src/ai/schemas/description.schema.js +0 -19
package/src/components/pages/RetailerProductEdition/context/provider-product-edition.context.jsx
CHANGED
|
@@ -12,7 +12,6 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
12
12
|
import successIcon from "../../../../assets/images/genericModal/genericModalCheck.svg";
|
|
13
13
|
import errorIcon from "../../../../assets/images/genericModal/errorModal.svg";
|
|
14
14
|
import { getConceptByTab } from "../utils";
|
|
15
|
-
import { getImage } from "../../../../global-files/data";
|
|
16
15
|
|
|
17
16
|
const S3_BUCKET = process.env.REACT_APP_IMAGES_BUCKET;
|
|
18
17
|
const REGION = "us-east-1";
|
|
@@ -44,6 +43,8 @@ export const ProviderProductEditionProvider = ({ children }) => {
|
|
|
44
43
|
articleData: state.updated_descriptions_inputs,
|
|
45
44
|
};
|
|
46
45
|
|
|
46
|
+
// console.log({dataObject});
|
|
47
|
+
|
|
47
48
|
if (state.product?.id_order) {
|
|
48
49
|
dataObject.orderId = state.product?.id_order;
|
|
49
50
|
}
|
|
@@ -96,46 +97,6 @@ export const ProviderProductEditionProvider = ({ children }) => {
|
|
|
96
97
|
}
|
|
97
98
|
});
|
|
98
99
|
|
|
99
|
-
const body = JSON.parse(res.data.body);
|
|
100
|
-
const newStatus = body?.newStatus;
|
|
101
|
-
|
|
102
|
-
if (newStatus) {
|
|
103
|
-
const productFromLocalStorage = JSON.parse(
|
|
104
|
-
sessionStorage.getItem("productSelected"),
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
const updatedProduct = {
|
|
108
|
-
...(productFromLocalStorage || state.product),
|
|
109
|
-
description_status: newStatus,
|
|
110
|
-
statusByRetailer: (
|
|
111
|
-
productFromLocalStorage?.statusByRetailer ||
|
|
112
|
-
state.product?.statusByRetailer ||
|
|
113
|
-
[]
|
|
114
|
-
).map((retailerStatus) =>
|
|
115
|
-
retailerStatus.service === "description"
|
|
116
|
-
? { ...retailerStatus, status: newStatus }
|
|
117
|
-
: retailerStatus,
|
|
118
|
-
),
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
sessionStorage.setItem(
|
|
122
|
-
"productSelected",
|
|
123
|
-
JSON.stringify(updatedProduct),
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
dispatch({ type: "UPDATE_DESCRIPTION_STATUS", payload: newStatus });
|
|
127
|
-
|
|
128
|
-
dispatch({
|
|
129
|
-
type: "SET_SERVICES_DATA",
|
|
130
|
-
payload: (state.services_data || []).map((srv) =>
|
|
131
|
-
srv.service === "description" &&
|
|
132
|
-
srv.id_retailer === state.active_retailer?.id_retailer
|
|
133
|
-
? { ...srv, status: newStatus }
|
|
134
|
-
: srv,
|
|
135
|
-
),
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
100
|
dispatch({
|
|
140
101
|
type: "SET_MISSING_REQUIRED_FIELDS",
|
|
141
102
|
payload: {
|
|
@@ -236,46 +197,6 @@ export const ProviderProductEditionProvider = ({ children }) => {
|
|
|
236
197
|
}
|
|
237
198
|
});
|
|
238
199
|
|
|
239
|
-
const body = JSON.parse(res.data.body);
|
|
240
|
-
const newStatus = body?.newStatus;
|
|
241
|
-
|
|
242
|
-
if (newStatus) {
|
|
243
|
-
const productFromLocalStorage = JSON.parse(
|
|
244
|
-
sessionStorage.getItem("productSelected"),
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
const updatedProduct = {
|
|
248
|
-
...(productFromLocalStorage || state.product),
|
|
249
|
-
datasheet_status: newStatus,
|
|
250
|
-
statusByRetailer: (
|
|
251
|
-
productFromLocalStorage?.statusByRetailer ||
|
|
252
|
-
state.product?.statusByRetailer ||
|
|
253
|
-
[]
|
|
254
|
-
).map((retailerStatus) =>
|
|
255
|
-
retailerStatus.service === "datasheet"
|
|
256
|
-
? { ...retailerStatus, status: newStatus }
|
|
257
|
-
: retailerStatus,
|
|
258
|
-
),
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
sessionStorage.setItem(
|
|
262
|
-
"productSelected",
|
|
263
|
-
JSON.stringify(updatedProduct),
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
dispatch({ type: "UPDATE_DATASHEET_STATUS", payload: newStatus });
|
|
267
|
-
|
|
268
|
-
dispatch({
|
|
269
|
-
type: "SET_SERVICES_DATA",
|
|
270
|
-
payload: (state.services_data || []).map((srv) =>
|
|
271
|
-
srv.service === "datasheet" &&
|
|
272
|
-
srv.id_retailer === state.active_retailer?.id_retailer
|
|
273
|
-
? { ...srv, status: newStatus }
|
|
274
|
-
: srv,
|
|
275
|
-
),
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
|
|
279
200
|
dispatch({
|
|
280
201
|
type: "SET_MISSING_REQUIRED_FIELDS",
|
|
281
202
|
payload: {
|
|
@@ -343,7 +264,7 @@ export const ProviderProductEditionProvider = ({ children }) => {
|
|
|
343
264
|
data?.articleData?.every((e) => e?.image_id) &&
|
|
344
265
|
data?.updateImages?.every((e) => e?.image_id);
|
|
345
266
|
|
|
346
|
-
console.log({ data });
|
|
267
|
+
// console.log({ data });
|
|
347
268
|
|
|
348
269
|
if (valid) {
|
|
349
270
|
dispatch({ type: "SET_SAVING", payload: true });
|
|
@@ -400,100 +321,6 @@ export const ProviderProductEditionProvider = ({ children }) => {
|
|
|
400
321
|
type: "SET_UPDATED_IMAGES_VALUES",
|
|
401
322
|
payload: [],
|
|
402
323
|
});
|
|
403
|
-
|
|
404
|
-
const imageBody = JSON.parse(res.data.body);
|
|
405
|
-
const newStatus = imageBody?.newStatus;
|
|
406
|
-
|
|
407
|
-
if (newStatus) {
|
|
408
|
-
const productFromLocalStorage = JSON.parse(
|
|
409
|
-
sessionStorage.getItem("productSelected"),
|
|
410
|
-
);
|
|
411
|
-
|
|
412
|
-
const updatedProduct = {
|
|
413
|
-
...(productFromLocalStorage || state.product),
|
|
414
|
-
images_status: newStatus,
|
|
415
|
-
statusByRetailer: (
|
|
416
|
-
productFromLocalStorage?.statusByRetailer ||
|
|
417
|
-
state.product?.statusByRetailer ||
|
|
418
|
-
[]
|
|
419
|
-
).map((retailerStatus) =>
|
|
420
|
-
retailerStatus.service === "images"
|
|
421
|
-
? { ...retailerStatus, status: newStatus }
|
|
422
|
-
: retailerStatus,
|
|
423
|
-
),
|
|
424
|
-
};
|
|
425
|
-
|
|
426
|
-
sessionStorage.setItem(
|
|
427
|
-
"productSelected",
|
|
428
|
-
JSON.stringify(updatedProduct),
|
|
429
|
-
);
|
|
430
|
-
|
|
431
|
-
dispatch({ type: "UPDATE_IMAGES_STATUS", payload: newStatus });
|
|
432
|
-
|
|
433
|
-
dispatch({
|
|
434
|
-
type: "SET_SERVICES_DATA",
|
|
435
|
-
payload: (state.services_data || []).map((srv) =>
|
|
436
|
-
srv.service === "images" &&
|
|
437
|
-
srv.id_retailer === state.active_retailer?.id_retailer
|
|
438
|
-
? { ...srv, status: newStatus }
|
|
439
|
-
: srv,
|
|
440
|
-
),
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
// Refrescar images_values con datos reales del backend
|
|
445
|
-
try {
|
|
446
|
-
const { id_article, version } = state.product;
|
|
447
|
-
const { category, id_category, id_retailer } = state.active_retailer;
|
|
448
|
-
const imagesRes = await axios.post(
|
|
449
|
-
`${process.env.REACT_APP_ARTICLE_DATA_IMAGES_ENDPOINT}?articleId=${id_article}&version=${version}`,
|
|
450
|
-
{ category, retailersList: [id_retailer] },
|
|
451
|
-
{ headers: { Authorization: token } },
|
|
452
|
-
);
|
|
453
|
-
const freshImages = JSON.parse(imagesRes.data.body).data;
|
|
454
|
-
freshImages.values = freshImages?.values?.map((value) => {
|
|
455
|
-
value.name = freshImages.inputs.find((e) => e.id === value.image_id)?.name;
|
|
456
|
-
return getImage(value);
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
const orderMap = freshImages.inputsByRetailer
|
|
460
|
-
.flat()
|
|
461
|
-
.reduce((acc, item) => {
|
|
462
|
-
acc[item.id_image] = item.order;
|
|
463
|
-
return acc;
|
|
464
|
-
}, {});
|
|
465
|
-
|
|
466
|
-
const orderedValues = [...freshImages.values].sort((a, b) => {
|
|
467
|
-
const orderA = orderMap[a.image_id] ?? Number.MAX_SAFE_INTEGER;
|
|
468
|
-
const orderB = orderMap[b.image_id] ?? Number.MAX_SAFE_INTEGER;
|
|
469
|
-
return orderA - orderB;
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
const filteredValues = freshImages.values.filter((value) =>
|
|
473
|
-
freshImages.inputsByRetailer.some((retailerInput) =>
|
|
474
|
-
retailerInput.some(
|
|
475
|
-
(input) =>
|
|
476
|
-
input.id_retailer === id_retailer &&
|
|
477
|
-
input.id_image === value.image_id,
|
|
478
|
-
),
|
|
479
|
-
),
|
|
480
|
-
);
|
|
481
|
-
|
|
482
|
-
dispatch({
|
|
483
|
-
type: "SET_IMAGES_VALUES",
|
|
484
|
-
payload: { ...freshImages, values: filteredValues },
|
|
485
|
-
});
|
|
486
|
-
dispatch({
|
|
487
|
-
type: "SET_SERVICES",
|
|
488
|
-
payload: {
|
|
489
|
-
...state.services,
|
|
490
|
-
images: { ...freshImages, values: orderedValues },
|
|
491
|
-
},
|
|
492
|
-
});
|
|
493
|
-
} catch (refreshError) {
|
|
494
|
-
console.log("Error al refrescar images_values:", refreshError);
|
|
495
|
-
}
|
|
496
|
-
|
|
497
324
|
// Mostrar modal de éxito
|
|
498
325
|
dispatch({
|
|
499
326
|
type: "SET_MODAL",
|
|
@@ -581,46 +408,6 @@ export const ProviderProductEditionProvider = ({ children }) => {
|
|
|
581
408
|
payload: [],
|
|
582
409
|
});
|
|
583
410
|
|
|
584
|
-
const attrBody = JSON.parse(res.data.body);
|
|
585
|
-
const newStatus = attrBody?.newStatus;
|
|
586
|
-
|
|
587
|
-
if (newStatus) {
|
|
588
|
-
const productFromLocalStorage = JSON.parse(
|
|
589
|
-
sessionStorage.getItem("productSelected"),
|
|
590
|
-
);
|
|
591
|
-
|
|
592
|
-
const updatedProduct = {
|
|
593
|
-
...(productFromLocalStorage || state.product),
|
|
594
|
-
images_status: newStatus,
|
|
595
|
-
statusByRetailer: (
|
|
596
|
-
productFromLocalStorage?.statusByRetailer ||
|
|
597
|
-
state.product?.statusByRetailer ||
|
|
598
|
-
[]
|
|
599
|
-
).map((retailerStatus) =>
|
|
600
|
-
retailerStatus.service === "images"
|
|
601
|
-
? { ...retailerStatus, status: newStatus }
|
|
602
|
-
: retailerStatus,
|
|
603
|
-
),
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
sessionStorage.setItem(
|
|
607
|
-
"productSelected",
|
|
608
|
-
JSON.stringify(updatedProduct),
|
|
609
|
-
);
|
|
610
|
-
|
|
611
|
-
dispatch({ type: "UPDATE_IMAGES_STATUS", payload: newStatus });
|
|
612
|
-
|
|
613
|
-
dispatch({
|
|
614
|
-
type: "SET_SERVICES_DATA",
|
|
615
|
-
payload: (state.services_data || []).map((srv) =>
|
|
616
|
-
srv.service === "images" &&
|
|
617
|
-
srv.id_retailer === state.active_retailer?.id_retailer
|
|
618
|
-
? { ...srv, status: newStatus }
|
|
619
|
-
: srv,
|
|
620
|
-
),
|
|
621
|
-
});
|
|
622
|
-
}
|
|
623
|
-
|
|
624
411
|
dispatch({
|
|
625
412
|
type: "SET_MODAL",
|
|
626
413
|
payload: {
|
|
@@ -786,8 +573,3 @@ export const useProviderProductEdition = () => {
|
|
|
786
573
|
|
|
787
574
|
return context;
|
|
788
575
|
};
|
|
789
|
-
|
|
790
|
-
/*
|
|
791
|
-
src: "https://d24s337exbt5zr.cloudfront.net/eyJidWNrZXQiOiJjb250ZW50LW1hbmFnZW1lbnQtaW1hZ2VzLXByb2QiLCJrZXkiOiJpZC0xNDQ3MTEvMy8xLTRjZGVjNTZkLTVjYWMtNGY3NC04ZWM0LWZmMmRmOTFjZDdiOS5qcGciLCJlZGl0cyI6eyJyZXNpemUiOnsid2lkdGgiOjEwMDAsImhlaWdodCI6MTAwMCwiZml0IjoiY29udGFpbiIsImJhY2tncm91bmQiOnsiciI6MjU1LCJnIjoyNTUsImIiOjI1NSwiYWxwaGEiOjF9fX19"
|
|
792
|
-
srcDB: "id-144711/3/1-4cdec56d-5cac-4f74-8ec4-ff2df91cd7b9.jpg"
|
|
793
|
-
*/
|
|
@@ -9,9 +9,7 @@ export const PRODUCT_ACTIONS = {
|
|
|
9
9
|
SET_SERVICES: "SET_SERVICES",
|
|
10
10
|
SET_SERVICES_DATA: "SET_SERVICES_DATA",
|
|
11
11
|
SET_PRODUCT_VERSION: "SET_PRODUCT_VERSION",
|
|
12
|
-
|
|
13
|
-
UPDATE_DATASHEET_STATUS: "UPDATE_DATASHEET_STATUS",
|
|
14
|
-
UPDATE_IMAGES_STATUS: "UPDATE_IMAGES_STATUS",
|
|
12
|
+
SET_PERCENTAGES: "SET_PERCENTAGES",
|
|
15
13
|
};
|
|
16
14
|
|
|
17
15
|
export const productReducer = (state, action) => {
|
|
@@ -47,48 +45,10 @@ export const productReducer = (state, action) => {
|
|
|
47
45
|
};
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
case PRODUCT_ACTIONS.
|
|
48
|
+
case PRODUCT_ACTIONS.SET_PERCENTAGES: {
|
|
51
49
|
return {
|
|
52
50
|
...state,
|
|
53
|
-
product: {
|
|
54
|
-
...state.product,
|
|
55
|
-
statusByRetailer: (state.product?.statusByRetailer || []).map(
|
|
56
|
-
(retailerStatus) =>
|
|
57
|
-
retailerStatus.service === "description"
|
|
58
|
-
? { ...retailerStatus, status: action.payload }
|
|
59
|
-
: retailerStatus,
|
|
60
|
-
),
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
case PRODUCT_ACTIONS.UPDATE_DATASHEET_STATUS: {
|
|
66
|
-
return {
|
|
67
|
-
...state,
|
|
68
|
-
product: {
|
|
69
|
-
...state.product,
|
|
70
|
-
statusByRetailer: (state.product?.statusByRetailer || []).map(
|
|
71
|
-
(retailerStatus) =>
|
|
72
|
-
retailerStatus.service === "datasheet"
|
|
73
|
-
? { ...retailerStatus, status: action.payload }
|
|
74
|
-
: retailerStatus,
|
|
75
|
-
),
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
case PRODUCT_ACTIONS.UPDATE_IMAGES_STATUS: {
|
|
81
|
-
return {
|
|
82
|
-
...state,
|
|
83
|
-
product: {
|
|
84
|
-
...state.product,
|
|
85
|
-
statusByRetailer: (state.product?.statusByRetailer || []).map(
|
|
86
|
-
(retailerStatus) =>
|
|
87
|
-
retailerStatus.service === "images"
|
|
88
|
-
? { ...retailerStatus, status: action.payload }
|
|
89
|
-
: retailerStatus,
|
|
90
|
-
),
|
|
91
|
-
},
|
|
51
|
+
product: { ...state.product, percentages: action.payload },
|
|
92
52
|
};
|
|
93
53
|
}
|
|
94
54
|
|
|
@@ -284,9 +284,10 @@ const RetailerProductEditionView = ({
|
|
|
284
284
|
}
|
|
285
285
|
}, [auditableVersion]);
|
|
286
286
|
|
|
287
|
-
const loadData = async () => {
|
|
287
|
+
const loadData = async (enableLoading = true) => {
|
|
288
288
|
try {
|
|
289
|
-
|
|
289
|
+
|
|
290
|
+
if(enableLoading) dispatch({ type: "SET_LOADING", payload: true });
|
|
290
291
|
|
|
291
292
|
const { id_article, version, id_order } = state.product;
|
|
292
293
|
const { category, id_category, id_retailer } = state.active_retailer;
|
|
@@ -466,7 +467,7 @@ const RetailerProductEditionView = ({
|
|
|
466
467
|
if (state.active_retailer) {
|
|
467
468
|
loadData();
|
|
468
469
|
}
|
|
469
|
-
}, [state.active_retailer
|
|
470
|
+
}, [state.active_retailer]);
|
|
470
471
|
|
|
471
472
|
const handleOnChangeCurrentImage = (index) => {
|
|
472
473
|
if (typeof index === "number") {
|
|
@@ -595,21 +596,26 @@ const RetailerProductEditionView = ({
|
|
|
595
596
|
}
|
|
596
597
|
};
|
|
597
598
|
|
|
598
|
-
const handleOnClickSave = () => {
|
|
599
|
+
const handleOnClickSave = async () => {
|
|
599
600
|
if (state.saving) return;
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
|
|
600
604
|
switch (state.active_tab) {
|
|
601
605
|
case "Descripción":
|
|
602
|
-
saveDescriptions(token);
|
|
606
|
+
await saveDescriptions(token);
|
|
603
607
|
break;
|
|
604
608
|
case "Ficha técnica":
|
|
605
|
-
saveDatasheets(token);
|
|
609
|
+
await saveDatasheets(token);
|
|
606
610
|
break;
|
|
607
611
|
case "Imágenes":
|
|
608
|
-
updateImages(token);
|
|
612
|
+
await updateImages(token);
|
|
609
613
|
break;
|
|
610
614
|
default:
|
|
611
615
|
break;
|
|
612
616
|
}
|
|
617
|
+
|
|
618
|
+
await loadData(false);
|
|
613
619
|
};
|
|
614
620
|
|
|
615
621
|
const handleOnSetUpdatedDescriptions = (items) => {
|
|
@@ -684,10 +690,7 @@ const RetailerProductEditionView = ({
|
|
|
684
690
|
const articleId = state.product.id_article;
|
|
685
691
|
const orderId = state.product.id_order ?? state.product.orderId;
|
|
686
692
|
const sectionStatusKey = `${concept}_status`;
|
|
687
|
-
const evalStatus =
|
|
688
|
-
getStatusByCurrentServiceAndRetailer() ||
|
|
689
|
-
state.product[sectionStatusKey] ||
|
|
690
|
-
"NA";
|
|
693
|
+
const evalStatus = state.product[sectionStatusKey];
|
|
691
694
|
const retailerId = state.active_retailer?.id_retailer;
|
|
692
695
|
|
|
693
696
|
let data = { articleId, orderId, concept, evalStatus, retailerId };
|
|
@@ -1129,11 +1132,10 @@ const RetailerProductEditionView = ({
|
|
|
1129
1132
|
|
|
1130
1133
|
return (
|
|
1131
1134
|
<AiProductEditionProvider
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
+
isCreatorsEdition={true}
|
|
1136
|
+
user={user}
|
|
1137
|
+
token={token}
|
|
1135
1138
|
>
|
|
1136
|
-
\{" "}
|
|
1137
1139
|
<Container headerTop={headerTop}>
|
|
1138
1140
|
{showRejectModal && (
|
|
1139
1141
|
<Modal
|