contentoh-components-library 21.4.89 → 21.4.90

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.
@@ -1,4 +1,5 @@
1
1
  import React, { useEffect, useState } from "react";
2
+ import axios from "axios";
2
3
  //styles
3
4
  import { Container } from "./styles";
4
5
  //components
@@ -8,6 +9,8 @@ import Checkbox from "@mui/material/Checkbox";
8
9
  import ListItemText from "@mui/material/ListItemText";
9
10
  import OutlinedInput from "@mui/material/OutlinedInput";
10
11
  import { EditGroup } from "../../organisms/EditGroup";
12
+ import { Modal } from "../../organisms/Modal";
13
+ import { ButtonV2 } from "../ButtonV2";
11
14
 
12
15
  //svg
13
16
  import searchIcon from "../../../assets/images/Icons/search.svg";
@@ -21,20 +24,31 @@ export const Multiselect = ({
21
24
  placeHolder = "Buscar grupo",
22
25
  textButton = "Editar grupos",
23
26
  }) => {
27
+ const [filters, setFilters] = useState([]);
24
28
  const [selectValues, setSelectValues] = useState([]);
25
29
  const [text, setText] = useState("");
26
30
  const [isEditGroupVisible, setIsEditGroupVisible] = useState(false);
27
31
  const [isItemListVisible, setIsItemListVisible] = useState(true);
28
32
  const currentUser = arrayData.find((user) => user.idUser === userId);
29
33
  const { idUser, groups } = currentUser || {};
34
+ const [selectedItems, setSelectedItems] = useState([]);
35
+ const [modalData, setModalData] = useState({
36
+ show: false,
37
+ title: "Actualización completa",
38
+ message: "",
39
+ icon: "success",
40
+ });
30
41
 
31
42
  useEffect(() => {
32
- const hasUserContentGroup1 = groups.some((group) => group.userContentGroup === 1);
43
+ const hasUserContentGroup1 = groups.some(
44
+ (group) => group.userContentGroup === 1
45
+ );
33
46
 
34
47
  if (hasUserContentGroup1) {
35
- const initialSelectedValues = groups
36
- .filter((group) => group.userContentGroup === 1)
37
- .map((group) => group.groupName) || [];
48
+ const initialSelectedValues =
49
+ groups
50
+ .filter((group) => group.userContentGroup === 1)
51
+ .map((group) => group.groupName) || [];
38
52
  setSelectValues((prevValues) => ({
39
53
  ...prevValues,
40
54
  [idUser]: initialSelectedValues,
@@ -45,41 +59,102 @@ export const Multiselect = ({
45
59
  [idUser]: ["Sin grupos asignados"],
46
60
  }));
47
61
  }
62
+ setFilters(groups ? groups : []);
48
63
  }, [idUser, groups]);
49
64
 
65
+ useEffect(() => {
66
+ if (selectValues[userId]) {
67
+ setSelectedItems(selectValues[userId]);
68
+ }
69
+ }, [selectValues, userId]);
70
+
50
71
  const onChange = (evt) => {
51
72
  setText(evt.target.value);
52
73
  };
53
74
 
54
-
55
75
  const handleChange = (userId) => (event) => {
56
76
  const {
57
77
  target: { value },
58
78
  } = event;
59
79
 
60
- const updatedValues = value.filter((groupName) => {
80
+ const updatedValues = value.map((groupName) => {
61
81
  const groupInfo = groups.find((g) => g.groupName === groupName);
62
- return groupInfo;
63
-
82
+ return groupInfo ? groupInfo.groupName : null;
83
+ });
84
+
85
+ setSelectedItems((prevItems) => {
86
+ updateGroup(
87
+ value
88
+ .map((groupName) => {
89
+ const groupInfo = groups.find((g) => g.groupName === groupName);
90
+ return groupInfo ? groupInfo.groupId : null;
91
+ })
92
+ .filter((groupId) => groupId !== null)
93
+ );
94
+ return updatedValues;
64
95
  });
65
96
 
66
97
  setSelectValues((prevValues) => ({
67
98
  ...prevValues,
68
99
  [userId]: updatedValues,
69
100
  }));
101
+ };
70
102
 
103
+ //actualiza los grupos seleccionados
104
+ const updateGroup = async (groupsIds) => {
105
+ try {
106
+ const body = {
107
+ userId,
108
+ groupsIds,
109
+ };
110
+ const response = await axios.post(
111
+ `${process.env.REACT_APP_USERS_ONBOARDING_ENDPOINT}/update`,
112
+ body,
113
+ {
114
+ headers: {
115
+ Authorization: token,
116
+ },
117
+ }
118
+ );
119
+ setModalData({
120
+ show: true,
121
+ className: "modal-save",
122
+ title: "",
123
+ message: `El cambio de grupo fue aplicado correctamente.`,
124
+ icon: "successv2",
125
+ buttons: [
126
+ <ButtonV2
127
+ key="btn-Aceptar-guardar"
128
+ type="pink"
129
+ label="Aceptar"
130
+ size={12}
131
+ onClick={() => {
132
+ setModalData(false);
133
+ }}
134
+ />,
135
+ ],
136
+ })
137
+ console.log("grupo actualizado correctamente", response.data.body);
138
+ console.log("body", body);
139
+ } catch (error) {
140
+ console.error("Error al cambiar grupos de usuarios:", error);
141
+ }
71
142
  };
72
143
 
73
- useEffect(() => {
74
- },[selectValues])
144
+ useEffect(() => {}, [selectValues]);
75
145
 
76
146
  useEffect(() => {
77
147
  let filteredArray = groups?.slice() || [];
78
- if (text.length > 0) {
148
+ const normalizedText = text.trim().toLowerCase();
149
+
150
+ if (normalizedText.length > 0) {
79
151
  filteredArray = filteredArray.filter((option) =>
80
- option?.name.toLowerCase().includes(text.toLocaleLowerCase())
152
+ option?.groupName?.toLowerCase().includes(normalizedText)
81
153
  );
82
154
  }
155
+ setFilters(filteredArray);
156
+ console.log("text:", normalizedText);
157
+ console.log("filteredArray:", filteredArray);
83
158
  }, [text]);
84
159
 
85
160
  const ITEM_HEIGHT = 48;
@@ -90,35 +165,41 @@ export const Multiselect = ({
90
165
  maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
91
166
  width: "auto",
92
167
  display: isItemListVisible ? "block" : "none",
93
- left:"1013px"
168
+ left: "1013px",
94
169
  },
95
170
  },
96
171
  };
97
172
 
98
173
  return (
99
174
  <Container>
100
- {currentUser && (
101
- <Select
102
- labelId={`demo-multiple-checkbox-label-${idUser}`}
103
- id={`demo-multiple-checkbox-${idUser}`}
104
- multiple
105
- value={selectValues[idUser] || []}
106
- onChange={handleChange(idUser)}
107
- input={
108
- <OutlinedInput
109
- sx={{
110
- width: "80%",
111
- height: "34px",
112
- paddingBottom: "1px solid #F0F0F0",
113
- color:"#707070",
114
- fontSize:"12px"
115
- }}
116
- />
117
- }
118
- renderValue={(selected) => selected.join(", ")}
119
- MenuProps={MenuProps}
120
- sx={{ width: "80%", height: "24px" }}
121
- >
175
+ {currentUser && (
176
+ <Select
177
+ labelId={`demo-multiple-checkbox-label-${idUser}`}
178
+ id={`demo-multiple-checkbox-${idUser}`}
179
+ multiple
180
+ value={selectValues[idUser] || []}
181
+ onChange={handleChange(idUser)}
182
+ input={
183
+ <OutlinedInput
184
+ sx={{
185
+ width: "80%",
186
+ height: "34px",
187
+ paddingBottom: "1px solid #F0F0F0",
188
+ }}
189
+ />
190
+ }
191
+ renderValue={(selected) => selected.join(", ")}
192
+ MenuProps={MenuProps}
193
+ sx={{
194
+ width: "80%",
195
+ height: "24px",
196
+ "& div": {
197
+ color: "#707070",
198
+ fontSize: "12px",
199
+ },
200
+ }}
201
+ >
202
+ {showSearchBar && (
122
203
  <MenuItem
123
204
  sx={{
124
205
  maxHeight: "34px",
@@ -145,93 +226,91 @@ export const Multiselect = ({
145
226
  },
146
227
  }}
147
228
  >
148
- {showSearchBar && (
149
- <div className="search-bar-filter">
150
- <img src={searchIcon} alt="search icon" />
151
- <input
152
- type="text"
153
- placeholder={placeHolder}
154
- value={text}
155
- onChange={onChange}
156
- />
157
- </div>
158
- )}
229
+ <div className="search-bar-filter">
230
+ <img src={searchIcon} alt="search icon" />
231
+ <input
232
+ type="text"
233
+ placeholder={placeHolder}
234
+ value={text}
235
+ onChange={onChange}
236
+ />
237
+ </div>
159
238
  </MenuItem>
160
- {groups &&
161
- groups
162
- .filter((group) => group.groupId !== "Sin id")
163
- .map((group) => (
164
- <MenuItem
165
- key={group.groupId}
166
- value={group.groupName}
239
+ )}
240
+ {groups &&
241
+ groups
242
+ .filter((group) => group.groupId !== "Sin id")
243
+ .map((group) => (
244
+ <MenuItem
245
+ key={group.groupId}
246
+ value={group.groupName}
247
+ sx={{
248
+ paddingLeft: "0px",
249
+ maxHeight: "34px",
250
+ ":focus-visible, :hover": {
251
+ border: "none",
252
+ background: "transparent",
253
+ },
254
+ }}
255
+ >
256
+ <Checkbox
257
+ checked={
258
+ (selectValues[idUser] || []).indexOf(group.groupName) >
259
+ -1 && group.userContentGroup === 1
260
+ }
167
261
  sx={{
168
- paddingLeft: "0px",
169
262
  maxHeight: "34px",
170
- ":focus-visible, :hover": {
171
- border: "none",
172
- background: "transparent",
263
+ "&.Mui-checked": {
264
+ color: "#85BC5B",
265
+ },
266
+ "input, svg": {
267
+ maxWidth: "12px",
268
+ maxHeight: "12px",
173
269
  },
174
270
  }}
175
- >
176
- <Checkbox
177
- checked={
178
- (selectValues[idUser] || []).indexOf(
179
- group.groupName
180
- ) > -1 && group.userContentGroup === 1
181
- }
182
- sx={{
183
- maxHeight: "34px",
184
- "&.Mui-checked": {
185
- color: "#85BC5B",
186
- },
187
- "input, svg": {
188
- maxWidth: "12px",
189
- maxHeight: "12px",
190
- },
191
- }}
192
- />
193
- <ListItemText
194
- primary={group.groupName}
195
- sx={{
196
- span: { fontSize: "12px", color: "#000000" },
197
- "input, svg": {
198
- maxWidth: "12px",
199
- maxHeight: "12px",
200
- },
201
- }}
202
- />
203
- </MenuItem>
204
- ))}
205
- <MenuItem
206
- sx={{
207
- minHeight: "34px",
208
- paddingLeft: "10px",
209
- ".btn-edit-group": {
210
- color: "#E33AA9",
211
- border: "none",
212
- background: "transparent",
213
- display: "flex",
214
- gap: "10px",
215
- alignItems: "center",
216
- },
217
- ":focus-visible, :hover": {
218
- border: "none",
219
- background: "transparent",
220
- },
271
+ />
272
+ <ListItemText
273
+ primary={group.groupName}
274
+ sx={{
275
+ span: { fontSize: "12px", color: "#000000" },
276
+ "input, svg": {
277
+ maxWidth: "12px",
278
+ maxHeight: "12px",
279
+ },
280
+ }}
281
+ />
282
+ </MenuItem>
283
+ ))}
284
+ <MenuItem
285
+ sx={{
286
+ minHeight: "34px",
287
+ paddingLeft: "10px",
288
+ ".btn-edit-group": {
289
+ color: "#E33AA9",
290
+ border: "none",
291
+ background: "transparent",
292
+ display: "flex",
293
+ gap: "10px",
294
+ alignItems: "center",
295
+ },
296
+ ":focus-visible, :hover": {
297
+ border: "none",
298
+ background: "transparent",
299
+ },
300
+ }}
301
+ >
302
+ <button
303
+ className="btn-edit-group"
304
+ onClick={() => {
305
+ setIsItemListVisible(false);
306
+ setIsEditGroupVisible(true);
221
307
  }}
222
308
  >
223
- <button
224
- className="btn-edit-group"
225
- onClick={() => {
226
- setIsItemListVisible(false);
227
- setIsEditGroupVisible(true);
228
- }}
229
- >
230
- <img src={settings} className="icon" alt="search icon" />
231
- {textButton}
232
- </button>
233
- </MenuItem>
234
- </Select>
309
+ <img src={settings} className="icon" alt="search icon" />
310
+ {textButton}
311
+ </button>
312
+ </MenuItem>
313
+ </Select>
235
314
  )}
236
315
  <EditGroup
237
316
  token={token}
@@ -241,6 +320,12 @@ export const Multiselect = ({
241
320
  setIsItemListVisible(true);
242
321
  }}
243
322
  />
323
+ <Modal
324
+ {...modalData}
325
+ onClickBtnDefault={() =>
326
+ setModalData((prev) => ({ ...prev, show: false }))
327
+ }
328
+ ></Modal>
244
329
  </Container>
245
330
  );
246
331
  };
@@ -26,4 +26,8 @@ export const Container = styled.div`
26
26
  width: 15px;
27
27
  height: 15px;
28
28
  }
29
+
30
+ .modal-save .contentModal {
31
+ max-width:200px;
32
+ }
29
33
  `;
@@ -5,21 +5,6 @@ export default {
5
5
  title: "Components/molecules/Phase",
6
6
  component: Phase,
7
7
  argTypes: {
8
- statusType: {
9
- options: Object.values(GlobalStatus),
10
- control: { type: "select" },
11
- },
12
- percent: {
13
- control: { type: "range", min: 0, max: 100, step: 1 },
14
- },
15
- backgroundColor: {
16
- options: Object.keys(GlobalColors),
17
- control: { type: "select" },
18
- },
19
- priority: {
20
- options: ["no priority", "low", "medium", "high"],
21
- control: { type: "select" },
22
- },
23
8
  },
24
9
  };
25
10
 
@@ -28,10 +13,95 @@ const Template = (args) => <Phase {...args} />;
28
13
  export const PhaseDefault = Template.bind({});
29
14
 
30
15
  PhaseDefault.args = {
31
- productName: "Nombre del producto",
32
- statusType: "AP",
33
- percent: 10,
34
- backgroundColor: "s2",
35
- priority: "no priority",
36
- date: new Date().toLocaleDateString(),
16
+ id:0,
17
+ phases:[
18
+ {
19
+ "phaseId": 2,
20
+ "phaseName": "Fase Evaluación",
21
+ "isInitialPhase": 1,
22
+ "nextPhaseIfApproved": 3,
23
+ "groupsAssigned": [
24
+ {
25
+ "groupId": 1,
26
+ "groupName": "Preguntas",
27
+ "groupActive": 1
28
+ },
29
+ {
30
+ "groupId": 8,
31
+ "groupName": "Inteligencia",
32
+ "groupActive": 1
33
+ },
34
+ {
35
+ "groupId": 9,
36
+ "groupName": "Legal",
37
+ "groupActive": 0
38
+ }
39
+ ]
40
+ },
41
+ {
42
+ "phaseId": 3,
43
+ "phaseName": "Fase comercial",
44
+ "isInitialPhase": 0,
45
+ "nextPhaseIfApproved": 4,
46
+ "groupsAssigned": [
47
+ {
48
+ "groupId": 1,
49
+ "groupName": "Preguntas",
50
+ "groupActive": 1
51
+ },
52
+ {
53
+ "groupId": 8,
54
+ "groupName": "Inteligencia",
55
+ "groupActive": 1
56
+ },
57
+ {
58
+ "groupId": 9,
59
+ "groupName": "Legal",
60
+ "groupActive": 0
61
+ }
62
+ ]
63
+ },
64
+ {
65
+ "phaseId": 4,
66
+ "phaseName": "Fase legal",
67
+ "isInitialPhase": 0,
68
+ "nextPhaseIfApproved": null,
69
+ "groupsAssigned": [
70
+ {
71
+ "groupId": 1,
72
+ "groupName": "Preguntas",
73
+ "groupActive": 0
74
+ },
75
+ {
76
+ "groupId": 8,
77
+ "groupName": "Inteligencia",
78
+ "groupActive": 0
79
+ },
80
+ {
81
+ "groupId": 9,
82
+ "groupName": "Legal",
83
+ "groupActive": 0
84
+ }
85
+ ]
86
+ }
87
+ ],
88
+ phaseName:"Fase Evaluación",
89
+ nextPhase:3,
90
+ groups: [
91
+ {
92
+ "groupId": 1,
93
+ "groupName": "Preguntas",
94
+ "groupActive": 1
95
+ },
96
+ {
97
+ "groupId": 8,
98
+ "groupName": "Inteligencia",
99
+ "groupActive": 1
100
+ },
101
+ {
102
+ "groupId": 9,
103
+ "groupName": "Legal",
104
+ "groupActive": 0
105
+ }
106
+ ]
37
107
  };