contentoh-components-library 21.4.80 → 21.4.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,7 @@ var Template = function Template(args) {
26
26
  var EditGroupDefault = Template.bind({});
27
27
  exports.EditGroupDefault = EditGroupDefault;
28
28
  EditGroupDefault.args = {
29
+ show: true,
29
30
  groups: [{
30
31
  groupName: 'Impuestos',
31
32
  editing: false
@@ -78,7 +78,9 @@ var reducerGroups = function reducerGroups(state, action) {
78
78
  };
79
79
 
80
80
  var EditGroup = function EditGroup(_ref) {
81
- var token = _ref.token;
81
+ var token = _ref.token,
82
+ show = _ref.show,
83
+ onClose = _ref.onClose;
82
84
 
83
85
  var _useState = (0, _react.useState)([]),
84
86
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
@@ -105,35 +107,35 @@ var EditGroup = function EditGroup(_ref) {
105
107
  deletingIndex = _useState8[0],
106
108
  setDeletingIndex = _useState8[1];
107
109
 
108
- var _useState9 = (0, _react.useState)([]),
110
+ var _useState9 = (0, _react.useState)(null),
109
111
  _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
110
- deletedRows = _useState10[0],
111
- setDeletedRows = _useState10[1];
112
+ hoveredIndex = _useState10[0],
113
+ setHoveredIndex = _useState10[1];
112
114
 
113
- var _useState11 = (0, _react.useState)(null),
115
+ var _useState11 = (0, _react.useState)([]),
114
116
  _useState12 = (0, _slicedToArray2.default)(_useState11, 2),
115
- hoveredIndex = _useState12[0],
116
- setHoveredIndex = _useState12[1];
117
+ isEditingList = _useState12[0],
118
+ setIsEditingList = _useState12[1];
117
119
 
118
- var _useState13 = (0, _react.useState)([]),
120
+ var _useState13 = (0, _react.useState)(false),
119
121
  _useState14 = (0, _slicedToArray2.default)(_useState13, 2),
120
- isEditingList = _useState14[0],
121
- setIsEditingList = _useState14[1];
122
+ newGroup = _useState14[0],
123
+ setNewGroup = _useState14[1];
122
124
 
123
- var _useState15 = (0, _react.useState)(false),
125
+ var _useState15 = (0, _react.useState)(null),
124
126
  _useState16 = (0, _slicedToArray2.default)(_useState15, 2),
125
- newGroup = _useState16[0],
126
- setNewGroup = _useState16[1];
127
+ currentEditIndex = _useState16[0],
128
+ setCurrentEditIndex = _useState16[1];
127
129
 
128
- var _useState17 = (0, _react.useState)(null),
130
+ var _useState17 = (0, _react.useState)([]),
129
131
  _useState18 = (0, _slicedToArray2.default)(_useState17, 2),
130
- currentEditIndex = _useState18[0],
131
- setCurrentEditIndex = _useState18[1];
132
+ inputValue = _useState18[0],
133
+ setInputValue = _useState18[1];
132
134
 
133
- var _useState19 = (0, _react.useState)([]),
135
+ var _useState19 = (0, _react.useState)(false),
134
136
  _useState20 = (0, _slicedToArray2.default)(_useState19, 2),
135
- inputValue = _useState20[0],
136
- setInputValue = _useState20[1];
137
+ shouldClose = _useState20[0],
138
+ setShouldClose = _useState20[1];
137
139
 
138
140
  var _useState21 = (0, _react.useState)({
139
141
  show: false,
@@ -150,6 +152,11 @@ var EditGroup = function EditGroup(_ref) {
150
152
  (0, _react.useEffect)(function () {
151
153
  loadData();
152
154
  }, []);
155
+ (0, _react.useEffect)(function () {
156
+ if (shouldClose) {
157
+ onClose && onClose();
158
+ }
159
+ }, [shouldClose, onClose]);
153
160
 
154
161
  var loadData = /*#__PURE__*/function () {
155
162
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
@@ -449,110 +456,113 @@ var EditGroup = function EditGroup(_ref) {
449
456
  }
450
457
  };
451
458
 
452
- var handleCloseModal = function handleCloseModal(e) {
453
- if (modalRef.current && !modalRef.current.contains(e.target)) {
454
- setEditingIndex(null);
455
- }
456
- };
457
-
458
- (0, _react.useEffect)(function () {
459
- document.addEventListener("mousedown", handleCloseModal);
460
- return function () {
461
- document.removeEventListener("mousedown", handleCloseModal);
462
- };
463
- }, []);
464
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Container, {
465
- ref: modalRef,
466
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
467
- className: "contentModal",
468
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
469
- className: "header",
470
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
471
- className: "title-edit",
472
- children: "Editar grupos"
473
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Button, {
474
- className: "circular-button close-button",
475
- onClick: handleCloseModal,
476
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
477
- src: _close.default,
478
- alt: "close icon"
479
- })
480
- })]
481
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
482
- className: "details-edit",
483
- children: "Agrega, edita y borra. Luego guarda los cambios."
484
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
485
- className: "".concat(isMoreThanTenGroups ? "table-groups-max" : "table-groups-edit"),
486
- children: groups.map(function (group, index) {
487
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.GroupRow, {
488
- editing: editingIndex === index,
489
- deleting: deletingIndex === index,
490
- onMouseEnter: function onMouseEnter() {
491
- return setHoveredIndex(index);
492
- },
493
- onMouseLeave: function onMouseLeave() {
494
- return setHoveredIndex(null);
495
- },
496
- className: "group-row ".concat(isEditingList[index] ? "editing" : ""),
497
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
498
- className: "input-group",
499
- placeholder: "Escribe el nombre del grupo",
500
- value: index !== undefined ? group.groupName : inputValue,
501
- onChange: function onChange(e) {
502
- return handleInputChange(e.target.value, index);
503
- },
504
- disabled: !isEditingList[index],
505
- autoFocus: isEditingList[index] && editingIndex === index
506
- }, index), currentEditIndex === index ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Button, {
507
- className: "circular-button save-button visible",
508
- onClick: function onClick() {
509
- return handleSaveChanges(index);
510
- },
459
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Backdrop, {
460
+ open: show,
461
+ className: "container-backgroundModal",
462
+ timeout: 400,
463
+ style: {
464
+ backgroundColor: "transparent",
465
+ zIndex: 10
466
+ },
467
+ onClick: onClose,
468
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Fade, {
469
+ in: show,
470
+ timeout: 400,
471
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_styles.Container, {
472
+ ref: modalRef,
473
+ open: show,
474
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
475
+ className: "contentModal",
476
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
477
+ className: "header",
478
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
479
+ className: "title-edit",
480
+ children: "Editar grupos"
481
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Button, {
482
+ className: "circular-button close-button",
483
+ onClick: onClose,
511
484
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
512
- src: _save.default,
513
- alt: "save update icon"
485
+ src: _close.default,
486
+ alt: "close icon"
514
487
  })
515
- }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
516
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Button, {
517
- className: "circular-button edit-button ".concat(hoveredIndex === index ? "visible" : ""),
518
- onClick: function onClick() {
519
- return handleEditButtonClick(index);
488
+ })]
489
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
490
+ className: "details-edit",
491
+ children: "Agrega, edita y borra. Luego guarda los cambios."
492
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
493
+ className: "".concat(isMoreThanTenGroups ? "table-groups-max" : "table-groups-edit"),
494
+ children: groups.map(function (group, index) {
495
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.GroupRow, {
496
+ editing: editingIndex === index,
497
+ deleting: deletingIndex === index,
498
+ onMouseEnter: function onMouseEnter() {
499
+ return setHoveredIndex(index);
520
500
  },
521
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
522
- src: _edit.default,
523
- alt: "edit icon"
524
- })
525
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Button, {
526
- className: "circular-button delete-button ".concat(hoveredIndex === index ? "visible" : ""),
527
- onClick: function onClick() {
528
- return handleDeleteButtonClick(group.groupId);
501
+ onMouseLeave: function onMouseLeave() {
502
+ return setHoveredIndex(null);
529
503
  },
530
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
531
- src: _trash.default,
532
- alt: "trash icon"
533
- })
534
- })]
535
- })]
536
- }, group.groupId);
537
- })
538
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
539
- className: "container-save-add",
540
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Button, {
541
- className: "button-add",
542
- onClick: function onClick() {
543
- return handleAddButtonClick();
544
- },
545
- children: "+ Agregar Grupo"
504
+ className: "group-row ".concat(isEditingList[index] ? "editing" : ""),
505
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
506
+ className: "input-group",
507
+ placeholder: "Escribe el nombre del grupo",
508
+ value: index !== undefined ? group.groupName : inputValue,
509
+ onChange: function onChange(e) {
510
+ return handleInputChange(e.target.value, index);
511
+ },
512
+ disabled: !isEditingList[index],
513
+ autoFocus: isEditingList[index] && editingIndex === index
514
+ }, index), currentEditIndex === index ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Button, {
515
+ className: "circular-button save-button visible",
516
+ onClick: function onClick() {
517
+ return handleSaveChanges(index);
518
+ },
519
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
520
+ src: _save.default,
521
+ alt: "save update icon"
522
+ })
523
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
524
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Button, {
525
+ className: "circular-button edit-button ".concat(hoveredIndex === index ? "visible" : ""),
526
+ onClick: function onClick() {
527
+ return handleEditButtonClick(index);
528
+ },
529
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
530
+ src: _edit.default,
531
+ alt: "edit icon"
532
+ })
533
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Button, {
534
+ className: "circular-button delete-button ".concat(hoveredIndex === index ? "visible" : ""),
535
+ onClick: function onClick() {
536
+ return handleDeleteButtonClick(group.groupId);
537
+ },
538
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
539
+ src: _trash.default,
540
+ alt: "trash icon"
541
+ })
542
+ })]
543
+ })]
544
+ }, group.groupId);
545
+ })
546
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
547
+ className: "container-save-add",
548
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Button, {
549
+ className: "button-add",
550
+ onClick: function onClick() {
551
+ return handleAddButtonClick();
552
+ },
553
+ children: "+ Agregar Grupo"
554
+ })
555
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Modal.Modal, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, modalData), {}, {
556
+ onClickBtnDefault: function onClickBtnDefault() {
557
+ return setModalData(function (prev) {
558
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, prev), {}, {
559
+ show: false
560
+ });
561
+ });
562
+ }
563
+ }))]
546
564
  })
547
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Modal.Modal, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, modalData), {}, {
548
- onClickBtnDefault: function onClickBtnDefault() {
549
- return setModalData(function (prev) {
550
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, prev), {}, {
551
- show: false
552
- });
553
- });
554
- }
555
- }))]
565
+ })
556
566
  })
557
567
  });
558
568
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contentoh-components-library",
3
- "version": "21.4.80",
3
+ "version": "21.4.81",
4
4
  "dependencies": {
5
5
  "@aws-amplify/auth": "^4.5.3",
6
6
  "@aws-amplify/datastore": "^3.11.0",
@@ -10,6 +10,7 @@ const Template = (args) => <EditGroup {...args} />;
10
10
 
11
11
  export const EditGroupDefault = Template.bind({});
12
12
  EditGroupDefault.args = {
13
+ show:true,
13
14
  groups : [
14
15
  { groupName: 'Impuestos', editing: false },
15
16
  { groupName: 'Legal', editing: false },
@@ -8,6 +8,7 @@ import edit from "../../../assets/images/Icons/edit.svg";
8
8
  import close from "../../../assets/images/Icons/close.svg";
9
9
  import save from "../../../assets/images/Icons/save.svg";
10
10
  import { Modal } from "../../organisms/Modal";
11
+ import { Fade, Grow, Zoom, Backdrop } from "@mui/material";
11
12
  import axios from "axios";
12
13
 
13
14
  const reducerGroups = (state, action) => {
@@ -32,18 +33,18 @@ const reducerGroups = (state, action) => {
32
33
  }
33
34
  };
34
35
 
35
- export const EditGroup = ({ token }) => {
36
+ export const EditGroup = ({ token, show, onClose }) => {
36
37
  const [groups, setGroups] = useState([]);
37
38
  const [state, dispatch] = useReducer(reducerGroups, {});
38
39
  const [isMoreThanTenGroups, setIsMoreThanTenGroups] = useState(false);
39
40
  const [editingIndex, setEditingIndex] = useState(null);
40
41
  const [deletingIndex, setDeletingIndex] = useState(null);
41
- const [deletedRows, setDeletedRows] = useState([]);
42
42
  const [hoveredIndex, setHoveredIndex] = useState(null);
43
43
  const [isEditingList, setIsEditingList] = useState([]);
44
44
  const [newGroup, setNewGroup] = useState(false);
45
45
  const [currentEditIndex, setCurrentEditIndex] = useState(null);
46
46
  const [inputValue, setInputValue] = useState([]);
47
+ const [shouldClose, setShouldClose] = useState(false);
47
48
  const [modalData, setModalData] = useState({
48
49
  show: false,
49
50
  title: "Actualización completa",
@@ -53,13 +54,18 @@ export const EditGroup = ({ token }) => {
53
54
 
54
55
  const modalRef = useRef();
55
56
 
56
- useEffect(() => {
57
- }, [groups]);
57
+ useEffect(() => {}, [groups]);
58
58
 
59
59
  useEffect(() => {
60
60
  loadData();
61
61
  }, []);
62
62
 
63
+ useEffect(() => {
64
+ if (shouldClose) {
65
+ onClose && onClose();
66
+ }
67
+ }, [shouldClose, onClose]);
68
+
63
69
  const loadData = async () => {
64
70
  try {
65
71
  const response = await axios.post(
@@ -123,7 +129,7 @@ export const EditGroup = ({ token }) => {
123
129
  try {
124
130
  const response = await axios.post(
125
131
  `${process.env.REACT_APP_GROUPS_ENDPOINT}/update?id=${groupId}&groupName=${updatedGroupName}`,
126
- {},
132
+ {},
127
133
  {
128
134
  headers: {
129
135
  Authorization: token,
@@ -231,101 +237,108 @@ export const EditGroup = ({ token }) => {
231
237
  if (newGroup !== undefined) {
232
238
  handleUpdateGroup(index, newGroup, concatenatedValue);
233
239
  } else {
234
- AddGroup(index,concatenatedValue);
240
+ AddGroup(index, concatenatedValue);
235
241
  }
236
242
  };
237
243
 
238
- const handleCloseModal = (e) => {
239
- if (modalRef.current && !modalRef.current.contains(e.target)) {
240
- setEditingIndex(null);
241
- }
242
- };
243
-
244
- useEffect(() => {
245
- document.addEventListener("mousedown", handleCloseModal);
246
-
247
- return () => {
248
- document.removeEventListener("mousedown", handleCloseModal);
249
- };
250
- }, []);
251
-
252
244
  return (
253
- <Container ref={modalRef}>
254
- <div className={`contentModal`}>
255
- <div className="header">
256
- <h2 className="title-edit">Editar grupos</h2>
257
- <Button className={`circular-button close-button`} onClick={handleCloseModal}>
258
- <img src={close} alt="close icon" />
259
- </Button>
260
- </div>
261
- <p className="details-edit">
262
- Agrega, edita y borra. Luego guarda los cambios.
263
- </p>
264
- <div
265
- className={`${
266
- isMoreThanTenGroups ? "table-groups-max" : "table-groups-edit"
267
- }`}
268
- >
269
- {groups.map((group, index) => (
270
- <GroupRow
271
- key={group.groupId}
272
- editing={editingIndex === index}
273
- deleting={deletingIndex === index}
274
- onMouseEnter={() => setHoveredIndex(index)}
275
- onMouseLeave={() => setHoveredIndex(null)}
276
- className={`group-row ${isEditingList[index] ? "editing" : ""}`}
245
+ <Backdrop
246
+ open={show}
247
+ className="container-backgroundModal"
248
+ timeout={400}
249
+ style={{
250
+ backgroundColor: "transparent",
251
+ zIndex: 10,
252
+ }}
253
+ onClick={onClose}
254
+ >
255
+ <Fade in={show} timeout={400}>
256
+ <Container ref={modalRef} open={show}>
257
+ <div className={`contentModal`}>
258
+ <div className="header">
259
+ <h2 className="title-edit">Editar grupos</h2>
260
+ <Button
261
+ className={`circular-button close-button`}
262
+ onClick={onClose}
263
+ >
264
+ <img src={close} alt="close icon" />
265
+ </Button>
266
+ </div>
267
+ <p className="details-edit">
268
+ Agrega, edita y borra. Luego guarda los cambios.
269
+ </p>
270
+ <div
271
+ className={`${
272
+ isMoreThanTenGroups ? "table-groups-max" : "table-groups-edit"
273
+ }`}
277
274
  >
278
- <input
279
- key={index}
280
- className={`input-group`}
281
- placeholder="Escribe el nombre del grupo"
282
- value={index !== undefined ? group.groupName : inputValue}
283
- onChange={(e) => handleInputChange(e.target.value, index)}
284
- disabled={!isEditingList[index]}
285
- autoFocus={isEditingList[index] && editingIndex === index}
286
- />
287
- { currentEditIndex === index ? (
288
- <Button
289
- className={`circular-button save-button visible`}
290
- onClick={() => handleSaveChanges(index)}
275
+ {groups.map((group, index) => (
276
+ <GroupRow
277
+ key={group.groupId}
278
+ editing={editingIndex === index}
279
+ deleting={deletingIndex === index}
280
+ onMouseEnter={() => setHoveredIndex(index)}
281
+ onMouseLeave={() => setHoveredIndex(null)}
282
+ className={`group-row ${
283
+ isEditingList[index] ? "editing" : ""
284
+ }`}
291
285
  >
292
- <img src={save} alt="save update icon" />
293
- </Button>
294
- ) : (
295
- <>
296
- <Button
297
- className={`circular-button edit-button ${
298
- hoveredIndex === index ? "visible" : ""
299
- }`}
300
- onClick={() => handleEditButtonClick(index)}
301
- >
302
- <img src={edit} alt="edit icon" />
303
- </Button>
304
- <Button
305
- className={`circular-button delete-button ${
306
- hoveredIndex === index ? "visible" : ""
307
- }`}
308
- onClick={() => handleDeleteButtonClick(group.groupId)}
309
- >
310
- <img src={trash} alt="trash icon" />
311
- </Button>
312
- </>
313
- )}
314
- </GroupRow>
315
- ))}
316
- </div>
317
- <div className="container-save-add">
318
- <Button className="button-add" onClick={() => handleAddButtonClick()}>
319
- + Agregar Grupo
320
- </Button>
321
- </div>
322
- <Modal
323
- {...modalData}
324
- onClickBtnDefault={() =>
325
- setModalData((prev) => ({ ...prev, show: false }))
326
- }
327
- />
328
- </div>
329
- </Container>
286
+ <input
287
+ key={index}
288
+ className={`input-group`}
289
+ placeholder="Escribe el nombre del grupo"
290
+ value={index !== undefined ? group.groupName : inputValue}
291
+ onChange={(e) => handleInputChange(e.target.value, index)}
292
+ disabled={!isEditingList[index]}
293
+ autoFocus={isEditingList[index] && editingIndex === index}
294
+ />
295
+ {currentEditIndex === index ? (
296
+ <Button
297
+ className={`circular-button save-button visible`}
298
+ onClick={() => handleSaveChanges(index)}
299
+ >
300
+ <img src={save} alt="save update icon" />
301
+ </Button>
302
+ ) : (
303
+ <>
304
+ <Button
305
+ className={`circular-button edit-button ${
306
+ hoveredIndex === index ? "visible" : ""
307
+ }`}
308
+ onClick={() => handleEditButtonClick(index)}
309
+ >
310
+ <img src={edit} alt="edit icon" />
311
+ </Button>
312
+ <Button
313
+ className={`circular-button delete-button ${
314
+ hoveredIndex === index ? "visible" : ""
315
+ }`}
316
+ onClick={() => handleDeleteButtonClick(group.groupId)}
317
+ >
318
+ <img src={trash} alt="trash icon" />
319
+ </Button>
320
+ </>
321
+ )}
322
+ </GroupRow>
323
+ ))}
324
+ </div>
325
+ <div className="container-save-add">
326
+ <Button
327
+ className="button-add"
328
+ onClick={() => handleAddButtonClick()}
329
+ >
330
+ + Agregar Grupo
331
+ </Button>
332
+ </div>
333
+ <Modal
334
+ {...modalData}
335
+ onClickBtnDefault={() =>
336
+ setModalData((prev) => ({ ...prev, show: false }))
337
+ }
338
+ />
339
+ </div>
340
+ </Container>
341
+ </Fade>
342
+ </Backdrop>
330
343
  );
331
344
  };