mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-19 05:54:07 +01:00
Add function to create and save new column
This commit is contained in:
parent
063e7eda70
commit
81914dd7fa
@ -10,6 +10,7 @@ import axiosInstance from "../../api/configs/AxiosConfig";
|
|||||||
function KanbanBoard() {
|
function KanbanBoard() {
|
||||||
const [columns, setColumns] = useState([]);
|
const [columns, setColumns] = useState([]);
|
||||||
const columnsId = useMemo(() => columns.map(col => col.id), [columns]);
|
const columnsId = useMemo(() => columns.map(col => col.id), [columns]);
|
||||||
|
const [boardId, setBoardData] = useState();
|
||||||
|
|
||||||
const [tasks, setTasks] = useState([]);
|
const [tasks, setTasks] = useState([]);
|
||||||
|
|
||||||
@ -106,6 +107,20 @@ function KanbanBoard() {
|
|||||||
fetchData();
|
fetchData();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchBoardData = async () => {
|
||||||
|
try {
|
||||||
|
const response = await axiosInstance.get('boards/');
|
||||||
|
if (response.data && response.data.length > 0) {
|
||||||
|
setBoardData(response.data[0]);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching board data:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchBoardData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="
|
className="
|
||||||
@ -207,12 +222,19 @@ function KanbanBoard() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createNewColumn() {
|
function createNewColumn() {
|
||||||
const columnToAdd = {
|
axiosInstance.post('lists/', { name: `Column ${columns.length + 1}`, position: 1, board: boardId })
|
||||||
id: generateId(),
|
.then(response => {
|
||||||
title: `Column ${columns.length + 1}`,
|
const newColumn = {
|
||||||
};
|
id: response.data.id,
|
||||||
|
title: response.data.name,
|
||||||
setColumns([...columns, columnToAdd]);
|
};
|
||||||
|
|
||||||
|
setColumns([...columns, newColumn]);
|
||||||
|
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error("Error creating ListBoard:", error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteColumn(id) {
|
function deleteColumn(id) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user