contentoh-components-library 21.5.92 → 21.5.93

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.
Files changed (70) hide show
  1. package/dist/components/atoms/GeneralButton/styles.js +1 -1
  2. package/dist/components/atoms/GeneralInput/index.js +54 -245
  3. package/dist/components/atoms/GeneralInput/styles.js +3 -7
  4. package/dist/components/atoms/InputFormatter/index.js +68 -223
  5. package/dist/components/atoms/InputFormatter/styles.js +4 -20
  6. package/dist/components/molecules/StatusAsignationInfo/index.js +1 -11
  7. package/dist/components/molecules/TabsMenu/index.js +12 -13
  8. package/dist/components/molecules/TagAndInput/index.js +24 -361
  9. package/dist/components/molecules/TagAndInput/styles.js +2 -2
  10. package/dist/components/organisms/FullProductNameHeader/index.js +22 -6
  11. package/dist/components/organisms/InputGroup/index.js +18 -22
  12. package/dist/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +337 -150
  13. package/dist/components/pages/ProviderProductEdition/context/provider-product-edition.context.js +15 -15
  14. package/dist/components/pages/ProviderProductEdition/index.js +362 -368
  15. package/dist/components/pages/ProviderProductEdition/utils.js +0 -1
  16. package/dist/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +196 -179
  17. package/dist/components/pages/RetailerProductEdition/context/provider-product-edition.context.js +260 -59
  18. package/dist/components/pages/RetailerProductEdition/context/reducers/product.js +38 -50
  19. package/dist/components/pages/RetailerProductEdition/index.js +2234 -1716
  20. package/dist/components/pages/RetailerProductEdition/styles.js +2 -4
  21. package/dist/components/pages/RetailerProductEdition/utils.js +2 -251
  22. package/dist/contexts/AiProductEdition.js +158 -230
  23. package/package.json +2 -4
  24. package/src/components/atoms/GeneralButton/styles.js +0 -4
  25. package/src/components/atoms/GeneralInput/index.js +60 -237
  26. package/src/components/atoms/GeneralInput/styles.js +0 -81
  27. package/src/components/atoms/InputFormatter/index.js +51 -200
  28. package/src/components/atoms/InputFormatter/styles.js +0 -284
  29. package/src/components/molecules/StatusAsignationInfo/index.js +1 -9
  30. package/src/components/molecules/TabsMenu/index.js +11 -12
  31. package/src/components/molecules/TagAndInput/index.js +21 -286
  32. package/src/components/molecules/TagAndInput/styles.js +17 -59
  33. package/src/components/organisms/FullProductNameHeader/index.js +28 -4
  34. package/src/components/organisms/FullTabsMenu/index.js +1 -1
  35. package/src/components/organisms/InputGroup/index.js +4 -12
  36. package/src/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +202 -174
  37. package/src/components/pages/ProviderProductEdition/context/provider-product-edition.context.jsx +14 -14
  38. package/src/components/pages/ProviderProductEdition/index.js +452 -453
  39. package/src/components/pages/ProviderProductEdition/utils.js +2 -2
  40. package/src/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +224 -201
  41. package/src/components/pages/RetailerProductEdition/index.js +1718 -1547
  42. package/src/components/pages/RetailerProductEdition/styles.js +2 -67
  43. package/src/components/pages/RetailerProductEdition/utils.js +0 -240
  44. package/dist/ai/utils/compare-strings.js +0 -45
  45. package/dist/components/organisms/ChangeStatusModal/index.js +0 -531
  46. package/dist/components/organisms/ChangeStatusModal/styles.js +0 -85
  47. package/dist/global-files/statusDictionary.js +0 -103
  48. package/src/ai/utils/compare-strings.js +0 -45
  49. package/src/assets/images/Icons/arrow.png +0 -0
  50. package/src/assets/images/Icons/cancel.png +0 -0
  51. package/src/assets/images/Icons/ia-icon.png +0 -0
  52. package/src/assets/images/Icons/loading.svg +0 -5
  53. package/src/assets/images/Icons/reload.png +0 -0
  54. package/src/components/atoms/RetailerSelector/RetailerSelector.stories.js +0 -10
  55. package/src/components/atoms/RetailerSelector/index.js +0 -3
  56. package/src/components/atoms/RetailerSelector/styles.js +0 -0
  57. package/src/components/organisms/ChangeStatusModal/index.jsx +0 -488
  58. package/src/components/organisms/ChangeStatusModal/styles.js +0 -333
  59. package/src/components/pages/RetailerProductEdition/context/provider-product-edition.context.jsx +0 -575
  60. package/src/components/pages/RetailerProductEdition/context/provider-product-edition.reducer.js +0 -62
  61. package/src/components/pages/RetailerProductEdition/context/reducers/active-state.js +0 -344
  62. package/src/components/pages/RetailerProductEdition/context/reducers/inputs.js +0 -155
  63. package/src/components/pages/RetailerProductEdition/context/reducers/product.js +0 -114
  64. package/src/components/pages/RetailerProductEdition/context/reducers/system.js +0 -60
  65. package/src/components/pages/RetailerProductEdition/index_old.js +0 -1979
  66. package/src/components/pages/RetailerProductEdition/stories/Auditor.stories.js +0 -101
  67. package/src/components/pages/RetailerProductEdition/stories/ImageEditor.stories.js +0 -115
  68. package/src/components/pages/RetailerProductEdition/stories/TextEditor.stories.js +0 -174
  69. package/src/contexts/AiProductEdition.jsx +0 -339
  70. package/src/global-files/statusDictionary.js +0 -103
@@ -1,339 +0,0 @@
1
- import { useContext, useEffect, useState } from "react";
2
- import { createContext } from "react";
3
- import axios from "axios";
4
-
5
- export const AiProductEdition = createContext();
6
-
7
- export const useAiProductEdition = () => {
8
- const context = useContext(AiProductEdition);
9
-
10
- if (!context) throw new Error("El contexto debe tener un provider");
11
-
12
- return context;
13
- };
14
-
15
- export const AiProductEditionProvider = ({
16
- children,
17
- isCreatorsEdition = false,
18
- user = {},
19
- token = "",
20
- state
21
- }) => {
22
-
23
- const isCreators = isCreatorsEdition;
24
-
25
- const productSelected = state.product;
26
- const activeRetailer = state.active_retailer;
27
- const datasheetInputs = state.datasheets_inputs?.[1];
28
- const imagesData = state.images_values;
29
-
30
- const [product, setProduct] = useState(null);
31
-
32
- const [parsedDatasheet, setParsedDatasheet] = useState([]);
33
- const [parsedImages, setParsedImages] = useState([]);
34
-
35
- const [suggestions, setSuggestions] = useState({});
36
- const [currentSuggestion, setCurrentSuggestion] = useState({});
37
-
38
- const [isAiAvailable, setIsAiAvailable] = useState(false);
39
-
40
- const [inputsGeneratedWithAi, setInputsGeneratedWithAi] = useState({});
41
- const [inputsUsingAi, setInputsUsingAi] = useState({});
42
-
43
- const MAX_CREDITS = 10;
44
- const COOLDOWN_MS = 5 * 60 * 1000;
45
- const RATE_LIMIT_KEY = "ai_generation_limit_data";
46
-
47
- const checkAndManageRateLimit = (currentArticleId) => {
48
- const now = Date.now();
49
- const storedData = localStorage.getItem(RATE_LIMIT_KEY);
50
-
51
- let allRateData = storedData ? JSON.parse(storedData) : {};
52
-
53
- let productTimestamps = allRateData[currentArticleId] || [];
54
-
55
- productTimestamps = productTimestamps.filter(timestamp => (now - timestamp) < COOLDOWN_MS);
56
-
57
- if (productTimestamps.length >= MAX_CREDITS) {
58
-
59
- allRateData[currentArticleId] = productTimestamps;
60
- localStorage.setItem(RATE_LIMIT_KEY, JSON.stringify(allRateData));
61
-
62
- return {
63
- allowed: false,
64
- message: "Has alcanzado el limite de intentos frecuentes para este producto. Por favor, espera unos minutos."
65
- };
66
- }
67
-
68
-
69
- productTimestamps.push(now);
70
- allRateData[currentArticleId] = productTimestamps;
71
-
72
- localStorage.setItem(RATE_LIMIT_KEY, JSON.stringify(allRateData));
73
-
74
- return { allowed: true };
75
- };
76
-
77
- function setCurrentSuggestionValue({
78
- inputId,
79
- index,
80
- value
81
- }) {
82
- setCurrentSuggestion(prev => ({
83
- ...prev,
84
- [inputId]: {
85
- index,
86
- value
87
- }
88
- }));
89
- }
90
-
91
- function clearCurrentSuggestions() {
92
- setCurrentSuggestion({});
93
- }
94
-
95
- async function regenerateProductSuggestions ({
96
- inputName,
97
- currentValue,
98
- description,
99
- maxChar,
100
- type,
101
-
102
- articleId,
103
- versionId,
104
- descriptionId,
105
- attributeId
106
- }) {
107
-
108
- if(!description || !maxChar || !type) return console.log("Error: No se obtuvieron los parametros obligatorios");
109
-
110
- const newSuggestions = await generateProductSuggestions({
111
- inputName,
112
- currentValue,
113
- description,
114
- maxChar,
115
- type,
116
-
117
- articleId,
118
- versionId,
119
- descriptionId,
120
- attributeId
121
- });
122
-
123
- if(newSuggestions?.error) return {
124
- error: newSuggestions.error
125
- }
126
-
127
- if(!Array.isArray(newSuggestions) || newSuggestions.length === 0)
128
- return console.log("Error: No se obtuvieron nuevas sugerencias");
129
-
130
- if(!newSuggestions) return console.log("Error: No exiten resultados nuevos");
131
-
132
- return newSuggestions;
133
-
134
- }
135
-
136
- async function generateProductSuggestions ({
137
- inputName = "",
138
- currentValue = "",
139
- description = "",
140
- maxChar = 100,
141
- type = 'description',
142
-
143
- articleId,
144
- versionId,
145
- descriptionId,
146
- attributeId
147
- }) {
148
-
149
- try {
150
-
151
- if(!isAiAvailable) return;
152
-
153
- const rateLimitStatus = checkAndManageRateLimit(articleId);
154
-
155
- if (!rateLimitStatus.allowed) {
156
- return {
157
- error: rateLimitStatus.message,
158
- isRateLimitInfo: true
159
- };
160
- }
161
-
162
- if(!product)
163
- throw new Error("El producto no está definido");
164
-
165
- if(!Array.isArray(parsedDatasheet) || parsedDatasheet.length === 0)
166
- throw new Error("No es encontró la ficha técnica");
167
-
168
- if(!Array.isArray(parsedImages) || parsedImages.length === 0)
169
- throw new Error("No se encontraron imágenes para la cadena seleccionada");
170
-
171
- const {
172
- upc,
173
- productName,
174
- retailer,
175
- category
176
- } = product;
177
-
178
- const version = state?.product?.version;
179
-
180
- if (!upc || !description || !productName || !category || !retailer || !articleId || !version || (!descriptionId && !attributeId))
181
- throw new Error("Faltan parámetros obligatorios para generar sugerencias de IA");
182
-
183
- const payload = {
184
- upc,
185
- attributeTitle: inputName,
186
- attributeDescription: description,
187
- productName,
188
- currentValue,
189
- categoryName: category,
190
- retailerName: retailer,
191
- datasheet: parsedDatasheet,
192
- images: parsedImages,
193
- maxChar: maxChar,
194
-
195
- articleId,
196
- retailerId: activeRetailer?.id_retailer,
197
- versionId: version,
198
- descriptionId,
199
- attributeId
200
- }
201
-
202
- const { data } = await axios.post(process.env.REACT_APP_GENERATE_AI_ATTRIBUTES, payload, {
203
- headers: {
204
- Authorization: token
205
- }
206
- });
207
-
208
- const results = JSON.parse(data?.body)?.data ?? [];
209
-
210
- if(!results)
211
- throw new Error("No se encontraron resultados");
212
-
213
- return results;
214
-
215
- } catch (error) {
216
- console.log("Error generating AI suggestions:", error);
217
- return {
218
- error: error?.message ?? "Error generating AI suggestions"
219
- }
220
- }
221
-
222
- }
223
-
224
- // Verificamos si los servicios de ficha técnica e imágenes estan completos
225
- useEffect(() => {
226
-
227
- if (!productSelected) return;
228
-
229
- const {
230
- name: productName,
231
- upc: upc,
232
- categoryRetailer
233
- } = productSelected;
234
-
235
- if(!Array.isArray(categoryRetailer)) return console.log("Error: categoryRetailer no es un array");
236
-
237
- const currentCategory = categoryRetailer.find(retailer => retailer?.id_retailer === activeRetailer?.id_retailer);
238
-
239
- if(!currentCategory) return console.log("Error: No se encontro la categoría");
240
-
241
- const {
242
- retailer,
243
- category
244
- } = currentCategory;
245
-
246
- //Checamos si el servicio de ficha técnica e imagenes esta completo
247
-
248
- const currentRetailerPercentages = productSelected?.percentages?.find(retailer => retailer?.id_retailer === activeRetailer?.id_retailer);
249
-
250
- if(!currentRetailerPercentages) return console.log("Error: No hay porcentajes disponibles");
251
-
252
- const {
253
- required: datasheetRequiredPercent,
254
- } = currentRetailerPercentages?.datasheet;
255
-
256
- const {
257
- required: imagesRequiredPercent,
258
- } = currentRetailerPercentages?.images;
259
-
260
- const aiServiceAvailable = (datasheetRequiredPercent >= 100) && (imagesRequiredPercent >= 100) && [1,4,6,7].some(allowed => allowed = user?.id_role);
261
-
262
- setIsAiAvailable(aiServiceAvailable);
263
-
264
- setProduct({
265
- upc,
266
- productName,
267
- retailer,
268
- category,
269
- });
270
-
271
- }, [productSelected]);
272
-
273
- // Inicializamos la ficha técnica con el objetivo de posteriormente pasarlo a la generación con IA
274
- useEffect(() => {
275
-
276
- if (!datasheetInputs) return;
277
-
278
- const datasheetToArray = Object.values(datasheetInputs);
279
-
280
- const normalizedDatasheet = datasheetToArray.map(attribute => ({
281
- description: attribute?.description,
282
- name: attribute?.name,
283
- type: attribute?.type,
284
- value: attribute?.value
285
- }));
286
-
287
- setParsedDatasheet(normalizedDatasheet);
288
-
289
- }, [datasheetInputs]);
290
-
291
- // Inicializamos las imágenes con el objetivo de posteriormente pasarlo a la generación con IA
292
- useEffect(() => {
293
-
294
- const currentRetailerImageInputs = imagesData?.inputsByRetailer?.[0]?.filter(input => input?.id_retailer === activeRetailer?.id_retailer);
295
-
296
- if(!Array.isArray(currentRetailerImageInputs) || currentRetailerImageInputs.length === 0) return console.log('No existen imágenes para la cadena seleccionada')
297
-
298
- const allProductImages = imagesData?.values;
299
-
300
- if(!Array.isArray(allProductImages) || allProductImages.length === 0) return console.log("No existen imágenes para el producto");
301
-
302
- //Obtenemos las imágenes para el retailer seleccionado
303
- const currentParsedImages = allProductImages.filter(image => {
304
-
305
- const imageId = image?.image_id;
306
- const foundedImage = currentRetailerImageInputs.some(retailerImage => retailerImage?.id_image === imageId);
307
-
308
- return foundedImage;
309
- });
310
-
311
- setParsedImages(currentParsedImages);
312
-
313
- }, [imagesData]);
314
-
315
- return (
316
- <AiProductEdition.Provider
317
- value={{
318
- isCreators: isCreators,
319
- suggestions,
320
- currentSuggestion,
321
- isAiAvailable,
322
- inputsGeneratedWithAi,
323
- inputsUsingAi,
324
-
325
- setInputsUsingAi,
326
- setInputsGeneratedWithAi,
327
- setSuggestions,
328
- setCurrentSuggestionValue,
329
- generateProductSuggestions,
330
- regenerateProductSuggestions,
331
- clearCurrentSuggestions,
332
-
333
- }}
334
- >
335
- { children }
336
- </AiProductEdition.Provider>
337
- )
338
-
339
- }
@@ -1,103 +0,0 @@
1
- const STATUS_DICTIONARY = {
2
- // R: {
3
- // status: "R",
4
- // name: "Recepción",
5
- // weight: 1
6
- // },
7
- PA: {
8
- status: "PA",
9
- name: "Por Asignar",
10
- weight: 2
11
- },
12
- AS: {
13
- status: "AS",
14
- name: "Asignado",
15
- weight: 3
16
- },
17
- // CA: {
18
- // status: "CA",
19
- // name: "Capturando",
20
- // weight: 4
21
- // },
22
- // IE: {
23
- // status: "IE",
24
- // name: "Información Enviada",
25
- // weight: 5
26
- // },
27
- RCA: {
28
- status: "RCA",
29
- name: "Rechazado Cadena",
30
- weight: 6
31
- },
32
- RP: {
33
- status: "RP",
34
- name: "Rechazado Proveedor",
35
- weight: 7
36
- },
37
- RA: {
38
- status: "RA",
39
- name: "Rechazado Auditor",
40
- weight: 8
41
- },
42
- RC: {
43
- status: "RC",
44
- name: "Rechazo Coordinador",
45
- weight: 9
46
- },
47
- AC: {
48
- status: "AC",
49
- name: "Aprobado Coordinador",
50
- weight: 10
51
- },
52
- AA: {
53
- status: "AA",
54
- name: "Aprobado Auditor",
55
- weight: 11
56
- },
57
- AP: {
58
- status: "AP",
59
- name: "Aprobado Proveedor",
60
- weight: 12
61
- },
62
- ACA: {
63
- status: "ACA",
64
- name: "Aprobado Cadena",
65
- weight: 13
66
- },
67
- Ex: {
68
- status: "Ex",
69
- name: "Exportado",
70
- weight: 14
71
- },
72
- // RAC: {
73
- // status: "RAC",
74
- // name: "Rechazo de Auditoría Content-oh!",
75
- // weight: 15
76
- // },
77
- // SAC: {
78
- // status: "SAC",
79
- // name: "Solicitud de Auditoría Content-oh!",
80
- // weight: 16
81
- // },
82
- // AAC: {
83
- // status: "AAC",
84
- // name: "Aprobado Auditoría Content-oh!",
85
- // weight: 17
86
- // },
87
- // FAP: {
88
- // status: "FAP",
89
- // name: "Finalización de Auditoría por Proveedor",
90
- // weight: 18
91
- // },
92
-
93
- //El status NS necesita ser el mayor de todos
94
- NS: {
95
- status: "NS",
96
- name: "No Solicitado",
97
- weight: 100
98
- },
99
- };
100
-
101
- module.exports = {
102
- STATUS_DICTIONARY
103
- }