import * as React from "react"; import { Box, Modal, Fade, Backdrop, Button, TextField } from "@mui/material"; import theme from "../../../../../theme"; import { ArrayProps } from "../../../../../model/tariff"; import { useTariffStore } from "../../../../../stores/tariffs"; export interface MWProps { open: boolean; type: number; variant: number; close: () => void; } const ModalMini = ({ open, type, variant, close }: MWProps) => { let tariffsArray = useTariffStore(state => state.tariffs); const tariffsArraySet = useTariffStore(state => state.setTariffs); const types = ["", "Шаблонизатор документов", "Опросник", "Сокращатель ссылок"]; const variants = ["Количество", "Срок (дней)", "Количество (гб)"]; const fieldName = React.useRef(null); const fieldTime = React.useRef(null); const fieldPrice = React.useRef(null); const checkTariff = () => { if (fieldName.current != null && fieldTime.current != null && fieldPrice.current != null) { if (fieldName.current.value && fieldTime.current.value && fieldPrice.current.value) { const data = [0, 0, 0]; if (variant === 0) { data[0] = parseInt(fieldTime.current.value); } if (variant === 1) { data[1] = parseInt(fieldTime.current.value); } if (variant === 2) { data[2] = parseInt(fieldTime.current.value); } const tariffsArrayNew = [...tariffsArray, { "id": new Date().getTime(), "name": fieldName.current.value, "type": "tariff", "service": types[type], "disk": data[2], "time": data[1], "points": data[0], "price": +fieldPrice.current.value } as ArrayProps]; tariffsArraySet(tariffsArrayNew); close(); } } }; return ( close()} closeAfterTransition BackdropComponent={Backdrop} BackdropProps={{ timeout: 500, }} > ); }; export default ModalMini;