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.
- package/dist/components/atoms/CustomChip/CustomChip.stories.js +31 -0
- package/dist/components/atoms/CustomChip/index.js +63 -0
- package/dist/components/atoms/CustomChip/styles.js +20 -0
- package/dist/components/atoms/Multiselect/index.js +148 -23
- package/dist/components/atoms/Multiselect/styles.js +1 -1
- package/dist/components/molecules/Phase/Phase.stories.js +72 -34
- package/dist/components/molecules/Phase/index.js +243 -134
- package/dist/components/organisms/DragAndDropPhases/DragAndDropPhases.stories.js +0 -23
- package/dist/components/organisms/DragAndDropPhases/index.js +246 -163
- package/package.json +1 -1
- package/src/components/atoms/CustomChip/CustomChip.stories.js +16 -0
- package/src/components/atoms/CustomChip/index.js +35 -0
- package/src/components/atoms/CustomChip/styles.js +6 -0
- package/src/components/atoms/Multiselect/index.js +200 -115
- package/src/components/atoms/Multiselect/styles.js +4 -0
- package/src/components/molecules/Phase/Phase.stories.js +91 -21
- package/src/components/molecules/Phase/index.js +174 -98
- package/src/components/organisms/DragAndDropPhases/DragAndDropPhases.stories.js +0 -27
- package/src/components/organisms/DragAndDropPhases/index.js +98 -42
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import React, { useState, useEffect } from "react";
|
|
2
2
|
import { Container, ContainerIcon } from "./styles";
|
|
3
|
-
import Chip from "@mui/material/Chip";
|
|
4
3
|
import { Button, Menu, MenuItem } from "@mui/material";
|
|
5
4
|
import Select from "@mui/material/Select";
|
|
6
|
-
import
|
|
5
|
+
import axios from "axios";
|
|
6
|
+
|
|
7
|
+
//Componentes
|
|
7
8
|
import { Modal } from "../../organisms/Modal";
|
|
8
9
|
import { TextField } from "@mui/material/TextField";
|
|
9
10
|
import { GroupSelect } from "../../molecules/GroupSelect";
|
|
11
|
+
import { CustomChip } from "../../atoms/CustomChip";
|
|
12
|
+
import { CustomSelect } from "../../molecules/CustomSelect";
|
|
13
|
+
|
|
14
|
+
//svg
|
|
10
15
|
import options from "../../../assets/images/Icons/options.svg";
|
|
11
|
-
import
|
|
16
|
+
import add from "../../../assets/images/Icons/addv2.svg";
|
|
12
17
|
|
|
13
18
|
export const Phase = ({
|
|
14
19
|
id,
|
|
@@ -17,12 +22,18 @@ export const Phase = ({
|
|
|
17
22
|
nextPhase,
|
|
18
23
|
groups,
|
|
19
24
|
onDeletePhase,
|
|
20
|
-
|
|
25
|
+
onDragStart,
|
|
26
|
+
onDragOver,
|
|
27
|
+
onDragEnd,
|
|
28
|
+
token
|
|
21
29
|
}) => {
|
|
22
30
|
const [selectedValue, setSelectedValue] = useState("");
|
|
23
31
|
const [chips, setChips] = useState([]);
|
|
24
32
|
const [groupsSelected, setGroupsSelected] = useState([]);
|
|
25
33
|
const [showCustomSelect, setShowCustomSelect] = useState(false);
|
|
34
|
+
const [anchorEl, setAnchorEl] = React.useState(null);
|
|
35
|
+
const [nextPhaseState, setNextPhaseState] = useState("");
|
|
36
|
+
const open = Boolean(anchorEl);
|
|
26
37
|
const [modalData, setModalData] = useState({
|
|
27
38
|
show: false,
|
|
28
39
|
title: "Actualización completa",
|
|
@@ -31,35 +42,121 @@ export const Phase = ({
|
|
|
31
42
|
});
|
|
32
43
|
|
|
33
44
|
const idPhase = id + 1;
|
|
34
|
-
const [draggedItem, setDraggedItem] = useState(null);
|
|
35
45
|
const [tempItems, setTempItems] = useState([]);
|
|
36
46
|
|
|
37
|
-
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
const activeGroups = groups.filter((group) => group.groupActive === 1);
|
|
49
|
+
const initialChips = activeGroups.map((group) => ({
|
|
50
|
+
id: group.groupId,
|
|
51
|
+
label: group.groupName,
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
setChips(initialChips);
|
|
55
|
+
}, [groups]);
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
const nextPhaseObject = phases.find((phase) => phase.phaseId === nextPhase);
|
|
59
|
+
if (nextPhaseObject) {
|
|
60
|
+
setNextPhaseState(nextPhaseObject.phaseName);
|
|
61
|
+
} else {
|
|
62
|
+
console.log("Aún no se asigna siguiente fase");
|
|
63
|
+
}
|
|
64
|
+
}, [nextPhase, phases]);
|
|
65
|
+
|
|
66
|
+
const onAdd = async (idPhase) => {
|
|
38
67
|
if (selectedValue && !groupsSelected.includes(selectedValue)) {
|
|
68
|
+
const updatedGroups = groups.map((group) =>
|
|
69
|
+
group.groupName === selectedValue
|
|
70
|
+
? { ...group, groupActive: 1 }
|
|
71
|
+
: group
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
setGroups(updatedGroups);
|
|
75
|
+
|
|
76
|
+
// Actualizar el estado de chips y groupsSelected
|
|
77
|
+
setChips((prevChips) => [
|
|
78
|
+
...prevChips,
|
|
79
|
+
{ id: idPhase, label: selectedValue },
|
|
80
|
+
]);
|
|
81
|
+
|
|
39
82
|
setGroupsSelected((prevGroups) => [...prevGroups, selectedValue]);
|
|
40
|
-
setChips((prevChips) => [...prevChips, selectedValue]);
|
|
41
83
|
setSelectedValue("");
|
|
84
|
+
|
|
85
|
+
console.log("update",updatedGroups)
|
|
86
|
+
await addGroup(idPhase, updatedGroups);
|
|
42
87
|
}
|
|
43
88
|
};
|
|
89
|
+
|
|
44
90
|
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
91
|
+
const addGroup = async(phaseId, groups) => {
|
|
92
|
+
try {
|
|
93
|
+
console.log("fase y grupos",{phaseId, groups});
|
|
94
|
+
const response = await axios.post(
|
|
95
|
+
`${process.env.REACT_APP_PHASES_ENDPOINT}/update`,
|
|
96
|
+
{
|
|
97
|
+
retailerGroupsIds: {
|
|
98
|
+
groups
|
|
99
|
+
},
|
|
100
|
+
phaseId
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
headers: {
|
|
104
|
+
Authorization: token,
|
|
105
|
+
},
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
console.log("grupo eliminado correctamente")
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error("Error al eliminar grupo de fase:", error);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
48
113
|
|
|
49
114
|
const handleGroupSelect = (selectedGroup) => {
|
|
50
|
-
|
|
115
|
+
if (!chips.find((chip) => chip.label === selectedGroup)) {
|
|
116
|
+
setChips((prevChips) => [
|
|
117
|
+
...prevChips,
|
|
118
|
+
{ id: prevChips.length, label: selectedGroup },
|
|
119
|
+
]);
|
|
120
|
+
}
|
|
121
|
+
console.log("Se agrego el grupo", selectedGroup);
|
|
51
122
|
setSelectedValue(selectedGroup);
|
|
52
123
|
};
|
|
53
124
|
|
|
54
|
-
const handleChipDelete = (chipToRemove) => {
|
|
125
|
+
const handleChipDelete = (phaseId,chipToRemove) => {
|
|
55
126
|
setGroupsSelected((prevGroups) =>
|
|
56
|
-
prevGroups.filter((chip) => chip !== chipToRemove)
|
|
127
|
+
prevGroups.filter((chip) => chip.id !== chipToRemove.id)
|
|
57
128
|
);
|
|
58
|
-
|
|
129
|
+
console.log("Se elimino el grupo", chipToRemove.id);
|
|
130
|
+
setChips((prevChips) =>
|
|
131
|
+
prevChips.filter((chip) => chip.id !== chipToRemove.id)
|
|
132
|
+
);
|
|
133
|
+
deleteGroup(phaseId, chipToRemove.id);
|
|
59
134
|
};
|
|
60
135
|
|
|
61
|
-
const
|
|
62
|
-
|
|
136
|
+
const deleteGroup = async(phaseId, groupId) => {
|
|
137
|
+
try {
|
|
138
|
+
console.log("grupo de fase",{phaseId, groupId});
|
|
139
|
+
const response = await axios.post(
|
|
140
|
+
`${process.env.REACT_APP_PHASES_ENDPOINT}/delete`,
|
|
141
|
+
{
|
|
142
|
+
deleteGroupOfPhase: {
|
|
143
|
+
phaseId,
|
|
144
|
+
groupId
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
headers: {
|
|
149
|
+
Authorization: token,
|
|
150
|
+
// Authorization: sessionStorage.getItem("jwt"),
|
|
151
|
+
},
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
console.log("grupo eliminado correctamente")
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.error("Error al eliminar grupo de fase:", error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
63
160
|
const handleClick = (event) => {
|
|
64
161
|
setAnchorEl(event.currentTarget);
|
|
65
162
|
};
|
|
@@ -67,78 +164,22 @@ export const Phase = ({
|
|
|
67
164
|
setAnchorEl(null);
|
|
68
165
|
};
|
|
69
166
|
|
|
70
|
-
const HoverableChip = ({ label, onDelete }) => {
|
|
71
|
-
const [isHovered, setIsHovered] = useState(false);
|
|
72
|
-
|
|
73
|
-
const handleMouseEnter = () => {
|
|
74
|
-
setIsHovered(true);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const handleMouseLeave = () => {
|
|
78
|
-
setIsHovered(false);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
<Chip
|
|
83
|
-
label={label}
|
|
84
|
-
onDelete={onDelete}
|
|
85
|
-
onMouseEnter={handleMouseEnter}
|
|
86
|
-
onMouseLeave={handleMouseLeave}
|
|
87
|
-
deleteIcon={<DeleteIcon />}
|
|
88
|
-
style={{
|
|
89
|
-
borderRadius: "5px",
|
|
90
|
-
background: "transparent",
|
|
91
|
-
border: `1px solid ${isHovered ? "#B64545" : "#F0F0F0"}`,
|
|
92
|
-
color: `${isHovered ? "#B64545" : "#707070"}`,
|
|
93
|
-
}}
|
|
94
|
-
/>
|
|
95
|
-
);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const onDragStartHandler = (e) => {
|
|
99
|
-
e.dataTransfer.effectAllowed = "move";
|
|
100
|
-
e.dataTransfer.setData("text/html", e.target.parentNode);
|
|
101
|
-
e.dataTransfer.setDragImage(e.target.parentNode, 20, 20);
|
|
102
|
-
setDraggedItem(id);
|
|
103
|
-
onDragStart(e, id);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const onDragOverHandler = (index) => {
|
|
107
|
-
if (!draggedItem || draggedItem === id) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
onDragOver(id);
|
|
112
|
-
setDraggedItem(null);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const onDragEndHandler = () => {
|
|
116
|
-
onDragEnd();
|
|
117
|
-
setDraggedItem(null);
|
|
118
|
-
};
|
|
119
|
-
|
|
120
167
|
return (
|
|
121
168
|
<Container
|
|
122
|
-
|
|
123
|
-
onDragOver={
|
|
124
|
-
onDragEnd={
|
|
125
|
-
draggable
|
|
169
|
+
onDragStart={onDragStart}
|
|
170
|
+
onDragOver={onDragOver}
|
|
171
|
+
onDragEnd={onDragEnd}
|
|
172
|
+
draggable
|
|
126
173
|
>
|
|
127
174
|
<div key={idPhase} className="header-phase">
|
|
128
175
|
<h2>
|
|
129
176
|
Fase {idPhase} - {phaseName}
|
|
130
177
|
</h2>
|
|
131
178
|
<div className="text-button-container">
|
|
132
|
-
{idPhase === 1 ? (
|
|
133
|
-
<p className="text-phase">
|
|
134
|
-
Al rechazar en esta fase enviar a proveedor
|
|
135
|
-
</p>
|
|
136
|
-
) : (
|
|
137
179
|
<div className="phase-sel">
|
|
138
180
|
<p className="text-phase">Siguiente Fase </p>
|
|
139
181
|
<Select
|
|
140
|
-
|
|
141
|
-
value={selectedValue !== "" ? selectedValue : nextPhase}
|
|
182
|
+
value={selectedValue !== "" ? selectedValue : nextPhaseState}
|
|
142
183
|
placeholder={`Fase`}
|
|
143
184
|
onChange={(e) => {
|
|
144
185
|
const selectedPhase = phases.find(
|
|
@@ -146,7 +187,13 @@ export const Phase = ({
|
|
|
146
187
|
);
|
|
147
188
|
setSelectedValue(selectedPhase.nextPhaseIfApproved);
|
|
148
189
|
}}
|
|
149
|
-
sx={{
|
|
190
|
+
sx={{
|
|
191
|
+
minWidth: "100px",
|
|
192
|
+
height: "24px",
|
|
193
|
+
background: "#F7F7FC",
|
|
194
|
+
borderRadius: "5px",
|
|
195
|
+
fontSize:"12px",
|
|
196
|
+
}}
|
|
150
197
|
MenuProps={{
|
|
151
198
|
PaperProps: {
|
|
152
199
|
style: {
|
|
@@ -156,7 +203,15 @@ export const Phase = ({
|
|
|
156
203
|
}}
|
|
157
204
|
>
|
|
158
205
|
{phases.map((phase) => (
|
|
159
|
-
<MenuItem
|
|
206
|
+
<MenuItem
|
|
207
|
+
key={phase.phaseId}
|
|
208
|
+
value={phase.phaseName}
|
|
209
|
+
sx={{
|
|
210
|
+
fontSize: "12px",
|
|
211
|
+
color: "#262626",
|
|
212
|
+
minHeight: "auto",
|
|
213
|
+
}}
|
|
214
|
+
>
|
|
160
215
|
{phase.phaseName}
|
|
161
216
|
</MenuItem>
|
|
162
217
|
))}
|
|
@@ -166,7 +221,7 @@ export const Phase = ({
|
|
|
166
221
|
aria-controls={open ? "basic-menu" : undefined}
|
|
167
222
|
aria-haspopup="true"
|
|
168
223
|
aria-expanded={open ? "true" : undefined}
|
|
169
|
-
onClick={handleClick}
|
|
224
|
+
onClick={(e) => handleClick(e)}
|
|
170
225
|
>
|
|
171
226
|
<img src={options} alt="" />
|
|
172
227
|
</Button>
|
|
@@ -178,45 +233,66 @@ export const Phase = ({
|
|
|
178
233
|
MenuListProps={{
|
|
179
234
|
"aria-labelledby": "basic-button",
|
|
180
235
|
}}
|
|
236
|
+
sx={{
|
|
237
|
+
ul: {
|
|
238
|
+
paddingTop: "0px",
|
|
239
|
+
paddingBottom: "0px",
|
|
240
|
+
},
|
|
241
|
+
}}
|
|
181
242
|
>
|
|
182
|
-
<MenuItem
|
|
243
|
+
<MenuItem
|
|
244
|
+
onClick={() => onDeletePhase(id)}
|
|
245
|
+
sx={{ fontSize: "12px", color: "#262626", minHeight: "auto" }}
|
|
246
|
+
>
|
|
183
247
|
Eliminar Fase
|
|
184
248
|
</MenuItem>
|
|
185
249
|
</Menu>
|
|
186
250
|
</div>
|
|
187
|
-
)}
|
|
188
251
|
</div>
|
|
189
252
|
</div>
|
|
190
|
-
|
|
191
253
|
<div className="attributes-container">
|
|
192
|
-
{
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
))}
|
|
201
|
-
<GroupSelect
|
|
254
|
+
{chips.map((chip) => (
|
|
255
|
+
<CustomChip
|
|
256
|
+
key={chip.id}
|
|
257
|
+
label={chip.label}
|
|
258
|
+
onDelete={() => handleChipDelete(idPhase,chip)}
|
|
259
|
+
/>
|
|
260
|
+
))}
|
|
261
|
+
{/*<GroupSelect
|
|
202
262
|
options={groups
|
|
203
263
|
.filter((group) => group.groupActive === 0)
|
|
204
264
|
.map((group, index) => ({
|
|
205
265
|
id: index,
|
|
206
266
|
name: group.groupName,
|
|
207
267
|
}))}
|
|
208
|
-
showSearchBar
|
|
268
|
+
showSearchBar
|
|
269
|
+
isSingleSelect={false}
|
|
209
270
|
icon={add}
|
|
210
271
|
placeHolder={"Buscar grupo"}
|
|
211
|
-
customSelectId={"category-select-" + groups.
|
|
272
|
+
customSelectId={"category-select-" + groups.groupId}
|
|
212
273
|
defaultOption={"Todos los grupos"}
|
|
213
274
|
parameterArray={groupsSelected}
|
|
214
275
|
setParameterArray={setGroupsSelected}
|
|
215
276
|
onSelect={handleGroupSelect}
|
|
216
|
-
onClickItem={onAdd}
|
|
217
|
-
|
|
218
|
-
</div>
|
|
277
|
+
onClickItem={()=>onAdd(idPhase)}
|
|
278
|
+
/>*/}
|
|
219
279
|
|
|
280
|
+
{/* <CustomSelect
|
|
281
|
+
options={groups
|
|
282
|
+
.filter((group) => group.groupActive === 0)
|
|
283
|
+
.map((group, index) => ({
|
|
284
|
+
id: index,
|
|
285
|
+
name: group.groupName,
|
|
286
|
+
}))}
|
|
287
|
+
showSearchBar
|
|
288
|
+
icon={add}
|
|
289
|
+
placeHolder={"Buscar grupo"}
|
|
290
|
+
customSelectId={"group-select"}
|
|
291
|
+
defaultOption={"Todos los grupos"}
|
|
292
|
+
parameterArray={groupsSelected}
|
|
293
|
+
setParameterArray={setGroupsSelected}
|
|
294
|
+
/>*/}
|
|
295
|
+
</div>
|
|
220
296
|
<Modal
|
|
221
297
|
{...modalData}
|
|
222
298
|
onClickBtnDefault={() =>
|
|
@@ -9,32 +9,5 @@ const Template = (args) => <DragAndDropPhases {...args} />;
|
|
|
9
9
|
|
|
10
10
|
export const DragAndDropPhasesDefault = Template.bind({});
|
|
11
11
|
DragAndDropPhasesDefault.args = {
|
|
12
|
-
items :[
|
|
13
|
-
{ grupos: ["Impuestos", "Legal"] },
|
|
14
|
-
{ grupos: ["Legal", "Jefe comercial"] },
|
|
15
|
-
{ grupos: ["Finanzas", "Datos maestros"] },
|
|
16
|
-
],
|
|
17
|
-
grupos: [
|
|
18
|
-
{
|
|
19
|
-
id:1,
|
|
20
|
-
name:"Impuestos",
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
id:2,
|
|
24
|
-
name:"Legal",
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
id:3,
|
|
28
|
-
name:"Jefe comercial"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
id:4,
|
|
32
|
-
name:"Finanzas"
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
id:5,
|
|
36
|
-
name:"Datos maestros"
|
|
37
|
-
}
|
|
38
|
-
],
|
|
39
12
|
token:"eyJraWQiOiJkQWJkZCtlclwvTlwveVRQUWNvUlVyOCtrNUd2M1hMM2N1MWUzQ09zWExVRnc9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiIwZjQyNDdkZi1mMDJmLTRjYjgtOTA5YS1lNjI2NDlkMzQ3ODIiLCJjb2duaXRvOmdyb3VwcyI6WyJ1c3VhcmlvX2NvbnRlbnRvaCJdLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiaXNzIjoiaHR0cHM6XC9cL2NvZ25pdG8taWRwLnVzLWVhc3QtMS5hbWF6b25hd3MuY29tXC91cy1lYXN0LTFfWE1aUWRxa0dqIiwicGhvbmVfbnVtYmVyX3ZlcmlmaWVkIjpmYWxzZSwiY29nbml0bzp1c2VybmFtZSI6IjBmNDI0N2RmLWYwMmYtNGNiOC05MDlhLWU2MjY0OWQzNDc4MiIsImNvZ25pdG86cm9sZXMiOlsiYXJuOmF3czppYW06Ojg5ODY3MDIzMjgwNzpyb2xlXC9jb250ZW50b2gtZGV2LXVzLWVhc3QtMS1sYW1iZGFSb2xlIl0sImF1ZCI6IjVhYzh0cGdzNmdic3ExM2ZydnJwaWVlcDQwIiwiZXZlbnRfaWQiOiIzMTJjMzkzOC0yODFlLTRjZTMtOGQwMC1lNDJmMDJhMjliNDkiLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTcwMTgwNDA2MywibmFtZSI6IlByb3ZlZWRvciBVbm8gUmFkaW9zaGFjayIsInBob25lX251bWJlciI6Iis1MjEyMzQ1Njc4OTgiLCJleHAiOjE3MDE4MDc2NjIsImlhdCI6MTcwMTgwNDA2MywiZW1haWwiOiJwcm92ZWVkb3JyYWRpb3NoYWNrdW5vQGFsbGZyZWVtYWlsLm5ldCJ9.TlytxDFcBq6dMXaDGqIQ2Dr3P81JQgIJ2k8DgfVKvHmmJAyfj5hZcdaWPBCW_qXT_93HtXje2fmQuyTJeN4pL_AXkEEQJsi6Ye-8ipteb616OFLLm8AkMV7NmxyYn59yfY9bPoWmanTjicONFNtL_SOACebXUI4c1uZtFmMWMvAR29l_89uj3e5J-ZrS1PQn36Eid66LYtV7lBsKAn3JJeftDiXx750AHERXjoXdzHwjJttm4jmMZ4LJPk8efuvZWdPhcgXJ-4CuvWNbjxCmFiDkxSjFK_qLix73HtoCLWee-FJElqxW2ZjTflOiRZknmt2M-7kQj4FzhgEK3n6jyg"
|
|
40
13
|
}
|
|
@@ -7,13 +7,11 @@ import axios from "axios";
|
|
|
7
7
|
import successV2 from "../../../assets/images/Icons/checkv2.svg";
|
|
8
8
|
import { Input } from "@mui/material";
|
|
9
9
|
|
|
10
|
-
export const DragAndDropPhases = ({
|
|
11
|
-
const [items, setItems] = useState(initialItems);
|
|
10
|
+
export const DragAndDropPhases = ({ token}) => {
|
|
12
11
|
const [draggedItem, setDraggedItem] = useState(null);
|
|
13
|
-
const [tempItems, setTempItems] = useState(items);
|
|
14
|
-
const [user, setUser] = useState(JSON.parse(sessionStorage.getItem("user")));
|
|
15
12
|
const [listPhases, setListPhases]= useState([]);
|
|
16
|
-
const [
|
|
13
|
+
const [tempListPhases, setTempListPhases] = useState([]);
|
|
14
|
+
const [inputValue, setInputValue] = useState("");
|
|
17
15
|
const [modalData, setModalData] = useState({
|
|
18
16
|
show: false,
|
|
19
17
|
title: "Actualización completa",
|
|
@@ -21,25 +19,51 @@ export const DragAndDropPhases = ({items: initialItems, grupos: initialGroups, t
|
|
|
21
19
|
icon: "success",
|
|
22
20
|
});
|
|
23
21
|
|
|
22
|
+
useEffect(() => loadData(),[]);
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
console.log(inputValue)
|
|
26
|
+
}, [inputValue]);
|
|
27
|
+
|
|
28
|
+
const onDragStart = (e, id) => {
|
|
29
|
+
e.dataTransfer.effectAllowed = "move";
|
|
30
|
+
e.dataTransfer.setData("text/html", e.target.parentNode);
|
|
31
|
+
e.dataTransfer.setDragImage(e.target.parentNode, 20, 20);
|
|
32
|
+
setDraggedItem(id);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const onDragOver = (index) => {
|
|
36
|
+
const draggedIdx = tempListPhases.findIndex(
|
|
37
|
+
(phase) => phase.phaseId === draggedItem
|
|
38
|
+
);
|
|
39
|
+
const draggedItemData = tempListPhases[draggedIdx];
|
|
40
|
+
const targetIdx = index;
|
|
41
|
+
const newTempListPhases = [...tempListPhases];
|
|
42
|
+
newTempListPhases.splice(draggedIdx, 1);
|
|
43
|
+
newTempListPhases.splice(targetIdx, 0, draggedItemData);
|
|
44
|
+
setTempListPhases(newTempListPhases);
|
|
45
|
+
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
const onDragEnd = () => {
|
|
50
|
+
setDraggedItem(null);
|
|
51
|
+
};
|
|
52
|
+
|
|
24
53
|
// useEffect(() => {console.log("nuevo",newPhaseName)},[newPhaseName]);
|
|
25
54
|
|
|
26
55
|
|
|
27
56
|
|
|
28
|
-
|
|
57
|
+
const updatePhases = async () => {
|
|
29
58
|
try {
|
|
30
59
|
console.log("listPhases:", listPhases);
|
|
31
60
|
const updateData = {
|
|
32
|
-
body: {
|
|
33
61
|
updateReferencesOfNodes: listPhases.map((phase) => ({
|
|
34
62
|
name:phase.phaseName,
|
|
35
63
|
isInitialPhase: phase.isInitialPhase,
|
|
36
64
|
phaseId: phase.phaseId,
|
|
37
65
|
nextPhaseIfApproved: phase.nextPhaseIfApproved,
|
|
38
66
|
})),
|
|
39
|
-
},
|
|
40
|
-
path: {
|
|
41
|
-
action: "update",
|
|
42
|
-
},
|
|
43
67
|
headers: {
|
|
44
68
|
Authorization: token,
|
|
45
69
|
},
|
|
@@ -48,26 +72,32 @@ export const DragAndDropPhases = ({items: initialItems, grupos: initialGroups, t
|
|
|
48
72
|
|
|
49
73
|
const response = await axios.post(
|
|
50
74
|
`${process.env.REACT_APP_PHASES_ENDPOINT}/update`,
|
|
51
|
-
updateData
|
|
75
|
+
updateData,
|
|
76
|
+
{
|
|
77
|
+
headers: {
|
|
78
|
+
Authorization: token,
|
|
79
|
+
},
|
|
80
|
+
}
|
|
52
81
|
);
|
|
53
|
-
|
|
54
|
-
// Handle response if needed
|
|
55
82
|
console.log("Update response:", response.data);
|
|
56
83
|
} catch (error) {
|
|
57
84
|
console.error("Error al actualizar fases", error);
|
|
58
85
|
}
|
|
59
|
-
}
|
|
86
|
+
};
|
|
60
87
|
|
|
61
88
|
|
|
62
|
-
const handleInputChange = (
|
|
63
|
-
|
|
64
|
-
|
|
89
|
+
const handleInputChange = (value) => {
|
|
90
|
+
setInputValue((prevInputValue) => {
|
|
91
|
+
const newValue = prevInputValue + value;
|
|
92
|
+
console.log("currentInputValue", newValue);
|
|
93
|
+
return newValue;
|
|
94
|
+
});
|
|
65
95
|
};
|
|
66
96
|
|
|
67
|
-
const AddPhase = async() => {
|
|
97
|
+
const AddPhase = async(phaseName) => {
|
|
98
|
+
console.log("fase nueva", phaseName);
|
|
68
99
|
try {
|
|
69
|
-
|
|
70
|
-
{/*const body = {
|
|
100
|
+
const body = {
|
|
71
101
|
name: phaseName,
|
|
72
102
|
retailerGroupsIds: [],
|
|
73
103
|
nextPhaseId: null
|
|
@@ -82,12 +112,35 @@ export const DragAndDropPhases = ({items: initialItems, grupos: initialGroups, t
|
|
|
82
112
|
}
|
|
83
113
|
);
|
|
84
114
|
const createdPhase = response.data.body;
|
|
85
|
-
console.log(createdPhase)
|
|
115
|
+
console.log(createdPhase)
|
|
116
|
+
setInputValue("");
|
|
86
117
|
} catch (error) {
|
|
87
118
|
console.error("Error al agregar fase:", error);
|
|
88
119
|
}
|
|
89
120
|
}
|
|
90
121
|
|
|
122
|
+
const deletePhase = async(id, phases) => {
|
|
123
|
+
try {
|
|
124
|
+
console.log("Lista de fases actualizada",phases);
|
|
125
|
+
console.log("fase a eliminar", id)
|
|
126
|
+
const response = await axios.post(
|
|
127
|
+
`${process.env.REACT_APP_PHASES_ENDPOINT}/delete`,
|
|
128
|
+
{
|
|
129
|
+
updateReferencesOfNodes:phases,
|
|
130
|
+
deletePhase:id
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
headers: {
|
|
134
|
+
Authorization: token,
|
|
135
|
+
},
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
loadData();
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error("Error al eliminar fase:", error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
91
144
|
const handleAddPhaseButton = () => {
|
|
92
145
|
setModalData({
|
|
93
146
|
show: true,
|
|
@@ -108,10 +161,12 @@ export const DragAndDropPhases = ({items: initialItems, grupos: initialGroups, t
|
|
|
108
161
|
type="pink"
|
|
109
162
|
label="Guardar"
|
|
110
163
|
size={12}
|
|
111
|
-
onClick={
|
|
164
|
+
onClick={() => {
|
|
112
165
|
setModalData((prev) => ({ ...prev, show: false }));
|
|
113
|
-
|
|
114
|
-
|
|
166
|
+
setInputValue((prevInputValue) => {
|
|
167
|
+
AddPhase(prevInputValue);
|
|
168
|
+
return prevInputValue;
|
|
169
|
+
});
|
|
115
170
|
}}
|
|
116
171
|
/>
|
|
117
172
|
],
|
|
@@ -121,19 +176,14 @@ export const DragAndDropPhases = ({items: initialItems, grupos: initialGroups, t
|
|
|
121
176
|
<input
|
|
122
177
|
className={`input-phases`}
|
|
123
178
|
placeholder="Nombre de fase"
|
|
124
|
-
value={
|
|
125
|
-
onChange={handleInputChange}
|
|
179
|
+
value={inputValue}
|
|
180
|
+
onChange={(e)=>handleInputChange(e.target.value)}
|
|
126
181
|
/>
|
|
127
182
|
</div>
|
|
128
183
|
),
|
|
129
184
|
});
|
|
130
185
|
};
|
|
131
186
|
|
|
132
|
-
const handleAcceptModal = (PhaseName) => {
|
|
133
|
-
console.log("nombre",PhaseName)
|
|
134
|
-
AddPhase(PhaseName);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
187
|
const loadData = async () => {
|
|
138
188
|
try {
|
|
139
189
|
const response = await axios.post(
|
|
@@ -169,18 +219,20 @@ export const DragAndDropPhases = ({items: initialItems, grupos: initialGroups, t
|
|
|
169
219
|
|
|
170
220
|
console.table("fases Array", phasesDataArray);
|
|
171
221
|
setListPhases(phasesDataArray);
|
|
222
|
+
setTempListPhases(phasesDataArray);
|
|
172
223
|
} catch (error) {
|
|
173
224
|
console.error("Error al obtener fases:", error);
|
|
174
225
|
}
|
|
175
226
|
};
|
|
176
227
|
|
|
177
228
|
const handleDeletePhase = (id) => {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
);
|
|
229
|
+
const updatedListPhases = [...listPhases];
|
|
230
|
+
|
|
231
|
+
const filteredPhases = updatedListPhases.filter((phase) => phase.phaseId !== id);
|
|
232
|
+
setListPhases(filteredPhases);
|
|
181
233
|
setModalData({
|
|
182
234
|
show: true,
|
|
183
|
-
className: "modal-delete",
|
|
235
|
+
className: "modal-delete-phase",
|
|
184
236
|
message: "Fase eliminada correctamente.",
|
|
185
237
|
icon: "successv2",
|
|
186
238
|
buttons: [
|
|
@@ -195,10 +247,9 @@ const handleDeletePhase = (id) => {
|
|
|
195
247
|
/>,
|
|
196
248
|
],
|
|
197
249
|
});
|
|
250
|
+
deletePhase(id, filteredPhases)
|
|
198
251
|
};
|
|
199
252
|
|
|
200
|
-
useEffect(() => loadData(),[]);
|
|
201
|
-
|
|
202
253
|
// useEffect(() => {
|
|
203
254
|
// updatePhases();
|
|
204
255
|
// setModalData((prev) => ({ ...prev, show: false }));
|
|
@@ -213,8 +264,11 @@ const renderPhase = (phase, idx) => {
|
|
|
213
264
|
phaseName={phase.phaseName}
|
|
214
265
|
nextPhase={phase.nextPhaseIfApproved}
|
|
215
266
|
groups={phase.groupsAssigned}
|
|
216
|
-
onDeletePhase={() => handleDeletePhase(phase.
|
|
217
|
-
|
|
267
|
+
onDeletePhase={() => handleDeletePhase(phase.phaseId)}
|
|
268
|
+
onDragStart={(e) => onDragStart(e, idx)}
|
|
269
|
+
onDragOver={() => onDragOver(idx)}
|
|
270
|
+
onDragEnd={onDragEnd}
|
|
271
|
+
token={token}
|
|
218
272
|
/>
|
|
219
273
|
);
|
|
220
274
|
};
|
|
@@ -232,7 +286,9 @@ const renderPhase = (phase, idx) => {
|
|
|
232
286
|
type="pink"
|
|
233
287
|
label="Guardar Cambios"
|
|
234
288
|
size={12}
|
|
235
|
-
onClick={() =>
|
|
289
|
+
onClick={() => {
|
|
290
|
+
setListPhases(tempListPhases)
|
|
291
|
+
updatePhases();
|
|
236
292
|
setModalData({
|
|
237
293
|
show: true,
|
|
238
294
|
className: "modal-save",
|
|
@@ -250,7 +306,7 @@ const renderPhase = (phase, idx) => {
|
|
|
250
306
|
/>,
|
|
251
307
|
],
|
|
252
308
|
})
|
|
253
|
-
}
|
|
309
|
+
}}
|
|
254
310
|
></ButtonV2>
|
|
255
311
|
</Header>
|
|
256
312
|
<ul>
|