// @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 { authStore } from "@root/stores/auth"; import { Privilege, Tariff } from "@root/model/tariff"; import { useTariffStore } from "@root/stores/tariffsStore"; import { findPrivilegeById } from "@root/stores/privilegesStore"; import { requestTariffs } from "@root/services/tariffs.service"; import { enqueueSnackbar } from "notistack"; interface EditProps { tarifIid: string; tariffName: string; tariffPrice: number; privilege: Privilege; } type EditTariffBackendRequest = { name: string; price: number; isCustom: boolean; privilegies: Omit[]; }; const baseUrl = process.env.NODE_ENV === "production" ? "/strator" : "https://admin.pena.digital/strator"; const editTariff = ({ tarifIid, tariffName, tariffPrice, privilege }: EditProps): Promise => { const { makeRequest } = authStore.getState(); return makeRequest({ method: "put", url: baseUrl + `/tariff/${tarifIid}`, bearer: true, body: { name: tariffName, price: tariffPrice, isCustom: false, privilegies: [privilege], }, }); }; interface Props { tariff: Tariff; } export default function EditModal({ tariff = undefined }: Props) { const [open, setOpen] = useState(false); const [name, setName] = useState(""); const [price, setPrice] = useState(""); 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" }} /> )} ); }