diff --git a/src/KBBoard/BoardLogic.js b/src/KBBoard/BoardLogic.js index 0b857b2..05cecd0 100644 --- a/src/KBBoard/BoardLogic.js +++ b/src/KBBoard/BoardLogic.js @@ -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 }; }; \ No newline at end of file diff --git a/src/KBBoard/KBBoard.js b/src/KBBoard/KBBoard.js index 5783b9c..e92470e 100644 --- a/src/KBBoard/KBBoard.js +++ b/src/KBBoard/KBBoard.js @@ -15,12 +15,16 @@ const KBBoard = () => { const [crCateg, setCrCateg] = useState(false); const [edTask, setEdTask] = useState(false); const [edCateg, setEdCateg] = useState(false); + const [edBoard, setEdBoard] = useState(false); const [delTask, setDelTask] = useState(false); const [delCateg, setDelCateg] = useState(false); const [asgnMember, setAsgnMember] = useState(false); const [assignAction, setAssignAction] = useState(false); const [addMemb, setAddMemb] = useState(false); + const [delBoards, setDelBoards] = useState(false); + const [boardTitle, setBoardTitle] = useState(''); + const [boardDescription, setBoardDescription] = useState(''); const [categoryTitle, setCategoryTitle] = useState(''); const [taskTitle, setTaskTitle] = useState(''); const [taskDescription, setTaskDescription] = useState(''); @@ -33,18 +37,19 @@ const KBBoard = () => { const [assignedMember, setAssignedMember] = useState(0); const [addedUsername, setAddedUsername] = useState(''); - - const { loadBoardData, createTask, + checkOwner, createCategory, + editBoard, editTask, editCategory, deleteCategory, deleteTask, assignMember, - addMember + addMember, + deleteBoards } = useBoardLogic(id, setError, setInfo, setCategories, setLoading); useEffect(() => { @@ -61,6 +66,11 @@ const KBBoard = () => { setCrCateg(!crCateg); setCategoryTitle(''); } + const modalEditBoard = () => { + setEdBoard(!edBoard); + setBoardTitle(info.title); + setBoardDescription(info.description); + } const modalEditTask = (task, id_categ) => () => { setEdTask(!edTask); setTaskCategori(id_categ); @@ -90,8 +100,12 @@ const KBBoard = () => { const modalAddMember = () => { setAddMemb(!addMemb); } + const modalDeleteBoards = () => { + setDelBoards(!delBoards); + } + const handleCreateCategory = async (e) => { e.preventDefault(); await createCategory(categoryTitle, modalCrCateg); @@ -100,6 +114,11 @@ const KBBoard = () => { e.preventDefault(); await createTask(taskCategori, taskTitle, taskDescription, modalCrTask); }; + const handleEditBoard = async (e) => { + e.preventDefault(); + await editBoard(id, boardTitle, boardDescription, modalEditBoard); + }; + const handleEditCategory = async (e) => { e.preventDefault(); await editCategory(editedCateg.id, categoryTitle, modalEditCateg); @@ -124,9 +143,12 @@ const KBBoard = () => { e.preventDefault(); await addMember(addedUsername, id, modalAddMember); }; + const handleDeleteBoards = async (e) => { + e.preventDefault(); + await deleteBoards(id, modalDeleteBoards); + }; - return (
@@ -150,9 +172,28 @@ const KBBoard = () => {
- + {checkOwner(info?.owner?.id) ? ( + <> + + + + + + ) : ( + <> + + + )}
{categories.map((category) => ( @@ -255,6 +296,35 @@ const KBBoard = () => {
)} + {edBoard && ( +
+
+

Изменение доски

+
+
+ + setBoardTitle(e.target.value)} + required + /> + + setBoardDescription(e.target.value)} + /> +
+ +
+ +
+
+ )} + {edCateg && (
@@ -355,15 +425,31 @@ const KBBoard = () => {
)} + {delBoards && ( +
+
+

Удаление доски

+
+ + + +
+
+
+ )} + + {addMemb && (
-

Удаление категории

+

Добавление участников

setAddedUsername(e.target.value)} /> @@ -376,8 +462,6 @@ const KBBoard = () => {
)} - - {asgnMember && (
{assignAction ? ( diff --git a/src/css/Board.css b/src/css/Board.css index 33769f2..04bbf79 100644 --- a/src/css/Board.css +++ b/src/css/Board.css @@ -55,8 +55,13 @@ border-radius: 6px; margin-bottom: 16px; display: flex; - flex-direction: column; + flex-direction: row; justify-content: space-around; + gap: 8px; +} + +.set-panel button{ + margin: 0px; } .board-panel{