Merge pull request #102 from apuc/tracker-connect-back

priority tasks
This commit is contained in:
NikoM1k 2023-06-15 21:47:24 +03:00 committed by GitHub
commit 07740c3369
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 94 additions and 20 deletions

View File

@ -22,7 +22,8 @@ import {
setColumnPriority, setColumnPriority,
deletePersonOnProject, deletePersonOnProject,
filterCreatedByMe, filterCreatedByMe,
filteredParticipateTasks filteredParticipateTasks,
movePositionProjectTask
} from "../../redux/projectsTrackerSlice"; } from "../../redux/projectsTrackerSlice";
import ModalTicket from "../../components/UI/ModalTicket/ModalTicket"; import ModalTicket from "../../components/UI/ModalTicket/ModalTicket";
@ -47,6 +48,7 @@ export const ProjectTracker = () => {
const [selectedTab, setSelectedTab] = useState(0); const [selectedTab, setSelectedTab] = useState(0);
const [priorityTask, setPriorityTask] = useState(0); const [priorityTask, setPriorityTask] = useState(0);
const [wrapperHover, setWrapperHover] = useState({}); const [wrapperHover, setWrapperHover] = useState({});
const [taskHover, setTaskHover] = useState({})
const [modalAdd, setModalAdd] = useState(false); const [modalAdd, setModalAdd] = useState(false);
const [modalActiveTicket, setModalActiveTicket] = useState(false); const [modalActiveTicket, setModalActiveTicket] = useState(false);
const [selectedTicket, setSelectedTicket] = useState({}); const [selectedTicket, setSelectedTicket] = useState({});
@ -63,29 +65,56 @@ export const ProjectTracker = () => {
}, []); }, []);
useEffect(() => { useEffect(() => {
const tasksHover = {}
const columnHover = {}
if (Object.keys(projectBoard).length) { if (Object.keys(projectBoard).length) {
projectBoard.columns.forEach((column) => { projectBoard.columns.forEach((column) => {
setOpenColumnSelect((prevState) => ({ setOpenColumnSelect((prevState) => ({
...prevState, ...prevState,
[column.id]: false, [column.id]: false,
})); }));
setWrapperHover((prevState) => ({ ...prevState, [column.id]: false })); columnHover[column.id] = false
column.tasks.forEach(task => tasksHover[task.id] = false)
}); });
} }
setWrapperHover(columnHover)
setTaskHover(tasksHover)
}, [projectBoard]); }, [projectBoard]);
function dragStartHandler(e, task, columnId) { function dragStartHandler(e, task, columnId) {
startWrapperIndexTest.current = { task: task, index: columnId }; startWrapperIndexTest.current = { task: task, index: columnId };
setTimeout(() => {
e.target.classList.add("tasks__board__item__hide");
}, 0);
} }
function dragEndHandler(e) { function dragOverTaskHandler(e, task) {
e.preventDefault()
if (startWrapperIndexTest.current.task.id === task.id) {
return
}
setTaskHover((prevState) => ({[prevState]: false, [task.id]: true}))
}
function dragLeaveTaskHandler(e) {
setTaskHover((prevState) => ({[prevState]: false}))
}
function dragEndTaskHandler() {
setTaskHover((prevState) => ({[prevState]: false}))
setWrapperHover((prevState) => ({ setWrapperHover((prevState) => ({
[prevState]: false, [prevState]: false,
})); }));
e.target.classList.remove("tasks__board__item__hide"); }
function dragDropTaskHandler(e, task, column) {
e.preventDefault()
if (task.id === startWrapperIndexTest.current.task.id) {
return
}
const finishTask = column.tasks.indexOf(task)
dispatch(movePositionProjectTask({
startTask: startWrapperIndexTest.current.task,
finishTask: task,
finishIndex: finishTask
}))
} }
function dragOverHandler(e) { function dragOverHandler(e) {
@ -102,16 +131,20 @@ export const ProjectTracker = () => {
[columnId]: true, [columnId]: true,
})); }));
} }
function dragDropHandler(e, columnId) { function dragDropHandler(e, columnId) {
e.preventDefault(); e.preventDefault();
if (startWrapperIndexTest.current.index === columnId) {
return;
}
setWrapperHover((prevState) => ({ setWrapperHover((prevState) => ({
[prevState]: false, [prevState]: false,
})); }));
if (startWrapperIndexTest.current.index === columnId
||
e.target.className.includes('__item')) {
return;
}
if (columnId !== startWrapperIndexTest.current.index) { if (columnId !== startWrapperIndexTest.current.index) {
dispatch( dispatch(
moveProjectTask({ moveProjectTask({
@ -126,7 +159,7 @@ export const ProjectTracker = () => {
setSelectedTab(columnId); setSelectedTab(columnId);
dispatch(modalToggle("createTiketProject")); dispatch(modalToggle("createTiketProject"));
setModalAdd(true); setModalAdd(true);
setPriorityTask(length + 1) setPriorityTask(length)
} }
function openTicket(e, task) { function openTicket(e, task) {
@ -404,20 +437,23 @@ export const ProjectTracker = () => {
</div> </div>
</div> </div>
)} )}
{column.tasks.map((task, index) => { {column.tasks.map((task) => {
return ( return (
<div <div
key={task.id} key={task.id}
className="tasks__board__item" className={`tasks__board__item ${
taskHover[task.id] ? "task__hover" : ""
}`}
draggable={true} draggable={true}
onDragStart={(e) => onDragStart={(e) => dragStartHandler(e, task, column.id)}
dragStartHandler(e, task, column.id) onDragOver={(e) => dragOverTaskHandler(e, task)}
} onDragLeave={(e) => dragLeaveTaskHandler(e)}
onDragEnd={(e) => dragEndHandler(e)} onDragEnd={(e) => dragEndTaskHandler()}
onDrop={(e) => dragDropTaskHandler(e, task, column)}
onClick={(e) => openTicket(e, task)} onClick={(e) => openTicket(e, task)}
> >
<div className="tasks__board__item__title"> <div className="tasks__board__item__title">
<p>{task.title}</p> <p className='task__board__item__title'>{task.title}</p>
</div> </div>
<p className="tasks__board__item__description"> <p className="tasks__board__item__description">
{task.description} {task.description}

View File

@ -534,6 +534,10 @@
0px 1px 1px rgba(0, 0, 0, 0.06); 0px 1px 1px rgba(0, 0, 0, 0.06);
} }
.task__hover {
box-shadow: 0 0 5px gray;
}
&__item { &__item {
width: 328px; width: 328px;
max-height: 250px; max-height: 250px;

View File

@ -51,12 +51,13 @@ export const projectsTrackerSlice = createSlice({
moveProjectTask: (state, action) => { moveProjectTask: (state, action) => {
state.projectBoard.columns.forEach((column, index) => { state.projectBoard.columns.forEach((column, index) => {
if (column.id === action.payload.columnId) { if (column.id === action.payload.columnId) {
column.tasks.push(action.payload.startWrapperIndex.task); column.tasks.push({...action.payload.startWrapperIndex.task, column_id: column.id});
apiRequest(`/task/update-task`, { apiRequest(`/task/update-task`, {
method: "PUT", method: "PUT",
data: { data: {
task_id: action.payload.startWrapperIndex.task.id, task_id: action.payload.startWrapperIndex.task.id,
column_id: column.id, column_id: column.id,
priority: column.tasks.length - 1
}, },
}).then(() => {}); }).then(() => {});
} }
@ -67,6 +68,38 @@ export const projectsTrackerSlice = createSlice({
} }
}); });
}, },
movePositionProjectTask: (state, action) => {
state.projectBoard.columns.forEach((column, index) => {
if (column.id === action.payload.startTask.column_id) {
state.projectBoard.columns[index].tasks = column.tasks.filter((task) => task.id !== action.payload.startTask.id)
}
if (column.id === action.payload.finishTask.column_id) {
column.tasks.splice(action.payload.finishIndex, 0, {...action.payload.startTask, column_id: column.id})
apiRequest(`/task/update-task`, {
method: "PUT",
data: {
task_id: action.payload.startTask.id,
column_id: column.id,
},
}).then(() => {});
const priorityTasks = []
column.tasks.forEach((task, index) => {
const curTask = {
task_id: task.id,
priority: index
}
priorityTasks.push(curTask)
})
apiRequest(`/task/set-priority`, {
method: "POST",
data: {
data: JSON.stringify(priorityTasks),
column_id: column.id,
},
}).then(() => {});
}
})
},
filterCreatedByMe: (state, action) => { filterCreatedByMe: (state, action) => {
state.projectBoard.columns.forEach((column) => { state.projectBoard.columns.forEach((column) => {
column.tasks = column.tasks.filter((task) => task.user_id === action.payload) column.tasks = column.tasks.filter((task) => task.user_id === action.payload)
@ -128,7 +161,8 @@ export const {
deletePersonOnProject, deletePersonOnProject,
addPersonToProject, addPersonToProject,
filterCreatedByMe, filterCreatedByMe,
filteredParticipateTasks filteredParticipateTasks,
movePositionProjectTask
} = projectsTrackerSlice.actions; } = projectsTrackerSlice.actions;
export const getProjects = (state) => state.tracker.projects; export const getProjects = (state) => state.tracker.projects;