// @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 { arrayBuffer } from "stream/consumers"; import { useGetTariffs } from "@root/hooks/useGetTariffs.hook"; 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: true, privilegies: [privilege] }, }); } interface Props { tariff: Tariff } export default function EditModal({tariff = undefined}:Props) { console.log(tariff) 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 const { requestTariffs } = useGetTariffs() 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" }} /> )} }