contentoh-components-library 21.5.86 → 21.5.88
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/components/molecules/TagAndInput/index.js +55 -14
- package/dist/components/molecules/TagAndInput/styles.js +1 -1
- package/dist/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +149 -100
- package/dist/components/pages/RetailerProductEdition/context/reducers/product.js +11 -7
- package/dist/components/pages/RetailerProductEdition/index.js +80 -76
- package/dist/contexts/AiProductEdition.js +75 -22
- package/package.json +1 -1
- package/src/components/molecules/TagAndInput/index.js +32 -2
- package/src/components/molecules/TagAndInput/styles.js +11 -0
- package/src/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +159 -99
- package/src/components/pages/RetailerProductEdition/context/reducers/product.js +4 -4
- package/src/components/pages/RetailerProductEdition/index.js +47 -28
- package/src/contexts/AiProductEdition.jsx +45 -0
|
@@ -985,7 +985,7 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
|
|
|
985
985
|
var _ref10 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(result) {
|
|
986
986
|
var _state$product$id_ord, _state$active_retaile3;
|
|
987
987
|
|
|
988
|
-
var concept, articleId, orderId, sectionStatusKey, evalStatus, retailerId, data, res, message, icon, activeTab, newStatuses, serviceStatus, updatedStatusByRetailer, updatedProduct, specialistDone, _objectSpread2, _JSON$parse2, newStatus, newOrderStatus, newArticleStatus,
|
|
988
|
+
var concept, articleId, orderId, sectionStatusKey, evalStatus, retailerId, data, res, message, icon, activeTab, newStatuses, serviceStatus, updatedStatusByRetailer, updatedProduct, specialistDone, _objectSpread2, _state$services_data, _JSON$parse2, newStatus, newOrderStatus, newArticleStatus, _updatedProduct, updatedServicesData, sessionProduct, _objectSpread3, productInSession, updatedProductInSession;
|
|
989
989
|
|
|
990
990
|
return _regenerator.default.wrap(function _callee7$(_context7) {
|
|
991
991
|
while (1) {
|
|
@@ -1064,6 +1064,8 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
|
|
|
1064
1064
|
break;
|
|
1065
1065
|
|
|
1066
1066
|
case 26:
|
|
1067
|
+
//Caso del botón "Enviar evaluación"
|
|
1068
|
+
//Se construye el mensaje y se actualiza el estatus
|
|
1067
1069
|
specialistDone = ["RC", "RA", "CA"].includes(evalStatus);
|
|
1068
1070
|
|
|
1069
1071
|
if (specialistDone) {
|
|
@@ -1085,52 +1087,31 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
|
|
|
1085
1087
|
res = _context7.sent;
|
|
1086
1088
|
|
|
1087
1089
|
case 31:
|
|
1088
|
-
if (
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
Authorization: token
|
|
1114
|
-
}
|
|
1115
|
-
};
|
|
1116
|
-
_context7.next = 38;
|
|
1117
|
-
return (0, _utils.sendMessage)(messageData);
|
|
1118
|
-
|
|
1119
|
-
case 38:
|
|
1120
|
-
_updatedProduct = (0, _objectSpread5.default)((0, _objectSpread5.default)({}, state.product), {}, (_objectSpread2 = {}, (0, _defineProperty2.default)(_objectSpread2, "".concat(concept, "_status"), newStatus), (0, _defineProperty2.default)(_objectSpread2, "statusByRetailer", state.product.statusByRetailer.map(function (item) {
|
|
1121
|
-
if (item.retailer_id === retailerId && item.service === concept) {
|
|
1122
|
-
return (0, _objectSpread5.default)((0, _objectSpread5.default)({}, item), {}, {
|
|
1123
|
-
status: newStatus
|
|
1124
|
-
});
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
return item;
|
|
1128
|
-
})), _objectSpread2));
|
|
1129
|
-
sessionProduct = sessionStorage.getItem("productSelected");
|
|
1130
|
-
|
|
1131
|
-
if (sessionProduct) {
|
|
1132
|
-
productInSession = JSON.parse(sessionProduct);
|
|
1133
|
-
updatedProductInSession = (0, _objectSpread5.default)((0, _objectSpread5.default)({}, productInSession), {}, (_objectSpread3 = {}, (0, _defineProperty2.default)(_objectSpread3, "".concat(concept, "_status"), newStatus), (0, _defineProperty2.default)(_objectSpread3, "statusByRetailer", state.product.statusByRetailer.map(function (item) {
|
|
1090
|
+
if (res.data.statusCode === 200) {
|
|
1091
|
+
_JSON$parse2 = JSON.parse(res.data.body), newStatus = _JSON$parse2.newStatus, newOrderStatus = _JSON$parse2.newOrderStatus, newArticleStatus = _JSON$parse2.newArticleStatus; // const retailers = state.product.categoryRetailer.map((r) => ({
|
|
1092
|
+
// id: r.id_retailer,
|
|
1093
|
+
// name: r.retailerName,
|
|
1094
|
+
// }));
|
|
1095
|
+
// const messageToChat = createMessage(
|
|
1096
|
+
// retailers,
|
|
1097
|
+
// retailerId,
|
|
1098
|
+
// evalStatus,
|
|
1099
|
+
// newStatus,
|
|
1100
|
+
// activeTab,
|
|
1101
|
+
// );
|
|
1102
|
+
// const messageData = {
|
|
1103
|
+
// paramsBody: {
|
|
1104
|
+
// id: articleId,
|
|
1105
|
+
// version: state.product.version,
|
|
1106
|
+
// items: [{ type: "status", value: messageToChat }],
|
|
1107
|
+
// retailerId: retailerId,
|
|
1108
|
+
// status: state.product.status,
|
|
1109
|
+
// },
|
|
1110
|
+
// paramsHeader: { Authorization: token },
|
|
1111
|
+
// };
|
|
1112
|
+
// await sendMessage(messageData);
|
|
1113
|
+
|
|
1114
|
+
_updatedProduct = (0, _objectSpread5.default)((0, _objectSpread5.default)({}, state.product), {}, (_objectSpread2 = {}, (0, _defineProperty2.default)(_objectSpread2, "".concat(concept, "_status"), newStatus), (0, _defineProperty2.default)(_objectSpread2, "statusByRetailer", state.product.statusByRetailer.map(function (item) {
|
|
1134
1115
|
if (item.retailer_id === retailerId && item.service === concept) {
|
|
1135
1116
|
return (0, _objectSpread5.default)((0, _objectSpread5.default)({}, item), {}, {
|
|
1136
1117
|
status: newStatus
|
|
@@ -1138,33 +1119,56 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
|
|
|
1138
1119
|
}
|
|
1139
1120
|
|
|
1140
1121
|
return item;
|
|
1141
|
-
})),
|
|
1142
|
-
|
|
1143
|
-
|
|
1122
|
+
})), _objectSpread2)); //Actualizamos el services_data en el servicio específico del retailer actual
|
|
1123
|
+
|
|
1124
|
+
updatedServicesData = (_state$services_data = state.services_data) === null || _state$services_data === void 0 ? void 0 : _state$services_data.map(function (service) {
|
|
1125
|
+
return (0, _objectSpread5.default)((0, _objectSpread5.default)({}, service), {}, {
|
|
1126
|
+
status: (service === null || service === void 0 ? void 0 : service.id_retailer) === retailerId && (service === null || service === void 0 ? void 0 : service.service) === concept ? newStatus : service === null || service === void 0 ? void 0 : service.status
|
|
1127
|
+
});
|
|
1128
|
+
});
|
|
1129
|
+
sessionProduct = sessionStorage.getItem("productSelected");
|
|
1130
|
+
|
|
1131
|
+
if (sessionProduct) {
|
|
1132
|
+
productInSession = JSON.parse(sessionProduct);
|
|
1133
|
+
updatedProductInSession = (0, _objectSpread5.default)((0, _objectSpread5.default)({}, productInSession), {}, (_objectSpread3 = {}, (0, _defineProperty2.default)(_objectSpread3, "".concat(concept, "_status"), newStatus), (0, _defineProperty2.default)(_objectSpread3, "statusByRetailer", state.product.statusByRetailer.map(function (item) {
|
|
1134
|
+
if (item.retailer_id === retailerId && item.service === concept) {
|
|
1135
|
+
return (0, _objectSpread5.default)((0, _objectSpread5.default)({}, item), {}, {
|
|
1136
|
+
status: newStatus
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
return item;
|
|
1141
|
+
})), _objectSpread3));
|
|
1142
|
+
sessionStorage.setItem("productSelected", JSON.stringify(updatedProductInSession));
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
if (message) {
|
|
1146
|
+
dispatch({
|
|
1147
|
+
type: "SET_MODAL",
|
|
1148
|
+
payload: {
|
|
1149
|
+
show: true,
|
|
1150
|
+
title: "",
|
|
1151
|
+
message: message,
|
|
1152
|
+
image: _genericModalCheck.default
|
|
1153
|
+
}
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1144
1156
|
|
|
1145
|
-
if (message) {
|
|
1146
1157
|
dispatch({
|
|
1147
|
-
type: "
|
|
1148
|
-
payload:
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
}
|
|
1158
|
+
type: "SET_PRODUCT",
|
|
1159
|
+
payload: _updatedProduct
|
|
1160
|
+
});
|
|
1161
|
+
dispatch({
|
|
1162
|
+
type: "SET_SERVICES_DATA",
|
|
1163
|
+
payload: updatedServicesData
|
|
1154
1164
|
});
|
|
1155
1165
|
}
|
|
1156
1166
|
|
|
1157
|
-
|
|
1158
|
-
type: "SET_PRODUCT",
|
|
1159
|
-
payload: _updatedProduct
|
|
1160
|
-
});
|
|
1161
|
-
|
|
1162
|
-
case 43:
|
|
1163
|
-
_context7.next = 49;
|
|
1167
|
+
_context7.next = 38;
|
|
1164
1168
|
break;
|
|
1165
1169
|
|
|
1166
|
-
case
|
|
1167
|
-
_context7.prev =
|
|
1170
|
+
case 34:
|
|
1171
|
+
_context7.prev = 34;
|
|
1168
1172
|
_context7.t0 = _context7["catch"](11);
|
|
1169
1173
|
console.error("Error sending evaluation:", _context7.t0);
|
|
1170
1174
|
dispatch({
|
|
@@ -1177,20 +1181,20 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
|
|
|
1177
1181
|
}
|
|
1178
1182
|
});
|
|
1179
1183
|
|
|
1180
|
-
case
|
|
1181
|
-
_context7.prev =
|
|
1184
|
+
case 38:
|
|
1185
|
+
_context7.prev = 38;
|
|
1182
1186
|
dispatch({
|
|
1183
1187
|
type: "SET_SAVING",
|
|
1184
1188
|
payload: false
|
|
1185
1189
|
});
|
|
1186
|
-
return _context7.finish(
|
|
1190
|
+
return _context7.finish(38);
|
|
1187
1191
|
|
|
1188
|
-
case
|
|
1192
|
+
case 41:
|
|
1189
1193
|
case "end":
|
|
1190
1194
|
return _context7.stop();
|
|
1191
1195
|
}
|
|
1192
1196
|
}
|
|
1193
|
-
}, _callee7, null, [[11,
|
|
1197
|
+
}, _callee7, null, [[11, 34, 38, 41]]);
|
|
1194
1198
|
}));
|
|
1195
1199
|
|
|
1196
1200
|
return function sendSingleEvaluation(_x2) {
|
|
@@ -1227,7 +1231,7 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
|
|
|
1227
1231
|
|
|
1228
1232
|
var sendBulkEvaluation = /*#__PURE__*/function () {
|
|
1229
1233
|
var _ref12 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(result) {
|
|
1230
|
-
var _state$
|
|
1234
|
+
var _state$services_data2, evaluationArray, conceptArray, status, updatedStatusByRetailer, updatedProduct, productInSession, updatedProductInSession;
|
|
1231
1235
|
|
|
1232
1236
|
return _regenerator.default.wrap(function _callee9$(_context9) {
|
|
1233
1237
|
while (1) {
|
|
@@ -1241,7 +1245,7 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
|
|
|
1241
1245
|
evaluationArray = [];
|
|
1242
1246
|
conceptArray = (0, _utils.getConceptsByRole)(user.id_role); // Crear todas las evaluaciones para cada servicio y retailer
|
|
1243
1247
|
|
|
1244
|
-
(_state$
|
|
1248
|
+
(_state$services_data2 = state.services_data) === null || _state$services_data2 === void 0 ? void 0 : _state$services_data2.forEach(function (ret) {
|
|
1245
1249
|
var service = ret.service,
|
|
1246
1250
|
id_retailer = ret.id_retailer,
|
|
1247
1251
|
status = ret.status;
|
|
@@ -1505,7 +1509,7 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
|
|
|
1505
1509
|
case 4:
|
|
1506
1510
|
case 5:
|
|
1507
1511
|
var filteredSrv45 = servicesByTab === null || servicesByTab === void 0 ? void 0 : servicesByTab.filter(function (serv) {
|
|
1508
|
-
return statusArray.includes(serv.status);
|
|
1512
|
+
return statusArray.includes(serv === null || serv === void 0 ? void 0 : serv.status);
|
|
1509
1513
|
});
|
|
1510
1514
|
var condition45 = unvalidated && ["CA", "IE"].includes(product === null || product === void 0 ? void 0 : product.status) && (filteredSrv45 === null || filteredSrv45 === void 0 ? void 0 : filteredSrv45.length) === (servicesByTab === null || servicesByTab === void 0 ? void 0 : servicesByTab.length);
|
|
1511
1515
|
return condition45;
|
|
@@ -1513,7 +1517,7 @@ var RetailerProductEditionView = function RetailerProductEditionView(_ref) {
|
|
|
1513
1517
|
case 6:
|
|
1514
1518
|
var statusInArray = statusArray.includes(product === null || product === void 0 ? void 0 : product.status);
|
|
1515
1519
|
var allSrvValid = (_srv = srv) === null || _srv === void 0 ? void 0 : _srv.every(function (serv) {
|
|
1516
|
-
return ["RA", "AA", "AP", "ACA"].includes(serv.status);
|
|
1520
|
+
return ["RA", "AA", "AP", "ACA"].includes(serv === null || serv === void 0 ? void 0 : serv.status);
|
|
1517
1521
|
});
|
|
1518
1522
|
var condition6 = statusInArray && allSrvValid && auditorUnvalidated;
|
|
1519
1523
|
return condition6;
|
|
@@ -96,6 +96,36 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
|
96
96
|
inputsUsingAi = _useState16[0],
|
|
97
97
|
setInputsUsingAi = _useState16[1];
|
|
98
98
|
|
|
99
|
+
var MAX_CREDITS = 10;
|
|
100
|
+
var COOLDOWN_MS = 5 * 60 * 1000;
|
|
101
|
+
var RATE_LIMIT_KEY = "ai_generation_limit_data";
|
|
102
|
+
|
|
103
|
+
var checkAndManageRateLimit = function checkAndManageRateLimit(currentArticleId) {
|
|
104
|
+
var now = Date.now();
|
|
105
|
+
var storedData = localStorage.getItem(RATE_LIMIT_KEY);
|
|
106
|
+
var allRateData = storedData ? JSON.parse(storedData) : {};
|
|
107
|
+
var productTimestamps = allRateData[currentArticleId] || [];
|
|
108
|
+
productTimestamps = productTimestamps.filter(function (timestamp) {
|
|
109
|
+
return now - timestamp < COOLDOWN_MS;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (productTimestamps.length >= MAX_CREDITS) {
|
|
113
|
+
allRateData[currentArticleId] = productTimestamps;
|
|
114
|
+
localStorage.setItem(RATE_LIMIT_KEY, JSON.stringify(allRateData));
|
|
115
|
+
return {
|
|
116
|
+
allowed: false,
|
|
117
|
+
message: "Has alcanzado el limite de intentos frecuentes para este producto. Por favor, espera unos minutos."
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
productTimestamps.push(now);
|
|
122
|
+
allRateData[currentArticleId] = productTimestamps;
|
|
123
|
+
localStorage.setItem(RATE_LIMIT_KEY, JSON.stringify(allRateData));
|
|
124
|
+
return {
|
|
125
|
+
allowed: true
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
|
|
99
129
|
function setCurrentSuggestionValue(_ref2) {
|
|
100
130
|
var inputId = _ref2.inputId,
|
|
101
131
|
index = _ref2.index,
|
|
@@ -149,25 +179,35 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
|
149
179
|
case 5:
|
|
150
180
|
newSuggestions = _context.sent;
|
|
151
181
|
|
|
152
|
-
if (!(
|
|
182
|
+
if (!(newSuggestions !== null && newSuggestions !== void 0 && newSuggestions.error)) {
|
|
153
183
|
_context.next = 8;
|
|
154
184
|
break;
|
|
155
185
|
}
|
|
156
186
|
|
|
157
|
-
return _context.abrupt("return",
|
|
187
|
+
return _context.abrupt("return", {
|
|
188
|
+
error: newSuggestions.error
|
|
189
|
+
});
|
|
158
190
|
|
|
159
191
|
case 8:
|
|
160
|
-
if (newSuggestions) {
|
|
192
|
+
if (!(!Array.isArray(newSuggestions) || newSuggestions.length === 0)) {
|
|
161
193
|
_context.next = 10;
|
|
162
194
|
break;
|
|
163
195
|
}
|
|
164
196
|
|
|
165
|
-
return _context.abrupt("return", console.log("Error: No
|
|
197
|
+
return _context.abrupt("return", console.log("Error: No se obtuvieron nuevas sugerencias"));
|
|
166
198
|
|
|
167
199
|
case 10:
|
|
200
|
+
if (newSuggestions) {
|
|
201
|
+
_context.next = 12;
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return _context.abrupt("return", console.log("Error: No exiten resultados nuevos"));
|
|
206
|
+
|
|
207
|
+
case 12:
|
|
168
208
|
return _context.abrupt("return", newSuggestions);
|
|
169
209
|
|
|
170
|
-
case
|
|
210
|
+
case 13:
|
|
171
211
|
case "end":
|
|
172
212
|
return _context.stop();
|
|
173
213
|
}
|
|
@@ -184,7 +224,7 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
|
184
224
|
|
|
185
225
|
function _generateProductSuggestions() {
|
|
186
226
|
_generateProductSuggestions = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(_ref4) {
|
|
187
|
-
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, upc, productName, retailer, category, version, payload, _yield$axios$post, data, results, _error$message;
|
|
227
|
+
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;
|
|
188
228
|
|
|
189
229
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
190
230
|
while (1) {
|
|
@@ -201,41 +241,54 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
|
201
241
|
return _context2.abrupt("return");
|
|
202
242
|
|
|
203
243
|
case 4:
|
|
244
|
+
rateLimitStatus = checkAndManageRateLimit(articleId);
|
|
245
|
+
|
|
246
|
+
if (rateLimitStatus.allowed) {
|
|
247
|
+
_context2.next = 7;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return _context2.abrupt("return", {
|
|
252
|
+
error: rateLimitStatus.message,
|
|
253
|
+
isRateLimitInfo: true
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
case 7:
|
|
204
257
|
if (product) {
|
|
205
|
-
_context2.next =
|
|
258
|
+
_context2.next = 9;
|
|
206
259
|
break;
|
|
207
260
|
}
|
|
208
261
|
|
|
209
262
|
throw new Error("El producto no está definido");
|
|
210
263
|
|
|
211
|
-
case
|
|
264
|
+
case 9:
|
|
212
265
|
if (!(!Array.isArray(parsedDatasheet) || parsedDatasheet.length === 0)) {
|
|
213
|
-
_context2.next =
|
|
266
|
+
_context2.next = 11;
|
|
214
267
|
break;
|
|
215
268
|
}
|
|
216
269
|
|
|
217
270
|
throw new Error("No es encontró la ficha técnica");
|
|
218
271
|
|
|
219
|
-
case
|
|
272
|
+
case 11:
|
|
220
273
|
if (!(!Array.isArray(parsedImages) || parsedImages.length === 0)) {
|
|
221
|
-
_context2.next =
|
|
274
|
+
_context2.next = 13;
|
|
222
275
|
break;
|
|
223
276
|
}
|
|
224
277
|
|
|
225
278
|
throw new Error("No se encontraron imágenes para la cadena seleccionada");
|
|
226
279
|
|
|
227
|
-
case
|
|
280
|
+
case 13:
|
|
228
281
|
upc = product.upc, productName = product.productName, retailer = product.retailer, category = product.category;
|
|
229
282
|
version = state === null || state === void 0 ? void 0 : (_state$product = state.product) === null || _state$product === void 0 ? void 0 : _state$product.version;
|
|
230
283
|
|
|
231
284
|
if (!(!upc || !description || !productName || !category || !retailer || !articleId || !version || !descriptionId && !attributeId)) {
|
|
232
|
-
_context2.next =
|
|
285
|
+
_context2.next = 17;
|
|
233
286
|
break;
|
|
234
287
|
}
|
|
235
288
|
|
|
236
289
|
throw new Error("Faltan parámetros obligatorios para generar sugerencias de IA");
|
|
237
290
|
|
|
238
|
-
case
|
|
291
|
+
case 17:
|
|
239
292
|
payload = {
|
|
240
293
|
upc: upc,
|
|
241
294
|
attributeTitle: inputName,
|
|
@@ -253,42 +306,42 @@ var AiProductEditionProvider = function AiProductEditionProvider(_ref) {
|
|
|
253
306
|
descriptionId: descriptionId,
|
|
254
307
|
attributeId: attributeId
|
|
255
308
|
};
|
|
256
|
-
_context2.next =
|
|
309
|
+
_context2.next = 20;
|
|
257
310
|
return _axios.default.post(process.env.REACT_APP_GENERATE_AI_ATTRIBUTES, payload, {
|
|
258
311
|
headers: {
|
|
259
312
|
Authorization: token
|
|
260
313
|
}
|
|
261
314
|
});
|
|
262
315
|
|
|
263
|
-
case
|
|
316
|
+
case 20:
|
|
264
317
|
_yield$axios$post = _context2.sent;
|
|
265
318
|
data = _yield$axios$post.data;
|
|
266
319
|
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 : [];
|
|
267
320
|
|
|
268
321
|
if (results) {
|
|
269
|
-
_context2.next =
|
|
322
|
+
_context2.next = 25;
|
|
270
323
|
break;
|
|
271
324
|
}
|
|
272
325
|
|
|
273
326
|
throw new Error("No se encontraron resultados");
|
|
274
327
|
|
|
275
|
-
case
|
|
328
|
+
case 25:
|
|
276
329
|
return _context2.abrupt("return", results);
|
|
277
330
|
|
|
278
|
-
case
|
|
279
|
-
_context2.prev =
|
|
331
|
+
case 28:
|
|
332
|
+
_context2.prev = 28;
|
|
280
333
|
_context2.t0 = _context2["catch"](1);
|
|
281
334
|
console.log("Error generating AI suggestions:", _context2.t0);
|
|
282
335
|
return _context2.abrupt("return", {
|
|
283
336
|
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"
|
|
284
337
|
});
|
|
285
338
|
|
|
286
|
-
case
|
|
339
|
+
case 32:
|
|
287
340
|
case "end":
|
|
288
341
|
return _context2.stop();
|
|
289
342
|
}
|
|
290
343
|
}
|
|
291
|
-
}, _callee2, null, [[1,
|
|
344
|
+
}, _callee2, null, [[1, 28]]);
|
|
292
345
|
}));
|
|
293
346
|
return _generateProductSuggestions.apply(this, arguments);
|
|
294
347
|
}
|
package/package.json
CHANGED
|
@@ -71,6 +71,8 @@ export const TagAndInput = ({
|
|
|
71
71
|
const [isAiRegenerationLoading, setIsAiRegenerationLoading] = useState(false);
|
|
72
72
|
const [isAiGenerated, setIsAiGenerated] = useState(false);
|
|
73
73
|
|
|
74
|
+
const [errorMessage, setErrorMessage] = useState("");
|
|
75
|
+
|
|
74
76
|
async function handlerAiGeneration({
|
|
75
77
|
type
|
|
76
78
|
}) {
|
|
@@ -88,6 +90,7 @@ export const TagAndInput = ({
|
|
|
88
90
|
if(Array.isArray(currentSuggestions) && currentSuggestions.length > 0)
|
|
89
91
|
return setIsAiActive(true);
|
|
90
92
|
|
|
93
|
+
setErrorMessage("");
|
|
91
94
|
setIsAiGenerationLoading(true);
|
|
92
95
|
|
|
93
96
|
const aiSuggestions = await generateProductSuggestions({
|
|
@@ -104,7 +107,15 @@ export const TagAndInput = ({
|
|
|
104
107
|
});
|
|
105
108
|
|
|
106
109
|
if(!aiSuggestions && aiSuggestions.length === 0) {
|
|
107
|
-
|
|
110
|
+
const errorMsg = "Error: No se recibieron sugerencias de IA";
|
|
111
|
+
console.log(errorMsg);
|
|
112
|
+
setIsAiGenerationLoading(false);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if(aiSuggestions?.error) {
|
|
117
|
+
console.log('Error: ', aiSuggestions.error);
|
|
118
|
+
setErrorMessage(aiSuggestions.error);
|
|
108
119
|
setIsAiGenerationLoading(false);
|
|
109
120
|
return;
|
|
110
121
|
}
|
|
@@ -126,6 +137,7 @@ export const TagAndInput = ({
|
|
|
126
137
|
|
|
127
138
|
if(isAiRegenerationLoading) return;
|
|
128
139
|
|
|
140
|
+
setErrorMessage("");
|
|
129
141
|
setIsAiRegenerationLoading(true);
|
|
130
142
|
|
|
131
143
|
const currentSuggestions = suggestions?.[inputId];
|
|
@@ -144,7 +156,18 @@ export const TagAndInput = ({
|
|
|
144
156
|
});
|
|
145
157
|
|
|
146
158
|
if(!aiSuggestions && aiSuggestions.length === 0) {
|
|
147
|
-
|
|
159
|
+
const errorMsg = "Error: No se recibieron sugerencias de IA";
|
|
160
|
+
console.log(errorMsg);
|
|
161
|
+
setErrorMessage(errorMsg);
|
|
162
|
+
setIsAiRegenerationLoading(false);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
console.log({aiSuggestionsRenew: aiSuggestions})
|
|
167
|
+
|
|
168
|
+
if(aiSuggestions?.error) {
|
|
169
|
+
console.log('Error: ', aiSuggestions.error);
|
|
170
|
+
setErrorMessage(aiSuggestions.error);
|
|
148
171
|
setIsAiRegenerationLoading(false);
|
|
149
172
|
return;
|
|
150
173
|
}
|
|
@@ -320,6 +343,13 @@ export const TagAndInput = ({
|
|
|
320
343
|
}
|
|
321
344
|
</div>
|
|
322
345
|
)}
|
|
346
|
+
{errorMessage && (
|
|
347
|
+
<div
|
|
348
|
+
className="error-message-container"
|
|
349
|
+
>
|
|
350
|
+
<p>{errorMessage}</p>
|
|
351
|
+
</div>
|
|
352
|
+
)}
|
|
323
353
|
<GeneralInput
|
|
324
354
|
inputId={inputId}
|
|
325
355
|
inputType={inputType}
|
|
@@ -75,4 +75,15 @@ export const Container = styled.div`
|
|
|
75
75
|
& + * {
|
|
76
76
|
margin-top: ${({ inputType }) => (inputType !== "textarea" ? 0 : 10)}px;
|
|
77
77
|
}
|
|
78
|
+
|
|
79
|
+
.error-message-container {
|
|
80
|
+
|
|
81
|
+
font-family: "Raleway";
|
|
82
|
+
font-size: 12px;
|
|
83
|
+
font-weight: 500;
|
|
84
|
+
color: #E1251B;
|
|
85
|
+
margin-bottom: 8px;
|
|
86
|
+
margin-top: 0;
|
|
87
|
+
|
|
88
|
+
}
|
|
78
89
|
`;
|