// @ts-nocheck import React, { useEffect, useState } from "react"; import Box from "@mui/material/Box"; import Button from "@mui/material/Button"; import Typography from "@mui/material/Typography"; import Modal from "@mui/material/Modal"; import TextField from "@mui/material/TextField"; import axios from "axios"; import { authStore } from "@root/stores/auth"; import { Privilege, Tariff } from "@root/model/tariff"; import { useTariffStore, updateTariff } from "@root/stores/tariffsStore"; import { findPrivilegeById } from "@root/stores/privilegesStore"; import { enqueueSnackbar } from "notistack"; interface EditProps { tarifIid: string; tariffName: string; tariffPrice: number; privilege: Privilege; token: string; } const editTariff = ({ tarifIid, tariffName, tariffPrice, privilege, token, }: EditProps): Promise => { return axios({ method: "put", url: `https://admin.pena.digital/strator/tariff/${tarifIid}`, headers: { Authorization: `Bearer ${token}`, }, data: { name: tariffName, price: tariffPrice, isCustom: false, privilegies: [privilege], }, }); }; interface Props { tariff: Tariff; requestTariffs: () => Promise; } export default function EditModal({ tariff = undefined, requestTariffs, }: Props) { const [open, setOpen] = useState(false); const [name, setName] = useState(""); const [price, setPrice] = useState(""); const { token } = authStore(); const tariffs = useTariffStore((state) => state.tariffs); const currentTariff = tariff ? tariffs[tariff.id] : undefined; useEffect(() => { setOpen(tariff !== undefined); }, [tariff]); return ( setOpen(false)} aria-labelledby="modal-modal-title" aria-describedby="modal-modal-description" > Редактирование тариффа {currentTariff !== undefined && ( Название Тарифа: {currentTariff.name} setName(event.target.value)} label="Имя" name="name" value={name} sx={{ marginBottom: "10px" }} /> Цена за единицу: {currentTariff.pricePerUnit} setPrice(event.target.value)} label="Цена за единицу" name="price" value={price} sx={{ marginBottom: "10px" }} /> )} ); }