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.
Files changed (70) hide show
  1. package/dist/ai/utils/compare-strings.js +45 -0
  2. package/dist/components/atoms/GeneralButton/styles.js +1 -1
  3. package/dist/components/atoms/GeneralInput/index.js +245 -54
  4. package/dist/components/atoms/GeneralInput/styles.js +7 -3
  5. package/dist/components/atoms/InputFormatter/index.js +223 -68
  6. package/dist/components/atoms/InputFormatter/styles.js +20 -4
  7. package/dist/components/molecules/StatusAsignationInfo/index.js +11 -1
  8. package/dist/components/molecules/TabsMenu/index.js +13 -12
  9. package/dist/components/molecules/TagAndInput/index.js +361 -24
  10. package/dist/components/molecules/TagAndInput/styles.js +2 -2
  11. package/dist/components/organisms/ChangeStatusModal/index.js +531 -0
  12. package/dist/components/organisms/ChangeStatusModal/styles.js +85 -0
  13. package/dist/components/organisms/FullProductNameHeader/index.js +6 -22
  14. package/dist/components/organisms/InputGroup/index.js +22 -18
  15. package/dist/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +150 -337
  16. package/dist/components/pages/ProviderProductEdition/context/provider-product-edition.context.js +15 -15
  17. package/dist/components/pages/ProviderProductEdition/index.js +408 -381
  18. package/dist/components/pages/ProviderProductEdition/utils.js +1 -0
  19. package/dist/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +179 -196
  20. package/dist/components/pages/RetailerProductEdition/context/provider-product-edition.context.js +59 -260
  21. package/dist/components/pages/RetailerProductEdition/context/reducers/product.js +50 -38
  22. package/dist/components/pages/RetailerProductEdition/index.js +1719 -2237
  23. package/dist/components/pages/RetailerProductEdition/styles.js +4 -2
  24. package/dist/components/pages/RetailerProductEdition/utils.js +251 -2
  25. package/dist/contexts/AiProductEdition.js +230 -158
  26. package/dist/global-files/statusDictionary.js +103 -0
  27. package/package.json +4 -2
  28. package/src/ai/utils/compare-strings.js +45 -0
  29. package/src/assets/images/Icons/arrow.png +0 -0
  30. package/src/assets/images/Icons/cancel.png +0 -0
  31. package/src/assets/images/Icons/ia-icon.png +0 -0
  32. package/src/assets/images/Icons/loading.svg +5 -0
  33. package/src/assets/images/Icons/reload.png +0 -0
  34. package/src/components/atoms/GeneralButton/styles.js +4 -0
  35. package/src/components/atoms/GeneralInput/index.js +237 -60
  36. package/src/components/atoms/GeneralInput/styles.js +81 -0
  37. package/src/components/atoms/InputFormatter/index.js +200 -51
  38. package/src/components/atoms/InputFormatter/styles.js +284 -0
  39. package/src/components/atoms/RetailerSelector/RetailerSelector.stories.js +10 -0
  40. package/src/components/atoms/RetailerSelector/index.js +3 -0
  41. package/src/components/atoms/RetailerSelector/styles.js +0 -0
  42. package/src/components/molecules/StatusAsignationInfo/index.js +9 -1
  43. package/src/components/molecules/TabsMenu/index.js +12 -11
  44. package/src/components/molecules/TagAndInput/index.js +286 -21
  45. package/src/components/molecules/TagAndInput/styles.js +59 -17
  46. package/src/components/organisms/ChangeStatusModal/index.jsx +488 -0
  47. package/src/components/organisms/ChangeStatusModal/styles.js +333 -0
  48. package/src/components/organisms/FullProductNameHeader/index.js +4 -28
  49. package/src/components/organisms/FullTabsMenu/index.js +1 -1
  50. package/src/components/organisms/InputGroup/index.js +12 -4
  51. package/src/components/pages/ProviderProductEdition/ProviderProductEdition.stories.js +174 -202
  52. package/src/components/pages/ProviderProductEdition/context/provider-product-edition.context.jsx +14 -14
  53. package/src/components/pages/ProviderProductEdition/index.js +489 -457
  54. package/src/components/pages/ProviderProductEdition/utils.js +2 -2
  55. package/src/components/pages/RetailerProductEdition/RetailerProductEdition.stories.js +201 -224
  56. package/src/components/pages/RetailerProductEdition/context/provider-product-edition.context.jsx +575 -0
  57. package/src/components/pages/RetailerProductEdition/context/provider-product-edition.reducer.js +62 -0
  58. package/src/components/pages/RetailerProductEdition/context/reducers/active-state.js +344 -0
  59. package/src/components/pages/RetailerProductEdition/context/reducers/inputs.js +155 -0
  60. package/src/components/pages/RetailerProductEdition/context/reducers/product.js +114 -0
  61. package/src/components/pages/RetailerProductEdition/context/reducers/system.js +60 -0
  62. package/src/components/pages/RetailerProductEdition/index.js +1545 -1718
  63. package/src/components/pages/RetailerProductEdition/index_old.js +1979 -0
  64. package/src/components/pages/RetailerProductEdition/stories/Auditor.stories.js +101 -0
  65. package/src/components/pages/RetailerProductEdition/stories/ImageEditor.stories.js +115 -0
  66. package/src/components/pages/RetailerProductEdition/stories/TextEditor.stories.js +174 -0
  67. package/src/components/pages/RetailerProductEdition/styles.js +67 -2
  68. package/src/components/pages/RetailerProductEdition/utils.js +240 -0
  69. package/src/contexts/AiProductEdition.jsx +339 -0
  70. package/src/global-files/statusDictionary.js +103 -0
@@ -0,0 +1,45 @@
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
+ if (!originalText || !candidateText) return;
11
+
12
+ var normalize = function normalize(text) {
13
+ return text.trim().toLowerCase().replace(/\s+/g, ' ');
14
+ };
15
+
16
+ var source = normalize(originalText);
17
+ var target = normalize(candidateText);
18
+ if (source === target) return 100;
19
+ if (source.length === 0 || target.length === 0) return 0;
20
+ var sourceLength = source.length;
21
+ var targetLength = target.length;
22
+ var distanceMatrix = Array(targetLength + 1).fill(null).map(function () {
23
+ return [];
24
+ });
25
+
26
+ for (var i = 0; i <= sourceLength; i++) {
27
+ distanceMatrix[0][i] = i;
28
+ }
29
+
30
+ for (var j = 0; j <= targetLength; j++) {
31
+ distanceMatrix[j][0] = j;
32
+ }
33
+
34
+ for (var _j = 1; _j <= targetLength; _j++) {
35
+ for (var _i = 1; _i <= sourceLength; _i++) {
36
+ var substitutionCost = source[_i - 1] === target[_j - 1] ? 0 : 1;
37
+ distanceMatrix[_j][_i] = Math.min(distanceMatrix[_j - 1][_i] + 1, distanceMatrix[_j][_i - 1] + 1, distanceMatrix[_j - 1][_i - 1] + substitutionCost);
38
+ }
39
+ }
40
+
41
+ var editDistance = distanceMatrix[targetLength][sourceLength];
42
+ var maxLength = Math.max(sourceLength, targetLength);
43
+ var similarityScore = 1 - editDistance / maxLength;
44
+ return similarityScore * 100;
45
+ }
@@ -47,7 +47,7 @@ var _variables = require("../../../global-files/variables");
47
47
 
48
48
  var _templateObject;
49
49
 
50
- var Container = _styledComponents.default.button(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n background-color: #e33aa9;\n border: none;\n border-radius: 30px;\n color: #fff;\n font-family: ", ";\n font-style: normal;\n font-weight: normal;\n font-size: 18px;\n line-height: 22px;\n padding: 10px 25px;\n cursor: pointer;\n\n &:hover {\n opacity: 0.7;\n }\n\n &.general-purple-button {\n background-color: #603888;\n }\n\n &.general-transparent-button {\n background-color: transparent;\n border: 1px solid #503d66;\n color: #503d66;\n }\n &.general-white-button {\n background-color: ", ";\n color: ", ";\n }\n\n &.general-green-button {\n background-color: #71de56;\n }\n\n &.circular-button {\n width: 25px;\n height: 25px;\n padding: 0;\n background-color: transparent;\n background-repeat: no-repeat;\n background-position: center;\n\n &.accept-button {\n background-image: url(", ");\n }\n\n &.reject-button {\n background-image: url(", ");\n }\n\n &.null-button {\n background-image: url(", ");\n }\n\n &.save-button {\n background-image: url(", ");\n border: 1px solid ", ";\n border-radius: 15px;\n\n &:hover {\n background-image: url(", ");\n background-color: ", ";\n border: 1px solid ", ";\n }\n }\n\n &.delete-button {\n background-image: url(", ");\n border: 1px solid ", ";\n border-radius: 15px;\n background-size: 15px;\n\n &:hover {\n background-image: url(", ");\n background-color: ", ";\n border: 1px solid ", ";\n }\n }\n\n &.download-button {\n background-image: url(", ");\n border: 1px solid ", ";\n border-radius: 15px;\n background-size: 15px;\n\n &:hover {\n color: white;\n background-color: ", ";\n border: 1px solid ", ";\n }\n }\n\n &.disabled {\n opacity: 0.5;\n }\n\n img {\n width: 100%;\n }\n\n &.version-button {\n color: ", ";\n border: 1px solid ", ";\n border-radius: 15px;\n font-size: 12px;\n line-height: 25px;\n text-align: center;\n filter: brightness(.35);\n }\n }\n\n &.general-arrow-button {\n background-image: url(", ");\n width: 27px;\n height: 27px;\n background-color: transparent;\n background-repeat: no-repeat;\n background-position: center;\n }\n\n &.close-button {\n width: 52px;\n height: 52px;\n background-color: transparent;\n background-repeat: no-repeat;\n background-position: center;\n background-image: url(", ");\n }\n\n &.close-buttonv2 {\n width: 52px;\n height: 52px;\n background-color: transparent;\n background-repeat: no-repeat;\n background-position: center;\n background-image: url(", ");\n }\n\n &.close-button-white {\n width: 52px;\n height: 52px;\n background-color: transparent;\n background-repeat: no-repeat;\n background-position: center;\n background-image: url(", ");\n }\n\n &.open-modal-button {\n background-color: transparent;\n border: none;\n cursor: pointer;\n position: absolute;\n right: 10px;\n bottom: 10px;\n background-color: transparent;\n background-repeat: no-repeat;\n background-position: center;\n width: 21px;\n height: 21px;\n padding: 0;\n border-radius: 0;\n background-image: url(", ");\n }\n\n &.grid-layout,\n &.row-layout {\n background-color: transparent;\n background-repeat: no-repeat;\n width: 24px;\n height: 24px;\n padding: 0;\n }\n\n &.grid-layout {\n background-image: url(", ");\n }\n\n &.row-layout {\n background-image: url(", ");\n }\n\n &.general-button-disabled {\n background-color: grey;\n color: ", ";\n\n &:hover {\n opacity: 1;\n }\n }\n &.general-button-rec {\n background:#85BC5B;\n color: ", ";\n padding: 4px 5px;\n border-radius: 3px;\n font-size: 10px;\n height: 20px;\n line-height: 12px;\n text-align: center;\n }\n\n &.general-button-sol {\n background-color: #e33aa9;\n border: none;\n border-radius: 50px;\n color: ", ";\n height: 34px;\n font-family: Avenir Next;\n font-style: normal;\n font-weight: normal;\n font-size: 12px;\n line-height: 14px;\n padding: 10px 15px;\n cursor: pointer;\n }\n"])), function (props) {
50
+ var Container = _styledComponents.default.button(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n background-color: #e33aa9;\n border: none;\n border-radius: 30px;\n color: #fff;\n font-family: ", ";\n font-style: normal;\n font-weight: normal;\n font-size: 18px;\n line-height: 22px;\n padding: 10px 25px;\n cursor: pointer;\n\n &:hover {\n opacity: 0.7;\n }\n\n &.general-purple-button {\n background-color: #603888;\n }\n\n &.general-pink-button {\n background-color: #E33AA9;\n }\n\n &.general-transparent-button {\n background-color: transparent;\n border: 1px solid #503d66;\n color: #503d66;\n }\n &.general-white-button {\n background-color: ", ";\n color: ", ";\n }\n\n &.general-green-button {\n background-color: #71de56;\n }\n\n &.circular-button {\n width: 25px;\n height: 25px;\n padding: 0;\n background-color: transparent;\n background-repeat: no-repeat;\n background-position: center;\n\n &.accept-button {\n background-image: url(", ");\n }\n\n &.reject-button {\n background-image: url(", ");\n }\n\n &.null-button {\n background-image: url(", ");\n }\n\n &.save-button {\n background-image: url(", ");\n border: 1px solid ", ";\n border-radius: 15px;\n\n &:hover {\n background-image: url(", ");\n background-color: ", ";\n border: 1px solid ", ";\n }\n }\n\n &.delete-button {\n background-image: url(", ");\n border: 1px solid ", ";\n border-radius: 15px;\n background-size: 15px;\n\n &:hover {\n background-image: url(", ");\n background-color: ", ";\n border: 1px solid ", ";\n }\n }\n\n &.download-button {\n background-image: url(", ");\n border: 1px solid ", ";\n border-radius: 15px;\n background-size: 15px;\n\n &:hover {\n color: white;\n background-color: ", ";\n border: 1px solid ", ";\n }\n }\n\n &.disabled {\n opacity: 0.5;\n }\n\n img {\n width: 100%;\n }\n\n &.version-button {\n color: ", ";\n border: 1px solid ", ";\n border-radius: 15px;\n font-size: 12px;\n line-height: 25px;\n text-align: center;\n filter: brightness(.35);\n }\n }\n\n &.general-arrow-button {\n background-image: url(", ");\n width: 27px;\n height: 27px;\n background-color: transparent;\n background-repeat: no-repeat;\n background-position: center;\n }\n\n &.close-button {\n width: 52px;\n height: 52px;\n background-color: transparent;\n background-repeat: no-repeat;\n background-position: center;\n background-image: url(", ");\n }\n\n &.close-buttonv2 {\n width: 52px;\n height: 52px;\n background-color: transparent;\n background-repeat: no-repeat;\n background-position: center;\n background-image: url(", ");\n }\n\n &.close-button-white {\n width: 52px;\n height: 52px;\n background-color: transparent;\n background-repeat: no-repeat;\n background-position: center;\n background-image: url(", ");\n }\n\n &.open-modal-button {\n background-color: transparent;\n border: none;\n cursor: pointer;\n position: absolute;\n right: 10px;\n bottom: 10px;\n background-color: transparent;\n background-repeat: no-repeat;\n background-position: center;\n width: 21px;\n height: 21px;\n padding: 0;\n border-radius: 0;\n background-image: url(", ");\n }\n\n &.grid-layout,\n &.row-layout {\n background-color: transparent;\n background-repeat: no-repeat;\n width: 24px;\n height: 24px;\n padding: 0;\n }\n\n &.grid-layout {\n background-image: url(", ");\n }\n\n &.row-layout {\n background-image: url(", ");\n }\n\n &.general-button-disabled {\n background-color: grey;\n color: ", ";\n\n &:hover {\n opacity: 1;\n }\n }\n &.general-button-rec {\n background:#85BC5B;\n color: ", ";\n padding: 4px 5px;\n border-radius: 3px;\n font-size: 10px;\n height: 20px;\n line-height: 12px;\n text-align: center;\n }\n\n &.general-button-sol {\n background-color: #e33aa9;\n border: none;\n border-radius: 50px;\n color: ", ";\n height: 34px;\n font-family: Avenir Next;\n font-style: normal;\n font-weight: normal;\n font-size: 12px;\n line-height: 14px;\n padding: 10px 15px;\n cursor: pointer;\n }\n"])), function (props) {
51
51
  return props.buttonFont;
52
52
  }, _variables.GlobalColors.s1, _variables.GlobalColors.original_purpura, _acceptIcon.default, _rejectIcon.default, _nullIcon.default, _saveIcon.default, _variables.GlobalColors.color_gray, _saveIconHover.default, _variables.GlobalColors.color_pink, _variables.GlobalColors.color_pink, _deleteIcon.default, _variables.GlobalColors.s3, _deleteIconHover.default, _variables.GlobalColors.magenta_s2, _variables.GlobalColors.magenta_s2, _downloadIcon.default, _variables.GlobalColors.s3, _variables.GlobalColors.magenta_s2, _variables.GlobalColors.magenta_s2, _variables.GlobalColors.color_purple, _variables.GlobalColors.color_purple, _arrowIcon.default, _closeIcon.default, _closeIconv.default, _closeIconWhite.default, _openModal.default, _rowLayout.default, _gridLayout.default, _variables.GlobalColors.white, _variables.GlobalColors.white, _variables.GlobalColors.white);
53
53
 
@@ -17,9 +17,27 @@ var _InputFormatter = require("../InputFormatter");
17
17
 
18
18
  var _CheckBox = require("../CheckBox");
19
19
 
20
+ var _iaIcon = _interopRequireDefault(require("../../../assets/images/Icons/ia-icon.png"));
21
+
22
+ var _loading = _interopRequireDefault(require("../../../assets/images/Icons/loading.svg"));
23
+
24
+ var _arrow = _interopRequireDefault(require("../../../assets/images/Icons/arrow.png"));
25
+
26
+ var _cancel = _interopRequireDefault(require("../../../assets/images/Icons/cancel.png"));
27
+
28
+ var _reload = _interopRequireDefault(require("../../../assets/images/Icons/reload.png"));
29
+
30
+ var _AiProductEdition = require("../../../contexts/AiProductEdition");
31
+
32
+ var _styles2 = require("../InputFormatter/styles");
33
+
34
+ var _compareStrings = require("../../../ai/utils/compare-strings");
35
+
20
36
  var _jsxRuntime = require("react/jsx-runtime");
21
37
 
22
38
  var GeneralInput = function GeneralInput(_ref) {
39
+ var _currentSuggestion$in, _currentSuggestion$in2, _currentSuggestion$in3, _suggestions$inputId2, _currentSuggestion$in4, _suggestions$inputId3;
40
+
23
41
  var inputType = _ref.inputType,
24
42
  inputId = _ref.inputId,
25
43
  inputName = _ref.inputName,
@@ -44,7 +62,34 @@ var GeneralInput = function GeneralInput(_ref) {
44
62
  inputOnChange = _ref.inputOnChange,
45
63
  disabled = _ref.disabled,
46
64
  onKeyDown = _ref.onKeyDown,
47
- auditClass = _ref.auditClass;
65
+ auditClass = _ref.auditClass,
66
+ _ref$hasAiGeneration = _ref.hasAiGeneration,
67
+ hasAiGeneration = _ref$hasAiGeneration === void 0 ? false : _ref$hasAiGeneration,
68
+ _ref$isBenefitInput = _ref.isBenefitInput,
69
+ isBenefitInput = _ref$isBenefitInput === void 0 ? false : _ref$isBenefitInput,
70
+ _ref$isAiGenerationLo = _ref.isAiGenerationLoading,
71
+ isAiGenerationLoading = _ref$isAiGenerationLo === void 0 ? false : _ref$isAiGenerationLo,
72
+ _ref$isAiRegeneration = _ref.isAiRegenerationLoading,
73
+ isAiRegenerationLoading = _ref$isAiRegeneration === void 0 ? false : _ref$isAiRegeneration,
74
+ _ref$isAiActive = _ref.isAiActive,
75
+ isAiActive = _ref$isAiActive === void 0 ? false : _ref$isAiActive,
76
+ _ref$isAiAvailable = _ref.isAiAvailable,
77
+ isAiAvailable = _ref$isAiAvailable === void 0 ? false : _ref$isAiAvailable,
78
+ _ref$aiGenerated = _ref.aiGenerated,
79
+ aiGenerated = _ref$aiGenerated === void 0 ? false : _ref$aiGenerated,
80
+ _ref$setIsAiActive = _ref.setIsAiActive,
81
+ setIsAiActive = _ref$setIsAiActive === void 0 ? function () {} : _ref$setIsAiActive,
82
+ _ref$handlerAiGenerat = _ref.handlerAiGeneration,
83
+ _handlerAiGeneration = _ref$handlerAiGenerat === void 0 ? function () {} : _ref$handlerAiGenerat,
84
+ _ref$handlerRegenerat = _ref.handlerRegenerateSuggestions,
85
+ _handlerRegenerateSuggestions = _ref$handlerRegenerat === void 0 ? function () {} : _ref$handlerRegenerat,
86
+ _ref$handleChangeSugg = _ref.handleChangeSuggestion,
87
+ handleChangeSuggestion = _ref$handleChangeSugg === void 0 ? function () {} : _ref$handleChangeSugg;
88
+
89
+ var _useAiProductEdition = (0, _AiProductEdition.useAiProductEdition)(),
90
+ suggestions = _useAiProductEdition.suggestions,
91
+ currentSuggestion = _useAiProductEdition.currentSuggestion,
92
+ setCurrentSuggestionValue = _useAiProductEdition.setCurrentSuggestionValue;
48
93
 
49
94
  var _useState = (0, _react.useState)({
50
95
  value: inputValue
@@ -58,28 +103,27 @@ var GeneralInput = function GeneralInput(_ref) {
58
103
  requiredEmpty = _useState4[0],
59
104
  setRequiredEmpty = _useState4[1];
60
105
 
61
- var onHandleChange = function onHandleChange(evt) {
62
- if (validateInput) {
63
- setTextValue({
64
- value: validateInput(evt, position, inputsArray)
65
- });
66
- } else if (updatedDatasheets || updatedDescriptions || inputType === "textarea") {
67
- var generalValue;
106
+ var _useState5 = (0, _react.useState)(false),
107
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
108
+ aiSuggestionAccepted = _useState6[0],
109
+ setAiSuggestionAccepted = _useState6[1];
68
110
 
69
- if ((optionList === null || optionList === void 0 ? void 0 : optionList.length) > 0) {
70
- var valueSelected = evt.target.value;
71
- generalValue = valueSelected;
72
- setTextValue({
73
- value: generalValue
74
- });
75
- } else {
76
- generalValue = inputType === "checkbox" ? evt.target.checked : evt.target.value;
77
- setTextValue({
78
- value: generalValue
79
- });
80
- }
111
+ var _useState7 = (0, _react.useState)(inputValue),
112
+ _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
113
+ valueAccepted = _useState8[0],
114
+ setValueAccepted = _useState8[1];
115
+
116
+ var updateParentData = function updateParentData(generalValue, isAiAccepted) {
117
+ var newBaseValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
118
+ setTextValue({
119
+ value: generalValue
120
+ });
121
+ var baseToCompare = newBaseValue !== null ? newBaseValue : valueAccepted;
122
+ var similarity = (0, _compareStrings.getTextSimilarityPercentage)(baseToCompare, generalValue);
123
+ var generatedWithAi = (isAiAccepted || aiGenerated) && similarity >= 50;
81
124
 
82
- var dataSave = updatedDatasheets === null || updatedDatasheets === void 0 ? void 0 : updatedDatasheets.slice();
125
+ if (updatedDatasheets || updatedDescriptions || inputType === "textarea") {
126
+ var dataSave = (updatedDatasheets === null || updatedDatasheets === void 0 ? void 0 : updatedDatasheets.slice()) || [];
83
127
 
84
128
  if ((dataSave === null || dataSave === void 0 ? void 0 : dataSave.length) > 0) {
85
129
  var index = dataSave.findIndex(function (e) {
@@ -87,25 +131,52 @@ var GeneralInput = function GeneralInput(_ref) {
87
131
  });
88
132
 
89
133
  if (index !== -1) {
90
- if (generalValue !== inputValue) dataSave[index].value = generalValue;else dataSave.splice(index, 1);
134
+ if (generalValue !== inputValue) {
135
+ dataSave[index].value = generalValue;
136
+ dataSave[index].aiSuggestionAccepted = generatedWithAi;
137
+ } else {
138
+ dataSave.splice(index, 1);
139
+ }
91
140
  } else {
92
- dataSave.push({
93
- articleId: articleId,
94
- attributeId: inputId,
95
- value: generalValue
96
- });
141
+ if (generalValue !== inputValue) {
142
+ dataSave.push({
143
+ articleId: articleId,
144
+ attributeId: inputId,
145
+ value: generalValue,
146
+ aiSuggestionAccepted: generatedWithAi
147
+ });
148
+ }
97
149
  }
98
150
  } else {
99
151
  if (generalValue !== inputValue) {
100
152
  dataSave.push({
101
153
  articleId: articleId,
102
154
  attributeId: inputId,
103
- value: generalValue
155
+ value: generalValue,
156
+ aiSuggestionAccepted: generatedWithAi
104
157
  });
105
158
  }
106
159
  }
107
160
 
108
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);
109
180
  } else {
110
181
  setTextValue({
111
182
  value: evt.target.value
@@ -114,21 +185,50 @@ var GeneralInput = function GeneralInput(_ref) {
114
185
  }
115
186
  };
116
187
 
188
+ (0, _react.useEffect)(function () {
189
+ var _suggestions$inputId;
190
+
191
+ if (Object.keys(suggestions).length === 0) return;
192
+ if (currentSuggestion !== null && currentSuggestion !== void 0 && currentSuggestion[inputId]) return;
193
+ var firstSuggestion = suggestions === null || suggestions === void 0 ? void 0 : (_suggestions$inputId = suggestions[inputId]) === null || _suggestions$inputId === void 0 ? void 0 : _suggestions$inputId[0];
194
+ if (!firstSuggestion) return;
195
+ setCurrentSuggestionValue({
196
+ inputId: inputId,
197
+ index: 0,
198
+ value: firstSuggestion === null || firstSuggestion === void 0 ? void 0 : firstSuggestion.value
199
+ });
200
+ }, [suggestions]);
201
+ (0, _react.useEffect)(function () {
202
+ if (!isAiActive) return;
203
+ setAiSuggestionAccepted(false);
204
+ }, [isAiActive]);
205
+ (0, _react.useEffect)(function () {
206
+ if (!isAiActive && !aiSuggestionAccepted) {
207
+ setTextValue({
208
+ value: valueAccepted
209
+ });
210
+ }
211
+ }, [suggestions, isAiActive]);
117
212
  (0, _react.useEffect)(function () {
118
213
  var _textValue$value;
119
214
 
120
215
  setRequiredEmpty(isRequired && (((_textValue$value = textValue.value) === null || _textValue$value === void 0 ? void 0 : _textValue$value.length) === 0 || textValue.value === undefined));
121
- }, [textValue]);
122
-
123
- var numberInputOnWheelPreventChange = function numberInputOnWheelPreventChange(e) {
124
- // Prevent the input value change
125
- e.target.blur(); // Prevent the page/container scrolling
126
-
127
- e.stopPropagation(); // Refocus immediately, on the next tick (after the current function is done)
216
+ }, [textValue]); // const numberInputOnWheelPreventChange = (e) => {
217
+ // // Prevent the input value change
218
+ // e.target.blur();
219
+ // // Prevent the page/container scrolling
220
+ // e.stopPropagation();
221
+ // // Refocus immediately, on the next tick (after the current function is done)
222
+ // setTimeout(() => e.target.focus(), 0);
223
+ // };
224
+ //AI Generation
128
225
 
129
- setTimeout(function () {
130
- return e.target.focus();
131
- }, 0);
226
+ var handleAcceptSuggestion = function handleAcceptSuggestion(suggestionValue) {
227
+ if (!suggestionValue) return;
228
+ setValueAccepted(suggestionValue);
229
+ setAiSuggestionAccepted(true);
230
+ setIsAiActive(false);
231
+ updateParentData(suggestionValue, true, suggestionValue);
132
232
  };
133
233
 
134
234
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Container, {
@@ -157,21 +257,94 @@ var GeneralInput = function GeneralInput(_ref) {
157
257
  },
158
258
  defaultChecked: textValue.value === "true" ? true : false,
159
259
  disabled: disabled
160
- }) : inputType !== "textarea" ? /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
161
- type: inputType,
162
- disabled: disabled,
163
- id: inputId,
164
- size: inputSize,
165
- className: "general-input",
166
- placeholder: inputPlaceholder,
167
- value: textValue.value,
168
- onInput: function onInput(e) {
169
- return onHandleChange(e);
170
- },
171
- maxLength: maxChar,
172
- required: isRequired,
173
- onKeyDown: onKeyDown,
174
- onWheel: numberInputOnWheelPreventChange
260
+ }) : inputType !== "textarea" ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
261
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles2.InputContainer, {
262
+ className: hasAiGeneration ? "ai-generation" : "",
263
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
264
+ type: inputType,
265
+ disabled: disabled,
266
+ id: inputId,
267
+ size: inputSize,
268
+ className: "general-input ".concat(isAiActive && isBenefitInput && "ia-input"),
269
+ placeholder: inputPlaceholder,
270
+ value: isAiActive ? currentSuggestion === null || currentSuggestion === void 0 ? void 0 : (_currentSuggestion$in = currentSuggestion[inputId]) === null || _currentSuggestion$in === void 0 ? void 0 : _currentSuggestion$in.value : textValue.value,
271
+ onInput: function onInput(e) {
272
+ return onHandleChange(e);
273
+ },
274
+ maxLength: maxChar,
275
+ required: isRequired,
276
+ onKeyDown: onKeyDown // onWheel={numberInputOnWheelPreventChange}
277
+
278
+ }), hasAiGeneration && isBenefitInput && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
279
+ className: "icon_container ".concat(isAiAvailable ? "ai-available" : '', " ").concat(isAiActive ? 'ai-active' : ''),
280
+ title: !isAiAvailable ? 'Debes de completar ficha técnica e imágenes para desbloquear la generación con IA' : '',
281
+ onClick: function onClick() {
282
+ _handlerAiGeneration({
283
+ type: "attribute"
284
+ });
285
+ },
286
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
287
+ className: "".concat(isAiGenerationLoading ? 'loading' : ''),
288
+ src: isAiGenerationLoading ? _loading.default : isAiActive ? _cancel.default : _iaIcon.default
289
+ })
290
+ })]
291
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles2.BottomContainer, {
292
+ className: isAiActive ? "with-ai" : "",
293
+ children: isAiActive && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
294
+ className: "ai-options",
295
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles2.OptionsContainer, {
296
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
297
+ className: "arrow ".concat((currentSuggestion === null || currentSuggestion === void 0 ? void 0 : (_currentSuggestion$in2 = currentSuggestion[inputId]) === null || _currentSuggestion$in2 === void 0 ? void 0 : _currentSuggestion$in2.index) === 0 && "disabled"),
298
+ onClick: function onClick() {
299
+ handleChangeSuggestion({
300
+ action: "prev"
301
+ });
302
+ },
303
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
304
+ src: _arrow.default,
305
+ alt: ""
306
+ })
307
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
308
+ children: [(currentSuggestion === null || currentSuggestion === void 0 ? void 0 : (_currentSuggestion$in3 = currentSuggestion[inputId]) === null || _currentSuggestion$in3 === void 0 ? void 0 : _currentSuggestion$in3.index) + 1 || 1, "/", suggestions === null || suggestions === void 0 ? void 0 : (_suggestions$inputId2 = suggestions[inputId]) === null || _suggestions$inputId2 === void 0 ? void 0 : _suggestions$inputId2.length]
309
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
310
+ className: "arrow right ".concat((currentSuggestion === null || currentSuggestion === void 0 ? void 0 : (_currentSuggestion$in4 = currentSuggestion[inputId]) === null || _currentSuggestion$in4 === void 0 ? void 0 : _currentSuggestion$in4.index) === (suggestions === null || suggestions === void 0 ? void 0 : (_suggestions$inputId3 = suggestions[inputId]) === null || _suggestions$inputId3 === void 0 ? void 0 : _suggestions$inputId3.length) - 1 && "disabled"),
311
+ onClick: function onClick() {},
312
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
313
+ onClick: function onClick() {
314
+ handleChangeSuggestion({
315
+ action: "next"
316
+ });
317
+ },
318
+ src: _arrow.default,
319
+ alt: "ai icon"
320
+ })
321
+ })]
322
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles2.ButtonsContainer, {
323
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
324
+ className: "reload-suggestions ".concat(isAiRegenerationLoading && "loading"),
325
+ onClick: function onClick() {
326
+ _handlerRegenerateSuggestions({
327
+ type: "attribute"
328
+ });
329
+ },
330
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
331
+ className: "",
332
+ src: isAiRegenerationLoading ? _loading.default : _reload.default
333
+ })
334
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
335
+ className: "accept-suggestion",
336
+ onClick: function onClick() {
337
+ var _currentSuggestion$in5;
338
+
339
+ handleAcceptSuggestion(currentSuggestion === null || currentSuggestion === void 0 ? void 0 : (_currentSuggestion$in5 = currentSuggestion[inputId]) === null || _currentSuggestion$in5 === void 0 ? void 0 : _currentSuggestion$in5.value);
340
+ },
341
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
342
+ children: "Aceptar sugerencia"
343
+ })
344
+ })]
345
+ })]
346
+ })
347
+ })]
175
348
  }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputFormatter.InputFormatter, {
176
349
  name: inputName,
177
350
  inputId: inputId,
@@ -183,7 +356,25 @@ var GeneralInput = function GeneralInput(_ref) {
183
356
  setUpdatedDescriptions: setUpdatedDescriptions,
184
357
  maxChar: maxChar,
185
358
  isRequired: isRequired,
186
- disabled: disabled
359
+ disabled: disabled,
360
+ hasAiGeneration: hasAiGeneration && inputId != 'commentary-box',
361
+ isAiAvailable: isAiAvailable,
362
+ aiGenerated: aiGenerated,
363
+ handlerAiGeneration: function handlerAiGeneration() {
364
+ _handlerAiGeneration({
365
+ type: "description"
366
+ });
367
+ },
368
+ handlerRegenerateSuggestions: function handlerRegenerateSuggestions() {
369
+ _handlerRegenerateSuggestions({
370
+ type: "description"
371
+ });
372
+ },
373
+ handleChangeSuggestion: handleChangeSuggestion,
374
+ isAiGenerationLoading: isAiGenerationLoading,
375
+ isAiRegenerationLoading: isAiRegenerationLoading,
376
+ isAiActive: isAiActive,
377
+ setIsAiActive: setIsAiActive
187
378
  })
188
379
  });
189
380
  };
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.Container = void 0;
8
+ exports.InputContainer = exports.Container = void 0;
9
9
 
10
10
  var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/taggedTemplateLiteral"));
11
11
 
@@ -13,7 +13,7 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
13
13
 
14
14
  var _variables = require("../../../global-files/variables");
15
15
 
16
- var _templateObject;
16
+ var _templateObject, _templateObject2;
17
17
 
18
18
  var Container = _styledComponents.default.div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n width: 100%;\n\n > div {\n label {\n &:before {\n outline: 1px solid ", ";\n }\n }\n }\n\n input,\n textarea {\n width: 100%;\n border: 1px solid\n ", ";\n\n font-family: ", ";\n color: ", ";\n font-weight: normal;\n font-size: 12px;\n line-height: 15px;\n padding: 10px;\n outline: none;\n border-radius: 5px;\n resize: none;\n\n &:focus {\n border: 1px solid ", ";\n }\n }\n\n select {\n background: #fafafa;\n outline: none;\n border: 1px solid\n ", ";\n width: 100%;\n cursor: pointer;\n font-family: ", ";\n color: ", ";\n font-size: 12px;\n line-height: 21px;\n padding: 10px;\n border-right: 2px solid #e33aa9;\n\n &:focus {\n border: 1px solid ", ";\n }\n }\n\n p {\n font-family: ", ";\n font-size: 12px;\n color: ", ";\n }\n\n &.audit-class {\n input,\n .quill {\n border: 1px solid #8a6caa;\n background-color: #ededfc;\n }\n }\n\n .btnReviewState {\n display: \"flex\";\n flex-direction: \"column\";\n border: 1px solid lightgray;\n border-radius: 3px;\n z-index: 1000;\n /* position: absolute; */\n }\n\n .btnReviewState button {\n border: none;\n background: white;\n border-radius: 3px;\n }\n .btnReviewState button:hover {\n background: lightgray;\n }\n"])), function (_ref) {
19
19
  var isRequired = _ref.isRequired;
@@ -26,4 +26,8 @@ var Container = _styledComponents.default.div(_templateObject || (_templateObjec
26
26
  return isRequired ? "red" : "".concat(_variables.GlobalColors.s2);
27
27
  }, _variables.FontFamily.AvenirNext, _variables.GlobalColors.deep_gray, _variables.GlobalColors.magenta_s2, _variables.FontFamily.Raleway, _variables.GlobalColors.deep_gray);
28
28
 
29
- exports.Container = Container;
29
+ exports.Container = Container;
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 &.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
+
33
+ exports.InputContainer = InputContainer;