diff --git a/src/components/App/App.jsx b/src/components/App/App.jsx index 7da5545..b6eaece 100644 --- a/src/components/App/App.jsx +++ b/src/components/App/App.jsx @@ -6,7 +6,7 @@ import { refreshUser, getUserInfo } from "../../redux/auth/operations"; import { selectIsRefreshing, selectIsLoggedIn, -} from "../../redux/auth/selectror"; +} from "../../redux/auth/selectors"; import RestrictedRoute from "../RestrictedRoute/RestrictedRoute"; import PrivateRoute from "../PrivateRoute/PrivateRoute"; @@ -68,5 +68,4 @@ export const App = () => { )} > ); - }; diff --git a/src/components/Board/Board.jsx b/src/components/Board/Board.jsx index 37c5bf8..d4e1f85 100644 --- a/src/components/Board/Board.jsx +++ b/src/components/Board/Board.jsx @@ -1,11 +1,24 @@ import { useState } from "react"; import EditBoardModal from "../EditBoardModal/EditBoardModal"; +import { useDispatch } from "react-redux"; +import { deleteBoard, getBoards } from "../../redux/boards/operations"; +import toast from "react-hot-toast"; import svg from "../../img/icons.svg"; import css from "./Board.module.css"; -export default function Board({ title, icon, background }) { +export default function Board({ board }) { + const { _id, title, icon, background } = board; const [isModalOpen, setIsModalOpen] = useState(false); + const dispatch = useDispatch(); + + const boardDeleteNotify = () => + toast.error(`You deleted the board ${board.title}`); + const handleDelete = () => { + dispatch(deleteBoard(_id)); + dispatch(getBoards()); + boardDeleteNotify(); + }; const openModal = () => { setIsModalOpen(true); @@ -15,43 +28,40 @@ export default function Board({ title, icon, background }) { setIsModalOpen(false); }; - // local storage - start - тут буде dispatch - const deleteHandler = () => { - const storedData = JSON.parse(localStorage.getItem("boardData")); - const updatedData = storedData.filter((board) => board.title !== title); - localStorage.setItem("boardData", JSON.stringify(updatedData)); - }; - // / local storage - start - return ( -