contentoh-components-library 21.6.19 → 21.6.21
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/.env.test +2 -1
- package/dist/components/atoms/InheritanceTag/index.js +8 -0
- package/dist/components/molecules/TagAndInput/index.js +1 -0
- package/dist/components/molecules/TagAndInputv2/index.js +1 -0
- package/dist/components/organisms/LinkVariantsModal/api.js +102 -0
- package/dist/components/organisms/LinkVariantsModal/index.js +620 -0
- package/dist/components/organisms/LinkVariantsModal/styles.js +60 -0
- package/dist/components/pages/ProviderProductEdition/context/reducers/inputs.js +8 -2
- package/dist/components/pages/ProviderProductEdition/index.js +198 -89
- package/dist/components/pages/ProviderProductEdition/styles.js +2 -2
- package/dist/components/pages/ProviderProductEdition/utils.js +8 -0
- package/dist/index.js +25 -12
- package/package.json +1 -1
- package/src/components/atoms/InheritanceTag/index.js +7 -0
- package/src/components/molecules/TagAndInput/index.js +1 -0
- package/src/components/molecules/TagAndInputv2/index.js +1 -0
- package/src/components/organisms/LinkVariantsModal/api.js +61 -0
- package/src/components/organisms/LinkVariantsModal/index.js +479 -0
- package/src/components/organisms/LinkVariantsModal/styles.js +264 -0
- package/src/components/pages/ProviderProductEdition/context/reducers/inputs.js +21 -13
- package/src/components/pages/ProviderProductEdition/index.js +76 -0
- package/src/components/pages/ProviderProductEdition/styles.js +23 -0
- package/src/components/pages/ProviderProductEdition/utils.js +8 -0
- package/src/index.js +1 -0
- package/dist/ai/prompts/attribute.prompt.js +0 -28
- package/dist/ai/prompts/description.prompt.js +0 -33
- package/dist/ai/schemas/attribute.schema.js +0 -35
- package/dist/ai/schemas/description.schema.js +0 -27
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.LinkVariantsModal = void 0;
|
|
9
|
+
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
+
|
|
12
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
|
|
13
|
+
|
|
14
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator"));
|
|
15
|
+
|
|
16
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
|
|
17
|
+
|
|
18
|
+
var _react = require("react");
|
|
19
|
+
|
|
20
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
21
|
+
|
|
22
|
+
var _api = require("./api");
|
|
23
|
+
|
|
24
|
+
var _styles = require("./styles");
|
|
25
|
+
|
|
26
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
Modal para ligar productos como padre/variante.
|
|
30
|
+
|
|
31
|
+
props (* requerido):
|
|
32
|
+
- *articleId: producto desde el que se liga (el que está en edición)
|
|
33
|
+
- articleName / articleUpc: para que el usuario sepa sobre qué está trabajando
|
|
34
|
+
- *token: JWT que va en el header Authorization
|
|
35
|
+
- endpoint: base del API de variantes. Por defecto REACT_APP_VARIANTS_ENDPOINT
|
|
36
|
+
- *onClose: cerrar sin cambios
|
|
37
|
+
- onLinked: se llama con la respuesta del backend cuando la liga tuvo éxito
|
|
38
|
+
|
|
39
|
+
Los dos modos son los de POST /variants/link:
|
|
40
|
+
parent → este producto pasa a ser variante del que se elija
|
|
41
|
+
children → los elegidos pasan a ser variantes de este producto
|
|
42
|
+
|
|
43
|
+
En ambos el padre baja al hijo, nunca al revés. Lo que cambia es quién es quién.
|
|
44
|
+
*/
|
|
45
|
+
// El backend devuelve códigos estables justamente para no mandar textos de UI
|
|
46
|
+
// desde el servidor. La traducción a lenguaje humano vive aquí.
|
|
47
|
+
var ERROR_TEXT = {
|
|
48
|
+
VARIANT_SELF_LINK: "Un producto no puede ser variante de sí mismo.",
|
|
49
|
+
VARIANT_PARENT_IS_CHILD: "Ese producto ya es variante de otro. Las familias son de un solo nivel.",
|
|
50
|
+
VARIANT_CHILD_IS_PARENT: "Ese producto ya tiene variantes propias, así que no puede colgar de otro.",
|
|
51
|
+
VARIANT_ALREADY_LINKED: "Ese producto ya pertenece a otra familia. Desvincúlalo primero.",
|
|
52
|
+
VARIANT_NOT_OWNED_BY_USER: "Ese producto está fuera de tu alcance.",
|
|
53
|
+
VARIANT_CROSS_COMPANY: "Ese producto pertenece a otra compañía.",
|
|
54
|
+
VARIANT_INACTIVE_ARTICLE: "Ese producto está desactivado.",
|
|
55
|
+
VARIANT_NOT_FOUND: "No encontramos ese producto.",
|
|
56
|
+
VARIANT_PLAN_LIMIT_REACHED: "Tu plan no tiene cupo disponible para más productos."
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
var readError = function readError(error) {
|
|
60
|
+
if (error instanceof _api.ApiError || (error === null || error === void 0 ? void 0 : error.name) === "ApiError") {
|
|
61
|
+
return ERROR_TEXT[error.code] || error.message;
|
|
62
|
+
} // Falla de transporte de verdad: red caída, DNS, CORS.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
return "No se pudo conectar con el servidor.";
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
var LinkVariantsModal = function LinkVariantsModal(_ref) {
|
|
69
|
+
var articleId = _ref.articleId,
|
|
70
|
+
articleName = _ref.articleName,
|
|
71
|
+
articleUpc = _ref.articleUpc,
|
|
72
|
+
activeRetailerId = _ref.activeRetailerId,
|
|
73
|
+
token = _ref.token,
|
|
74
|
+
_ref$endpoint = _ref.endpoint,
|
|
75
|
+
endpoint = _ref$endpoint === void 0 ? process.env.REACT_APP_VARIANTS_ENDPOINT : _ref$endpoint,
|
|
76
|
+
onClose = _ref.onClose,
|
|
77
|
+
onLinked = _ref.onLinked;
|
|
78
|
+
|
|
79
|
+
var _useState = (0, _react.useState)("parent"),
|
|
80
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
81
|
+
mode = _useState2[0],
|
|
82
|
+
setMode = _useState2[1];
|
|
83
|
+
|
|
84
|
+
var _useState3 = (0, _react.useState)("search"),
|
|
85
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
86
|
+
step = _useState4[0],
|
|
87
|
+
setStep = _useState4[1];
|
|
88
|
+
|
|
89
|
+
var _useState5 = (0, _react.useState)(""),
|
|
90
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
91
|
+
query = _useState6[0],
|
|
92
|
+
setQuery = _useState6[1];
|
|
93
|
+
|
|
94
|
+
var _useState7 = (0, _react.useState)([]),
|
|
95
|
+
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
|
96
|
+
candidates = _useState8[0],
|
|
97
|
+
setCandidates = _useState8[1];
|
|
98
|
+
|
|
99
|
+
var _useState9 = (0, _react.useState)(null),
|
|
100
|
+
_useState10 = (0, _slicedToArray2.default)(_useState9, 2),
|
|
101
|
+
rejected = _useState10[0],
|
|
102
|
+
setRejected = _useState10[1];
|
|
103
|
+
|
|
104
|
+
var _useState11 = (0, _react.useState)(false),
|
|
105
|
+
_useState12 = (0, _slicedToArray2.default)(_useState11, 2),
|
|
106
|
+
searched = _useState12[0],
|
|
107
|
+
setSearched = _useState12[1];
|
|
108
|
+
|
|
109
|
+
var _useState13 = (0, _react.useState)([]),
|
|
110
|
+
_useState14 = (0, _slicedToArray2.default)(_useState13, 2),
|
|
111
|
+
selected = _useState14[0],
|
|
112
|
+
setSelected = _useState14[1];
|
|
113
|
+
|
|
114
|
+
var _useState15 = (0, _react.useState)([]),
|
|
115
|
+
_useState16 = (0, _slicedToArray2.default)(_useState15, 2),
|
|
116
|
+
attributes = _useState16[0],
|
|
117
|
+
setAttributes = _useState16[1];
|
|
118
|
+
|
|
119
|
+
var _useState17 = (0, _react.useState)(null),
|
|
120
|
+
_useState18 = (0, _slicedToArray2.default)(_useState17, 2),
|
|
121
|
+
nameScope = _useState18[0],
|
|
122
|
+
setNameScope = _useState18[1];
|
|
123
|
+
|
|
124
|
+
var _useState19 = (0, _react.useState)("all-filled"),
|
|
125
|
+
_useState20 = (0, _slicedToArray2.default)(_useState19, 2),
|
|
126
|
+
inheritMode = _useState20[0],
|
|
127
|
+
setInheritMode = _useState20[1];
|
|
128
|
+
|
|
129
|
+
var _useState21 = (0, _react.useState)([]),
|
|
130
|
+
_useState22 = (0, _slicedToArray2.default)(_useState21, 2),
|
|
131
|
+
chosenAttributes = _useState22[0],
|
|
132
|
+
setChosenAttributes = _useState22[1];
|
|
133
|
+
|
|
134
|
+
var _useState23 = (0, _react.useState)(true),
|
|
135
|
+
_useState24 = (0, _slicedToArray2.default)(_useState23, 2),
|
|
136
|
+
inheritImages = _useState24[0],
|
|
137
|
+
setInheritImages = _useState24[1];
|
|
138
|
+
|
|
139
|
+
var _useState25 = (0, _react.useState)(true),
|
|
140
|
+
_useState26 = (0, _slicedToArray2.default)(_useState25, 2),
|
|
141
|
+
inheritDescriptions = _useState26[0],
|
|
142
|
+
setInheritDescriptions = _useState26[1];
|
|
143
|
+
|
|
144
|
+
var _useState27 = (0, _react.useState)(true),
|
|
145
|
+
_useState28 = (0, _slicedToArray2.default)(_useState27, 2),
|
|
146
|
+
inheritCategoryRetailers = _useState28[0],
|
|
147
|
+
setInheritCategoryRetailers = _useState28[1];
|
|
148
|
+
|
|
149
|
+
var _useState29 = (0, _react.useState)(false),
|
|
150
|
+
_useState30 = (0, _slicedToArray2.default)(_useState29, 2),
|
|
151
|
+
loading = _useState30[0],
|
|
152
|
+
setLoading = _useState30[1];
|
|
153
|
+
|
|
154
|
+
var _useState31 = (0, _react.useState)(null),
|
|
155
|
+
_useState32 = (0, _slicedToArray2.default)(_useState31, 2),
|
|
156
|
+
error = _useState32[0],
|
|
157
|
+
setError = _useState32[1];
|
|
158
|
+
|
|
159
|
+
var request = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
160
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(action, body) {
|
|
161
|
+
var res;
|
|
162
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
163
|
+
while (1) {
|
|
164
|
+
switch (_context.prev = _context.next) {
|
|
165
|
+
case 0:
|
|
166
|
+
_context.next = 2;
|
|
167
|
+
return _axios.default.post("".concat(endpoint, "/").concat(action), body, {
|
|
168
|
+
headers: {
|
|
169
|
+
Authorization: token
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
case 2:
|
|
174
|
+
res = _context.sent;
|
|
175
|
+
return _context.abrupt("return", (0, _api.readPayload)(res));
|
|
176
|
+
|
|
177
|
+
case 4:
|
|
178
|
+
case "end":
|
|
179
|
+
return _context.stop();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}, _callee);
|
|
183
|
+
}));
|
|
184
|
+
|
|
185
|
+
return function (_x, _x2) {
|
|
186
|
+
return _ref2.apply(this, arguments);
|
|
187
|
+
};
|
|
188
|
+
}(), [endpoint, token]); // En modo children el padre es el producto en edición; en modo parent es el
|
|
189
|
+
// candidato que el usuario acaba de elegir. De ahí sale qué atributos ofrecer.
|
|
190
|
+
|
|
191
|
+
var parentArticleId = (0, _react.useMemo)(function () {
|
|
192
|
+
return mode === "children" ? articleId : selected[0];
|
|
193
|
+
}, [mode, articleId, selected]); // Cambiar de dirección invalida la selección: los candidatos elegibles no son
|
|
194
|
+
// los mismos, y arrastrar la anterior llevaría a ligar algo que no se buscó.
|
|
195
|
+
|
|
196
|
+
(0, _react.useEffect)(function () {
|
|
197
|
+
setCandidates([]);
|
|
198
|
+
setSelected([]);
|
|
199
|
+
setRejected(null);
|
|
200
|
+
setSearched(false);
|
|
201
|
+
setError(null);
|
|
202
|
+
setStep("search");
|
|
203
|
+
}, [mode]);
|
|
204
|
+
|
|
205
|
+
var search = /*#__PURE__*/function () {
|
|
206
|
+
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(event) {
|
|
207
|
+
var data;
|
|
208
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
209
|
+
while (1) {
|
|
210
|
+
switch (_context2.prev = _context2.next) {
|
|
211
|
+
case 0:
|
|
212
|
+
event === null || event === void 0 ? void 0 : event.preventDefault();
|
|
213
|
+
setLoading(true);
|
|
214
|
+
setError(null);
|
|
215
|
+
_context2.prev = 3;
|
|
216
|
+
_context2.next = 6;
|
|
217
|
+
return request("search", {
|
|
218
|
+
mode: mode,
|
|
219
|
+
articleId: articleId,
|
|
220
|
+
query: query.trim()
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
case 6:
|
|
224
|
+
data = _context2.sent;
|
|
225
|
+
setCandidates(data.candidates || []);
|
|
226
|
+
setRejected(data.rejected || null);
|
|
227
|
+
setSearched(true);
|
|
228
|
+
_context2.next = 15;
|
|
229
|
+
break;
|
|
230
|
+
|
|
231
|
+
case 12:
|
|
232
|
+
_context2.prev = 12;
|
|
233
|
+
_context2.t0 = _context2["catch"](3);
|
|
234
|
+
setError(readError(_context2.t0));
|
|
235
|
+
|
|
236
|
+
case 15:
|
|
237
|
+
_context2.prev = 15;
|
|
238
|
+
setLoading(false);
|
|
239
|
+
return _context2.finish(15);
|
|
240
|
+
|
|
241
|
+
case 18:
|
|
242
|
+
case "end":
|
|
243
|
+
return _context2.stop();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}, _callee2, null, [[3, 12, 15, 18]]);
|
|
247
|
+
}));
|
|
248
|
+
|
|
249
|
+
return function search(_x3) {
|
|
250
|
+
return _ref3.apply(this, arguments);
|
|
251
|
+
};
|
|
252
|
+
}();
|
|
253
|
+
|
|
254
|
+
var toggle = function toggle(id) {
|
|
255
|
+
setSelected(function (current) {
|
|
256
|
+
if (mode === "parent") return current[0] === id ? [] : [id];
|
|
257
|
+
return current.includes(id) ? current.filter(function (item) {
|
|
258
|
+
return item !== id;
|
|
259
|
+
}) : [].concat((0, _toConsumableArray2.default)(current), [id]);
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
var goToInheritance = /*#__PURE__*/function () {
|
|
264
|
+
var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
|
|
265
|
+
var _data$nameScope, data;
|
|
266
|
+
|
|
267
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
268
|
+
while (1) {
|
|
269
|
+
switch (_context3.prev = _context3.next) {
|
|
270
|
+
case 0:
|
|
271
|
+
setLoading(true);
|
|
272
|
+
setError(null);
|
|
273
|
+
_context3.prev = 2;
|
|
274
|
+
_context3.next = 5;
|
|
275
|
+
return request("attributes", {
|
|
276
|
+
parentArticleId: parentArticleId,
|
|
277
|
+
retailerId: activeRetailerId
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
case 5:
|
|
281
|
+
data = _context3.sent;
|
|
282
|
+
setAttributes(data.attributes || []);
|
|
283
|
+
setNameScope((_data$nameScope = data.nameScope) !== null && _data$nameScope !== void 0 ? _data$nameScope : null);
|
|
284
|
+
setChosenAttributes((data.attributes || []).map(function (item) {
|
|
285
|
+
return item.id;
|
|
286
|
+
}));
|
|
287
|
+
setStep("inherit");
|
|
288
|
+
_context3.next = 15;
|
|
289
|
+
break;
|
|
290
|
+
|
|
291
|
+
case 12:
|
|
292
|
+
_context3.prev = 12;
|
|
293
|
+
_context3.t0 = _context3["catch"](2);
|
|
294
|
+
setError(readError(_context3.t0));
|
|
295
|
+
|
|
296
|
+
case 15:
|
|
297
|
+
_context3.prev = 15;
|
|
298
|
+
setLoading(false);
|
|
299
|
+
return _context3.finish(15);
|
|
300
|
+
|
|
301
|
+
case 18:
|
|
302
|
+
case "end":
|
|
303
|
+
return _context3.stop();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}, _callee3, null, [[2, 12, 15, 18]]);
|
|
307
|
+
}));
|
|
308
|
+
|
|
309
|
+
return function goToInheritance() {
|
|
310
|
+
return _ref4.apply(this, arguments);
|
|
311
|
+
};
|
|
312
|
+
}();
|
|
313
|
+
|
|
314
|
+
var toggleAttribute = function toggleAttribute(id) {
|
|
315
|
+
setChosenAttributes(function (current) {
|
|
316
|
+
return current.includes(id) ? current.filter(function (item) {
|
|
317
|
+
return item !== id;
|
|
318
|
+
}) : [].concat((0, _toConsumableArray2.default)(current), [id]);
|
|
319
|
+
});
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
var submit = /*#__PURE__*/function () {
|
|
323
|
+
var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
|
|
324
|
+
var inherit, body, data;
|
|
325
|
+
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
326
|
+
while (1) {
|
|
327
|
+
switch (_context4.prev = _context4.next) {
|
|
328
|
+
case 0:
|
|
329
|
+
setLoading(true);
|
|
330
|
+
setError(null);
|
|
331
|
+
inherit = {
|
|
332
|
+
attributes: inheritMode === "all-filled" ? "all-filled" : chosenAttributes,
|
|
333
|
+
images: inheritImages,
|
|
334
|
+
descriptions: inheritDescriptions,
|
|
335
|
+
categoryRetailers: inheritCategoryRetailers
|
|
336
|
+
};
|
|
337
|
+
body = mode === "parent" ? {
|
|
338
|
+
mode: mode,
|
|
339
|
+
articleId: articleId,
|
|
340
|
+
parentArticleId: selected[0],
|
|
341
|
+
inherit: inherit
|
|
342
|
+
} : {
|
|
343
|
+
mode: mode,
|
|
344
|
+
parentArticleId: articleId,
|
|
345
|
+
childrenArticleIds: selected,
|
|
346
|
+
inherit: inherit
|
|
347
|
+
};
|
|
348
|
+
_context4.prev = 4;
|
|
349
|
+
_context4.next = 7;
|
|
350
|
+
return request("link", body);
|
|
351
|
+
|
|
352
|
+
case 7:
|
|
353
|
+
data = _context4.sent;
|
|
354
|
+
onLinked === null || onLinked === void 0 ? void 0 : onLinked(data);
|
|
355
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
356
|
+
_context4.next = 15;
|
|
357
|
+
break;
|
|
358
|
+
|
|
359
|
+
case 12:
|
|
360
|
+
_context4.prev = 12;
|
|
361
|
+
_context4.t0 = _context4["catch"](4);
|
|
362
|
+
setError(readError(_context4.t0));
|
|
363
|
+
|
|
364
|
+
case 15:
|
|
365
|
+
_context4.prev = 15;
|
|
366
|
+
setLoading(false);
|
|
367
|
+
return _context4.finish(15);
|
|
368
|
+
|
|
369
|
+
case 18:
|
|
370
|
+
case "end":
|
|
371
|
+
return _context4.stop();
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}, _callee4, null, [[4, 12, 15, 18]]);
|
|
375
|
+
}));
|
|
376
|
+
|
|
377
|
+
return function submit() {
|
|
378
|
+
return _ref5.apply(this, arguments);
|
|
379
|
+
};
|
|
380
|
+
}();
|
|
381
|
+
|
|
382
|
+
var selectionLabel = mode === "parent" ? "Se elige un solo producto padre." : "".concat(selected.length, " producto(s) pasar\xE1n a ser variantes.");
|
|
383
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Overlay, {
|
|
384
|
+
onClick: onClose,
|
|
385
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Panel, {
|
|
386
|
+
onClick: function onClick(event) {
|
|
387
|
+
return event.stopPropagation();
|
|
388
|
+
},
|
|
389
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Header, {
|
|
390
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
391
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
|
|
392
|
+
children: "Ligar productos"
|
|
393
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
|
|
394
|
+
children: [articleName || "Producto ".concat(articleId), articleUpc ? " \xB7 UPC ".concat(articleUpc) : ""]
|
|
395
|
+
})]
|
|
396
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
397
|
+
type: "button",
|
|
398
|
+
className: "close",
|
|
399
|
+
onClick: onClose,
|
|
400
|
+
"aria-label": "Cerrar",
|
|
401
|
+
children: "\xD7"
|
|
402
|
+
})]
|
|
403
|
+
}), step === "search" && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.ModeSwitch, {
|
|
404
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
405
|
+
type: "button",
|
|
406
|
+
className: mode === "parent" ? "active" : "",
|
|
407
|
+
onClick: function onClick() {
|
|
408
|
+
return setMode("parent");
|
|
409
|
+
},
|
|
410
|
+
children: "Este producto es variante de otro"
|
|
411
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
412
|
+
type: "button",
|
|
413
|
+
className: mode === "children" ? "active" : "",
|
|
414
|
+
onClick: function onClick() {
|
|
415
|
+
return setMode("children");
|
|
416
|
+
},
|
|
417
|
+
children: "Agregar variantes a este producto"
|
|
418
|
+
})]
|
|
419
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Body, {
|
|
420
|
+
children: [error && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Message, {
|
|
421
|
+
className: "error",
|
|
422
|
+
children: error
|
|
423
|
+
}), step === "search" && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
424
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.SearchRow, {
|
|
425
|
+
onSubmit: search,
|
|
426
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
427
|
+
type: "text",
|
|
428
|
+
value: query,
|
|
429
|
+
placeholder: "Busca por UPC, SKU o nombre",
|
|
430
|
+
onChange: function onChange(event) {
|
|
431
|
+
return setQuery(event.target.value);
|
|
432
|
+
}
|
|
433
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
434
|
+
type: "submit",
|
|
435
|
+
disabled: loading,
|
|
436
|
+
children: loading ? "Buscando…" : "Buscar"
|
|
437
|
+
})]
|
|
438
|
+
}), rejected && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Message, {
|
|
439
|
+
className: "error",
|
|
440
|
+
children: [rejected.name || rejected.upc, ": ", ERROR_TEXT[rejected.code]]
|
|
441
|
+
}), searched && !candidates.length && !rejected && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Message, {
|
|
442
|
+
children: "No hay productos que puedas ligar con esa b\xFAsqueda. Solo aparecen productos activos de la misma compa\xF1\xEDa que todav\xEDa no pertenecen a otra familia."
|
|
443
|
+
}), candidates.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.List, {
|
|
444
|
+
children: candidates.map(function (candidate) {
|
|
445
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
|
|
446
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
|
|
447
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
448
|
+
type: mode === "parent" ? "radio" : "checkbox",
|
|
449
|
+
name: "candidate",
|
|
450
|
+
checked: selected.includes(candidate.articleId),
|
|
451
|
+
onChange: function onChange() {
|
|
452
|
+
return toggle(candidate.articleId);
|
|
453
|
+
}
|
|
454
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
455
|
+
children: [candidate.name || "Producto ".concat(candidate.articleId), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
456
|
+
className: "meta",
|
|
457
|
+
children: ["UPC ", candidate.upc || "—", candidate.categoryName ? " \xB7 ".concat(candidate.categoryName) : ""]
|
|
458
|
+
})]
|
|
459
|
+
}), candidate.variantsCount > 0 && /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
460
|
+
className: "count",
|
|
461
|
+
children: [candidate.variantsCount, " variante", candidate.variantsCount === 1 ? "" : "s"]
|
|
462
|
+
})]
|
|
463
|
+
})
|
|
464
|
+
}, candidate.articleId);
|
|
465
|
+
})
|
|
466
|
+
})]
|
|
467
|
+
}), step === "inherit" && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
468
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Section, {
|
|
469
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
|
|
470
|
+
children: "\xBFQu\xE9 se hereda del producto padre?"
|
|
471
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
|
|
472
|
+
className: "choice",
|
|
473
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
474
|
+
type: "radio",
|
|
475
|
+
checked: inheritMode === "all-filled",
|
|
476
|
+
onChange: function onChange() {
|
|
477
|
+
return setInheritMode("all-filled");
|
|
478
|
+
}
|
|
479
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
480
|
+
children: ["Todos los atributos con valor", /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
481
|
+
className: "hint",
|
|
482
|
+
children: [attributes.length, " atributo(s) con informaci\xF3n en el padre."]
|
|
483
|
+
})]
|
|
484
|
+
})]
|
|
485
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
|
|
486
|
+
className: "choice",
|
|
487
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
488
|
+
type: "radio",
|
|
489
|
+
checked: inheritMode === "selected",
|
|
490
|
+
onChange: function onChange() {
|
|
491
|
+
return setInheritMode("selected");
|
|
492
|
+
}
|
|
493
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
494
|
+
children: ["Elegir cu\xE1les", /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
495
|
+
className: "hint",
|
|
496
|
+
children: "Lo que no elijas conserva el valor que ya tiene la variante."
|
|
497
|
+
})]
|
|
498
|
+
})]
|
|
499
|
+
})]
|
|
500
|
+
}), inheritMode === "selected" && activeRetailerId && !nameScope && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Message, {
|
|
501
|
+
children: "El producto padre no comparte la cadena que tienes abierta, as\xED que los nombres de abajo son los de otra de sus cadenas."
|
|
502
|
+
}), inheritMode === "selected" && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.AttributeList, {
|
|
503
|
+
children: attributes.map(function (attribute) {
|
|
504
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
|
|
505
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
|
|
506
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
507
|
+
type: "checkbox",
|
|
508
|
+
checked: chosenAttributes.includes(attribute.id),
|
|
509
|
+
onChange: function onChange() {
|
|
510
|
+
return toggleAttribute(attribute.id);
|
|
511
|
+
}
|
|
512
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
513
|
+
children: [attribute.name, attribute.unconfigured && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
514
|
+
className: "note",
|
|
515
|
+
children: "sin configuraci\xF3n en las cadenas del padre"
|
|
516
|
+
}), attribute.ambiguousName && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
517
|
+
className: "note",
|
|
518
|
+
children: "se llama distinto en otra cadena"
|
|
519
|
+
})]
|
|
520
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
521
|
+
className: "value",
|
|
522
|
+
title: attribute.value,
|
|
523
|
+
children: attribute.value
|
|
524
|
+
})]
|
|
525
|
+
})
|
|
526
|
+
}, attribute.id);
|
|
527
|
+
})
|
|
528
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Section, {
|
|
529
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
|
|
530
|
+
children: "Tambi\xE9n se hereda"
|
|
531
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
|
|
532
|
+
className: "choice",
|
|
533
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
534
|
+
type: "checkbox",
|
|
535
|
+
checked: inheritImages,
|
|
536
|
+
onChange: function onChange() {
|
|
537
|
+
return setInheritImages(function (value) {
|
|
538
|
+
return !value;
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
542
|
+
children: "Im\xE1genes"
|
|
543
|
+
})]
|
|
544
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
|
|
545
|
+
className: "choice",
|
|
546
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
547
|
+
type: "checkbox",
|
|
548
|
+
checked: inheritDescriptions,
|
|
549
|
+
onChange: function onChange() {
|
|
550
|
+
return setInheritDescriptions(function (value) {
|
|
551
|
+
return !value;
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
555
|
+
children: "Descripciones"
|
|
556
|
+
})]
|
|
557
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
|
|
558
|
+
className: "choice",
|
|
559
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
560
|
+
type: "checkbox",
|
|
561
|
+
checked: inheritCategoryRetailers,
|
|
562
|
+
onChange: function onChange() {
|
|
563
|
+
return setInheritCategoryRetailers(function (value) {
|
|
564
|
+
return !value;
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
|
|
568
|
+
children: ["Cadenas y categor\xEDas", /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
569
|
+
className: "hint",
|
|
570
|
+
children: "Las parejas cadena-categor\xEDa del padre se copian a la variante."
|
|
571
|
+
})]
|
|
572
|
+
})]
|
|
573
|
+
})]
|
|
574
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Message, {
|
|
575
|
+
children: "Lo que elijas heredar reemplaza el valor actual de la variante, incluso si alguien lo hab\xEDa capturado a mano."
|
|
576
|
+
})]
|
|
577
|
+
})]
|
|
578
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Footer, {
|
|
579
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
580
|
+
className: "summary",
|
|
581
|
+
children: step === "search" ? selectionLabel : "Revisa la herencia antes de ligar."
|
|
582
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
583
|
+
className: "actions",
|
|
584
|
+
children: [step === "inherit" && /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
585
|
+
type: "button",
|
|
586
|
+
className: "secondary",
|
|
587
|
+
onClick: function onClick() {
|
|
588
|
+
return setStep("search");
|
|
589
|
+
},
|
|
590
|
+
disabled: loading,
|
|
591
|
+
children: "Atr\xE1s"
|
|
592
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
593
|
+
type: "button",
|
|
594
|
+
className: "secondary",
|
|
595
|
+
onClick: onClose,
|
|
596
|
+
disabled: loading,
|
|
597
|
+
children: "Cancelar"
|
|
598
|
+
}), step === "search" ? /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
599
|
+
type: "button",
|
|
600
|
+
className: "primary",
|
|
601
|
+
onClick: goToInheritance,
|
|
602
|
+
disabled: loading || !selected.length,
|
|
603
|
+
children: "Continuar"
|
|
604
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
605
|
+
type: "button",
|
|
606
|
+
className: "primary",
|
|
607
|
+
onClick: submit,
|
|
608
|
+
disabled: loading || // Solo estorba cuando hay algo que elegir y no se eligió nada.
|
|
609
|
+
// Con el padre sin atributos heredables, ligar sigue siendo
|
|
610
|
+
// válido: se heredan imágenes, descripciones y cadenas.
|
|
611
|
+
inheritMode === "selected" && attributes.length > 0 && !chosenAttributes.length,
|
|
612
|
+
children: loading ? "Ligando…" : "Ligar"
|
|
613
|
+
})]
|
|
614
|
+
})]
|
|
615
|
+
})]
|
|
616
|
+
})
|
|
617
|
+
});
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
exports.LinkVariantsModal = LinkVariantsModal;
|