feat: добавлена возможность удаления и редактирования самой доски
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
//me,
|
||||
loadBoardDataAPI,
|
||||
createTaskAPI,
|
||||
createCategoryAPI,
|
||||
@@ -10,7 +11,9 @@ import {
|
||||
deleteTaskAPI,
|
||||
assignMemberAPI,
|
||||
unassignMemberAPI,
|
||||
addMemberAPI
|
||||
addMemberAPI,
|
||||
deleteBoardsAPI,
|
||||
updateBoardsAPI
|
||||
} from './BoardAPI';
|
||||
|
||||
export const useBoardLogic = (id, setError, setInfo, setCategories, setLoading) => {
|
||||
@@ -28,6 +31,9 @@ export const useBoardLogic = (id, setError, setInfo, setCategories, setLoading)
|
||||
err.response?.data?.message === 'Invalid Token') {
|
||||
setError('Вы не авторизованы');
|
||||
setTimeout(() => navigate('/login'), 1000);
|
||||
} else if (err.response?.data?.detail === "Доска не найдена.") {
|
||||
setError("Доска не существует");
|
||||
setTimeout(() => navigate('/kanban-boards-list'), 1000);
|
||||
} else {
|
||||
setError('Ошибка загрузки доски');
|
||||
}
|
||||
@@ -36,6 +42,23 @@ export const useBoardLogic = (id, setError, setInfo, setCategories, setLoading)
|
||||
}
|
||||
}, [id, setError, setInfo, setCategories, setLoading, navigate]);
|
||||
|
||||
const checkOwner = useCallback((ownerId) => {
|
||||
return /*me()*/22 === ownerId
|
||||
}, []);
|
||||
|
||||
const deleteBoards = useCallback(async (boardId, modalDelBoard) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
await deleteBoardsAPI(boardId);
|
||||
modalDelBoard();
|
||||
navigate('/kanban-boards-list');
|
||||
} catch (err) {
|
||||
setError('Ошибка удаления доски: '+ (err.response?.data?.message || err.response?.data?.detail));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [setLoading, setError]);
|
||||
|
||||
const createTask = useCallback(async (taskCategori, taskTitle, taskDescription, modalCrTask) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
@@ -65,7 +88,6 @@ export const useBoardLogic = (id, setError, setInfo, setCategories, setLoading)
|
||||
await createCategoryAPI(newCategory);
|
||||
await loadBoardData();
|
||||
} catch (err) {
|
||||
console.error('Ошибка создания категории:', err);
|
||||
setError(err.response?.data?.message || 'Ошибка создания категории');
|
||||
} finally {
|
||||
modalCrCateg();
|
||||
@@ -73,6 +95,29 @@ export const useBoardLogic = (id, setError, setInfo, setCategories, setLoading)
|
||||
}
|
||||
}, [id, loadBoardData, setLoading, setError]);
|
||||
|
||||
const editBoard = useCallback(async (editedBoardId, boardTitle, boardDescription, modalEditBoard) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
await updateBoardsAPI({
|
||||
id: editedBoardId,
|
||||
update_method: 'title',
|
||||
value: boardTitle
|
||||
});
|
||||
await updateBoardsAPI({
|
||||
id: editedBoardId,
|
||||
update_method: 'description',
|
||||
value: boardDescription
|
||||
});
|
||||
await modalEditBoard();
|
||||
await loadBoardData();
|
||||
} catch (err) {
|
||||
setError(err.response?.data?.message || 'Ошибка редактирования доски');
|
||||
} finally {
|
||||
modalEditBoard();
|
||||
setLoading(false);
|
||||
}
|
||||
}, [loadBoardData, setLoading, setError]);
|
||||
|
||||
const editTask = useCallback(async (editedTaskId, taskTitle, taskDescription, taskCategory, modalEditTask) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
@@ -193,12 +238,15 @@ export const useBoardLogic = (id, setError, setInfo, setCategories, setLoading)
|
||||
return {
|
||||
loadBoardData,
|
||||
createTask,
|
||||
checkOwner,
|
||||
createCategory,
|
||||
editBoard,
|
||||
editTask,
|
||||
editCategory,
|
||||
deleteCategory,
|
||||
deleteTask,
|
||||
assignMember,
|
||||
addMember
|
||||
addMember,
|
||||
deleteBoards
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user