feat: board deletion
This commit is contained in:
@ -10,7 +10,7 @@ type Props = {
|
||||
|
||||
const Board: FC<Props> = ({ board }) => {
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
const { selectedBoard } = useBoardsContext();
|
||||
const { selectedBoard, onDeleteBoardClick } = useBoardsContext();
|
||||
|
||||
return (
|
||||
<Group
|
||||
@ -47,7 +47,7 @@ const Board: FC<Props> = ({ board }) => {
|
||||
<Text>Переименовать</Text>
|
||||
</Group>
|
||||
</Menu.Item>
|
||||
<Menu.Item>
|
||||
<Menu.Item onClick={() => onDeleteBoardClick(board.id)}>
|
||||
<Group wrap={"nowrap"}>
|
||||
<IconTrash />
|
||||
<Text>Удалить</Text>
|
||||
|
||||
@ -12,7 +12,10 @@ import { LexoRank } from "lexorank";
|
||||
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
|
||||
import useBoardsList from "@/hooks/useBoardsList";
|
||||
import { BoardSchema } from "@/lib/client";
|
||||
import { createBoardMutation } from "@/lib/client/@tanstack/react-query.gen";
|
||||
import {
|
||||
createBoardMutation,
|
||||
deleteBoardMutation,
|
||||
} from "@/lib/client/@tanstack/react-query.gen";
|
||||
import { notifications } from "@/lib/notifications";
|
||||
import { getMaxByLexorank, getNewLexorank } from "@/utils/lexorank";
|
||||
|
||||
@ -23,6 +26,7 @@ type BoardsContextState = {
|
||||
setSelectedBoard: React.Dispatch<React.SetStateAction<BoardSchema | null>>;
|
||||
refetchBoards: () => void;
|
||||
onCreateBoardClick: (name: string) => void;
|
||||
onDeleteBoardClick: (boardId: number) => void;
|
||||
};
|
||||
|
||||
const BoardsContext = createContext<BoardsContextState | undefined>(undefined);
|
||||
@ -86,6 +90,26 @@ const useBoardsContextState = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const deleteBoard = useMutation({
|
||||
...deleteBoardMutation(),
|
||||
onError: error => {
|
||||
console.error(error);
|
||||
notifications.error({
|
||||
message: error.response?.data?.detail as string | undefined,
|
||||
});
|
||||
refetchBoards();
|
||||
},
|
||||
});
|
||||
|
||||
const onDeleteBoardClick = (boardId: number) => {
|
||||
deleteBoard.mutate({
|
||||
path: {
|
||||
boardId,
|
||||
},
|
||||
});
|
||||
setBoards(boards => boards.filter(board => board.id !== boardId));
|
||||
};
|
||||
|
||||
return {
|
||||
boards,
|
||||
setBoards,
|
||||
@ -93,6 +117,7 @@ const useBoardsContextState = () => {
|
||||
setSelectedBoard,
|
||||
refetchBoards,
|
||||
onCreateBoardClick,
|
||||
onDeleteBoardClick,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user