contentoh-components-library 21.6.48 → 21.6.49

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.
@@ -11,6 +11,8 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
11
11
 
12
12
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
13
13
 
14
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
15
+
14
16
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator"));
15
17
 
16
18
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
@@ -34,9 +36,18 @@ var _jsxRuntime = require("react/jsx-runtime");
34
36
  un código en `article.variant_group` y ya. Por eso el modal no pregunta qué
35
37
  heredar: no hay nada que heredar.
36
38
 
37
- Dos formas de agrupar, y son la misma operación por debajo:
38
- - elegir un grupo que ya existe
39
- - teclear un código nuevo, que crea el grupo con este producto dentro
39
+ El modal tiene dos pasos y el segundo depende del primero:
40
+
41
+ 1. QUÉ GRUPO. Se elige uno de los que ya existen, o se crea uno nuevo. El
42
+ campo para crearlo está escondido detrás de un botón a propósito: abrirlo
43
+ de entrada le contesta al usuario una pregunta que todavía no se ha
44
+ hecho —si quiere buscar o crear— y empuja a teclear un código que
45
+ probablemente ya existe.
46
+
47
+ 2. QUÉ PRODUCTOS. Aparece solo cuando ya hay un grupo. Permite sumar varios
48
+ de una vez sin salir de aquí; antes había que volver a la tabla, entrar a
49
+ cada producto y repetir el trámite, que para un grupo de cinco eran cinco
50
+ vueltas completas.
40
51
 
41
52
  No hay tabla de grupos: un grupo existe mientras algún producto use su código.
42
53
  Eso hace que una errata no falle, solo cree un grupo de un miembro — de ahí que
@@ -95,7 +106,39 @@ var VariantGroupModal = function VariantGroupModal(_ref) {
95
106
  var _useState13 = (0, _react.useState)(""),
96
107
  _useState14 = (0, _slicedToArray2.default)(_useState13, 2),
97
108
  nuevo = _useState14[0],
98
- setNuevo = _useState14[1];
109
+ setNuevo = _useState14[1]; // El creador arranca cerrado: que esté abierto ya es una sugerencia de crear.
110
+
111
+
112
+ var _useState15 = (0, _react.useState)(false),
113
+ _useState16 = (0, _slicedToArray2.default)(_useState15, 2),
114
+ creando = _useState16[0],
115
+ setCreando = _useState16[1]; // Paso 2: productos que se van a sumar junto con el de origen.
116
+
117
+
118
+ var _useState17 = (0, _react.useState)(""),
119
+ _useState18 = (0, _slicedToArray2.default)(_useState17, 2),
120
+ busquedaProd = _useState18[0],
121
+ setBusquedaProd = _useState18[1];
122
+
123
+ var _useState19 = (0, _react.useState)([]),
124
+ _useState20 = (0, _slicedToArray2.default)(_useState19, 2),
125
+ candidatos = _useState20[0],
126
+ setCandidatos = _useState20[1];
127
+
128
+ var _useState21 = (0, _react.useState)(0),
129
+ _useState22 = (0, _slicedToArray2.default)(_useState21, 2),
130
+ totalCandidatos = _useState22[0],
131
+ setTotalCandidatos = _useState22[1];
132
+
133
+ var _useState23 = (0, _react.useState)(false),
134
+ _useState24 = (0, _slicedToArray2.default)(_useState23, 2),
135
+ cargandoProd = _useState24[0],
136
+ setCargandoProd = _useState24[1];
137
+
138
+ var _useState25 = (0, _react.useState)([]),
139
+ _useState26 = (0, _slicedToArray2.default)(_useState25, 2),
140
+ elegidos = _useState26[0],
141
+ setElegidos = _useState26[1];
99
142
 
100
143
  var request = (0, _react.useCallback)( /*#__PURE__*/function () {
101
144
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(action, body) {
@@ -127,6 +170,11 @@ var VariantGroupModal = function VariantGroupModal(_ref) {
127
170
  return _ref2.apply(this, arguments);
128
171
  };
129
172
  }(), [endpoint, token]);
173
+
174
+ var mensajeDe = function mensajeDe(err, porDefecto) {
175
+ return err instanceof _api.ApiError || (err === null || err === void 0 ? void 0 : err.name) === "ApiError" ? err.message : porDefecto;
176
+ };
177
+
130
178
  var buscar = (0, _react.useCallback)( /*#__PURE__*/function () {
131
179
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(texto) {
132
180
  var _data$groups, data;
@@ -153,7 +201,7 @@ var VariantGroupModal = function VariantGroupModal(_ref) {
153
201
  case 9:
154
202
  _context2.prev = 9;
155
203
  _context2.t0 = _context2["catch"](2);
156
- setError(_context2.t0 instanceof _api.ApiError || (_context2.t0 === null || _context2.t0 === void 0 ? void 0 : _context2.t0.name) === "ApiError" ? _context2.t0.message : "No se pudieron cargar los grupos.");
204
+ setError(mensajeDe(_context2.t0, "No se pudieron cargar los grupos."));
157
205
 
158
206
  case 12:
159
207
  _context2.prev = 12;
@@ -191,68 +239,161 @@ var VariantGroupModal = function VariantGroupModal(_ref) {
191
239
  var codigoNuevo = normalizar(nuevo);
192
240
  var codigoFinal = selected !== null && selected !== void 0 ? selected : codigoNuevo;
193
241
  var esNuevo = !selected && !!codigoNuevo;
194
- var yaEstaba = codigoFinal && codigoFinal === currentGroup;
242
+ var yaEstaba = !!codigoFinal && codigoFinal === currentGroup;
243
+ var buscarProductos = (0, _react.useCallback)( /*#__PURE__*/function () {
244
+ var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(texto) {
245
+ var _data$candidates, _data$total, data;
246
+
247
+ return _regenerator.default.wrap(function _callee3$(_context3) {
248
+ while (1) {
249
+ switch (_context3.prev = _context3.next) {
250
+ case 0:
251
+ setCargandoProd(true);
252
+ setError(null);
253
+ _context3.prev = 2;
254
+ _context3.next = 5;
255
+ return request("group-candidates", {
256
+ articleId: articleId,
257
+ code: codigoFinal || "",
258
+ query: texto !== null && texto !== void 0 ? texto : ""
259
+ });
260
+
261
+ case 5:
262
+ data = _context3.sent;
263
+ setCandidatos((_data$candidates = data.candidates) !== null && _data$candidates !== void 0 ? _data$candidates : []);
264
+ setTotalCandidatos(Number((_data$total = data.total) !== null && _data$total !== void 0 ? _data$total : 0));
265
+ _context3.next = 13;
266
+ break;
267
+
268
+ case 10:
269
+ _context3.prev = 10;
270
+ _context3.t0 = _context3["catch"](2);
271
+ setError(mensajeDe(_context3.t0, "No se pudieron cargar los productos."));
272
+
273
+ case 13:
274
+ _context3.prev = 13;
275
+ setCargandoProd(false);
276
+ return _context3.finish(13);
277
+
278
+ case 16:
279
+ case "end":
280
+ return _context3.stop();
281
+ }
282
+ }
283
+ }, _callee3, null, [[2, 10, 13, 16]]);
284
+ }));
285
+
286
+ return function (_x4) {
287
+ return _ref4.apply(this, arguments);
288
+ };
289
+ }(), [request, articleId, codigoFinal]);
290
+ /*
291
+ La lista se recarga cuando cambia el código porque el servidor excluye a los
292
+ que ya están dentro: con otro grupo, el conjunto de candidatos es otro. Se
293
+ espera un momento porque el código nuevo se teclea letra por letra y sin la
294
+ pausa saldría una consulta por pulsación.
295
+ */
296
+
297
+ (0, _react.useEffect)(function () {
298
+ if (!codigoFinal) {
299
+ setCandidatos([]);
300
+ setTotalCandidatos(0);
301
+ return undefined;
302
+ }
303
+
304
+ var t = setTimeout(function () {
305
+ return buscarProductos(busquedaProd);
306
+ }, 300);
307
+ return function () {
308
+ return clearTimeout(t);
309
+ }; // eslint-disable-next-line react-hooks/exhaustive-deps
310
+ }, [codigoFinal]);
311
+
312
+ var alternar = function alternar(id) {
313
+ return setElegidos(function (previos) {
314
+ return previos.includes(id) ? previos.filter(function (x) {
315
+ return x !== id;
316
+ }) : [].concat((0, _toConsumableArray2.default)(previos), [id]);
317
+ });
318
+ };
195
319
 
196
320
  var guardar = /*#__PURE__*/function () {
197
- var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
321
+ var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
198
322
  var _data$group, data;
199
323
 
200
- return _regenerator.default.wrap(function _callee3$(_context3) {
324
+ return _regenerator.default.wrap(function _callee4$(_context4) {
201
325
  while (1) {
202
- switch (_context3.prev = _context3.next) {
326
+ switch (_context4.prev = _context4.next) {
203
327
  case 0:
204
- if (!(!codigoFinal || yaEstaba)) {
205
- _context3.next = 2;
328
+ if (codigoFinal) {
329
+ _context4.next = 2;
206
330
  break;
207
331
  }
208
332
 
209
- return _context3.abrupt("return");
333
+ return _context4.abrupt("return");
210
334
 
211
335
  case 2:
336
+ if (!(yaEstaba && elegidos.length === 0)) {
337
+ _context4.next = 4;
338
+ break;
339
+ }
340
+
341
+ return _context4.abrupt("return");
342
+
343
+ case 4:
212
344
  setSaving(true);
213
345
  setError(null);
214
- _context3.prev = 4;
215
- _context3.next = 7;
346
+ _context4.prev = 6;
347
+ _context4.next = 9;
216
348
  return request("join", {
217
349
  articleId: articleId,
218
- code: codigoFinal
350
+ code: codigoFinal,
351
+ alsoArticleIds: elegidos
219
352
  });
220
353
 
221
- case 7:
222
- data = _context3.sent;
354
+ case 9:
355
+ data = _context4.sent;
223
356
  onSaved === null || onSaved === void 0 ? void 0 : onSaved((0, _objectSpread2.default)((0, _objectSpread2.default)({}, data), {}, {
224
357
  group: (_data$group = data.group) !== null && _data$group !== void 0 ? _data$group : codigoFinal
225
358
  }));
226
359
  onClose === null || onClose === void 0 ? void 0 : onClose();
227
- _context3.next = 16;
360
+ _context4.next = 18;
228
361
  break;
229
362
 
230
- case 12:
231
- _context3.prev = 12;
232
- _context3.t0 = _context3["catch"](4);
233
- setError(_context3.t0 instanceof _api.ApiError || (_context3.t0 === null || _context3.t0 === void 0 ? void 0 : _context3.t0.name) === "ApiError" ? _context3.t0.message : "No se pudo agrupar el producto. Intenta de nuevo.");
363
+ case 14:
364
+ _context4.prev = 14;
365
+ _context4.t0 = _context4["catch"](6);
366
+ setError(mensajeDe(_context4.t0, "No se pudo agrupar el producto. Intenta de nuevo."));
234
367
  setSaving(false);
235
368
 
236
- case 16:
369
+ case 18:
237
370
  case "end":
238
- return _context3.stop();
371
+ return _context4.stop();
239
372
  }
240
373
  }
241
- }, _callee3, null, [[4, 12]]);
374
+ }, _callee4, null, [[6, 14]]);
242
375
  }));
243
376
 
244
377
  return function guardar() {
245
- return _ref4.apply(this, arguments);
378
+ return _ref5.apply(this, arguments);
246
379
  };
247
- }();
380
+ }(); // Cuántos de los elegidos cambian de grupo, para avisarlo antes y no después.
381
+
382
+
383
+ var seMueven = candidatos.filter(function (c) {
384
+ return elegidos.includes(c.articleId) && c.currentGroup && c.currentGroup !== codigoFinal;
385
+ }).length;
248
386
 
249
387
  var resumen = function resumen() {
250
- if (yaEstaba) return "Este producto ya est\xE1 en \xAB".concat(codigoFinal, "\xBB.");
251
- if (esNuevo) return "Se crear\xE1 el grupo \xAB".concat(codigoNuevo, "\xBB con este producto.");
252
- if (selected) return "Se agregar\xE1 a \xAB".concat(selected, "\xBB.");
253
- return "Elige un grupo o escribe un código nuevo.";
388
+ if (!codigoFinal) return "Elige un grupo o crea uno nuevo.";
389
+ var sufijo = elegidos.length ? " y ".concat(elegidos.length, " producto").concat(elegidos.length === 1 ? "" : "s", " m\xE1s") : "";
390
+ if (yaEstaba && !elegidos.length) return "Este producto ya est\xE1 en \xAB".concat(codigoFinal, "\xBB.");
391
+ if (yaEstaba) return "Se agregar\xE1n ".concat(elegidos.length, " producto").concat(elegidos.length === 1 ? "" : "s", " a \xAB").concat(codigoFinal, "\xBB.");
392
+ if (esNuevo) return "Se crear\xE1 \xAB".concat(codigoNuevo, "\xBB con este producto").concat(sufijo, ".");
393
+ return "Se agregar\xE1 a \xAB".concat(selected, "\xBB").concat(sufijo, ".");
254
394
  };
255
395
 
396
+ var puedeGuardar = !saving && !!codigoFinal && (!yaEstaba || elegidos.length > 0);
256
397
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Overlay, {
257
398
  onClick: saving ? undefined : onClose,
258
399
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Panel, {
@@ -269,6 +410,10 @@ var VariantGroupModal = function VariantGroupModal(_ref) {
269
410
  children: [error && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Message, {
270
411
  className: "error",
271
412
  children: error
413
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Step, {
414
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
415
+ children: "1 \xB7 Elige el grupo"
416
+ })
272
417
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.SearchRow, {
273
418
  onSubmit: function onSubmit(event) {
274
419
  event.preventDefault();
@@ -297,6 +442,7 @@ var VariantGroupModal = function VariantGroupModal(_ref) {
297
442
  onChange: function onChange() {
298
443
  setSelected(grupo.code);
299
444
  setNuevo("");
445
+ setCreando(false);
300
446
  }
301
447
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
302
448
  className: "codigo",
@@ -312,17 +458,35 @@ var VariantGroupModal = function VariantGroupModal(_ref) {
312
458
  }, grupo.code);
313
459
  })
314
460
  }), !loading && groups.length === 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Message, {
315
- children: query.trim() ? "Ningún grupo coincide con esa búsqueda." : "Todavía no hay grupos en esta compañía. Crea el primero abajo."
316
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.NewGroup, {
317
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
318
- htmlFor: "nuevo-grupo",
319
- children: "O crea un grupo nuevo"
461
+ children: query.trim() ? "Ningún grupo coincide con esa búsqueda." : "Todavía no hay grupos en esta compañía."
462
+ }), !creando ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.GhostButton, {
463
+ type: "button",
464
+ onClick: function onClick() {
465
+ setCreando(true);
466
+ setSelected(null);
467
+ },
468
+ children: "+ Crear un grupo nuevo"
469
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.NewGroup, {
470
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
471
+ className: "encabezado",
472
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
473
+ htmlFor: "nuevo-grupo",
474
+ children: "C\xF3digo del grupo nuevo"
475
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
476
+ type: "button",
477
+ onClick: function onClick() {
478
+ setCreando(false);
479
+ setNuevo("");
480
+ },
481
+ children: "Cancelar"
482
+ })]
320
483
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
321
484
  id: "nuevo-grupo",
322
485
  type: "text",
323
486
  value: nuevo,
324
487
  placeholder: "RELOJ-CASIO-A158",
325
488
  maxLength: 50,
489
+ autoFocus: true,
326
490
  onChange: function onChange(event) {
327
491
  setNuevo(event.target.value);
328
492
  setSelected(null);
@@ -331,6 +495,66 @@ var VariantGroupModal = function VariantGroupModal(_ref) {
331
495
  className: "ayuda",
332
496
  children: "Letras, n\xFAmeros, guion y guion bajo. Se guarda en may\xFAsculas, as\xED que \xABabc-1\xBB y \xABABC-1\xBB son el mismo grupo."
333
497
  })]
498
+ }), !!codigoFinal && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
499
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Step, {
500
+ className: "segundo",
501
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("h3", {
502
+ children: ["2 \xB7 Agrega m\xE1s productos a \xAB", codigoFinal, "\xBB"]
503
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
504
+ children: "Opcional. Evita entrar a cada producto por separado."
505
+ })]
506
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.SearchRow, {
507
+ onSubmit: function onSubmit(event) {
508
+ event.preventDefault();
509
+ buscarProductos(busquedaProd);
510
+ },
511
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
512
+ type: "text",
513
+ value: busquedaProd,
514
+ placeholder: "Busca por UPC, SKU o nombre",
515
+ onChange: function onChange(event) {
516
+ return setBusquedaProd(event.target.value);
517
+ }
518
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
519
+ type: "submit",
520
+ disabled: cargandoProd,
521
+ children: cargandoProd ? "Buscando…" : "Buscar"
522
+ })]
523
+ }), candidatos.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Candidates, {
524
+ children: candidatos.map(function (c) {
525
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
526
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
527
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
528
+ type: "checkbox",
529
+ checked: elegidos.includes(c.articleId),
530
+ onChange: function onChange() {
531
+ return alternar(c.articleId);
532
+ }
533
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
534
+ className: "datos",
535
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
536
+ className: "nombre",
537
+ children: c.name
538
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
539
+ className: "ids",
540
+ children: [c.upc ? "UPC ".concat(c.upc) : "", c.upc && c.sku ? " · " : "", c.sku ? "SKU ".concat(c.sku) : ""]
541
+ })]
542
+ }), c.currentGroup && c.currentGroup !== codigoFinal && /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
543
+ className: "mueve",
544
+ children: ["hoy en \xAB", c.currentGroup, "\xBB"]
545
+ })]
546
+ })
547
+ }, c.articleId);
548
+ })
549
+ }), !cargandoProd && candidatos.length === 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Message, {
550
+ children: busquedaProd.trim() ? "Ningún producto coincide con esa búsqueda." : "No hay otros productos que puedas agrupar aquí."
551
+ }), totalCandidatos > candidatos.length && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Message, {
552
+ className: "sutil",
553
+ children: ["Se muestran ", candidatos.length, " de ", totalCandidatos, ". Afina la b\xFAsqueda para ver el resto."]
554
+ }), seMueven > 0 && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Message, {
555
+ className: "aviso",
556
+ children: [seMueven, " de los productos elegidos ya est\xE1 en otro grupo y se mover\xE1 a \xAB", codigoFinal, "\xBB. Un producto solo puede estar en uno."]
557
+ })]
334
558
  })]
335
559
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Footer, {
336
560
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
@@ -348,7 +572,7 @@ var VariantGroupModal = function VariantGroupModal(_ref) {
348
572
  type: "button",
349
573
  className: "primary",
350
574
  onClick: guardar,
351
- disabled: saving || !codigoFinal || yaEstaba,
575
+ disabled: !puedeGuardar,
352
576
  children: saving ? "Guardando…" : "Aceptar"
353
577
  })]
354
578
  })]
@@ -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.SearchRow = exports.Panel = exports.Overlay = exports.NewGroup = exports.Message = exports.List = exports.Header = exports.Footer = exports.Body = void 0;
8
+ exports.Step = exports.SearchRow = exports.Panel = exports.Overlay = exports.NewGroup = exports.Message = exports.List = exports.Header = exports.GhostButton = exports.Footer = exports.Candidates = exports.Body = 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, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9;
16
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12;
17
17
 
18
18
  var PINK = "#E13AA8";
19
19
  var PINK_RGB = "225, 58, 168";
@@ -42,14 +42,34 @@ var List = _styledComponents.default.ul(_templateObject6 || (_templateObject6 =
42
42
 
43
43
  exports.List = List;
44
44
 
45
- var NewGroup = _styledComponents.default.div(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteral2.default)(["\n padding: 12px;\n border: 1px dashed rgba(", ", 0.5);\n border-radius: 6px;\n background-color: rgba(", ", 0.04);\n\n label {\n display: block;\n margin-bottom: 6px;\n font-family: ", ";\n font-size: 12px;\n color: ", ";\n }\n\n input {\n width: 100%;\n height: 36px;\n padding: 0 12px;\n border: 1px solid ", ";\n border-radius: 6px;\n font-family: inherit;\n font-size: 13px;\n text-transform: uppercase;\n color: ", ";\n }\n\n input:focus {\n outline: none;\n border-color: ", ";\n }\n\n .ayuda {\n display: block;\n margin-top: 6px;\n font-size: 11px;\n line-height: 1.4;\n color: ", ";\n }\n"])), PINK_RGB, PINK_RGB, _variables.FontFamily.Raleway_600, _variables.GlobalColors.deep_gray, _variables.GlobalColors.s2, _variables.GlobalColors.deep_gray, PINK, _variables.GlobalColors.gray);
45
+ var NewGroup = _styledComponents.default.div(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteral2.default)(["\n padding: 12px;\n border: 1px dashed rgba(", ", 0.5);\n border-radius: 6px;\n background-color: rgba(", ", 0.04);\n\n .encabezado {\n display: flex;\n align-items: baseline;\n justify-content: space-between;\n gap: 12px;\n margin-bottom: 6px;\n }\n\n /* Salir de aqui tiene que costar lo mismo que entrar: si abrir el creador es\n un clic, cerrarlo tambien. Sin esto el usuario queda atrapado en el paso de\n crear y la unica salida visible es cerrar el modal entero. */\n .encabezado button {\n border: none;\n background: none;\n padding: 0;\n font-family: ", ";\n font-size: 11px;\n color: ", ";\n cursor: pointer;\n text-decoration: underline;\n }\n\n label {\n display: block;\n font-family: ", ";\n font-size: 12px;\n color: ", ";\n }\n\n input {\n width: 100%;\n height: 36px;\n padding: 0 12px;\n border: 1px solid ", ";\n border-radius: 6px;\n font-family: inherit;\n font-size: 13px;\n text-transform: uppercase;\n color: ", ";\n }\n\n input:focus {\n outline: none;\n border-color: ", ";\n }\n\n .ayuda {\n display: block;\n margin-top: 6px;\n font-size: 11px;\n line-height: 1.4;\n color: ", ";\n }\n"])), PINK_RGB, PINK_RGB, _variables.FontFamily.Raleway_600, _variables.GlobalColors.gray, _variables.FontFamily.Raleway_600, _variables.GlobalColors.deep_gray, _variables.GlobalColors.s2, _variables.GlobalColors.deep_gray, PINK, _variables.GlobalColors.gray);
46
46
 
47
47
  exports.NewGroup = NewGroup;
48
48
 
49
- var Message = _styledComponents.default.p(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteral2.default)(["\n margin: 0 0 12px;\n padding: 10px 12px;\n border-radius: 6px;\n font-size: 13px;\n line-height: 1.4;\n background-color: ", ";\n color: ", ";\n\n &.error {\n background-color: rgba(", ", 0.1);\n color: ", ";\n }\n"])), _variables.GlobalColors.s2, _variables.GlobalColors.deep_gray, PINK_RGB, PINK);
49
+ var Step = _styledComponents.default.div(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteral2.default)(["\n margin: 4px 0 10px;\n\n h3 {\n margin: 0;\n font-family: ", ";\n font-size: 13px;\n color: ", ";\n }\n\n p {\n margin: 2px 0 0;\n font-size: 11px;\n color: ", ";\n }\n\n /* El segundo paso aparece y desaparece segun haya grupo elegido; la linea de\n arriba es lo que evita que se lea como continuacion del bloque anterior. */\n &.segundo {\n margin-top: 18px;\n padding-top: 14px;\n border-top: 1px solid ", ";\n }\n"])), _variables.FontFamily.Raleway_700, _variables.GlobalColors.deep_gray, _variables.GlobalColors.gray, _variables.GlobalColors.s2);
50
+ /*
51
+ El boton que revela el campo de codigo nuevo.
52
+
53
+ Va deliberadamente discreto: es la salida menos frecuente —lo normal es
54
+ sumarse a un grupo que ya existe— y competir en peso con "Buscar" volveria a
55
+ empujar hacia crear, que es justo lo que se queria dejar de hacer.
56
+ */
57
+
58
+
59
+ exports.Step = Step;
60
+
61
+ var GhostButton = _styledComponents.default.button(_templateObject9 || (_templateObject9 = (0, _taggedTemplateLiteral2.default)(["\n display: block;\n width: 100%;\n height: 36px;\n border: 1px dashed rgba(", ", 0.5);\n border-radius: 6px;\n background-color: rgba(", ", 0.04);\n font-family: ", ";\n font-size: 12px;\n color: ", ";\n cursor: pointer;\n\n &:hover {\n background-color: rgba(", ", 0.09);\n }\n"])), PINK_RGB, PINK_RGB, _variables.FontFamily.Raleway_600, PINK, PINK_RGB);
62
+
63
+ exports.GhostButton = GhostButton;
64
+
65
+ var Candidates = _styledComponents.default.ul(_templateObject10 || (_templateObject10 = (0, _taggedTemplateLiteral2.default)(["\n margin: 0 0 10px;\n padding: 0;\n list-style: none;\n border: 1px solid ", ";\n border-radius: 6px;\n /* Acotado a proposito: la lista vive dentro de un modal que ya scrollea, y sin\n tope empuja el pie fuera de la vista. */\n max-height: 210px;\n overflow-y: auto;\n\n li + li {\n border-top: 1px solid ", ";\n }\n\n label {\n display: flex;\n align-items: center;\n gap: 10px;\n padding: 8px 12px;\n cursor: pointer;\n font-size: 13px;\n color: ", ";\n }\n\n label:hover {\n background-color: ", ";\n }\n\n input[type=\"checkbox\"] {\n accent-color: ", ";\n flex-shrink: 0;\n }\n\n .datos {\n display: flex;\n flex-direction: column;\n min-width: 0;\n }\n\n .nombre {\n font-family: ", ";\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n\n .ids {\n font-size: 11px;\n color: ", ";\n }\n\n .mueve {\n margin-left: auto;\n flex-shrink: 0;\n font-size: 11px;\n font-style: italic;\n color: ", ";\n white-space: nowrap;\n }\n"])), _variables.GlobalColors.s2, _variables.GlobalColors.s2, _variables.GlobalColors.deep_gray, _variables.GlobalColors.s1, PINK, _variables.FontFamily.Raleway_600, _variables.GlobalColors.gray, PINK);
66
+
67
+ exports.Candidates = Candidates;
68
+
69
+ var Message = _styledComponents.default.p(_templateObject11 || (_templateObject11 = (0, _taggedTemplateLiteral2.default)(["\n margin: 0 0 12px;\n padding: 10px 12px;\n border-radius: 6px;\n font-size: 13px;\n line-height: 1.4;\n background-color: ", ";\n color: ", ";\n\n &.error {\n background-color: rgba(", ", 0.1);\n color: ", ";\n }\n\n /* Informativo, no accionable: no debe competir con el contenido. */\n &.sutil {\n background: none;\n padding: 2px 0 10px;\n font-size: 11px;\n color: ", ";\n }\n\n /* Agrupar es un UPDATE, asi que sumar un producto que ya tenia grupo lo MUEVE.\n Se avisa antes de guardar, no despues. */\n &.aviso {\n background-color: rgba(", ", 0.08);\n color: ", ";\n }\n"])), _variables.GlobalColors.s2, _variables.GlobalColors.deep_gray, PINK_RGB, PINK, _variables.GlobalColors.gray, PINK_RGB, _variables.GlobalColors.deep_gray);
50
70
 
51
71
  exports.Message = Message;
52
72
 
53
- var Footer = _styledComponents.default.div(_templateObject9 || (_templateObject9 = (0, _taggedTemplateLiteral2.default)(["\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 12px;\n padding: 16px 24px;\n border-top: 1px solid ", ";\n\n .resumen {\n font-size: 12px;\n color: ", ";\n }\n\n .acciones {\n display: flex;\n gap: 10px;\n }\n\n button {\n height: 38px;\n padding: 0 16px;\n border-radius: 6px;\n cursor: pointer;\n font-family: ", ";\n font-size: 13px;\n }\n\n button:disabled {\n opacity: 0.5;\n cursor: default;\n }\n\n .secondary {\n border: 1px solid ", ";\n background: none;\n color: ", ";\n }\n\n .primary {\n border: 1px solid ", ";\n background-color: ", ";\n color: ", ";\n }\n"])), _variables.GlobalColors.s2, _variables.GlobalColors.gray, _variables.FontFamily.Raleway_600, _variables.GlobalColors.s2, _variables.GlobalColors.deep_gray, PINK, PINK, _variables.GlobalColors.white);
73
+ var Footer = _styledComponents.default.div(_templateObject12 || (_templateObject12 = (0, _taggedTemplateLiteral2.default)(["\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 12px;\n padding: 16px 24px;\n border-top: 1px solid ", ";\n\n .resumen {\n font-size: 12px;\n color: ", ";\n }\n\n .acciones {\n display: flex;\n gap: 10px;\n }\n\n button {\n height: 38px;\n padding: 0 16px;\n border-radius: 6px;\n cursor: pointer;\n font-family: ", ";\n font-size: 13px;\n }\n\n button:disabled {\n opacity: 0.5;\n cursor: default;\n }\n\n .secondary {\n border: 1px solid ", ";\n background: none;\n color: ", ";\n }\n\n .primary {\n border: 1px solid ", ";\n background-color: ", ";\n color: ", ";\n }\n"])), _variables.GlobalColors.s2, _variables.GlobalColors.gray, _variables.FontFamily.Raleway_600, _variables.GlobalColors.s2, _variables.GlobalColors.deep_gray, PINK, PINK, _variables.GlobalColors.white);
54
74
 
55
75
  exports.Footer = Footer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentoh-components-library",
3
- "version": "21.6.48",
3
+ "version": "21.6.49",
4
4
  "dependencies": {
5
5
  "@aws-amplify/auth": "^4.5.3",
6
6
  "@aws-amplify/datastore": "^3.11.0",
@@ -7,9 +7,12 @@ import {
7
7
  Panel,
8
8
  Header,
9
9
  Body,
10
+ Step,
10
11
  SearchRow,
11
12
  List,
13
+ GhostButton,
12
14
  NewGroup,
15
+ Candidates,
13
16
  Message,
14
17
  Footer,
15
18
  } from "./styles";
@@ -23,9 +26,18 @@ import {
23
26
  un código en `article.variant_group` y ya. Por eso el modal no pregunta qué
24
27
  heredar: no hay nada que heredar.
25
28
 
26
- Dos formas de agrupar, y son la misma operación por debajo:
27
- - elegir un grupo que ya existe
28
- - teclear un código nuevo, que crea el grupo con este producto dentro
29
+ El modal tiene dos pasos y el segundo depende del primero:
30
+
31
+ 1. QUÉ GRUPO. Se elige uno de los que ya existen, o se crea uno nuevo. El
32
+ campo para crearlo está escondido detrás de un botón a propósito: abrirlo
33
+ de entrada le contesta al usuario una pregunta que todavía no se ha
34
+ hecho —si quiere buscar o crear— y empuja a teclear un código que
35
+ probablemente ya existe.
36
+
37
+ 2. QUÉ PRODUCTOS. Aparece solo cuando ya hay un grupo. Permite sumar varios
38
+ de una vez sin salir de aquí; antes había que volver a la tabla, entrar a
39
+ cada producto y repetir el trámite, que para un grupo de cinco eran cinco
40
+ vueltas completas.
29
41
 
30
42
  No hay tabla de grupos: un grupo existe mientras algún producto use su código.
31
43
  Eso hace que una errata no falle, solo cree un grupo de un miembro — de ahí que
@@ -57,6 +69,15 @@ export const VariantGroupModal = ({
57
69
  // Qué eligió el usuario: un código de la lista, o el que está escribiendo.
58
70
  const [selected, setSelected] = useState(null);
59
71
  const [nuevo, setNuevo] = useState("");
72
+ // El creador arranca cerrado: que esté abierto ya es una sugerencia de crear.
73
+ const [creando, setCreando] = useState(false);
74
+
75
+ // Paso 2: productos que se van a sumar junto con el de origen.
76
+ const [busquedaProd, setBusquedaProd] = useState("");
77
+ const [candidatos, setCandidatos] = useState([]);
78
+ const [totalCandidatos, setTotalCandidatos] = useState(0);
79
+ const [cargandoProd, setCargandoProd] = useState(false);
80
+ const [elegidos, setElegidos] = useState([]);
60
81
 
61
82
  const request = useCallback(
62
83
  async (action, body) => {
@@ -69,6 +90,11 @@ export const VariantGroupModal = ({
69
90
  [endpoint, token]
70
91
  );
71
92
 
93
+ const mensajeDe = (err, porDefecto) =>
94
+ err instanceof ApiError || err?.name === "ApiError"
95
+ ? err.message
96
+ : porDefecto;
97
+
72
98
  const buscar = useCallback(
73
99
  async (texto) => {
74
100
  setLoading(true);
@@ -77,11 +103,7 @@ export const VariantGroupModal = ({
77
103
  const data = await request("groups", { articleId, query: texto ?? "" });
78
104
  setGroups(data.groups ?? []);
79
105
  } catch (err) {
80
- setError(
81
- err instanceof ApiError || err?.name === "ApiError"
82
- ? err.message
83
- : "No se pudieron cargar los grupos."
84
- );
106
+ setError(mensajeDe(err, "No se pudieron cargar los grupos."));
85
107
  } finally {
86
108
  setLoading(false);
87
109
  }
@@ -108,34 +130,95 @@ export const VariantGroupModal = ({
108
130
  const codigoNuevo = normalizar(nuevo);
109
131
  const codigoFinal = selected ?? codigoNuevo;
110
132
  const esNuevo = !selected && !!codigoNuevo;
111
- const yaEstaba = codigoFinal && codigoFinal === currentGroup;
133
+ const yaEstaba = !!codigoFinal && codigoFinal === currentGroup;
134
+
135
+ const buscarProductos = useCallback(
136
+ async (texto) => {
137
+ setCargandoProd(true);
138
+ setError(null);
139
+ try {
140
+ const data = await request("group-candidates", {
141
+ articleId,
142
+ code: codigoFinal || "",
143
+ query: texto ?? "",
144
+ });
145
+ setCandidatos(data.candidates ?? []);
146
+ setTotalCandidatos(Number(data.total ?? 0));
147
+ } catch (err) {
148
+ setError(mensajeDe(err, "No se pudieron cargar los productos."));
149
+ } finally {
150
+ setCargandoProd(false);
151
+ }
152
+ },
153
+ [request, articleId, codigoFinal]
154
+ );
155
+
156
+ /*
157
+ La lista se recarga cuando cambia el código porque el servidor excluye a los
158
+ que ya están dentro: con otro grupo, el conjunto de candidatos es otro. Se
159
+ espera un momento porque el código nuevo se teclea letra por letra y sin la
160
+ pausa saldría una consulta por pulsación.
161
+ */
162
+ useEffect(() => {
163
+ if (!codigoFinal) {
164
+ setCandidatos([]);
165
+ setTotalCandidatos(0);
166
+ return undefined;
167
+ }
168
+ const t = setTimeout(() => buscarProductos(busquedaProd), 300);
169
+ return () => clearTimeout(t);
170
+ // eslint-disable-next-line react-hooks/exhaustive-deps
171
+ }, [codigoFinal]);
172
+
173
+ const alternar = (id) =>
174
+ setElegidos((previos) =>
175
+ previos.includes(id)
176
+ ? previos.filter((x) => x !== id)
177
+ : [...previos, id]
178
+ );
112
179
 
113
180
  const guardar = async () => {
114
- if (!codigoFinal || yaEstaba) return;
181
+ if (!codigoFinal) return;
182
+ // Sin código nuevo y sin productos que sumar no hay nada que hacer.
183
+ if (yaEstaba && elegidos.length === 0) return;
115
184
 
116
185
  setSaving(true);
117
186
  setError(null);
118
187
  try {
119
- const data = await request("join", { articleId, code: codigoFinal });
188
+ const data = await request("join", {
189
+ articleId,
190
+ code: codigoFinal,
191
+ alsoArticleIds: elegidos,
192
+ });
120
193
  onSaved?.({ ...data, group: data.group ?? codigoFinal });
121
194
  onClose?.();
122
195
  } catch (err) {
123
- setError(
124
- err instanceof ApiError || err?.name === "ApiError"
125
- ? err.message
126
- : "No se pudo agrupar el producto. Intenta de nuevo."
127
- );
196
+ setError(mensajeDe(err, "No se pudo agrupar el producto. Intenta de nuevo."));
128
197
  setSaving(false);
129
198
  }
130
199
  };
131
200
 
201
+ // Cuántos de los elegidos cambian de grupo, para avisarlo antes y no después.
202
+ const seMueven = candidatos.filter(
203
+ (c) => elegidos.includes(c.articleId) && c.currentGroup && c.currentGroup !== codigoFinal
204
+ ).length;
205
+
132
206
  const resumen = () => {
133
- if (yaEstaba) return `Este producto ya está en «${codigoFinal}».`;
134
- if (esNuevo) return `Se creará el grupo «${codigoNuevo}» con este producto.`;
135
- if (selected) return `Se agregará a «${selected}».`;
136
- return "Elige un grupo o escribe un código nuevo.";
207
+ if (!codigoFinal) return "Elige un grupo o crea uno nuevo.";
208
+
209
+ const sufijo = elegidos.length
210
+ ? ` y ${elegidos.length} producto${elegidos.length === 1 ? "" : "s"} más`
211
+ : "";
212
+
213
+ if (yaEstaba && !elegidos.length) return `Este producto ya está en «${codigoFinal}».`;
214
+ if (yaEstaba) return `Se agregarán ${elegidos.length} producto${elegidos.length === 1 ? "" : "s"} a «${codigoFinal}».`;
215
+ if (esNuevo) return `Se creará «${codigoNuevo}» con este producto${sufijo}.`;
216
+ return `Se agregará a «${selected}»${sufijo}.`;
137
217
  };
138
218
 
219
+ const puedeGuardar =
220
+ !saving && !!codigoFinal && (!yaEstaba || elegidos.length > 0);
221
+
139
222
  return (
140
223
  <Overlay onClick={saving ? undefined : onClose}>
141
224
  <Panel onClick={(event) => event.stopPropagation()}>
@@ -151,6 +234,10 @@ export const VariantGroupModal = ({
151
234
  <Body>
152
235
  {error && <Message className="error">{error}</Message>}
153
236
 
237
+ <Step>
238
+ <h3>1 · Elige el grupo</h3>
239
+ </Step>
240
+
154
241
  <SearchRow
155
242
  onSubmit={(event) => {
156
243
  event.preventDefault();
@@ -180,6 +267,7 @@ export const VariantGroupModal = ({
180
267
  onChange={() => {
181
268
  setSelected(grupo.code);
182
269
  setNuevo("");
270
+ setCreando(false);
183
271
  }}
184
272
  />
185
273
  <span className="codigo">{grupo.code}</span>
@@ -201,28 +289,137 @@ export const VariantGroupModal = ({
201
289
  <Message>
202
290
  {query.trim()
203
291
  ? "Ningún grupo coincide con esa búsqueda."
204
- : "Todavía no hay grupos en esta compañía. Crea el primero abajo."}
292
+ : "Todavía no hay grupos en esta compañía."}
205
293
  </Message>
206
294
  )}
207
295
 
208
- <NewGroup>
209
- <label htmlFor="nuevo-grupo">O crea un grupo nuevo</label>
210
- <input
211
- id="nuevo-grupo"
212
- type="text"
213
- value={nuevo}
214
- placeholder="RELOJ-CASIO-A158"
215
- maxLength={50}
216
- onChange={(event) => {
217
- setNuevo(event.target.value);
296
+ {/*
297
+ El campo para crear vive detrás de este botón. Mostrarlo de entrada
298
+ daba por hecho que el usuario venía a crear, cuando la mayoría de las
299
+ veces lo que quiere es sumarse a un grupo que ya existe.
300
+ */}
301
+ {!creando ? (
302
+ <GhostButton
303
+ type="button"
304
+ onClick={() => {
305
+ setCreando(true);
218
306
  setSelected(null);
219
307
  }}
220
- />
221
- <span className="ayuda">
222
- Letras, números, guion y guion bajo. Se guarda en mayúsculas, así
223
- que «abc-1» y «ABC-1» son el mismo grupo.
224
- </span>
225
- </NewGroup>
308
+ >
309
+ + Crear un grupo nuevo
310
+ </GhostButton>
311
+ ) : (
312
+ <NewGroup>
313
+ <div className="encabezado">
314
+ <label htmlFor="nuevo-grupo">Código del grupo nuevo</label>
315
+ <button
316
+ type="button"
317
+ onClick={() => {
318
+ setCreando(false);
319
+ setNuevo("");
320
+ }}
321
+ >
322
+ Cancelar
323
+ </button>
324
+ </div>
325
+ <input
326
+ id="nuevo-grupo"
327
+ type="text"
328
+ value={nuevo}
329
+ placeholder="RELOJ-CASIO-A158"
330
+ maxLength={50}
331
+ autoFocus
332
+ onChange={(event) => {
333
+ setNuevo(event.target.value);
334
+ setSelected(null);
335
+ }}
336
+ />
337
+ <span className="ayuda">
338
+ Letras, números, guion y guion bajo. Se guarda en mayúsculas, así
339
+ que «abc-1» y «ABC-1» son el mismo grupo.
340
+ </span>
341
+ </NewGroup>
342
+ )}
343
+
344
+ {/*
345
+ Paso 2. Solo tiene sentido con un grupo ya elegido: sin código no hay
346
+ a dónde sumar, y el servidor necesita el código para excluir a los
347
+ que ya están dentro.
348
+ */}
349
+ {!!codigoFinal && (
350
+ <>
351
+ <Step className="segundo">
352
+ <h3>2 · Agrega más productos a «{codigoFinal}»</h3>
353
+ <p>Opcional. Evita entrar a cada producto por separado.</p>
354
+ </Step>
355
+
356
+ <SearchRow
357
+ onSubmit={(event) => {
358
+ event.preventDefault();
359
+ buscarProductos(busquedaProd);
360
+ }}
361
+ >
362
+ <input
363
+ type="text"
364
+ value={busquedaProd}
365
+ placeholder="Busca por UPC, SKU o nombre"
366
+ onChange={(event) => setBusquedaProd(event.target.value)}
367
+ />
368
+ <button type="submit" disabled={cargandoProd}>
369
+ {cargandoProd ? "Buscando…" : "Buscar"}
370
+ </button>
371
+ </SearchRow>
372
+
373
+ {candidatos.length > 0 && (
374
+ <Candidates>
375
+ {candidatos.map((c) => (
376
+ <li key={c.articleId}>
377
+ <label>
378
+ <input
379
+ type="checkbox"
380
+ checked={elegidos.includes(c.articleId)}
381
+ onChange={() => alternar(c.articleId)}
382
+ />
383
+ <span className="datos">
384
+ <span className="nombre">{c.name}</span>
385
+ <span className="ids">
386
+ {c.upc ? `UPC ${c.upc}` : ""}
387
+ {c.upc && c.sku ? " · " : ""}
388
+ {c.sku ? `SKU ${c.sku}` : ""}
389
+ </span>
390
+ </span>
391
+ {c.currentGroup && c.currentGroup !== codigoFinal && (
392
+ <span className="mueve">hoy en «{c.currentGroup}»</span>
393
+ )}
394
+ </label>
395
+ </li>
396
+ ))}
397
+ </Candidates>
398
+ )}
399
+
400
+ {!cargandoProd && candidatos.length === 0 && (
401
+ <Message>
402
+ {busquedaProd.trim()
403
+ ? "Ningún producto coincide con esa búsqueda."
404
+ : "No hay otros productos que puedas agrupar aquí."}
405
+ </Message>
406
+ )}
407
+
408
+ {totalCandidatos > candidatos.length && (
409
+ <Message className="sutil">
410
+ Se muestran {candidatos.length} de {totalCandidatos}. Afina la
411
+ búsqueda para ver el resto.
412
+ </Message>
413
+ )}
414
+
415
+ {seMueven > 0 && (
416
+ <Message className="aviso">
417
+ {seMueven} de los productos elegidos ya está en otro grupo y se
418
+ moverá a «{codigoFinal}». Un producto solo puede estar en uno.
419
+ </Message>
420
+ )}
421
+ </>
422
+ )}
226
423
  </Body>
227
424
 
228
425
  <Footer>
@@ -240,7 +437,7 @@ export const VariantGroupModal = ({
240
437
  type="button"
241
438
  className="primary"
242
439
  onClick={guardar}
243
- disabled={saving || !codigoFinal || yaEstaba}
440
+ disabled={!puedeGuardar}
244
441
  >
245
442
  {saving ? "Guardando…" : "Aceptar"}
246
443
  </button>
@@ -159,9 +159,30 @@ export const NewGroup = styled.div`
159
159
  border-radius: 6px;
160
160
  background-color: rgba(${PINK_RGB}, 0.04);
161
161
 
162
+ .encabezado {
163
+ display: flex;
164
+ align-items: baseline;
165
+ justify-content: space-between;
166
+ gap: 12px;
167
+ margin-bottom: 6px;
168
+ }
169
+
170
+ /* Salir de aqui tiene que costar lo mismo que entrar: si abrir el creador es
171
+ un clic, cerrarlo tambien. Sin esto el usuario queda atrapado en el paso de
172
+ crear y la unica salida visible es cerrar el modal entero. */
173
+ .encabezado button {
174
+ border: none;
175
+ background: none;
176
+ padding: 0;
177
+ font-family: ${FontFamily.Raleway_600};
178
+ font-size: 11px;
179
+ color: ${GlobalColors.gray};
180
+ cursor: pointer;
181
+ text-decoration: underline;
182
+ }
183
+
162
184
  label {
163
185
  display: block;
164
- margin-bottom: 6px;
165
186
  font-family: ${FontFamily.Raleway_600};
166
187
  font-size: 12px;
167
188
  color: ${GlobalColors.deep_gray};
@@ -193,6 +214,117 @@ export const NewGroup = styled.div`
193
214
  }
194
215
  `;
195
216
 
217
+ export const Step = styled.div`
218
+ margin: 4px 0 10px;
219
+
220
+ h3 {
221
+ margin: 0;
222
+ font-family: ${FontFamily.Raleway_700};
223
+ font-size: 13px;
224
+ color: ${GlobalColors.deep_gray};
225
+ }
226
+
227
+ p {
228
+ margin: 2px 0 0;
229
+ font-size: 11px;
230
+ color: ${GlobalColors.gray};
231
+ }
232
+
233
+ /* El segundo paso aparece y desaparece segun haya grupo elegido; la linea de
234
+ arriba es lo que evita que se lea como continuacion del bloque anterior. */
235
+ &.segundo {
236
+ margin-top: 18px;
237
+ padding-top: 14px;
238
+ border-top: 1px solid ${GlobalColors.s2};
239
+ }
240
+ `;
241
+
242
+ /*
243
+ El boton que revela el campo de codigo nuevo.
244
+
245
+ Va deliberadamente discreto: es la salida menos frecuente —lo normal es
246
+ sumarse a un grupo que ya existe— y competir en peso con "Buscar" volveria a
247
+ empujar hacia crear, que es justo lo que se queria dejar de hacer.
248
+ */
249
+ export const GhostButton = styled.button`
250
+ display: block;
251
+ width: 100%;
252
+ height: 36px;
253
+ border: 1px dashed rgba(${PINK_RGB}, 0.5);
254
+ border-radius: 6px;
255
+ background-color: rgba(${PINK_RGB}, 0.04);
256
+ font-family: ${FontFamily.Raleway_600};
257
+ font-size: 12px;
258
+ color: ${PINK};
259
+ cursor: pointer;
260
+
261
+ &:hover {
262
+ background-color: rgba(${PINK_RGB}, 0.09);
263
+ }
264
+ `;
265
+
266
+ export const Candidates = styled.ul`
267
+ margin: 0 0 10px;
268
+ padding: 0;
269
+ list-style: none;
270
+ border: 1px solid ${GlobalColors.s2};
271
+ border-radius: 6px;
272
+ /* Acotado a proposito: la lista vive dentro de un modal que ya scrollea, y sin
273
+ tope empuja el pie fuera de la vista. */
274
+ max-height: 210px;
275
+ overflow-y: auto;
276
+
277
+ li + li {
278
+ border-top: 1px solid ${GlobalColors.s2};
279
+ }
280
+
281
+ label {
282
+ display: flex;
283
+ align-items: center;
284
+ gap: 10px;
285
+ padding: 8px 12px;
286
+ cursor: pointer;
287
+ font-size: 13px;
288
+ color: ${GlobalColors.deep_gray};
289
+ }
290
+
291
+ label:hover {
292
+ background-color: ${GlobalColors.s1};
293
+ }
294
+
295
+ input[type="checkbox"] {
296
+ accent-color: ${PINK};
297
+ flex-shrink: 0;
298
+ }
299
+
300
+ .datos {
301
+ display: flex;
302
+ flex-direction: column;
303
+ min-width: 0;
304
+ }
305
+
306
+ .nombre {
307
+ font-family: ${FontFamily.Raleway_600};
308
+ overflow: hidden;
309
+ text-overflow: ellipsis;
310
+ white-space: nowrap;
311
+ }
312
+
313
+ .ids {
314
+ font-size: 11px;
315
+ color: ${GlobalColors.gray};
316
+ }
317
+
318
+ .mueve {
319
+ margin-left: auto;
320
+ flex-shrink: 0;
321
+ font-size: 11px;
322
+ font-style: italic;
323
+ color: ${PINK};
324
+ white-space: nowrap;
325
+ }
326
+ `;
327
+
196
328
  export const Message = styled.p`
197
329
  margin: 0 0 12px;
198
330
  padding: 10px 12px;
@@ -206,6 +338,21 @@ export const Message = styled.p`
206
338
  background-color: rgba(${PINK_RGB}, 0.1);
207
339
  color: ${PINK};
208
340
  }
341
+
342
+ /* Informativo, no accionable: no debe competir con el contenido. */
343
+ &.sutil {
344
+ background: none;
345
+ padding: 2px 0 10px;
346
+ font-size: 11px;
347
+ color: ${GlobalColors.gray};
348
+ }
349
+
350
+ /* Agrupar es un UPDATE, asi que sumar un producto que ya tenia grupo lo MUEVE.
351
+ Se avisa antes de guardar, no despues. */
352
+ &.aviso {
353
+ background-color: rgba(${PINK_RGB}, 0.08);
354
+ color: ${GlobalColors.deep_gray};
355
+ }
209
356
  `;
210
357
 
211
358
  export const Footer = styled.div`