import * as React from "react"; import { Box, Modal, Fade, Backdrop, Typography, Button, TextField } from "@mui/material"; import { ArrayProps } from "../types"; import useStore, { StoreState } from "../../../../../store"; import theme from "../../../../../theme"; export interface MWProps { open: boolean type: number variant: number close: () => void } const ModalMini = ({open, type, variant, close}: MWProps ) => { let tariffsArray:Array = useStore((state) => state.tariffsArray); const { tariffsArraySet } = useStore((state) => state); 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 getData = localStorage.getItem("tariffs"); if( getData != null ) { tariffsArray = JSON.parse(getData); } const data = [ "", "", "" ]; if( variant == 0 ) { data[ 0 ] = fieldTime.current.value; } if( variant == 1 ) { data[ 1 ] = fieldTime.current.value; } if( variant == 2 ) { data[ 2 ] = 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 } ]; tariffsArraySet( tariffsArrayNew ); localStorage.setItem( "tariffs", JSON.stringify( tariffsArrayNew ) ); close(); console.log( tariffsArrayNew ); } } } return ( close() } closeAfterTransition BackdropComponent={Backdrop} BackdropProps={{ timeout: 500, }} > ); } export default ModalMini;