contentoh-components-library 21.5.79 → 21.5.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/utils/compare-strings.js +43 -0
- package/dist/components/atoms/GeneralInput/index.js +64 -36
- package/dist/components/atoms/GeneralInput/styles.js +1 -1
- package/dist/components/atoms/InputFormatter/index.js +45 -21
- package/dist/components/atoms/InputFormatter/styles.js +1 -1
- package/dist/components/molecules/StatusAsignationInfo/index.js +11 -1
- package/dist/components/molecules/TagAndInput/index.js +110 -29
- package/dist/components/molecules/TagAndInput/styles.js +2 -2
- package/dist/components/organisms/InputGroup/index.js +22 -18
- package/dist/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +92 -785
- package/dist/components/pages/RetailerProductEdition/context/provider-product-edition.context.js +59 -260
- package/dist/components/pages/RetailerProductEdition/context/reducers/product.js +3 -41
- package/dist/components/pages/RetailerProductEdition/index.js +188 -120
- package/dist/contexts/AiProductEdition.js +179 -155
- package/package.json +1 -1
- package/src/ai/utils/compare-strings.js +43 -0
- package/src/components/atoms/GeneralInput/index.js +63 -42
- package/src/components/atoms/GeneralInput/styles.js +7 -0
- package/src/components/atoms/InputFormatter/index.js +51 -23
- package/src/components/atoms/InputFormatter/styles.js +62 -10
- package/src/components/molecules/StatusAsignationInfo/index.js +9 -1
- package/src/components/molecules/TagAndInput/index.js +113 -28
- package/src/components/molecules/TagAndInput/styles.js +48 -17
- package/src/components/organisms/FullTabsMenu/index.js +1 -1
- package/src/components/organisms/InputGroup/index.js +4 -0
- package/src/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +111 -832
- package/src/components/pages/RetailerProductEdition/context/provider-product-edition.context.jsx +3 -221
- package/src/components/pages/RetailerProductEdition/context/reducers/product.js +3 -43
- package/src/components/pages/RetailerProductEdition/index.js +17 -14
- package/src/contexts/AiProductEdition.jsx +138 -96
- package/src/ai/prompts/attribute.prompt.js +0 -46
- package/src/ai/prompts/description.prompt.js +0 -52
- package/src/ai/schemas/attribute.schema.js +0 -23
- package/src/ai/schemas/description.schema.js +0 -19
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getTextSimilarityPercentage = getTextSimilarityPercentage;
|
|
7
|
+
|
|
8
|
+
//Calcula el porcentaje de similitud entre la descripción generada por IA y la versión editada por el usuario.
|
|
9
|
+
function getTextSimilarityPercentage(originalText, candidateText) {
|
|
10
|
+
var normalize = function normalize(text) {
|
|
11
|
+
return text.trim().toLowerCase().replace(/\s+/g, ' ');
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
var source = normalize(originalText);
|
|
15
|
+
var target = normalize(candidateText);
|
|
16
|
+
if (source === target) return 100;
|
|
17
|
+
if (source.length === 0 || target.length === 0) return 0;
|
|
18
|
+
var sourceLength = source.length;
|
|
19
|
+
var targetLength = target.length;
|
|
20
|
+
var distanceMatrix = Array(targetLength + 1).fill(null).map(function () {
|
|
21
|
+
return [];
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
for (var i = 0; i <= sourceLength; i++) {
|
|
25
|
+
distanceMatrix[0][i] = i;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
for (var j = 0; j <= targetLength; j++) {
|
|
29
|
+
distanceMatrix[j][0] = j;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (var _j = 1; _j <= targetLength; _j++) {
|
|
33
|
+
for (var _i = 1; _i <= sourceLength; _i++) {
|
|
34
|
+
var substitutionCost = source[_i - 1] === target[_j - 1] ? 0 : 1;
|
|
35
|
+
distanceMatrix[_j][_i] = Math.min(distanceMatrix[_j - 1][_i] + 1, distanceMatrix[_j][_i - 1] + 1, distanceMatrix[_j - 1][_i - 1] + substitutionCost);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var editDistance = distanceMatrix[targetLength][sourceLength];
|
|
40
|
+
var maxLength = Math.max(sourceLength, targetLength);
|
|
41
|
+
var similarityScore = 1 - editDistance / maxLength;
|
|
42
|
+
return similarityScore * 100;
|
|
43
|
+
}
|
|
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.GeneralInput = void 0;
|
|
9
9
|
|
|
10
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/typeof"));
|
|
11
|
+
|
|
10
12
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
|
|
11
13
|
|
|
12
14
|
var _react = require("react");
|
|
@@ -31,6 +33,8 @@ var _AiProductEdition = require("../../../contexts/AiProductEdition");
|
|
|
31
33
|
|
|
32
34
|
var _styles2 = require("../InputFormatter/styles");
|
|
33
35
|
|
|
36
|
+
var _compareStrings = require("../../../ai/utils/compare-strings");
|
|
37
|
+
|
|
34
38
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
35
39
|
|
|
36
40
|
var GeneralInput = function GeneralInput(_ref) {
|
|
@@ -71,6 +75,10 @@ var GeneralInput = function GeneralInput(_ref) {
|
|
|
71
75
|
isAiRegenerationLoading = _ref$isAiRegeneration === void 0 ? false : _ref$isAiRegeneration,
|
|
72
76
|
_ref$isAiActive = _ref.isAiActive,
|
|
73
77
|
isAiActive = _ref$isAiActive === void 0 ? false : _ref$isAiActive,
|
|
78
|
+
_ref$isAiAvailable = _ref.isAiAvailable,
|
|
79
|
+
isAiAvailable = _ref$isAiAvailable === void 0 ? false : _ref$isAiAvailable,
|
|
80
|
+
_ref$aiGenerated = _ref.aiGenerated,
|
|
81
|
+
aiGenerated = _ref$aiGenerated === void 0 ? false : _ref$aiGenerated,
|
|
74
82
|
_ref$setIsAiActive = _ref.setIsAiActive,
|
|
75
83
|
setIsAiActive = _ref$setIsAiActive === void 0 ? function () {} : _ref$setIsAiActive,
|
|
76
84
|
_ref$handlerAiGenerat = _ref.handlerAiGeneration,
|
|
@@ -107,28 +115,15 @@ var GeneralInput = function GeneralInput(_ref) {
|
|
|
107
115
|
valueAccepted = _useState8[0],
|
|
108
116
|
setValueAccepted = _useState8[1];
|
|
109
117
|
|
|
110
|
-
var
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
var generalValue;
|
|
117
|
-
|
|
118
|
-
if ((optionList === null || optionList === void 0 ? void 0 : optionList.length) > 0) {
|
|
119
|
-
var valueSelected = evt.target.value;
|
|
120
|
-
generalValue = valueSelected;
|
|
121
|
-
setTextValue({
|
|
122
|
-
value: generalValue
|
|
123
|
-
});
|
|
124
|
-
} else {
|
|
125
|
-
generalValue = inputType === "checkbox" ? evt.target.checked : evt.target.value;
|
|
126
|
-
setTextValue({
|
|
127
|
-
value: generalValue
|
|
128
|
-
});
|
|
129
|
-
}
|
|
118
|
+
var updateParentData = function updateParentData(generalValue, isAiAccepted) {
|
|
119
|
+
setTextValue({
|
|
120
|
+
value: generalValue
|
|
121
|
+
});
|
|
122
|
+
var similarity = (0, _compareStrings.getTextSimilarityPercentage)(valueAccepted, inputValue);
|
|
123
|
+
var generatedWithAi = isAiAccepted || aiGenerated && similarity >= 50;
|
|
130
124
|
|
|
131
|
-
|
|
125
|
+
if (updatedDatasheets || updatedDescriptions || inputType === "textarea") {
|
|
126
|
+
var dataSave = (updatedDatasheets === null || updatedDatasheets === void 0 ? void 0 : updatedDatasheets.slice()) || [];
|
|
132
127
|
|
|
133
128
|
if ((dataSave === null || dataSave === void 0 ? void 0 : dataSave.length) > 0) {
|
|
134
129
|
var index = dataSave.findIndex(function (e) {
|
|
@@ -136,25 +131,52 @@ var GeneralInput = function GeneralInput(_ref) {
|
|
|
136
131
|
});
|
|
137
132
|
|
|
138
133
|
if (index !== -1) {
|
|
139
|
-
if (generalValue !== inputValue)
|
|
134
|
+
if (generalValue !== inputValue) {
|
|
135
|
+
dataSave[index].value = generalValue;
|
|
136
|
+
dataSave[index].aiSuggestionAccepted = generatedWithAi;
|
|
137
|
+
} else {
|
|
138
|
+
dataSave.splice(index, 1);
|
|
139
|
+
}
|
|
140
140
|
} else {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
141
|
+
if (generalValue !== inputValue) {
|
|
142
|
+
dataSave.push({
|
|
143
|
+
articleId: articleId,
|
|
144
|
+
attributeId: inputId,
|
|
145
|
+
value: generalValue,
|
|
146
|
+
aiSuggestionAccepted: generatedWithAi
|
|
147
|
+
});
|
|
148
|
+
}
|
|
146
149
|
}
|
|
147
150
|
} else {
|
|
148
151
|
if (generalValue !== inputValue) {
|
|
149
152
|
dataSave.push({
|
|
150
153
|
articleId: articleId,
|
|
151
154
|
attributeId: inputId,
|
|
152
|
-
value: generalValue
|
|
155
|
+
value: generalValue,
|
|
156
|
+
aiSuggestionAccepted: generatedWithAi
|
|
153
157
|
});
|
|
154
158
|
}
|
|
155
159
|
}
|
|
156
160
|
|
|
157
161
|
setUpdatedDatasheets(dataSave);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
var onHandleChange = function onHandleChange(evt) {
|
|
166
|
+
if (validateInput) {
|
|
167
|
+
setTextValue({
|
|
168
|
+
value: validateInput(evt, position, inputsArray)
|
|
169
|
+
});
|
|
170
|
+
} else if (updatedDatasheets || updatedDescriptions || inputType === "textarea") {
|
|
171
|
+
var generalValue;
|
|
172
|
+
|
|
173
|
+
if ((optionList === null || optionList === void 0 ? void 0 : optionList.length) > 0) {
|
|
174
|
+
generalValue = evt.target.value;
|
|
175
|
+
} else {
|
|
176
|
+
generalValue = inputType === "checkbox" ? evt.target.checked : evt.target.value;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
updateParentData(generalValue, aiSuggestionAccepted);
|
|
158
180
|
} else {
|
|
159
181
|
setTextValue({
|
|
160
182
|
value: evt.target.value
|
|
@@ -179,9 +201,12 @@ var GeneralInput = function GeneralInput(_ref) {
|
|
|
179
201
|
});
|
|
180
202
|
}, [suggestions]);
|
|
181
203
|
(0, _react.useEffect)(function () {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
204
|
+
if (!isAiActive && !aiSuggestionAccepted) {
|
|
205
|
+
var restoredValue = (0, _typeof2.default)(valueAccepted) === 'object' ? valueAccepted.value : valueAccepted;
|
|
206
|
+
setTextValue({
|
|
207
|
+
value: restoredValue
|
|
208
|
+
});
|
|
209
|
+
}
|
|
185
210
|
}, [suggestions, isAiActive]);
|
|
186
211
|
(0, _react.useEffect)(function () {
|
|
187
212
|
var _textValue$value;
|
|
@@ -203,12 +228,12 @@ var GeneralInput = function GeneralInput(_ref) {
|
|
|
203
228
|
|
|
204
229
|
var handleAcceptSuggestion = function handleAcceptSuggestion(suggestionValue) {
|
|
205
230
|
if (!suggestionValue) return;
|
|
206
|
-
|
|
231
|
+
setValueAccepted({
|
|
207
232
|
value: suggestionValue
|
|
208
233
|
});
|
|
209
|
-
setValueAccepted(suggestionValue);
|
|
210
234
|
setAiSuggestionAccepted(true);
|
|
211
235
|
setIsAiActive(false);
|
|
236
|
+
updateParentData(suggestionValue, true);
|
|
212
237
|
};
|
|
213
238
|
|
|
214
239
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Container, {
|
|
@@ -256,14 +281,15 @@ var GeneralInput = function GeneralInput(_ref) {
|
|
|
256
281
|
onKeyDown: onKeyDown,
|
|
257
282
|
onWheel: numberInputOnWheelPreventChange
|
|
258
283
|
}), hasAiGeneration && isBenefitInput && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
259
|
-
className: "icon_container",
|
|
284
|
+
className: "icon_container ".concat(isAiAvailable ? "ai-available" : '', " ").concat(isAiActive ? 'ai-active' : ''),
|
|
285
|
+
title: !isAiAvailable ? 'Debes de completar ficha técnica e imágenes para desbloquear la generación con IA' : '',
|
|
260
286
|
onClick: function onClick() {
|
|
261
287
|
_handlerAiGeneration({
|
|
262
288
|
type: "attribute"
|
|
263
289
|
});
|
|
264
290
|
},
|
|
265
291
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
|
|
266
|
-
className: isAiGenerationLoading ?
|
|
292
|
+
className: "".concat(isAiGenerationLoading ? 'loading' : ''),
|
|
267
293
|
src: isAiGenerationLoading ? _loading.default : isAiActive ? _cancel.default : _iaIcon.default
|
|
268
294
|
})
|
|
269
295
|
})]
|
|
@@ -336,7 +362,9 @@ var GeneralInput = function GeneralInput(_ref) {
|
|
|
336
362
|
maxChar: maxChar,
|
|
337
363
|
isRequired: isRequired,
|
|
338
364
|
disabled: disabled,
|
|
339
|
-
hasAiGeneration: hasAiGeneration,
|
|
365
|
+
hasAiGeneration: hasAiGeneration && inputId != 'commentary-box',
|
|
366
|
+
isAiAvailable: isAiAvailable,
|
|
367
|
+
aiGenerated: aiGenerated,
|
|
340
368
|
handlerAiGeneration: function handlerAiGeneration() {
|
|
341
369
|
_handlerAiGeneration({
|
|
342
370
|
type: "description"
|
|
@@ -28,6 +28,6 @@ var Container = _styledComponents.default.div(_templateObject || (_templateObjec
|
|
|
28
28
|
|
|
29
29
|
exports.Container = Container;
|
|
30
30
|
|
|
31
|
-
var InputContainer = _styledComponents.default.div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n\n &.ai-generation {\n position: relative;\n\n cursor: pointer;\n\n .ia-input {\n padding-right: 2.5rem;\n }\n\n .icon_container {\n position: absolute;\n right: 10px;\n top: 50%;\n transform: translateY(-50%);\n width: 20px;\n height: 20px;\n padding: 4px;\n\n border-radius: 50%;\n overflow: hidden;\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 1;\n\n &::before {\n content: '';\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n\n background: linear-gradient(\n 120deg,\n #ffffff 10%,\n #ffe0f4 50%,\n #ffffff 90%\n );\n background-size: 200% 200%;\n\n animation: ai-shimmer 3s ease-in-out infinite alternate;\n z-index: -1;\n }\n\n img {\n width: 100%;\n height: 100%;\n object-fit: contain;\n position: relative;\n z-index: 2;\n }\n\n img.loading {\n width: 20px;\n height: 20px;\n }\n\n }\n }\n\n @keyframes ai-shimmer {\n 0% {\n background-position: 0% 50%;\n }\n 100% {\n background-position: 100% 50%;\n }\n }\n\n"])));
|
|
31
|
+
var InputContainer = _styledComponents.default.div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n\n &.ai-generation {\n position: relative;\n\n cursor: pointer;\n\n .ia-input {\n padding-right: 2.5rem;\n }\n\n .icon_container {\n position: absolute;\n right: 10px;\n top: 50%;\n transform: translateY(-50%);\n width: 20px;\n height: 20px;\n padding: 4px;\n\n border-radius: 50%;\n overflow: hidden;\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 1;\n\n &::before {\n content: '';\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n\n background: linear-gradient(\n 120deg,\n #ffffff 10%,\n #ffe0f4 50%,\n #ffffff 90%\n );\n background-size: 200% 200%;\n\n animation: ai-shimmer 3s ease-in-out infinite alternate;\n z-index: -1;\n }\n\n &.ai-available::before{\n\n background: gray;\n background-size: 200% 200%;\n\n }\n\n img {\n width: 100%;\n height: 100%;\n object-fit: contain;\n position: relative;\n z-index: 2;\n }\n\n img.loading {\n width: 20px;\n height: 20px;\n }\n\n }\n }\n\n @keyframes ai-shimmer {\n 0% {\n background-position: 0% 50%;\n }\n 100% {\n background-position: 100% 50%;\n }\n }\n\n"])));
|
|
32
32
|
|
|
33
33
|
exports.InputContainer = InputContainer;
|
|
@@ -29,6 +29,8 @@ var _reload = _interopRequireDefault(require("../../../assets/images/Icons/reloa
|
|
|
29
29
|
|
|
30
30
|
var _AiProductEdition = require("../../../contexts/AiProductEdition");
|
|
31
31
|
|
|
32
|
+
var _compareStrings = require("../../../ai/utils/compare-strings");
|
|
33
|
+
|
|
32
34
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
33
35
|
|
|
34
36
|
var InputFormatter = function InputFormatter(_ref) {
|
|
@@ -51,6 +53,10 @@ var InputFormatter = function InputFormatter(_ref) {
|
|
|
51
53
|
isAiRegenerationLoading = _ref$isAiRegeneration === void 0 ? false : _ref$isAiRegeneration,
|
|
52
54
|
_ref$isAiActive = _ref.isAiActive,
|
|
53
55
|
isAiActive = _ref$isAiActive === void 0 ? false : _ref$isAiActive,
|
|
56
|
+
_ref$isAiAvailable = _ref.isAiAvailable,
|
|
57
|
+
isAiAvailable = _ref$isAiAvailable === void 0 ? false : _ref$isAiAvailable,
|
|
58
|
+
_ref$aiGenerated = _ref.aiGenerated,
|
|
59
|
+
aiGenerated = _ref$aiGenerated === void 0 ? false : _ref$aiGenerated,
|
|
54
60
|
_ref$setIsAiActive = _ref.setIsAiActive,
|
|
55
61
|
setIsAiActive = _ref$setIsAiActive === void 0 ? function () {} : _ref$setIsAiActive,
|
|
56
62
|
_ref$handlerAiGenerat = _ref.handlerAiGeneration,
|
|
@@ -141,37 +147,50 @@ var InputFormatter = function InputFormatter(_ref) {
|
|
|
141
147
|
|
|
142
148
|
setCharsCounter(h.getLength() - 1);
|
|
143
149
|
value = valueFormater(value);
|
|
150
|
+
updateParentDescriptions(value, aiSuggestionAccepted);
|
|
151
|
+
};
|
|
144
152
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
153
|
+
var updateParentDescriptions = function updateParentDescriptions(finalValue, isAiAccepted) {
|
|
154
|
+
if (!updatedDescriptions) return;
|
|
155
|
+
var idInput = inputId;
|
|
156
|
+
var dataSave = updatedDescriptions === null || updatedDescriptions === void 0 ? void 0 : updatedDescriptions.slice();
|
|
157
|
+
var similarity = (0, _compareStrings.getTextSimilarityPercentage)(valueAccepted, inputValue);
|
|
158
|
+
var generatedWithAi = isAiAccepted || aiGenerated && similarity >= 50;
|
|
148
159
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
160
|
+
if ((dataSave === null || dataSave === void 0 ? void 0 : dataSave.length) > 0) {
|
|
161
|
+
var index = dataSave.findIndex(function (e) {
|
|
162
|
+
return e.attributeId === idInput;
|
|
163
|
+
});
|
|
153
164
|
|
|
154
|
-
|
|
155
|
-
|
|
165
|
+
if (index !== -1) {
|
|
166
|
+
if (finalValue !== mainValue) {
|
|
167
|
+
dataSave[index].value = finalValue;
|
|
168
|
+
dataSave[index].aiSuggestionAccepted = generatedWithAi;
|
|
156
169
|
} else {
|
|
157
|
-
dataSave.
|
|
158
|
-
articleId: articleId,
|
|
159
|
-
attributeId: idInput,
|
|
160
|
-
value: value
|
|
161
|
-
});
|
|
170
|
+
dataSave.splice(index, 1);
|
|
162
171
|
}
|
|
163
172
|
} else {
|
|
164
|
-
if (
|
|
173
|
+
if (finalValue !== mainValue) {
|
|
165
174
|
dataSave.push({
|
|
166
175
|
articleId: articleId,
|
|
167
176
|
attributeId: idInput,
|
|
168
|
-
value:
|
|
177
|
+
value: finalValue,
|
|
178
|
+
aiSuggestionAccepted: generatedWithAi
|
|
169
179
|
});
|
|
170
180
|
}
|
|
171
181
|
}
|
|
172
|
-
|
|
173
|
-
|
|
182
|
+
} else {
|
|
183
|
+
if (finalValue !== mainValue) {
|
|
184
|
+
dataSave.push({
|
|
185
|
+
articleId: articleId,
|
|
186
|
+
attributeId: idInput,
|
|
187
|
+
value: finalValue,
|
|
188
|
+
aiSuggestionAccepted: generatedWithAi
|
|
189
|
+
});
|
|
190
|
+
}
|
|
174
191
|
}
|
|
192
|
+
|
|
193
|
+
setUpdatedDescriptions(dataSave);
|
|
175
194
|
};
|
|
176
195
|
|
|
177
196
|
var getSelection = function getSelection(range, a, b) {
|
|
@@ -194,7 +213,11 @@ var InputFormatter = function InputFormatter(_ref) {
|
|
|
194
213
|
setInputValue(suggestionValue);
|
|
195
214
|
setValueAccepted(suggestionValue);
|
|
196
215
|
setAiSuggestionAccepted(true);
|
|
197
|
-
setIsAiActive(false);
|
|
216
|
+
setIsAiActive(false); // Formateamos el valor sugerido igual que en el onChange
|
|
217
|
+
|
|
218
|
+
var formattedSuggestion = valueFormater(suggestionValue); // Disparamos la actualización enviando "true" directamente
|
|
219
|
+
|
|
220
|
+
updateParentDescriptions(formattedSuggestion, true);
|
|
198
221
|
};
|
|
199
222
|
|
|
200
223
|
(0, _react.useEffect)(function () {
|
|
@@ -222,7 +245,7 @@ var InputFormatter = function InputFormatter(_ref) {
|
|
|
222
245
|
value: isAiActive ? currentSuggestion === null || currentSuggestion === void 0 ? void 0 : (_currentSuggestion$in = currentSuggestion[inputId]) === null || _currentSuggestion$in === void 0 ? void 0 : _currentSuggestion$in.value : getValue(inputValue),
|
|
223
246
|
readOnly: isAiActive || disabled,
|
|
224
247
|
modules: {
|
|
225
|
-
toolbar:
|
|
248
|
+
toolbar: false
|
|
226
249
|
},
|
|
227
250
|
onKeyPress: function onKeyPress(e) {
|
|
228
251
|
if (charsCounter >= maxLength && e.key !== "Backspace") {
|
|
@@ -244,7 +267,8 @@ var InputFormatter = function InputFormatter(_ref) {
|
|
|
244
267
|
onChangeSelection: getSelection,
|
|
245
268
|
className: "quill ".concat(hasAiGeneration && "has-ai", " ").concat(isAiActive && "ai-generation")
|
|
246
269
|
}), hasAiGeneration && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
247
|
-
className: "icon_container ".concat(isAiActive
|
|
270
|
+
className: "icon_container ".concat(isAiActive ? "ai-active" : '', " ").concat(isAiAvailable ? "ai-available" : ''),
|
|
271
|
+
title: !isAiAvailable ? 'Debes de completar ficha técnica e imágenes para desbloquear la generación con IA' : '',
|
|
248
272
|
onClick: handlerAiGeneration,
|
|
249
273
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
|
|
250
274
|
className: isAiGenerationLoading ? "loading" : "",
|
|
@@ -32,7 +32,7 @@ var Container = _styledComponents.default.div(_templateObject || (_templateObjec
|
|
|
32
32
|
|
|
33
33
|
exports.Container = Container;
|
|
34
34
|
|
|
35
|
-
var InputContainer = _styledComponents.default.div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n\n &.ai-generation {\n position: relative;\n\n
|
|
35
|
+
var InputContainer = _styledComponents.default.div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n\n &.ai-generation {\n\n position: relative;\n\n > input[type=text] {\n padding-right: 2.5rem;\n }\n\n > input[type=text].ia-input {\n background-color: rgba(59, 147, 224, 0.05);\n border: 1px solid #3F8AED;\n }\n\n .icon_container {\n position: absolute;\n right: 10px;\n top: 7px;\n width: 22.5px;\n height: 22.5px;\n padding: 4px;\n\n cursor: not-allowed;\n\n border-radius: 50%;\n overflow: hidden;\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 1;\n\n &::before {\n content: '';\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n\n background: gray;\n background-size: 200% 200%;\n\n animation: ai-shimmer 3s ease-in-out infinite alternate;\n z-index: -1;\n }\n\n &.ai-available {\n cursor: pointer;\n }\n\n &.ai-available::before{\n background: linear-gradient(\n 120deg,\n #4285F4 20%,\n #33A3C8 50%,\n #4285F4 80%\n );\n background-size: 200% 200%;\n }\n\n &.ai-available::after {\n content: \"\";\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n opacity: 0.75;\n\n background: linear-gradient(\n 135deg,\n rgba(255, 255, 255, 0) 0%,\n rgba(255, 255, 255, 0) 40%,\n rgba(255, 255, 255, 0.8) 50%,\n rgba(255, 255, 255, 0) 60%,\n rgba(255, 255, 255, 0) 100%\n );\n\n transform: scale(2) translate(-100%, -100%);\n z-index: 3;\n\n animation: ai-glint 3s infinite ease-in-out;\n }\n\n &.ai-available img.loading ~ ::after {\n animation: none;\n display: none;\n }\n\n &.ai-active::after {\n animation: none;\n display: none;\n }\n\n img {\n width: 100%;\n height: 100%;\n object-fit: contain;\n position: relative;\n z-index: 2;\n filter: invert(1) grayscale(1) brightness(2);\n }\n\n img.loading {\n width: 22.5px;\n height: 22.5px;\n }\n\n &.ai-active::before {\n background: oklch(57.7% 0.245 27.325);\n }\n\n\n }\n }\n\n @keyframes ai-shimmer {\n 0% {\n background-position: 0% 50%;\n }\n 100% {\n background-position: 100% 50%;\n }\n }\n\n @keyframes ai-glint {\n 0% {\n transform: scale(2) translate(-100%, -100%);\n }\n 70%, 100% {\n transform: scale(2) translate(100%, 100%);\n }\n }\n\n"])));
|
|
36
36
|
|
|
37
37
|
exports.InputContainer = InputContainer;
|
|
38
38
|
|
|
@@ -39,6 +39,8 @@ var _FinancedCompanies = require("./FinancedCompanies");
|
|
|
39
39
|
|
|
40
40
|
var _variables = require("../../../global-files/variables");
|
|
41
41
|
|
|
42
|
+
var _AiProductEdition = require("../../../contexts/AiProductEdition");
|
|
43
|
+
|
|
42
44
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
43
45
|
|
|
44
46
|
var StatusAsignationInfo = function StatusAsignationInfo(_ref) {
|
|
@@ -81,6 +83,9 @@ var StatusAsignationInfo = function StatusAsignationInfo(_ref) {
|
|
|
81
83
|
|
|
82
84
|
var isFinanced = _FinancedCompanies.FinancedCompanies.includes(user === null || user === void 0 ? void 0 : user.id_company);
|
|
83
85
|
|
|
86
|
+
var _useAiProductEdition = (0, _AiProductEdition.useAiProductEdition)(),
|
|
87
|
+
inputsUsingAi = _useAiProductEdition.inputsUsingAi;
|
|
88
|
+
|
|
84
89
|
var closeAsignations = function closeAsignations(e) {
|
|
85
90
|
if (!e.target.closest("#default-id") && showAsignationPanel) {
|
|
86
91
|
document.removeEventListener("click", closeAsignations, false);
|
|
@@ -126,7 +131,12 @@ var StatusAsignationInfo = function StatusAsignationInfo(_ref) {
|
|
|
126
131
|
ovalForm: true
|
|
127
132
|
}), showSaveButton && !isFinanced && /*#__PURE__*/(0, _jsxRuntime.jsx)(_GeneralButton.Button, {
|
|
128
133
|
buttonType: "circular-button save-button",
|
|
129
|
-
onClick:
|
|
134
|
+
onClick: function onClick() {
|
|
135
|
+
if (Object.values(inputsUsingAi).some(function (input) {
|
|
136
|
+
return !!(input !== null && input !== void 0 && input.using);
|
|
137
|
+
})) return console.warn("Para guardar se debe de dejar de usar la generación con IA");
|
|
138
|
+
onClickSave();
|
|
139
|
+
}
|
|
130
140
|
}), imagesSection && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
131
141
|
className: "images-buttons",
|
|
132
142
|
children: [showSaveButton && /*#__PURE__*/(0, _jsxRuntime.jsx)(_GeneralButton.Button, {
|
|
@@ -13,7 +13,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
|
|
|
13
13
|
|
|
14
14
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _objectSpread6 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
|
|
17
17
|
|
|
18
18
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator"));
|
|
19
19
|
|
|
@@ -39,6 +39,8 @@ var _Tooltip = require("../../atoms/Tooltip");
|
|
|
39
39
|
|
|
40
40
|
var _AiProductEdition = require("../../../contexts/AiProductEdition");
|
|
41
41
|
|
|
42
|
+
var _iaIcon = _interopRequireDefault(require("../../../assets/images/Icons/ia-icon.png"));
|
|
43
|
+
|
|
42
44
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
43
45
|
|
|
44
46
|
var TagAndInput = function TagAndInput(_ref) {
|
|
@@ -60,6 +62,7 @@ var TagAndInput = function TagAndInput(_ref) {
|
|
|
60
62
|
inputRows = _ref.inputRows,
|
|
61
63
|
maxChar = _ref.maxChar,
|
|
62
64
|
required = _ref.required,
|
|
65
|
+
aiGenerated = _ref.aiGenerated,
|
|
63
66
|
optionList = _ref.optionList,
|
|
64
67
|
description = _ref.description,
|
|
65
68
|
inputOnChange = _ref.inputOnChange,
|
|
@@ -85,7 +88,12 @@ var TagAndInput = function TagAndInput(_ref) {
|
|
|
85
88
|
suggestions = _useAiProductEdition.suggestions,
|
|
86
89
|
setSuggestions = _useAiProductEdition.setSuggestions,
|
|
87
90
|
currentSuggestion = _useAiProductEdition.currentSuggestion,
|
|
88
|
-
setCurrentSuggestionValue = _useAiProductEdition.setCurrentSuggestionValue
|
|
91
|
+
setCurrentSuggestionValue = _useAiProductEdition.setCurrentSuggestionValue,
|
|
92
|
+
isAiAvailable = _useAiProductEdition.isAiAvailable,
|
|
93
|
+
inputsGeneratedWithAi = _useAiProductEdition.inputsGeneratedWithAi,
|
|
94
|
+
setInputsGeneratedWithAi = _useAiProductEdition.setInputsGeneratedWithAi,
|
|
95
|
+
inputsUsingAi = _useAiProductEdition.inputsUsingAi,
|
|
96
|
+
setInputsUsingAi = _useAiProductEdition.setInputsUsingAi;
|
|
89
97
|
|
|
90
98
|
var isBenefitInput = label === null || label === void 0 ? void 0 : label.toLowerCase().includes("beneficios");
|
|
91
99
|
|
|
@@ -104,6 +112,11 @@ var TagAndInput = function TagAndInput(_ref) {
|
|
|
104
112
|
isAiRegenerationLoading = _useState8[0],
|
|
105
113
|
setIsAiRegenerationLoading = _useState8[1];
|
|
106
114
|
|
|
115
|
+
var _useState9 = (0, _react.useState)(false),
|
|
116
|
+
_useState10 = (0, _slicedToArray2.default)(_useState9, 2),
|
|
117
|
+
isAiGenerated = _useState10[0],
|
|
118
|
+
setIsAiGenerated = _useState10[1];
|
|
119
|
+
|
|
107
120
|
function handlerAiGeneration(_x) {
|
|
108
121
|
return _handlerAiGeneration.apply(this, arguments);
|
|
109
122
|
}
|
|
@@ -117,7 +130,7 @@ var TagAndInput = function TagAndInput(_ref) {
|
|
|
117
130
|
case 0:
|
|
118
131
|
type = _ref2.type;
|
|
119
132
|
|
|
120
|
-
if (!isAiGenerationLoading) {
|
|
133
|
+
if (!(isAiGenerationLoading || !isAiAvailable)) {
|
|
121
134
|
_context.next = 3;
|
|
122
135
|
break;
|
|
123
136
|
}
|
|
@@ -152,7 +165,12 @@ var TagAndInput = function TagAndInput(_ref) {
|
|
|
152
165
|
currentValue: value,
|
|
153
166
|
description: description,
|
|
154
167
|
maxChar: maxChar !== null && maxChar !== void 0 ? maxChar : 99,
|
|
155
|
-
type: type
|
|
168
|
+
type: type,
|
|
169
|
+
// Informacion del producto
|
|
170
|
+
articleId: articleId,
|
|
171
|
+
versionId: version,
|
|
172
|
+
descriptionId: !isBenefitInput ? inputId : null,
|
|
173
|
+
attributeId: isBenefitInput ? inputId : null
|
|
156
174
|
});
|
|
157
175
|
|
|
158
176
|
case 12:
|
|
@@ -169,7 +187,7 @@ var TagAndInput = function TagAndInput(_ref) {
|
|
|
169
187
|
|
|
170
188
|
case 17:
|
|
171
189
|
setSuggestions(function (prev) {
|
|
172
|
-
return (0,
|
|
190
|
+
return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, prev), {}, (0, _defineProperty2.default)({}, inputId, aiSuggestions));
|
|
173
191
|
});
|
|
174
192
|
setIsAiActive(true);
|
|
175
193
|
setIsAiGenerationLoading(false);
|
|
@@ -210,22 +228,37 @@ var TagAndInput = function TagAndInput(_ref) {
|
|
|
210
228
|
currentSuggestions = suggestions === null || suggestions === void 0 ? void 0 : suggestions[inputId];
|
|
211
229
|
_context2.next = 7;
|
|
212
230
|
return regenerateProductSuggestions({
|
|
213
|
-
inputId: inputId,
|
|
214
231
|
inputName: label,
|
|
215
232
|
currentValue: value,
|
|
216
233
|
description: description,
|
|
217
|
-
maxChar: maxChar,
|
|
218
|
-
type: type
|
|
234
|
+
maxChar: maxChar !== null && maxChar !== void 0 ? maxChar : 99,
|
|
235
|
+
type: type,
|
|
236
|
+
//Información del producto
|
|
237
|
+
articleId: articleId,
|
|
238
|
+
versionId: version,
|
|
239
|
+
descriptionId: !isBenefitInput ? inputId : null,
|
|
240
|
+
attributeId: isBenefitInput ? inputId : null
|
|
219
241
|
});
|
|
220
242
|
|
|
221
243
|
case 7:
|
|
222
244
|
aiSuggestions = _context2.sent;
|
|
245
|
+
|
|
246
|
+
if (!(!aiSuggestions && aiSuggestions.length === 0)) {
|
|
247
|
+
_context2.next = 12;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
console.log("Error: No se recibieron sugerencias de IA");
|
|
252
|
+
setIsAiRegenerationLoading(false);
|
|
253
|
+
return _context2.abrupt("return");
|
|
254
|
+
|
|
255
|
+
case 12:
|
|
223
256
|
setSuggestions(function (prev) {
|
|
224
|
-
return (0,
|
|
257
|
+
return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, prev), {}, (0, _defineProperty2.default)({}, inputId, [].concat((0, _toConsumableArray2.default)(currentSuggestions), (0, _toConsumableArray2.default)(aiSuggestions))));
|
|
225
258
|
});
|
|
226
259
|
setIsAiRegenerationLoading(false);
|
|
227
260
|
|
|
228
|
-
case
|
|
261
|
+
case 14:
|
|
229
262
|
case "end":
|
|
230
263
|
return _context2.stop();
|
|
231
264
|
}
|
|
@@ -301,28 +334,74 @@ var TagAndInput = function TagAndInput(_ref) {
|
|
|
301
334
|
(0, _react.useEffect)(function () {
|
|
302
335
|
onChange && onChange(boxOnboardingList);
|
|
303
336
|
}, [boxOnboardingList]);
|
|
337
|
+
(0, _react.useEffect)(function () {
|
|
338
|
+
if (Array.isArray(updatedDescriptions)) {
|
|
339
|
+
var currentDescriptionUpdate = updatedDescriptions.find(function (description) {
|
|
340
|
+
return (description === null || description === void 0 ? void 0 : description.attributeId) === inputId;
|
|
341
|
+
});
|
|
342
|
+
var calculatedIsAiGenerated = currentDescriptionUpdate ? !!currentDescriptionUpdate.aiSuggestionAccepted : aiGenerated;
|
|
343
|
+
setInputsGeneratedWithAi(function (prev) {
|
|
344
|
+
return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, prev), {}, (0, _defineProperty2.default)({}, "".concat(inputId, "-").concat(inputType, "-").concat(version), {
|
|
345
|
+
inputType: inputType,
|
|
346
|
+
inputId: inputId,
|
|
347
|
+
version: version,
|
|
348
|
+
isAiGenerated: calculatedIsAiGenerated,
|
|
349
|
+
label: label
|
|
350
|
+
}));
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (Array.isArray(updatedDatasheets) && updatedDatasheets.length > 0) {
|
|
355
|
+
console.log({
|
|
356
|
+
isAiGenerated: isAiGenerated,
|
|
357
|
+
updatedDatasheets: updatedDatasheets
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}, [updatedDescriptions, updatedDatasheets, aiGenerated, inputId]);
|
|
361
|
+
(0, _react.useEffect)(function () {
|
|
362
|
+
var _inputsGeneratedWithA;
|
|
363
|
+
|
|
364
|
+
setIsAiGenerated(!!((_inputsGeneratedWithA = inputsGeneratedWithAi["".concat(inputId, "-").concat(inputType, "-").concat(version)]) !== null && _inputsGeneratedWithA !== void 0 && _inputsGeneratedWithA.isAiGenerated));
|
|
365
|
+
}, [inputsGeneratedWithAi]);
|
|
366
|
+
(0, _react.useEffect)(function () {
|
|
367
|
+
setInputsUsingAi(function (prev) {
|
|
368
|
+
return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, prev), {}, (0, _defineProperty2.default)({}, "".concat(inputId, "-").concat(inputType, "-").concat(version), {
|
|
369
|
+
using: isAiActive
|
|
370
|
+
}));
|
|
371
|
+
});
|
|
372
|
+
}, [isAiActive]);
|
|
304
373
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Container, {
|
|
305
374
|
inputType: inputType,
|
|
306
375
|
className: "input-container",
|
|
307
376
|
children: [(label === null || label === void 0 ? void 0 : label.length) && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
308
377
|
className: "title-container",
|
|
309
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
378
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
379
|
+
className: "titles",
|
|
380
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index.ScreenHeader, {
|
|
381
|
+
text: label,
|
|
382
|
+
headerType: "input-name-header",
|
|
383
|
+
color: color
|
|
384
|
+
}), description && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.Tooltip, {
|
|
385
|
+
componentTooltip: /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
386
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
|
|
387
|
+
children: description
|
|
388
|
+
})
|
|
389
|
+
}),
|
|
390
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
|
|
391
|
+
src: _infoIcon.default,
|
|
392
|
+
alt: "info icon",
|
|
393
|
+
className: 'icon_information'
|
|
394
|
+
}),
|
|
395
|
+
classNameTooltip: "container-tooltip"
|
|
396
|
+
})]
|
|
397
|
+
}), isCreators && isAiGenerated ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
398
|
+
className: "ai-generated",
|
|
399
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
|
|
400
|
+
src: _iaIcon.default
|
|
401
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
|
|
402
|
+
children: "Atributo generado con IA"
|
|
403
|
+
})]
|
|
404
|
+
}) : null]
|
|
326
405
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.GeneralInput, {
|
|
327
406
|
inputId: inputId,
|
|
328
407
|
inputType: inputType,
|
|
@@ -353,7 +432,9 @@ var TagAndInput = function TagAndInput(_ref) {
|
|
|
353
432
|
isAiGenerationLoading: isAiGenerationLoading,
|
|
354
433
|
isAiRegenerationLoading: isAiRegenerationLoading,
|
|
355
434
|
isAiActive: isAiActive,
|
|
356
|
-
setIsAiActive: setIsAiActive
|
|
435
|
+
setIsAiActive: setIsAiActive,
|
|
436
|
+
isAiAvailable: isAiAvailable,
|
|
437
|
+
aiGenerated: aiGenerated // aiSuggestions={aiSuggestions}
|
|
357
438
|
,
|
|
358
439
|
handlerAiGeneration: handlerAiGeneration,
|
|
359
440
|
handlerRegenerateSuggestions: handlerRegenerateSuggestions,
|
|
@@ -365,7 +446,7 @@ var TagAndInput = function TagAndInput(_ref) {
|
|
|
365
446
|
return box;
|
|
366
447
|
}
|
|
367
448
|
|
|
368
|
-
return (0,
|
|
449
|
+
return (0, _objectSpread6.default)((0, _objectSpread6.default)({}, box), {}, {
|
|
369
450
|
value: e
|
|
370
451
|
});
|
|
371
452
|
});
|