contentoh-components-library 21.5.98 → 21.5.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.
Files changed (63) hide show
  1. package/dist/components/atoms/GeneralButton/styles.js +1 -1
  2. package/dist/components/atoms/GeneralInput/index.js +54 -249
  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 +1 -13
  8. package/dist/components/molecules/TagAndInput/index.js +24 -364
  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 +377 -413
  15. package/dist/components/pages/ProviderProductEdition/utils.js +0 -1
  16. package/dist/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +211 -125
  17. package/dist/components/pages/RetailerProductEdition/index.js +2236 -1738
  18. package/dist/components/pages/RetailerProductEdition/styles.js +2 -4
  19. package/dist/components/pages/RetailerProductEdition/utils.js +2 -251
  20. package/package.json +2 -4
  21. package/src/components/atoms/GeneralButton/styles.js +0 -4
  22. package/src/components/atoms/GeneralInput/index.js +60 -241
  23. package/src/components/atoms/GeneralInput/styles.js +0 -81
  24. package/src/components/atoms/InputFormatter/index.js +51 -200
  25. package/src/components/atoms/InputFormatter/styles.js +0 -284
  26. package/src/components/molecules/StatusAsignationInfo/index.js +1 -9
  27. package/src/components/molecules/TabsMenu/index.js +0 -12
  28. package/src/components/molecules/TagAndInput/index.js +21 -294
  29. package/src/components/molecules/TagAndInput/styles.js +17 -59
  30. package/src/components/organisms/FullProductNameHeader/index.js +28 -4
  31. package/src/components/organisms/FullTabsMenu/index.js +1 -1
  32. package/src/components/organisms/InputGroup/index.js +4 -12
  33. package/src/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +202 -174
  34. package/src/components/pages/ProviderProductEdition/context/provider-product-edition.context.jsx +14 -14
  35. package/src/components/pages/ProviderProductEdition/index.js +418 -486
  36. package/src/components/pages/ProviderProductEdition/utils.js +2 -2
  37. package/src/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +243 -136
  38. package/src/components/pages/RetailerProductEdition/index.js +1717 -1563
  39. package/src/components/pages/RetailerProductEdition/styles.js +2 -67
  40. package/src/components/pages/RetailerProductEdition/utils.js +0 -240
  41. package/src/ai/utils/compare-strings.js +0 -45
  42. package/src/assets/images/Icons/arrow.png +0 -0
  43. package/src/assets/images/Icons/cancel.png +0 -0
  44. package/src/assets/images/Icons/ia-icon.png +0 -0
  45. package/src/assets/images/Icons/loading.svg +0 -5
  46. package/src/assets/images/Icons/reload.png +0 -0
  47. package/src/components/atoms/RetailerSelector/RetailerSelector.stories.js +0 -10
  48. package/src/components/atoms/RetailerSelector/index.js +0 -3
  49. package/src/components/atoms/RetailerSelector/styles.js +0 -0
  50. package/src/components/organisms/ChangeStatusModal/index.jsx +0 -488
  51. package/src/components/organisms/ChangeStatusModal/styles.js +0 -333
  52. package/src/components/pages/RetailerProductEdition/context/provider-product-edition.context.jsx +0 -575
  53. package/src/components/pages/RetailerProductEdition/context/provider-product-edition.reducer.js +0 -62
  54. package/src/components/pages/RetailerProductEdition/context/reducers/active-state.js +0 -344
  55. package/src/components/pages/RetailerProductEdition/context/reducers/inputs.js +0 -155
  56. package/src/components/pages/RetailerProductEdition/context/reducers/product.js +0 -114
  57. package/src/components/pages/RetailerProductEdition/context/reducers/system.js +0 -60
  58. package/src/components/pages/RetailerProductEdition/index_old.js +0 -1979
  59. package/src/components/pages/RetailerProductEdition/stories/Auditor.stories.js +0 -101
  60. package/src/components/pages/RetailerProductEdition/stories/ImageEditor.stories.js +0 -115
  61. package/src/components/pages/RetailerProductEdition/stories/TextEditor.stories.js +0 -174
  62. package/src/contexts/AiProductEdition.jsx +0 -347
  63. package/src/global-files/statusDictionary.js +0 -103
@@ -1,347 +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) return {};
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 errorsRaw = JSON.parse(data?.body)?.error;
209
-
210
- const errorMessage = errorsRaw ? JSON.parse(errorsRaw)?.error?.message : null;
211
-
212
- if(errorMessage) throw new Error(errorMessage ?? 'Error desconocido')
213
-
214
- const results = JSON.parse(data?.body)?.data ?? [];
215
-
216
- if(!results)
217
- throw new Error("No se encontraron resultados");
218
-
219
- return results;
220
-
221
- } catch (error) {
222
- console.log("Error generating AI suggestions:", error);
223
- return {
224
- error: error?.message ?? "Error generating AI suggestions"
225
- }
226
- }
227
-
228
- }
229
-
230
- // Verificamos si los servicios de ficha técnica e imágenes estan completos
231
- useEffect(() => {
232
-
233
- if (!productSelected || !isCreators) return;
234
-
235
- const {
236
- name: productName,
237
- upc: upc,
238
- categoryRetailer
239
- } = productSelected;
240
-
241
- if(!Array.isArray(categoryRetailer)) return console.log("Error: categoryRetailer no es un array");
242
-
243
- const currentCategory = categoryRetailer.find(retailer => retailer?.id_retailer === activeRetailer?.id_retailer);
244
-
245
- if(!currentCategory) return console.log("Error: No se encontro la categoría");
246
-
247
- const {
248
- retailer,
249
- category
250
- } = currentCategory;
251
-
252
- //Checamos si el servicio de ficha técnica e imagenes esta completo
253
-
254
- const currentRetailerPercentages = productSelected?.percentages?.find(retailer => retailer?.id_retailer === activeRetailer?.id_retailer);
255
-
256
- if(!currentRetailerPercentages) return console.log("Error: No hay porcentajes disponibles");
257
-
258
- const {
259
- required: datasheetRequiredPercent,
260
- } = currentRetailerPercentages?.datasheet;
261
-
262
- const {
263
- required: imagesRequiredPercent,
264
- } = currentRetailerPercentages?.images;
265
-
266
- const aiServiceAvailable = (datasheetRequiredPercent >= 100) && (imagesRequiredPercent >= 100) && [1,4,6,7].some(allowed => allowed = user?.id_role);
267
-
268
- setIsAiAvailable(aiServiceAvailable);
269
-
270
- setProduct({
271
- upc,
272
- productName,
273
- retailer,
274
- category,
275
- });
276
-
277
- }, [productSelected]);
278
-
279
- // Inicializamos la ficha técnica con el objetivo de posteriormente pasarlo a la generación con IA
280
- useEffect(() => {
281
-
282
- if (!datasheetInputs || !isCreators) return;
283
-
284
- const datasheetToArray = Object.values(datasheetInputs);
285
-
286
- const normalizedDatasheet = datasheetToArray.map(attribute => ({
287
- description: attribute?.description,
288
- name: attribute?.name,
289
- type: attribute?.type,
290
- value: attribute?.value
291
- }));
292
-
293
- setParsedDatasheet(normalizedDatasheet);
294
-
295
- }, [datasheetInputs]);
296
-
297
- // Inicializamos las imágenes con el objetivo de posteriormente pasarlo a la generación con IA
298
- useEffect(() => {
299
-
300
- if(!isCreators) return;
301
-
302
- const currentRetailerImageInputs = imagesData?.inputsByRetailer?.[0]?.filter(input => input?.id_retailer === activeRetailer?.id_retailer);
303
-
304
- if(!Array.isArray(currentRetailerImageInputs) || currentRetailerImageInputs.length === 0) return console.log('No existen imágenes para la cadena seleccionada')
305
-
306
- const allProductImages = imagesData?.values;
307
-
308
- if(!Array.isArray(allProductImages) || allProductImages.length === 0) return console.log("No existen imágenes para el producto");
309
-
310
- //Obtenemos las imágenes para el retailer seleccionado
311
- const currentParsedImages = allProductImages.filter(image => {
312
-
313
- const imageId = image?.image_id;
314
- const foundedImage = currentRetailerImageInputs.some(retailerImage => retailerImage?.id_image === imageId);
315
-
316
- return foundedImage;
317
- });
318
-
319
- setParsedImages(currentParsedImages);
320
-
321
- }, [imagesData]);
322
-
323
- return (
324
- <AiProductEdition.Provider
325
- value={{
326
- isCreators: isCreators,
327
- suggestions,
328
- currentSuggestion,
329
- isAiAvailable,
330
- inputsGeneratedWithAi,
331
- inputsUsingAi,
332
-
333
- setInputsUsingAi,
334
- setInputsGeneratedWithAi,
335
- setSuggestions,
336
- setCurrentSuggestionValue,
337
- generateProductSuggestions,
338
- regenerateProductSuggestions,
339
- clearCurrentSuggestions,
340
-
341
- }}
342
- >
343
- { children }
344
- </AiProductEdition.Provider>
345
- )
346
-
347
- }
@@ -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
- }