Sync task location when move to different column

This commit is contained in:
sosokker 2023-11-21 06:20:10 +07:00
parent 5b4a11b374
commit dc154c0122

View File

@ -328,20 +328,17 @@ function KanbanBoard() {
if (isActiveATask && isOverAColumn) {
setTasks(tasks => {
const activeIndex = tasks.findIndex(t => t.id === activeId);
const overIndex = tasks.findIndex(t => t.id === overId);
const newColumnId = overId;
const new_index = event.over?.index;
tasks[activeIndex].columnId = overId;
// Update the columnId of the task
tasks[activeIndex].columnId = newColumnId;
axiosInstance.put(`todo/change_task_list_board/`, { todo_id:activeId, new_list_board_id:overId, new_index: 0})
.then(response => {
})
.catch(error => {
console.error('Error updating task columnId:', error);
});
// If new_index is not provided, insert the task at the end
if (new_index !== null && 0 <= new_index && new_index <= tasks.length) {
return arrayMove(tasks, activeIndex, new_index);
} else {
return arrayMove(tasks, activeIndex, tasks.length);
}
return arrayMove(tasks, activeIndex, activeIndex);
});
}
}