feat: board deletion
This commit is contained in:
@ -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