From 643ac28e6f8ede4518c5ea0a88833403996513dc Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 8 Mar 2024 22:43:41 +0700 Subject: [PATCH] delete chain ui --- src/features/delete-chain/index.ts | 1 + .../delete-chain/ui/DeleteChainButton.tsx | 85 +++++++++++++++++++ src/widgets/chain-buttons/ui/ChainButtons.tsx | 4 +- 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/features/delete-chain/index.ts create mode 100644 src/features/delete-chain/ui/DeleteChainButton.tsx diff --git a/src/features/delete-chain/index.ts b/src/features/delete-chain/index.ts new file mode 100644 index 0000000..e7f1ff6 --- /dev/null +++ b/src/features/delete-chain/index.ts @@ -0,0 +1 @@ +export { default as DeleteChainButton } from "./ui/DeleteChainButton"; diff --git a/src/features/delete-chain/ui/DeleteChainButton.tsx b/src/features/delete-chain/ui/DeleteChainButton.tsx new file mode 100644 index 0000000..c71b8fd --- /dev/null +++ b/src/features/delete-chain/ui/DeleteChainButton.tsx @@ -0,0 +1,85 @@ +import type { Chain } from "@/entities/chain/schema"; +import { deleteChainById } from "@/entities/chain/api/delete"; + +import { useState } from "react"; +import { useChainState } from "@/entities/chain/model"; +import { useNavigate } from "@tanstack/react-router"; + +import Dialog from "@mui/material/Dialog"; +import DialogTitle from "@mui/material/DialogTitle"; +import DialogContent from "@mui/material/DialogContent"; +import DialogContentText from "@mui/material/DialogContentText"; +import DialogActions from "@mui/material/DialogActions"; +import { Button } from "@mui/material"; +import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline"; + +interface DeleteChainButtonProps { + chain: Chain; +} + +export default function DeleteChainButton({ chain }: DeleteChainButtonProps) { + const [isOpen, setIsOpen] = useState(false); + const [loading, setLoading] = useState(false); + const deleteChain = useChainState((state) => state.deleteChain); + const navigate = useNavigate({ from: "/$namespace/$chainId" }); + + async function handleDeletion() { + setLoading(true); + + await deleteChainById(chain._id!); + deleteChain(chain._id!); + navigate({ to: "/$namespace" }); + + setLoading(false); + setIsOpen(false); + } + + return ( + <> + + + { + if (!loading) setIsOpen(false); + }} + > + Удаление цепочки + + + + Вы уверены, что хотите удалить эту цепочку? + + + + + + + + + + ); +} diff --git a/src/widgets/chain-buttons/ui/ChainButtons.tsx b/src/widgets/chain-buttons/ui/ChainButtons.tsx index 49c71ad..5bff773 100644 --- a/src/widgets/chain-buttons/ui/ChainButtons.tsx +++ b/src/widgets/chain-buttons/ui/ChainButtons.tsx @@ -1,5 +1,6 @@ import type { Chain } from "@/entities/chain/schema"; import { RenameChainButton } from "@/features/rename-chain"; +import { DeleteChainButton } from "@/features/delete-chain"; interface ChainButtonsProps { chain: Chain; @@ -7,8 +8,9 @@ interface ChainButtonsProps { export default function ChainButtons({ chain }: ChainButtonsProps) { return ( -
+
+
); }