contentoh-components-library 21.5.93 → 21.5.95
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 +45 -0
- package/dist/components/atoms/GeneralButton/styles.js +1 -1
- package/dist/components/atoms/GeneralInput/index.js +245 -54
- package/dist/components/atoms/GeneralInput/styles.js +7 -3
- package/dist/components/atoms/InputFormatter/index.js +223 -68
- package/dist/components/atoms/InputFormatter/styles.js +20 -4
- package/dist/components/molecules/StatusAsignationInfo/index.js +11 -1
- package/dist/components/molecules/TabsMenu/index.js +13 -12
- package/dist/components/molecules/TagAndInput/index.js +361 -24
- package/dist/components/molecules/TagAndInput/styles.js +2 -2
- package/dist/components/organisms/ChangeStatusModal/index.js +531 -0
- package/dist/components/organisms/ChangeStatusModal/styles.js +85 -0
- package/dist/components/organisms/FullProductNameHeader/index.js +6 -22
- package/dist/components/organisms/InputGroup/index.js +22 -18
- package/dist/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +150 -337
- package/dist/components/pages/ProviderProductEdition/context/provider-product-edition.context.js +15 -15
- package/dist/components/pages/ProviderProductEdition/index.js +408 -381
- package/dist/components/pages/ProviderProductEdition/utils.js +1 -0
- package/dist/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +179 -196
- package/dist/components/pages/RetailerProductEdition/context/provider-product-edition.context.js +59 -260
- package/dist/components/pages/RetailerProductEdition/context/reducers/product.js +50 -38
- package/dist/components/pages/RetailerProductEdition/index.js +1719 -2237
- package/dist/components/pages/RetailerProductEdition/styles.js +4 -2
- package/dist/components/pages/RetailerProductEdition/utils.js +251 -2
- package/dist/contexts/AiProductEdition.js +230 -158
- package/dist/global-files/statusDictionary.js +103 -0
- package/package.json +4 -2
- package/src/ai/utils/compare-strings.js +45 -0
- package/src/assets/images/Icons/arrow.png +0 -0
- package/src/assets/images/Icons/cancel.png +0 -0
- package/src/assets/images/Icons/ia-icon.png +0 -0
- package/src/assets/images/Icons/loading.svg +5 -0
- package/src/assets/images/Icons/reload.png +0 -0
- package/src/components/atoms/GeneralButton/styles.js +4 -0
- package/src/components/atoms/GeneralInput/index.js +237 -60
- package/src/components/atoms/GeneralInput/styles.js +81 -0
- package/src/components/atoms/InputFormatter/index.js +200 -51
- package/src/components/atoms/InputFormatter/styles.js +284 -0
- package/src/components/atoms/RetailerSelector/RetailerSelector.stories.js +10 -0
- package/src/components/atoms/RetailerSelector/index.js +3 -0
- package/src/components/atoms/RetailerSelector/styles.js +0 -0
- package/src/components/molecules/StatusAsignationInfo/index.js +9 -1
- package/src/components/molecules/TabsMenu/index.js +12 -11
- package/src/components/molecules/TagAndInput/index.js +286 -21
- package/src/components/molecules/TagAndInput/styles.js +59 -17
- package/src/components/organisms/ChangeStatusModal/index.jsx +488 -0
- package/src/components/organisms/ChangeStatusModal/styles.js +333 -0
- package/src/components/organisms/FullProductNameHeader/index.js +4 -28
- package/src/components/organisms/FullTabsMenu/index.js +1 -1
- package/src/components/organisms/InputGroup/index.js +12 -4
- package/src/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +174 -202
- package/src/components/pages/ProviderProductEdition/context/provider-product-edition.context.jsx +14 -14
- package/src/components/pages/ProviderProductEdition/index.js +489 -457
- package/src/components/pages/ProviderProductEdition/utils.js +2 -2
- package/src/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +201 -224
- package/src/components/pages/RetailerProductEdition/context/provider-product-edition.context.jsx +575 -0
- package/src/components/pages/RetailerProductEdition/context/provider-product-edition.reducer.js +62 -0
- package/src/components/pages/RetailerProductEdition/context/reducers/active-state.js +344 -0
- package/src/components/pages/RetailerProductEdition/context/reducers/inputs.js +155 -0
- package/src/components/pages/RetailerProductEdition/context/reducers/product.js +114 -0
- package/src/components/pages/RetailerProductEdition/context/reducers/system.js +60 -0
- package/src/components/pages/RetailerProductEdition/index.js +1545 -1718
- package/src/components/pages/RetailerProductEdition/index_old.js +1979 -0
- package/src/components/pages/RetailerProductEdition/stories/Auditor.stories.js +101 -0
- package/src/components/pages/RetailerProductEdition/stories/ImageEditor.stories.js +115 -0
- package/src/components/pages/RetailerProductEdition/stories/TextEditor.stories.js +174 -0
- package/src/components/pages/RetailerProductEdition/styles.js +67 -2
- package/src/components/pages/RetailerProductEdition/utils.js +240 -0
- package/src/contexts/AiProductEdition.jsx +339 -0
- package/src/global-files/statusDictionary.js +103 -0
|
@@ -21,19 +21,8 @@ var _react = require("react");
|
|
|
21
21
|
|
|
22
22
|
var _axios = _interopRequireDefault(require("axios"));
|
|
23
23
|
|
|
24
|
-
var _attributeSchema = _interopRequireDefault(require("../ai/schemas/attribute.schema.js"));
|
|
25
|
-
|
|
26
|
-
var _descriptionSchema = _interopRequireDefault(require("../ai/schemas/description.schema.js"));
|
|
27
|
-
|
|
28
|
-
var _genai = require("@google/genai");
|
|
29
|
-
|
|
30
|
-
var _description = require("../ai/prompts/description.prompt");
|
|
31
|
-
|
|
32
|
-
var _attribute = require("../ai/prompts/attribute.prompt");
|
|
33
|
-
|
|
34
24
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
35
25
|
|
|
36
|
-
var GeminiApiKey = process.env.REACT_APP_GEMINI_API_KEY;
|
|
37
26
|
var AiProductEdition = /*#__PURE__*/(0, _react.createContext)();
|
|
38
27
|
exports.AiProductEdition = AiProductEdition;
|
|
39
28
|
|
|
@@ -46,37 +35,90 @@ var useAiProductEdition = function useAiProductEdition() {
|
|
|
46
35
|
exports.useAiProductEdition = useAiProductEdition;
|
|
47
36
|
|
|
48
37
|
var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
38
|
+
var _state$datasheets_inp;
|
|
39
|
+
|
|
49
40
|
var children = _ref.children,
|
|
50
41
|
_ref$isCreatorsEditio = _ref.isCreatorsEdition,
|
|
51
|
-
isCreatorsEdition = _ref$isCreatorsEditio === void 0 ?
|
|
52
|
-
_ref$
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
isCreatorsEdition = _ref$isCreatorsEditio === void 0 ? false : _ref$isCreatorsEditio,
|
|
43
|
+
_ref$user = _ref.user,
|
|
44
|
+
user = _ref$user === void 0 ? {} : _ref$user,
|
|
45
|
+
_ref$token = _ref.token,
|
|
46
|
+
token = _ref$token === void 0 ? "" : _ref$token,
|
|
47
|
+
state = _ref.state;
|
|
55
48
|
var isCreators = isCreatorsEdition;
|
|
49
|
+
var productSelected = state.product;
|
|
50
|
+
var activeRetailer = state.active_retailer;
|
|
51
|
+
var datasheetInputs = (_state$datasheets_inp = state.datasheets_inputs) === null || _state$datasheets_inp === void 0 ? void 0 : _state$datasheets_inp[1];
|
|
52
|
+
var imagesData = state.images_values;
|
|
56
53
|
|
|
57
54
|
var _useState = (0, _react.useState)(null),
|
|
58
55
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
59
56
|
product = _useState2[0],
|
|
60
57
|
setProduct = _useState2[1];
|
|
61
58
|
|
|
62
|
-
var _useState3 = (0, _react.useState)(
|
|
59
|
+
var _useState3 = (0, _react.useState)([]),
|
|
63
60
|
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
parsedDatasheet = _useState4[0],
|
|
62
|
+
setParsedDatasheet = _useState4[1];
|
|
66
63
|
|
|
67
|
-
var _useState5 = (0, _react.useState)(
|
|
64
|
+
var _useState5 = (0, _react.useState)([]),
|
|
68
65
|
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
var
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
parsedImages = _useState6[0],
|
|
67
|
+
setParsedImages = _useState6[1];
|
|
68
|
+
|
|
69
|
+
var _useState7 = (0, _react.useState)({}),
|
|
70
|
+
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
|
71
|
+
suggestions = _useState8[0],
|
|
72
|
+
setSuggestions = _useState8[1];
|
|
73
|
+
|
|
74
|
+
var _useState9 = (0, _react.useState)({}),
|
|
75
|
+
_useState10 = (0, _slicedToArray2.default)(_useState9, 2),
|
|
76
|
+
currentSuggestion = _useState10[0],
|
|
77
|
+
setCurrentSuggestion = _useState10[1];
|
|
78
|
+
|
|
79
|
+
var _useState11 = (0, _react.useState)(false),
|
|
80
|
+
_useState12 = (0, _slicedToArray2.default)(_useState11, 2),
|
|
81
|
+
isAiAvailable = _useState12[0],
|
|
82
|
+
setIsAiAvailable = _useState12[1];
|
|
83
|
+
|
|
84
|
+
var _useState13 = (0, _react.useState)({}),
|
|
85
|
+
_useState14 = (0, _slicedToArray2.default)(_useState13, 2),
|
|
86
|
+
inputsGeneratedWithAi = _useState14[0],
|
|
87
|
+
setInputsGeneratedWithAi = _useState14[1];
|
|
88
|
+
|
|
89
|
+
var _useState15 = (0, _react.useState)({}),
|
|
90
|
+
_useState16 = (0, _slicedToArray2.default)(_useState15, 2),
|
|
91
|
+
inputsUsingAi = _useState16[0],
|
|
92
|
+
setInputsUsingAi = _useState16[1];
|
|
93
|
+
|
|
94
|
+
var MAX_CREDITS = 10;
|
|
95
|
+
var COOLDOWN_MS = 5 * 60 * 1000;
|
|
96
|
+
var RATE_LIMIT_KEY = "ai_generation_limit_data";
|
|
97
|
+
|
|
98
|
+
var checkAndManageRateLimit = function checkAndManageRateLimit(currentArticleId) {
|
|
99
|
+
var now = Date.now();
|
|
100
|
+
var storedData = localStorage.getItem(RATE_LIMIT_KEY);
|
|
101
|
+
var allRateData = storedData ? JSON.parse(storedData) : {};
|
|
102
|
+
var productTimestamps = allRateData[currentArticleId] || [];
|
|
103
|
+
productTimestamps = productTimestamps.filter(function (timestamp) {
|
|
104
|
+
return now - timestamp < COOLDOWN_MS;
|
|
79
105
|
});
|
|
106
|
+
|
|
107
|
+
if (productTimestamps.length >= MAX_CREDITS) {
|
|
108
|
+
allRateData[currentArticleId] = productTimestamps;
|
|
109
|
+
localStorage.setItem(RATE_LIMIT_KEY, JSON.stringify(allRateData));
|
|
110
|
+
return {
|
|
111
|
+
allowed: false,
|
|
112
|
+
message: "Has alcanzado el limite de intentos frecuentes para este producto. Por favor, espera unos minutos."
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
productTimestamps.push(now);
|
|
117
|
+
allRateData[currentArticleId] = productTimestamps;
|
|
118
|
+
localStorage.setItem(RATE_LIMIT_KEY, JSON.stringify(allRateData));
|
|
119
|
+
return {
|
|
120
|
+
allowed: true
|
|
121
|
+
};
|
|
80
122
|
};
|
|
81
123
|
|
|
82
124
|
function setCurrentSuggestionValue(_ref2) {
|
|
@@ -101,14 +143,14 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
|
101
143
|
|
|
102
144
|
function _regenerateProductSuggestions() {
|
|
103
145
|
_regenerateProductSuggestions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref3) {
|
|
104
|
-
var
|
|
146
|
+
var inputName, currentValue, description, maxChar, type, articleId, versionId, descriptionId, attributeId, newSuggestions;
|
|
105
147
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
106
148
|
while (1) {
|
|
107
149
|
switch (_context.prev = _context.next) {
|
|
108
150
|
case 0:
|
|
109
|
-
|
|
151
|
+
inputName = _ref3.inputName, currentValue = _ref3.currentValue, description = _ref3.description, maxChar = _ref3.maxChar, type = _ref3.type, articleId = _ref3.articleId, versionId = _ref3.versionId, descriptionId = _ref3.descriptionId, attributeId = _ref3.attributeId;
|
|
110
152
|
|
|
111
|
-
if (!(!
|
|
153
|
+
if (!(!description || !maxChar || !type)) {
|
|
112
154
|
_context.next = 3;
|
|
113
155
|
break;
|
|
114
156
|
}
|
|
@@ -122,31 +164,45 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
|
122
164
|
currentValue: currentValue,
|
|
123
165
|
description: description,
|
|
124
166
|
maxChar: maxChar,
|
|
125
|
-
type: type
|
|
167
|
+
type: type,
|
|
168
|
+
articleId: articleId,
|
|
169
|
+
versionId: versionId,
|
|
170
|
+
descriptionId: descriptionId,
|
|
171
|
+
attributeId: attributeId
|
|
126
172
|
});
|
|
127
173
|
|
|
128
174
|
case 5:
|
|
129
175
|
newSuggestions = _context.sent;
|
|
130
176
|
|
|
131
|
-
if (!(
|
|
177
|
+
if (!(newSuggestions !== null && newSuggestions !== void 0 && newSuggestions.error)) {
|
|
132
178
|
_context.next = 8;
|
|
133
179
|
break;
|
|
134
180
|
}
|
|
135
181
|
|
|
136
|
-
return _context.abrupt("return",
|
|
182
|
+
return _context.abrupt("return", {
|
|
183
|
+
error: newSuggestions.error
|
|
184
|
+
});
|
|
137
185
|
|
|
138
186
|
case 8:
|
|
139
|
-
if (newSuggestions) {
|
|
187
|
+
if (!(!Array.isArray(newSuggestions) || newSuggestions.length === 0)) {
|
|
140
188
|
_context.next = 10;
|
|
141
189
|
break;
|
|
142
190
|
}
|
|
143
191
|
|
|
144
|
-
return _context.abrupt("return", console.log("Error: No
|
|
192
|
+
return _context.abrupt("return", console.log("Error: No se obtuvieron nuevas sugerencias"));
|
|
145
193
|
|
|
146
194
|
case 10:
|
|
195
|
+
if (newSuggestions) {
|
|
196
|
+
_context.next = 12;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return _context.abrupt("return", console.log("Error: No exiten resultados nuevos"));
|
|
201
|
+
|
|
202
|
+
case 12:
|
|
147
203
|
return _context.abrupt("return", newSuggestions);
|
|
148
204
|
|
|
149
|
-
case
|
|
205
|
+
case 13:
|
|
150
206
|
case "end":
|
|
151
207
|
return _context.stop();
|
|
152
208
|
}
|
|
@@ -158,175 +214,136 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
|
158
214
|
|
|
159
215
|
function generateProductSuggestions(_x2) {
|
|
160
216
|
return _generateProductSuggestions.apply(this, arguments);
|
|
161
|
-
}
|
|
217
|
+
} // Verificamos si los servicios de ficha técnica e imágenes estan completos
|
|
218
|
+
|
|
162
219
|
|
|
163
220
|
function _generateProductSuggestions() {
|
|
164
221
|
_generateProductSuggestions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(_ref4) {
|
|
165
|
-
var _ref4$inputName, inputName, _ref4$currentValue, currentValue, _ref4$description, description, _ref4$maxChar, maxChar, _ref4$type, type, upc, productName, retailer, category,
|
|
222
|
+
var _ref4$inputName, inputName, _ref4$currentValue, currentValue, _ref4$description, description, _ref4$maxChar, maxChar, _ref4$type, type, articleId, versionId, descriptionId, attributeId, _state$product, _JSON$parse$data, _JSON$parse, rateLimitStatus, upc, productName, retailer, category, version, payload, _yield$axios$post, data, results, _error$message;
|
|
166
223
|
|
|
167
224
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
168
225
|
while (1) {
|
|
169
226
|
switch (_context2.prev = _context2.next) {
|
|
170
227
|
case 0:
|
|
171
|
-
_ref4$inputName = _ref4.inputName, inputName = _ref4$inputName === void 0 ? "" : _ref4$inputName, _ref4$currentValue = _ref4.currentValue, currentValue = _ref4$currentValue === void 0 ? "" : _ref4$currentValue, _ref4$description = _ref4.description, description = _ref4$description === void 0 ? "" : _ref4$description, _ref4$maxChar = _ref4.maxChar, maxChar = _ref4$maxChar === void 0 ? 100 : _ref4$maxChar, _ref4$type = _ref4.type, type = _ref4$type === void 0 ?
|
|
228
|
+
_ref4$inputName = _ref4.inputName, inputName = _ref4$inputName === void 0 ? "" : _ref4$inputName, _ref4$currentValue = _ref4.currentValue, currentValue = _ref4$currentValue === void 0 ? "" : _ref4$currentValue, _ref4$description = _ref4.description, description = _ref4$description === void 0 ? "" : _ref4$description, _ref4$maxChar = _ref4.maxChar, maxChar = _ref4$maxChar === void 0 ? 100 : _ref4$maxChar, _ref4$type = _ref4.type, type = _ref4$type === void 0 ? 'description' : _ref4$type, articleId = _ref4.articleId, versionId = _ref4.versionId, descriptionId = _ref4.descriptionId, attributeId = _ref4.attributeId;
|
|
172
229
|
_context2.prev = 1;
|
|
173
230
|
|
|
174
|
-
if (
|
|
231
|
+
if (isAiAvailable) {
|
|
175
232
|
_context2.next = 4;
|
|
176
233
|
break;
|
|
177
234
|
}
|
|
178
235
|
|
|
179
|
-
|
|
236
|
+
return _context2.abrupt("return");
|
|
180
237
|
|
|
181
238
|
case 4:
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
239
|
+
rateLimitStatus = checkAndManageRateLimit(articleId);
|
|
240
|
+
|
|
241
|
+
if (rateLimitStatus.allowed) {
|
|
242
|
+
_context2.next = 7;
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return _context2.abrupt("return", {
|
|
247
|
+
error: rateLimitStatus.message,
|
|
248
|
+
isRateLimitInfo: true
|
|
188
249
|
});
|
|
250
|
+
|
|
251
|
+
case 7:
|
|
252
|
+
if (product) {
|
|
253
|
+
_context2.next = 9;
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
throw new Error("El producto no está definido");
|
|
258
|
+
|
|
259
|
+
case 9:
|
|
260
|
+
if (!(!Array.isArray(parsedDatasheet) || parsedDatasheet.length === 0)) {
|
|
261
|
+
_context2.next = 11;
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
throw new Error("No es encontró la ficha técnica");
|
|
266
|
+
|
|
267
|
+
case 11:
|
|
268
|
+
if (!(!Array.isArray(parsedImages) || parsedImages.length === 0)) {
|
|
269
|
+
_context2.next = 13;
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
throw new Error("No se encontraron imágenes para la cadena seleccionada");
|
|
274
|
+
|
|
275
|
+
case 13:
|
|
189
276
|
upc = product.upc, productName = product.productName, retailer = product.retailer, category = product.category;
|
|
277
|
+
version = state === null || state === void 0 ? void 0 : (_state$product = state.product) === null || _state$product === void 0 ? void 0 : _state$product.version;
|
|
190
278
|
|
|
191
|
-
if (!(!upc || !description || !productName || !category || !retailer)) {
|
|
192
|
-
_context2.next =
|
|
279
|
+
if (!(!upc || !description || !productName || !category || !retailer || !articleId || !version || !descriptionId && !attributeId)) {
|
|
280
|
+
_context2.next = 17;
|
|
193
281
|
break;
|
|
194
282
|
}
|
|
195
283
|
|
|
196
284
|
throw new Error("Faltan parámetros obligatorios para generar sugerencias de IA");
|
|
197
285
|
|
|
198
|
-
case
|
|
199
|
-
|
|
200
|
-
upc: upc,
|
|
201
|
-
inputName: inputName,
|
|
202
|
-
description: description,
|
|
203
|
-
name: productName,
|
|
204
|
-
category: category,
|
|
205
|
-
currentValue: currentValue,
|
|
206
|
-
retailer: retailer,
|
|
207
|
-
maxChar: maxChar
|
|
208
|
-
}) : (0, _attribute.generateAttributePrompt)({
|
|
286
|
+
case 17:
|
|
287
|
+
payload = {
|
|
209
288
|
upc: upc,
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
category: category,
|
|
289
|
+
attributeTitle: inputName,
|
|
290
|
+
attributeDescription: description,
|
|
291
|
+
productName: productName,
|
|
214
292
|
currentValue: currentValue,
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
responseSchema: schema,
|
|
231
|
-
temperature: 0.1
|
|
293
|
+
categoryName: category,
|
|
294
|
+
retailerName: retailer,
|
|
295
|
+
datasheet: parsedDatasheet,
|
|
296
|
+
images: parsedImages,
|
|
297
|
+
maxChar: maxChar,
|
|
298
|
+
articleId: articleId,
|
|
299
|
+
retailerId: activeRetailer === null || activeRetailer === void 0 ? void 0 : activeRetailer.id_retailer,
|
|
300
|
+
versionId: version,
|
|
301
|
+
descriptionId: descriptionId,
|
|
302
|
+
attributeId: attributeId
|
|
303
|
+
};
|
|
304
|
+
_context2.next = 20;
|
|
305
|
+
return _axios.default.post(process.env.REACT_APP_GENERATE_AI_ATTRIBUTES, payload, {
|
|
306
|
+
headers: {
|
|
307
|
+
Authorization: token
|
|
232
308
|
}
|
|
233
309
|
});
|
|
234
310
|
|
|
235
|
-
case
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
results =
|
|
311
|
+
case 20:
|
|
312
|
+
_yield$axios$post = _context2.sent;
|
|
313
|
+
data = _yield$axios$post.data;
|
|
314
|
+
results = (_JSON$parse$data = (_JSON$parse = JSON.parse(data === null || data === void 0 ? void 0 : data.body)) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse.data) !== null && _JSON$parse$data !== void 0 ? _JSON$parse$data : [];
|
|
239
315
|
|
|
240
316
|
if (results) {
|
|
241
|
-
_context2.next =
|
|
317
|
+
_context2.next = 25;
|
|
242
318
|
break;
|
|
243
319
|
}
|
|
244
320
|
|
|
245
321
|
throw new Error("No se encontraron resultados");
|
|
246
322
|
|
|
247
|
-
case
|
|
323
|
+
case 25:
|
|
248
324
|
return _context2.abrupt("return", results);
|
|
249
325
|
|
|
250
|
-
case
|
|
251
|
-
_context2.prev =
|
|
326
|
+
case 28:
|
|
327
|
+
_context2.prev = 28;
|
|
252
328
|
_context2.t0 = _context2["catch"](1);
|
|
253
329
|
console.log("Error generating AI suggestions:", _context2.t0);
|
|
254
330
|
return _context2.abrupt("return", {
|
|
255
331
|
error: (_error$message = _context2.t0 === null || _context2.t0 === void 0 ? void 0 : _context2.t0.message) !== null && _error$message !== void 0 ? _error$message : "Error generating AI suggestions"
|
|
256
332
|
});
|
|
257
333
|
|
|
258
|
-
case
|
|
334
|
+
case 32:
|
|
259
335
|
case "end":
|
|
260
336
|
return _context2.stop();
|
|
261
337
|
}
|
|
262
338
|
}
|
|
263
|
-
}, _callee2, null, [[1,
|
|
339
|
+
}, _callee2, null, [[1, 28]]);
|
|
264
340
|
}));
|
|
265
341
|
return _generateProductSuggestions.apply(this, arguments);
|
|
266
342
|
}
|
|
267
343
|
|
|
268
|
-
function generateContentWithRetry(_x3) {
|
|
269
|
-
return _generateContentWithRetry.apply(this, arguments);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
function _generateContentWithRetry() {
|
|
273
|
-
_generateContentWithRetry = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(modelParams) {
|
|
274
|
-
var retries,
|
|
275
|
-
backoff,
|
|
276
|
-
failoverModel,
|
|
277
|
-
model,
|
|
278
|
-
_error$message2,
|
|
279
|
-
isOverloaded,
|
|
280
|
-
_args3 = arguments;
|
|
281
|
-
|
|
282
|
-
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
283
|
-
while (1) {
|
|
284
|
-
switch (_context3.prev = _context3.next) {
|
|
285
|
-
case 0:
|
|
286
|
-
retries = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : 5;
|
|
287
|
-
backoff = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : 1000;
|
|
288
|
-
_context3.prev = 2;
|
|
289
|
-
failoverModel = "gemini-2.5-flash";
|
|
290
|
-
model = retries > 3 ? "gemini-2.5-flash-lite" : failoverModel;
|
|
291
|
-
_context3.next = 7;
|
|
292
|
-
return ai.models.generateContent((0, _objectSpread3.default)((0, _objectSpread3.default)({}, modelParams), {}, {
|
|
293
|
-
model: model
|
|
294
|
-
}));
|
|
295
|
-
|
|
296
|
-
case 7:
|
|
297
|
-
return _context3.abrupt("return", _context3.sent);
|
|
298
|
-
|
|
299
|
-
case 10:
|
|
300
|
-
_context3.prev = 10;
|
|
301
|
-
_context3.t0 = _context3["catch"](2);
|
|
302
|
-
isOverloaded = _context3.t0.status === 503 || ((_error$message2 = _context3.t0.message) === null || _error$message2 === void 0 ? void 0 : _error$message2.includes("overloaded"));
|
|
303
|
-
|
|
304
|
-
if (!(retries > 0 && isOverloaded)) {
|
|
305
|
-
_context3.next = 18;
|
|
306
|
-
break;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
console.warn("\u26A0\uFE0F Modelo saturado (503). Reintentando en ".concat(backoff, "ms... (Quedan ").concat(retries, " intentos)"));
|
|
310
|
-
_context3.next = 17;
|
|
311
|
-
return delay(backoff);
|
|
312
|
-
|
|
313
|
-
case 17:
|
|
314
|
-
return _context3.abrupt("return", generateContentWithRetry(modelParams, retries - 1, backoff * 2));
|
|
315
|
-
|
|
316
|
-
case 18:
|
|
317
|
-
throw _context3.t0;
|
|
318
|
-
|
|
319
|
-
case 19:
|
|
320
|
-
case "end":
|
|
321
|
-
return _context3.stop();
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}, _callee3, null, [[2, 10]]);
|
|
325
|
-
}));
|
|
326
|
-
return _generateContentWithRetry.apply(this, arguments);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
344
|
(0, _react.useEffect)(function () {
|
|
345
|
+
var _productSelected$perc;
|
|
346
|
+
|
|
330
347
|
if (!productSelected) return;
|
|
331
348
|
var productName = productSelected.name,
|
|
332
349
|
upc = productSelected.upc,
|
|
@@ -337,23 +354,78 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
|
337
354
|
});
|
|
338
355
|
if (!currentCategory) return console.log("Error: No se encontro la categoría");
|
|
339
356
|
var retailer = currentCategory.retailer,
|
|
340
|
-
category = currentCategory.category;
|
|
357
|
+
category = currentCategory.category; //Checamos si el servicio de ficha técnica e imagenes esta completo
|
|
358
|
+
|
|
359
|
+
var currentRetailerPercentages = productSelected === null || productSelected === void 0 ? void 0 : (_productSelected$perc = productSelected.percentages) === null || _productSelected$perc === void 0 ? void 0 : _productSelected$perc.find(function (retailer) {
|
|
360
|
+
return (retailer === null || retailer === void 0 ? void 0 : retailer.id_retailer) === (activeRetailer === null || activeRetailer === void 0 ? void 0 : activeRetailer.id_retailer);
|
|
361
|
+
});
|
|
362
|
+
if (!currentRetailerPercentages) return console.log("Error: No hay porcentajes disponibles");
|
|
363
|
+
|
|
364
|
+
var _currentRetailerPerce = currentRetailerPercentages === null || currentRetailerPercentages === void 0 ? void 0 : currentRetailerPercentages.datasheet,
|
|
365
|
+
datasheetRequiredPercent = _currentRetailerPerce.required;
|
|
366
|
+
|
|
367
|
+
var _currentRetailerPerce2 = currentRetailerPercentages === null || currentRetailerPercentages === void 0 ? void 0 : currentRetailerPercentages.images,
|
|
368
|
+
imagesRequiredPercent = _currentRetailerPerce2.required;
|
|
369
|
+
|
|
370
|
+
var aiServiceAvailable = datasheetRequiredPercent >= 100 && imagesRequiredPercent >= 100 && [1, 4, 6, 7].some(function (allowed) {
|
|
371
|
+
return allowed = user === null || user === void 0 ? void 0 : user.id_role;
|
|
372
|
+
});
|
|
373
|
+
setIsAiAvailable(aiServiceAvailable);
|
|
341
374
|
setProduct({
|
|
342
375
|
upc: upc,
|
|
343
376
|
productName: productName,
|
|
344
377
|
retailer: retailer,
|
|
345
378
|
category: category
|
|
346
379
|
});
|
|
347
|
-
}, [productSelected]);
|
|
380
|
+
}, [productSelected]); // Inicializamos la ficha técnica con el objetivo de posteriormente pasarlo a la generación con IA
|
|
381
|
+
|
|
382
|
+
(0, _react.useEffect)(function () {
|
|
383
|
+
if (!datasheetInputs) return;
|
|
384
|
+
var datasheetToArray = Object.values(datasheetInputs);
|
|
385
|
+
var normalizedDatasheet = datasheetToArray.map(function (attribute) {
|
|
386
|
+
return {
|
|
387
|
+
description: attribute === null || attribute === void 0 ? void 0 : attribute.description,
|
|
388
|
+
name: attribute === null || attribute === void 0 ? void 0 : attribute.name,
|
|
389
|
+
type: attribute === null || attribute === void 0 ? void 0 : attribute.type,
|
|
390
|
+
value: attribute === null || attribute === void 0 ? void 0 : attribute.value
|
|
391
|
+
};
|
|
392
|
+
});
|
|
393
|
+
setParsedDatasheet(normalizedDatasheet);
|
|
394
|
+
}, [datasheetInputs]); // Inicializamos las imágenes con el objetivo de posteriormente pasarlo a la generación con IA
|
|
395
|
+
|
|
396
|
+
(0, _react.useEffect)(function () {
|
|
397
|
+
var _imagesData$inputsByR, _imagesData$inputsByR2;
|
|
398
|
+
|
|
399
|
+
var currentRetailerImageInputs = imagesData === null || imagesData === void 0 ? void 0 : (_imagesData$inputsByR = imagesData.inputsByRetailer) === null || _imagesData$inputsByR === void 0 ? void 0 : (_imagesData$inputsByR2 = _imagesData$inputsByR[0]) === null || _imagesData$inputsByR2 === void 0 ? void 0 : _imagesData$inputsByR2.filter(function (input) {
|
|
400
|
+
return (input === null || input === void 0 ? void 0 : input.id_retailer) === (activeRetailer === null || activeRetailer === void 0 ? void 0 : activeRetailer.id_retailer);
|
|
401
|
+
});
|
|
402
|
+
if (!Array.isArray(currentRetailerImageInputs) || currentRetailerImageInputs.length === 0) return console.log('No existen imágenes para la cadena seleccionada');
|
|
403
|
+
var allProductImages = imagesData === null || imagesData === void 0 ? void 0 : imagesData.values;
|
|
404
|
+
if (!Array.isArray(allProductImages) || allProductImages.length === 0) return console.log("No existen imágenes para el producto"); //Obtenemos las imágenes para el retailer seleccionado
|
|
405
|
+
|
|
406
|
+
var currentParsedImages = allProductImages.filter(function (image) {
|
|
407
|
+
var imageId = image === null || image === void 0 ? void 0 : image.image_id;
|
|
408
|
+
var foundedImage = currentRetailerImageInputs.some(function (retailerImage) {
|
|
409
|
+
return (retailerImage === null || retailerImage === void 0 ? void 0 : retailerImage.id_image) === imageId;
|
|
410
|
+
});
|
|
411
|
+
return foundedImage;
|
|
412
|
+
});
|
|
413
|
+
setParsedImages(currentParsedImages);
|
|
414
|
+
}, [imagesData]);
|
|
348
415
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(AiProductEdition.Provider, {
|
|
349
416
|
value: {
|
|
350
417
|
isCreators: isCreators,
|
|
351
418
|
suggestions: suggestions,
|
|
352
419
|
currentSuggestion: currentSuggestion,
|
|
353
|
-
|
|
354
|
-
|
|
420
|
+
isAiAvailable: isAiAvailable,
|
|
421
|
+
inputsGeneratedWithAi: inputsGeneratedWithAi,
|
|
422
|
+
inputsUsingAi: inputsUsingAi,
|
|
423
|
+
setInputsUsingAi: setInputsUsingAi,
|
|
424
|
+
setInputsGeneratedWithAi: setInputsGeneratedWithAi,
|
|
355
425
|
setSuggestions: setSuggestions,
|
|
356
426
|
setCurrentSuggestionValue: setCurrentSuggestionValue,
|
|
427
|
+
generateProductSuggestions: generateProductSuggestions,
|
|
428
|
+
regenerateProductSuggestions: regenerateProductSuggestions,
|
|
357
429
|
clearCurrentSuggestions: clearCurrentSuggestions
|
|
358
430
|
},
|
|
359
431
|
children: children
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var STATUS_DICTIONARY = {
|
|
4
|
+
// R: {
|
|
5
|
+
// status: "R",
|
|
6
|
+
// name: "Recepción",
|
|
7
|
+
// weight: 1
|
|
8
|
+
// },
|
|
9
|
+
PA: {
|
|
10
|
+
status: "PA",
|
|
11
|
+
name: "Por Asignar",
|
|
12
|
+
weight: 2
|
|
13
|
+
},
|
|
14
|
+
AS: {
|
|
15
|
+
status: "AS",
|
|
16
|
+
name: "Asignado",
|
|
17
|
+
weight: 3
|
|
18
|
+
},
|
|
19
|
+
// CA: {
|
|
20
|
+
// status: "CA",
|
|
21
|
+
// name: "Capturando",
|
|
22
|
+
// weight: 4
|
|
23
|
+
// },
|
|
24
|
+
// IE: {
|
|
25
|
+
// status: "IE",
|
|
26
|
+
// name: "Información Enviada",
|
|
27
|
+
// weight: 5
|
|
28
|
+
// },
|
|
29
|
+
RCA: {
|
|
30
|
+
status: "RCA",
|
|
31
|
+
name: "Rechazado Cadena",
|
|
32
|
+
weight: 6
|
|
33
|
+
},
|
|
34
|
+
RP: {
|
|
35
|
+
status: "RP",
|
|
36
|
+
name: "Rechazado Proveedor",
|
|
37
|
+
weight: 7
|
|
38
|
+
},
|
|
39
|
+
RA: {
|
|
40
|
+
status: "RA",
|
|
41
|
+
name: "Rechazado Auditor",
|
|
42
|
+
weight: 8
|
|
43
|
+
},
|
|
44
|
+
RC: {
|
|
45
|
+
status: "RC",
|
|
46
|
+
name: "Rechazo Coordinador",
|
|
47
|
+
weight: 9
|
|
48
|
+
},
|
|
49
|
+
AC: {
|
|
50
|
+
status: "AC",
|
|
51
|
+
name: "Aprobado Coordinador",
|
|
52
|
+
weight: 10
|
|
53
|
+
},
|
|
54
|
+
AA: {
|
|
55
|
+
status: "AA",
|
|
56
|
+
name: "Aprobado Auditor",
|
|
57
|
+
weight: 11
|
|
58
|
+
},
|
|
59
|
+
AP: {
|
|
60
|
+
status: "AP",
|
|
61
|
+
name: "Aprobado Proveedor",
|
|
62
|
+
weight: 12
|
|
63
|
+
},
|
|
64
|
+
ACA: {
|
|
65
|
+
status: "ACA",
|
|
66
|
+
name: "Aprobado Cadena",
|
|
67
|
+
weight: 13
|
|
68
|
+
},
|
|
69
|
+
Ex: {
|
|
70
|
+
status: "Ex",
|
|
71
|
+
name: "Exportado",
|
|
72
|
+
weight: 14
|
|
73
|
+
},
|
|
74
|
+
// RAC: {
|
|
75
|
+
// status: "RAC",
|
|
76
|
+
// name: "Rechazo de Auditoría Content-oh!",
|
|
77
|
+
// weight: 15
|
|
78
|
+
// },
|
|
79
|
+
// SAC: {
|
|
80
|
+
// status: "SAC",
|
|
81
|
+
// name: "Solicitud de Auditoría Content-oh!",
|
|
82
|
+
// weight: 16
|
|
83
|
+
// },
|
|
84
|
+
// AAC: {
|
|
85
|
+
// status: "AAC",
|
|
86
|
+
// name: "Aprobado Auditoría Content-oh!",
|
|
87
|
+
// weight: 17
|
|
88
|
+
// },
|
|
89
|
+
// FAP: {
|
|
90
|
+
// status: "FAP",
|
|
91
|
+
// name: "Finalización de Auditoría por Proveedor",
|
|
92
|
+
// weight: 18
|
|
93
|
+
// },
|
|
94
|
+
//El status NS necesita ser el mayor de todos
|
|
95
|
+
NS: {
|
|
96
|
+
status: "NS",
|
|
97
|
+
name: "No Solicitado",
|
|
98
|
+
weight: 100
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
module.exports = {
|
|
102
|
+
STATUS_DICTIONARY: STATUS_DICTIONARY
|
|
103
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "contentoh-components-library",
|
|
3
|
-
"version": "21.5.
|
|
3
|
+
"version": "21.5.95",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@aws-amplify/auth": "^4.5.3",
|
|
6
6
|
"@aws-amplify/datastore": "^3.11.0",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"@fortawesome/free-regular-svg-icons": "^6.2.0",
|
|
13
13
|
"@fortawesome/free-solid-svg-icons": "^6.2.0",
|
|
14
14
|
"@fortawesome/react-fontawesome": "^0.2.0",
|
|
15
|
+
"@google/genai": "^1.35.0",
|
|
15
16
|
"@mui/icons-material": "^5.11.16",
|
|
16
17
|
"@mui/material": "^5.12.0",
|
|
17
18
|
"@mui/styled-engine-sc": "^5.12.0",
|
|
@@ -51,7 +52,8 @@
|
|
|
51
52
|
"styled-components": "^5.3.9",
|
|
52
53
|
"swiper": "^8.4.4",
|
|
53
54
|
"uuid": "^8.3.2",
|
|
54
|
-
"web-vitals": "^1.0.1"
|
|
55
|
+
"web-vitals": "^1.0.1",
|
|
56
|
+
"zod": "^4.3.5"
|
|
55
57
|
},
|
|
56
58
|
"scripts": {
|
|
57
59
|
"start": "start-storybook -p 6006",
|