contentoh-components-library 21.4.115 → 21.4.116

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.
@@ -6,15 +6,12 @@ import axios from "axios";
6
6
 
7
7
  //Componentes
8
8
  import { Modal } from "../../organisms/Modal";
9
- import { TextField } from "@mui/material/TextField";
10
- import { GroupSelect } from "../../molecules/GroupSelect";
11
9
  import { CustomChip } from "../../atoms/CustomChip";
12
- import { CustomSelect } from "../../molecules/CustomSelect";
13
10
  import { ButtonV2 } from "../../atoms/ButtonV2";
14
11
 
15
12
  //svg
16
13
  import options from "../../../assets/images/Icons/options.svg";
17
- import add from "../../../assets/images/Icons/addv2.svg";
14
+ import { AddGroup } from "../AddGroup";
18
15
 
19
16
  export const Phase = ({
20
17
  key,
@@ -34,6 +31,7 @@ export const Phase = ({
34
31
  const [groupsSelected, setGroupsSelected] = useState([]);
35
32
  const [anchorEl, setAnchorEl] = React.useState(null);
36
33
  const [nextPhaseState, setNextPhaseState] = useState("");
34
+ const [tempChips, setTempChips] = useState([]);
37
35
  const open = Boolean(anchorEl);
38
36
  const [modalData, setModalData] = useState({
39
37
  show: false,
@@ -90,17 +88,13 @@ export const Phase = ({
90
88
  const updatedGroups = groups.map((group) =>
91
89
  group.groupName === selectedValue ? { ...group, groupActive: 1 } : group
92
90
  );
93
-
94
- // Actualizar el estado de chips y groupsSelected
95
- setChips((prevChips) => [
91
+ setTempChips((prevChips) => [
96
92
  ...prevChips,
97
93
  { id: phaseId, label: selectedValue },
98
94
  ]);
99
-
95
+
100
96
  setGroupsSelected((prevGroups) => [...prevGroups, selectedValue]);
101
97
  setSelectedValue("");
102
-
103
- console.log("update", updatedGroups);
104
98
  loadData();
105
99
  }
106
100
  };
@@ -120,8 +114,7 @@ export const Phase = ({
120
114
  },
121
115
  }
122
116
  );
123
- console.log("response", response.data.body)
124
- console.log("grupo agregado correctamente");
117
+ console.log(response.data.body)
125
118
  loadData();
126
119
  } catch (error) {
127
120
  console.error("Error al agregar grupo a fase:", error);
@@ -144,36 +137,32 @@ export const Phase = ({
144
137
  },
145
138
  }
146
139
  );
147
- console.log("response", response.data.body);
148
- console.log("grupo agregado correctamente");
140
+ console.log(response.data.body);
149
141
  } catch (error) {
150
142
  console.error("Error al actualizar grupo de fase:", error);
151
143
  }
152
144
  };
153
145
 
154
- const handleGroupSelect = () => {
155
- groupsSelected.forEach((groupId) => {
146
+ const handleGroupSelect = async () => {
147
+ for (const groupId of groupsSelected) {
156
148
  const matchingGroup = groups.find((group) => group.groupId === groupId);
157
149
  if (matchingGroup) {
158
- if (!chips.find((chip) => chip.key === matchingGroup.groupId)) {
159
- setChips((prevChips) => [
150
+ if (!tempChips.find((chip) => chip.key === matchingGroup.groupId)) {
151
+ setTempChips((prevChips) => [
160
152
  ...prevChips,
161
- { id: matchingGroup.groupId,
162
- label: matchingGroup.groupName },
153
+ { id: matchingGroup.groupId, label: matchingGroup.groupName },
163
154
  ]);
164
155
  }
165
- addGroup(phaseId,groupsSelected)
156
+ await addGroup(phaseId, [groupId]);
166
157
  }
167
- });
158
+ }
168
159
  };
169
160
 
170
161
 
171
162
  const handleNextPhaseSelect = () => {
172
163
  if (selectedValue.length > 0) {
173
164
  const Id = selectedValue[0];
174
- console.log("phaseId",Id)
175
165
  const matchingPhase = phases.find((phase) => phase.phaseId === Id);
176
- console.log("matchingPhase",matchingPhase)
177
166
  if (matchingPhase) {
178
167
  checkAvailablePhase(phaseId, matchingPhase.phaseId);
179
168
  }
@@ -229,7 +218,6 @@ export const Phase = ({
229
218
  setGroupsSelected((prevGroups) =>
230
219
  prevGroups.filter((chip) => chip.id !== chipToRemove.id)
231
220
  );
232
- console.log("Se elimino el grupo", chipToRemove.id);
233
221
  setChips((prevChips) =>
234
222
  prevChips.filter((chip) => chip.id !== chipToRemove.id)
235
223
  );
@@ -239,7 +227,6 @@ export const Phase = ({
239
227
  //eliminar grupo de fase
240
228
  const deleteGroup = async (phaseId, groupId) => {
241
229
  try {
242
- console.log("grupo de fase", { phaseId, groupId });
243
230
  const response = await axios.post(
244
231
  `${process.env.REACT_APP_PHASES_ENDPOINT}/delete`,
245
232
  {
@@ -251,7 +238,6 @@ export const Phase = ({
251
238
  {
252
239
  headers: {
253
240
  Authorization: token,
254
- // Authorization: sessionStorage.getItem("jwt"),
255
241
  },
256
242
  }
257
243
  );
@@ -272,7 +258,7 @@ export const Phase = ({
272
258
  <Container>
273
259
  <div key={key} className="header-phase">
274
260
  <h2>
275
- Fase {phaseId} - {phaseName}
261
+ Fase {id} - {phaseName}
276
262
  </h2>
277
263
  <div className="text-button-container">
278
264
  <div className="phase-sel">
@@ -371,26 +357,20 @@ export const Phase = ({
371
357
  onDelete={() => handleChipDelete(phaseId, chip)}
372
358
  />
373
359
  ))}
374
-
375
- {showButtonChip && <GroupSelect
376
- options={groups
377
- .filter((group) => group.groupActive === 0)
378
- .map((group) => ({
379
- id: group.groupId,
380
- name: group.groupName,
381
- }))}
382
- showSearchBar
383
- isSingleSelect={false}
384
- icon={add}
385
- placeHolder={"Buscar grupo"}
386
- customSelectId={"category-select-" + groups.groupId}
387
- defaultOption={"Todos los grupos"}
388
- parameterArray={groupsSelected}
389
- setParameterArray={setGroupsSelected}
390
- onClickItem={() => {
391
- handleGroupSelect();
360
+ {showButtonChip && <AddGroup
361
+ id={`add-group-select-${phaseId}`}
362
+ items={groups
363
+ .filter((group) => group.groupActive === 0)
364
+ .map((group) => ({
365
+ value: group.groupId,
366
+ label: group.groupName,
367
+ }))}
368
+ defaultOption="Todos los grupos"
369
+ placeholder="Buscar grupo"
370
+ onChange={(selectedItems) => {
371
+ setGroupsSelected(selectedItems);
392
372
  }}
393
- />}
373
+ />}
394
374
  </div>
395
375
  <Modal
396
376
  {...modalData}
@@ -4,13 +4,12 @@ import { Phase } from "../../molecules/Phase";
4
4
  import { ButtonV2 } from "../../atoms/ButtonV2";
5
5
  import { Modal } from "../Modal";
6
6
  import axios from "axios";
7
- import successV2 from "../../../assets/images/Icons/checkv2.svg";
8
- import { Input } from "@mui/material";
9
7
 
10
- export const DragAndDropPhases = ({ token}) => {
8
+ export const DragAndDropPhases = ({ token }) => {
11
9
  const [draggedItem, setDraggedItem] = useState(null);
12
10
  const [listPhases, setListPhases]= useState([]);
13
11
  const [tempListPhases, setTempListPhases] = useState([]);
12
+ const [search, setSearch] = useState();
14
13
  const [newPhaseName, setNewPhaseName] = useState("");
15
14
  const [inputValue, setInputValue] = useState("");
16
15
  const [modalData, setModalData] = useState({
@@ -19,18 +18,22 @@ export const DragAndDropPhases = ({ token}) => {
19
18
  message: "",
20
19
  icon: "success",
21
20
  });
21
+ const newPhaseNameRef = useRef("");
22
22
 
23
23
  useEffect(() => loadData(),[]);
24
24
 
25
- const newPhaseNameRef = useRef("");
25
+ useEffect(() => {
26
+ setNewPhaseName((prev) => prev + inputValue);
27
+ }, [inputValue]);
26
28
 
27
29
  useEffect(() => {
28
- newPhaseNameRef.current = newPhaseName;
30
+ newPhaseNameRef.current = search;
29
31
  }, [newPhaseName]);
30
32
 
31
- useEffect(() => {
32
- setNewPhaseName((prev) => prev + inputValue);
33
- }, [inputValue]);
33
+ const handleInputChange = (e) => {
34
+ setInputValue(e.target.value);
35
+ };
36
+
34
37
 
35
38
  const onDragStart = (e, id) => {
36
39
  e.dataTransfer.effectAllowed = "move";
@@ -59,7 +62,6 @@ export const DragAndDropPhases = ({ token}) => {
59
62
 
60
63
  const updatePhases = async () => {
61
64
  try {
62
- console.log("listPhases:", listPhases);
63
65
  const updateData = {
64
66
  updateReferencesOfNodes: listPhases.map((phase) => ({
65
67
  name:phase.phaseName,
@@ -71,7 +73,6 @@ export const DragAndDropPhases = ({ token}) => {
71
73
  Authorization: token,
72
74
  },
73
75
  };
74
- console.log("updateData:", updateData);
75
76
 
76
77
  const response = await axios.post(
77
78
  `${process.env.REACT_APP_PHASES_ENDPOINT}/update`,
@@ -82,24 +83,20 @@ export const DragAndDropPhases = ({ token}) => {
82
83
  },
83
84
  }
84
85
  );
85
- console.log("Update response:", response.data);
86
+ console.log("Update response:", response.body.data);
86
87
  } catch (error) {
87
88
  console.error("Error al actualizar fases", error);
88
89
  }
89
90
  };
90
91
 
91
- const handleInputChange = (e) => {
92
- setInputValue(e.target.value);
93
- };
94
-
95
- const addPhase = async(phaseName) => {
92
+ const addPhase = async(search) => {
96
93
  try {
97
94
  const body = {
98
- name: phaseName,
95
+ name: search,
99
96
  retailerGroupsIds: [],
100
97
  nextPhaseId: null
101
98
  }
102
- const response = await axios.post(
99
+ const response = await axios.post(
103
100
  `${process.env.REACT_APP_PHASES_ENDPOINT}/create`,
104
101
  body,
105
102
  {
@@ -110,6 +107,7 @@ export const DragAndDropPhases = ({ token}) => {
110
107
  );
111
108
  const createdPhase = response.data.body;
112
109
  console.log(createdPhase)
110
+ setSearch();
113
111
  setInputValue("");
114
112
  loadData();
115
113
  } catch (error) {
@@ -119,8 +117,6 @@ export const DragAndDropPhases = ({ token}) => {
119
117
 
120
118
  const deletePhase = async(id, phases) => {
121
119
  try {
122
- console.log("Lista de fases actualizada",phases);
123
- console.log("fase a eliminar", id)
124
120
  const response = await axios.post(
125
121
  `${process.env.REACT_APP_PHASES_ENDPOINT}/delete`,
126
122
  {
@@ -161,19 +157,23 @@ export const DragAndDropPhases = ({ token}) => {
161
157
  size={12}
162
158
  onClick={() => {
163
159
  setModalData((prev) => ({ ...prev, show: false }));
164
- handleSavePhase();
160
+ handleSavePhase(search);
165
161
  }}
166
162
  />
167
163
  ],
168
164
  customComponent: (
169
165
  <div className="container-input-name">
170
166
  <p>Las fases nuevas siempre se agregan al final.<br/>Puedes ordenar las fases arrastrándolas.</p>
171
- <input
172
- className={`input-phases`}
167
+ <input
168
+ type="text"
169
+ className="input-phases"
170
+ onChange={(e) => {
171
+ setSearch(e.target.value);
172
+ handleInputChange(e);
173
+ }}
174
+ value={search}
173
175
  placeholder="Nombre de fase"
174
- value={inputValue}
175
- onChange={(e) => handleInputChange(e)}
176
- />
176
+ ></input>
177
177
  </div>
178
178
  ),
179
179
  });
@@ -192,12 +192,9 @@ export const DragAndDropPhases = ({ token}) => {
192
192
  {
193
193
  headers: {
194
194
  Authorization: token,
195
- // Authorization: sessionStorage.getItem("jwt"),
196
195
  },
197
196
  }
198
197
  );
199
-
200
-
201
198
  const phasesData = JSON.parse(response.data.body).data;
202
199
  const phasesDataArray = [];
203
200
 
@@ -216,8 +213,6 @@ export const DragAndDropPhases = ({ token}) => {
216
213
  groupsAssigned,
217
214
  });
218
215
  });
219
-
220
- console.table("fases Array", phasesDataArray);
221
216
  setListPhases(phasesDataArray);
222
217
  setTempListPhases(phasesDataArray);
223
218
  } catch (error) {
@@ -250,11 +245,6 @@ const handleDeletePhase = (id) => {
250
245
  deletePhase(id, filteredPhases)
251
246
  };
252
247
 
253
- // useEffect(() => {
254
- // updatePhases();
255
- // setModalData((prev) => ({ ...prev, show: false }));
256
- // }, [listPhases]);
257
-
258
248
  const renderPhase = (phase, idx) => {
259
249
  if (phase.isInitialPhase===1){
260
250
  return (
@@ -326,6 +316,7 @@ const renderPhase = (phase, idx) => {
326
316
  />,
327
317
  ],
328
318
  })
319
+ loadData();
329
320
  }}
330
321
  ></ButtonV2>
331
322
  </Header>
@@ -1,29 +0,0 @@
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.Container = void 0;
9
-
10
- var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/taggedTemplateLiteral"));
11
-
12
- var _styledComponents = _interopRequireDefault(require("styled-components"));
13
-
14
- var _variables = require("../../../global-files/variables");
15
-
16
- var _templateObject;
17
-
18
- var Container = _styledComponents.default.div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n width: 100%;\n\n > div {\n label {\n &:before {\n outline: 1px solid ", ";\n }\n }\n }\n\n input,\n textarea {\n width: 100%;\n border: 1px solid\n ", ";\n\n font-family: ", ";\n color: ", ";\n font-weight: normal;\n font-size: 12px;\n line-height: 15px;\n padding: 10px;\n outline: none;\n border-radius: 2px;\n resize: none;\n\n &:focus {\n border: 1px solid ", ";\n }\n }\n\n select {\n background: #fafafa;\n outline: none;\n border: 1px solid\n ", ";\n width: 100%;\n cursor: pointer;\n font-family: ", ";\n color: ", ";\n font-size: 12px;\n line-height: 21px;\n padding: 10px;\n border-right: 2px solid #e33aa9;\n\n &:focus {\n border: 1px solid ", ";\n }\n }\n\n p {\n font-family: ", ";\n font-size: 12px;\n color: ", ";\n }\n\n &.audit-class {\n input,\n .quill {\n border: 1px solid #8a6caa;\n background-color: #ededfc;\n }\n }\n"])), function (_ref) {
19
- var isRequired = _ref.isRequired;
20
- return isRequired ? "red" : "none";
21
- }, function (_ref2) {
22
- var isRequired = _ref2.isRequired;
23
- return isRequired ? "red" : "".concat(_variables.GlobalColors.s2);
24
- }, _variables.FontFamily.AvenirNext, _variables.GlobalColors.deep_gray, _variables.GlobalColors.magenta_s2, function (_ref3) {
25
- var isRequired = _ref3.isRequired;
26
- return isRequired ? "red" : "".concat(_variables.GlobalColors.s2);
27
- }, _variables.FontFamily.AvenirNext, _variables.GlobalColors.deep_gray, _variables.GlobalColors.magenta_s2, _variables.FontFamily.Raleway, _variables.GlobalColors.deep_gray);
28
-
29
- exports.Container = Container;