2023-06-12 13:48:06 +00:00
|
|
|
|
import * as React 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";
|
2023-06-14 12:17:54 +00:00
|
|
|
|
import { GridSelectionModel } from "@mui/x-data-grid";
|
2023-07-03 16:56:30 +00:00
|
|
|
|
import { useTariffStore } from "@root/stores/tariffsStore";
|
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
|
|
|
|
import axios from "axios";
|
|
|
|
|
import { authStore } from "@root/stores/auth";
|
|
|
|
|
import { useGetTariffs } from "@root/hooks/useGetTariffs.hook";
|
2023-06-12 13:48:06 +00:00
|
|
|
|
|
|
|
|
|
type DeleteModalProps = {
|
2023-07-03 16:56:30 +00:00
|
|
|
|
open: boolean | string;
|
2023-06-12 13:48:06 +00:00
|
|
|
|
handleClose: () => void;
|
2023-07-03 16:56:30 +00:00
|
|
|
|
selectedTariffs: any;
|
2023-06-12 13:48:06 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default function DeleteModal({
|
|
|
|
|
open,
|
|
|
|
|
handleClose,
|
2023-07-03 16:56:30 +00:00
|
|
|
|
selectedTariffs
|
2023-06-12 13:48:06 +00:00
|
|
|
|
}: DeleteModalProps) {
|
2023-07-03 16:56:30 +00:00
|
|
|
|
const { requestTariffs } = useGetTariffs()
|
|
|
|
|
const { token } = authStore();
|
|
|
|
|
const tariffs = useTariffStore((state) => state.tariffs);
|
|
|
|
|
|
|
|
|
|
const deleteTariff = async (id: string): Promise<void> => {
|
|
|
|
|
const currentTariff = tariffs[id]
|
|
|
|
|
|
|
|
|
|
if (!currentTariff) {
|
|
|
|
|
enqueueSnackbar("Тариф не найден");
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await axios.delete("https://admin.pena.digital/strator/tariff/", {
|
|
|
|
|
data: { id },
|
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
|
});
|
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
|
|
enqueueSnackbar("Ошибка при удалении тарифа на бэкэнде");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-12 13:48:06 +00:00
|
|
|
|
const onClickTariffDelete = () => {
|
2023-07-03 16:56:30 +00:00
|
|
|
|
if (typeof open === 'string' ) {
|
|
|
|
|
deleteTariff(open)
|
|
|
|
|
requestTariffs()
|
|
|
|
|
handleClose();
|
|
|
|
|
return
|
2023-06-12 13:48:06 +00:00
|
|
|
|
}
|
2023-07-03 16:56:30 +00:00
|
|
|
|
selectedTariffs.forEach((id:string) => {
|
|
|
|
|
deleteTariff(id)
|
|
|
|
|
})
|
2023-06-12 13:48:06 +00:00
|
|
|
|
handleClose();
|
2023-07-03 16:56:30 +00:00
|
|
|
|
requestTariffs()
|
2023-06-12 13:48:06 +00:00
|
|
|
|
};
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<Modal
|
2023-07-03 16:56:30 +00:00
|
|
|
|
open={Boolean(open)}
|
2023-06-12 13:48:06 +00:00
|
|
|
|
onClose={handleClose}
|
|
|
|
|
aria-labelledby="modal-modal-title"
|
|
|
|
|
aria-describedby="modal-modal-description"
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: "50%",
|
|
|
|
|
left: "50%",
|
|
|
|
|
transform: "translate(-50%, -50%)",
|
|
|
|
|
width: 400,
|
|
|
|
|
bgcolor: "background.paper",
|
|
|
|
|
border: "2px solid gray",
|
|
|
|
|
borderRadius: "6px",
|
|
|
|
|
boxShadow: 24,
|
|
|
|
|
p: 4,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography id="modal-modal-title" variant="h6" component="h2">
|
2023-07-03 16:56:30 +00:00
|
|
|
|
Вы уверены, что хотите удалить {typeof open === 'string' ? "тариф" : "тарифы"} ?
|
2023-06-12 13:48:06 +00:00
|
|
|
|
</Typography>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{ mt: "20px", display: "flex", width: "332px", justifyContent: "space-between", alignItems: "center" }}
|
|
|
|
|
>
|
|
|
|
|
<Button onClick={() => onClickTariffDelete()} sx={{ width: "40px", height: "25px" }}>
|
|
|
|
|
Да
|
|
|
|
|
</Button>
|
2023-07-03 16:56:30 +00:00
|
|
|
|
{/* <Typography>Тариф:</Typography>
|
2023-06-14 12:17:54 +00:00
|
|
|
|
{tariffName.map((name, index) => (
|
|
|
|
|
<Typography key={index}>{name};</Typography>
|
2023-07-03 16:56:30 +00:00
|
|
|
|
))} */}
|
2023-06-12 13:48:06 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
</Modal>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|