From 21f34c283241d7274718242a889d69defe983442 Mon Sep 17 00:00:00 2001 From: Vladiysss <139554971+Vladiysss@users.noreply.github.com> Date: Sat, 7 Mar 2026 14:11:04 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B8=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D1=81=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=D0=B9=20=D0=B4=D0=BE=D1=81=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/KBBoard/BoardLogic.js | 54 +++++++++++++++++-- src/KBBoard/KBBoard.js | 106 ++++++++++++++++++++++++++++++++++---- src/css/Board.css | 7 ++- 3 files changed, 152 insertions(+), 15 deletions(-) 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{