diff --git a/src/features/change-wait-for/index.ts b/src/features/change-wait-for/index.ts new file mode 100644 index 0000000..625b443 --- /dev/null +++ b/src/features/change-wait-for/index.ts @@ -0,0 +1 @@ +export { default as ChangeWaitForButton } from "./ui/ChangeWaitForButton"; diff --git a/src/features/change-wait-for/ui/ChangeWaitForButton.tsx b/src/features/change-wait-for/ui/ChangeWaitForButton.tsx new file mode 100644 index 0000000..c040cde --- /dev/null +++ b/src/features/change-wait-for/ui/ChangeWaitForButton.tsx @@ -0,0 +1,157 @@ +import { upsertChain } from "@/entities/chain/api/upsert"; +import type { WaitAction } from "@/entities/action/schema"; +import SettingsIcon from "@mui/icons-material/Settings"; + +import { useState } from "react"; +import { useNavigate } from "@tanstack/react-router"; +import { useChainState } from "@/entities/chain/model"; + +import { + Dialog, + DialogContent, + Typography, + TextField, + FormControl, + Select, + MenuItem, + InputLabel, + DialogActions, + Button, +} from "@mui/material"; + +interface ChangeWaitForButtonProps { + chainId: string; + actionIndex: number; + action: WaitAction; +} + +export default function ChangeWaitForButton({ + chainId, + actionIndex, + action, +}: ChangeWaitForButtonProps) { + const [isOpen, setIsOpen] = useState(false); + const [isError, setIsError] = useState(false); + const [loading, setLoading] = useState(false); + + const navigate = useNavigate({ from: "/$namespace/$chainId" }); + const getChain = useChainState((state) => state.getChain); + const updateAction = useChainState((state) => state.updateAction); + + const [waitType, setWaitType] = useState<"seconds" | "minutes">( + action.waitFor! >= 60 ? "minutes" : "seconds", + ); + + const [waitFor, setWaitFor] = useState( + action.waitFor >= 60 ? action.waitFor / 60 : action.waitFor, + ); + + async function handleSave() { + setLoading(true); + let cleanWaitFor: number; + + if (waitFor === "") { + cleanWaitFor = 1; + } else if (typeof waitFor === "string") { + cleanWaitFor = parseInt(waitFor); + } else { + cleanWaitFor = waitFor; + } + + action.waitFor = waitType === "seconds" ? cleanWaitFor : cleanWaitFor * 60; + updateAction(chainId, actionIndex, action); + + const chain = getChain(chainId)!; + const upsertedChain = await upsertChain(chain); + setLoading(false); + + if (upsertedChain) { + navigate({ to: "/$namespace/$chainId" }); + setIsOpen(false); + return; + } + + setIsError(true); + } + + return ( + <> + + setIsOpen(false)}> + +
+
+ + Тайминг + + + + Отправить через + +
+ +
+ setWaitFor(event.target.value)} + /> + + + Тип + + +
+
+
+ + + + + + +
+ + ); +}