contentoh-components-library 21.6.0 → 21.6.11
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/atoms/ProgressBar/index.js +1 -1
- package/dist/components/atoms/ProgressBar/styles.js +4 -4
- package/dist/components/atoms/Status/index.js +16 -1
- package/dist/components/atoms/Status/styles.js +1 -1
- package/dist/components/organisms/ChangeStatusModal/index.js +166 -53
- package/dist/components/organisms/ChangeStatusModal/styles.js +12 -8
- package/dist/components/pages/ProviderProductEdition/context/provider-product-edition.context.js +3 -1
- package/dist/components/pages/ProviderProductEdition/index.js +65 -36
- package/dist/components/pages/ProviderProductEdition/utils.js +3 -1
- package/dist/components/pages/RetailerProductEdition/context/reducers/product.js +11 -19
- package/dist/components/pages/RetailerProductEdition/index.js +16 -10
- package/dist/components/pages/RetailerProductEdition/utils.js +1 -1
- package/dist/contexts/AiProductEdition.js +34 -22
- package/dist/global-files/statusDictionary.js +36 -1
- package/package.json +1 -1
- package/src/components/atoms/ProgressBar/index.js +2 -6
- package/src/components/atoms/ProgressBar/styles.js +4 -58
- package/src/components/atoms/Status/index.js +11 -3
- package/src/components/atoms/Status/styles.js +113 -0
- package/src/components/organisms/ChangeStatusModal/index.jsx +103 -29
- package/src/components/organisms/ChangeStatusModal/styles.js +20 -0
- package/src/components/pages/ProviderProductEdition/context/provider-product-edition.context.jsx +1 -0
- package/src/components/pages/ProviderProductEdition/index.js +40 -14
- package/src/components/pages/ProviderProductEdition/utils.js +5 -1
- package/src/components/pages/RetailerProductEdition/context/reducers/product.js +4 -20
- package/src/components/pages/RetailerProductEdition/index.js +20 -16
- package/src/components/pages/RetailerProductEdition/utils.js +1 -1
- package/src/contexts/AiProductEdition.jsx +22 -13
- package/src/global-files/statusDictionary.js +31 -1
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
ProviderProductEditionProvider,
|
|
9
9
|
useProviderProductEdition,
|
|
10
10
|
} from "./context/provider-product-edition.context";
|
|
11
|
+
import { getMinorStatusFromRetailer } from "./context/reducers/product";
|
|
11
12
|
import {
|
|
12
13
|
normalizeProduct,
|
|
13
14
|
getConceptByTab,
|
|
@@ -70,10 +71,16 @@ const allowedAccountsToViewChangeStatus = [
|
|
|
70
71
|
"gmorales@contentoh.com",
|
|
71
72
|
"rvega@contentoh.com",
|
|
72
73
|
"amora@contentoh.com",
|
|
74
|
+
//PRODUCT DEV ACCOUNTS
|
|
73
75
|
"oparra@contentoh.com",
|
|
74
76
|
"zsegura@contentoh.com",
|
|
75
77
|
"oserna@contentoh.com",
|
|
76
|
-
"jalvarado@contentoh.com"
|
|
78
|
+
"jalvarado@contentoh.com",
|
|
79
|
+
//DEV ACCOUNTS
|
|
80
|
+
"kikije1467@mtlcz.com", //IMÁGENES
|
|
81
|
+
"karafe3218@mom2kid.com", //TEXTOS
|
|
82
|
+
"ladiboh785@mi166.com", //QA
|
|
83
|
+
|
|
77
84
|
];
|
|
78
85
|
|
|
79
86
|
const RetailerProductEditionView = ({
|
|
@@ -759,9 +766,7 @@ const RetailerProductEditionView = ({
|
|
|
759
766
|
const updatedProduct = {
|
|
760
767
|
...state.product,
|
|
761
768
|
statusByRetailer: updatedStatusByRetailer,
|
|
762
|
-
|
|
763
|
-
// status: articleStatus,
|
|
764
|
-
// article_status: articleStatus
|
|
769
|
+
status: getMinorStatusFromRetailer(updatedStatusByRetailer),
|
|
765
770
|
};
|
|
766
771
|
|
|
767
772
|
dispatch({ type: "SET_PRODUCT", payload: updatedProduct });
|
|
@@ -835,19 +840,18 @@ const RetailerProductEditionView = ({
|
|
|
835
840
|
// };
|
|
836
841
|
// await sendMessage(messageData);
|
|
837
842
|
|
|
843
|
+
const updatedStatusByRetailerForSend = state.product.statusByRetailer.map((item) => {
|
|
844
|
+
if (item.retailer_id === retailerId && item.service === concept) {
|
|
845
|
+
return { ...item, status: newStatus };
|
|
846
|
+
}
|
|
847
|
+
return item;
|
|
848
|
+
});
|
|
849
|
+
|
|
838
850
|
const updatedProduct = {
|
|
839
851
|
...state.product,
|
|
840
852
|
[`${concept}_status`]: newStatus,
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
if (item.retailer_id === retailerId && item.service === concept) {
|
|
844
|
-
return { ...item, status: newStatus };
|
|
845
|
-
}
|
|
846
|
-
return item;
|
|
847
|
-
}),
|
|
848
|
-
// version_status: articleStatus,
|
|
849
|
-
// status: articleStatus,
|
|
850
|
-
// article_status: articleStatus
|
|
853
|
+
statusByRetailer: updatedStatusByRetailerForSend,
|
|
854
|
+
status: getMinorStatusFromRetailer(updatedStatusByRetailerForSend),
|
|
851
855
|
};
|
|
852
856
|
|
|
853
857
|
//Actualizamos el services_data en el servicio específico del retailer actual
|
|
@@ -927,7 +931,7 @@ const RetailerProductEditionView = ({
|
|
|
927
931
|
state.services_data?.forEach((ret, idx) => {
|
|
928
932
|
const { service: retailer_service, id_retailer, status: status_retailer_service } = ret;
|
|
929
933
|
|
|
930
|
-
const lastStatusLevel = status_retailer_service
|
|
934
|
+
const lastStatusLevel = status_retailer_service?.replace(/.*\//, "");
|
|
931
935
|
|
|
932
936
|
if (conceptArray.includes(retailer_service) && statusArray?.includes(lastStatusLevel)) {
|
|
933
937
|
const data = {
|
|
@@ -963,7 +967,7 @@ const RetailerProductEditionView = ({
|
|
|
963
967
|
const updatedProduct = {
|
|
964
968
|
...state.product,
|
|
965
969
|
article_status: status,
|
|
966
|
-
status:
|
|
970
|
+
status: getMinorStatusFromRetailer(updatedStatusByRetailer),
|
|
967
971
|
datasheet_status:
|
|
968
972
|
state.product.datasheet_status === "NA" ? "NA" : status,
|
|
969
973
|
description_status:
|
|
@@ -114,7 +114,7 @@ export const normalizeProduct = (product) => {
|
|
|
114
114
|
percentages: productData.percentages || null,
|
|
115
115
|
summary: productData.summary || null,
|
|
116
116
|
version: productData.version || 0,
|
|
117
|
-
id_order: productData.orderId || 0,
|
|
117
|
+
id_order: productData.orderId || productData.id_order || 0,
|
|
118
118
|
status: productData.status || null,
|
|
119
119
|
datasheet_status: productData.datasheet_status || null,
|
|
120
120
|
description_status: productData.description_status || null,
|
|
@@ -40,35 +40,39 @@ export const AiProductEditionProvider = ({
|
|
|
40
40
|
const [inputsGeneratedWithAi, setInputsGeneratedWithAi] = useState({});
|
|
41
41
|
const [inputsUsingAi, setInputsUsingAi] = useState({});
|
|
42
42
|
|
|
43
|
-
const
|
|
44
|
-
const
|
|
43
|
+
const AI_MAX_CREDITS = 2;
|
|
44
|
+
const AI_RESET_MS = 24 * 60 * 60 * 1000;
|
|
45
45
|
const RATE_LIMIT_KEY = "ai_generation_limit_data";
|
|
46
46
|
|
|
47
|
-
const checkAndManageRateLimit = (
|
|
47
|
+
const checkAndManageRateLimit = ({ articleId, descriptionId, attributeId, type }) => {
|
|
48
48
|
const now = Date.now();
|
|
49
49
|
const storedData = localStorage.getItem(RATE_LIMIT_KEY);
|
|
50
50
|
|
|
51
51
|
let allRateData = storedData ? JSON.parse(storedData) : {};
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
const idPart = descriptionId ?? attributeId;
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
const key = idPart ? `${articleId}_${idPart}_${type}` : `${articleId}`;
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
let keyTimestamps = allRateData[key] || [];
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
keyTimestamps = keyTimestamps.filter(timestamp => (now - timestamp) < AI_RESET_MS);
|
|
60
|
+
|
|
61
|
+
if (keyTimestamps.length >= AI_MAX_CREDITS) {
|
|
62
|
+
allRateData[key] = keyTimestamps;
|
|
60
63
|
localStorage.setItem(RATE_LIMIT_KEY, JSON.stringify(allRateData));
|
|
61
64
|
|
|
62
65
|
return {
|
|
63
66
|
allowed: false,
|
|
64
|
-
message:
|
|
67
|
+
message: idPart
|
|
68
|
+
? "Has alcanzado el límite de intentos para este atributo. Vuelve a intentarlo en 24 horas."
|
|
69
|
+
: "Has alcanzado el límite de intentos para este producto. Vuelve a intentarlo en 24 horas."
|
|
65
70
|
};
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
allRateData[
|
|
71
|
-
|
|
73
|
+
// Registramos el intento
|
|
74
|
+
keyTimestamps.push(now);
|
|
75
|
+
allRateData[key] = keyTimestamps;
|
|
72
76
|
localStorage.setItem(RATE_LIMIT_KEY, JSON.stringify(allRateData));
|
|
73
77
|
|
|
74
78
|
return { allowed: true };
|
|
@@ -150,7 +154,12 @@ export const AiProductEditionProvider = ({
|
|
|
150
154
|
|
|
151
155
|
if(!isAiAvailable) return;
|
|
152
156
|
|
|
153
|
-
const rateLimitStatus = checkAndManageRateLimit(
|
|
157
|
+
const rateLimitStatus = checkAndManageRateLimit({
|
|
158
|
+
articleId,
|
|
159
|
+
descriptionId,
|
|
160
|
+
attributeId,
|
|
161
|
+
type
|
|
162
|
+
});
|
|
154
163
|
|
|
155
164
|
if (!rateLimitStatus.allowed) {
|
|
156
165
|
return {
|
|
@@ -98,6 +98,36 @@ const STATUS_DICTIONARY = {
|
|
|
98
98
|
},
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
+
const resolveStatusObj = (statusStr) => {
|
|
102
|
+
if (!statusStr || typeof statusStr !== "string") return null;
|
|
103
|
+
if (STATUS_DICTIONARY[statusStr]) return STATUS_DICTIONARY[statusStr];
|
|
104
|
+
// Compound statuses like 'RA/AS' — use last segment for weight lookup
|
|
105
|
+
const parts = statusStr.split("/");
|
|
106
|
+
const lastPart = parts[parts.length - 1];
|
|
107
|
+
const dictEntry = STATUS_DICTIONARY[lastPart];
|
|
108
|
+
if (dictEntry) return { status: statusStr, name: statusStr, weight: dictEntry.weight };
|
|
109
|
+
return null;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Returns the status string with the lowest weight from an array of status strings
|
|
113
|
+
const getMinorStatus = (servicesStatus = []) => {
|
|
114
|
+
if (!servicesStatus || servicesStatus.length === 0)
|
|
115
|
+
return STATUS_DICTIONARY.NS.status;
|
|
116
|
+
const winner = servicesStatus.reduce((minorObj, current) => {
|
|
117
|
+
const currentObj = resolveStatusObj(
|
|
118
|
+
typeof current === "string" ? current : current?.status
|
|
119
|
+
);
|
|
120
|
+
if (!currentObj || typeof currentObj.weight === "undefined") return minorObj;
|
|
121
|
+
return currentObj.weight < minorObj.weight ? currentObj : minorObj;
|
|
122
|
+
}, STATUS_DICTIONARY.NS);
|
|
123
|
+
return winner?.status || STATUS_DICTIONARY.NS.status;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const getMinorStatusFromRetailerMap = (statusByRetailer = {}) =>
|
|
127
|
+
getMinorStatus(Object.values(statusByRetailer).flatMap(Object.values));
|
|
128
|
+
|
|
101
129
|
module.exports = {
|
|
102
|
-
STATUS_DICTIONARY
|
|
130
|
+
STATUS_DICTIONARY,
|
|
131
|
+
getMinorStatus,
|
|
132
|
+
getMinorStatusFromRetailerMap,
|
|
103
133
|
}
|