2023-06-12 13:48:06 +00:00
|
|
|
|
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-08-02 11:36:50 +00:00
|
|
|
|
import { closeDeleteTariffDialog, useTariffStore } from "@root/stores/tariffs";
|
2023-07-12 13:31:35 +00:00
|
|
|
|
import { requestTariffs } from "@root/services/tariffs.service";
|
2023-07-03 16:56:30 +00:00
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
2023-08-02 11:36:50 +00:00
|
|
|
|
import { deleteManyTariffs } from "@root/api/tariffs";
|
|
|
|
|
import { devlog } from "@frontend/kitui";
|
2023-06-12 13:48:06 +00:00
|
|
|
|
|
|
|
|
|
|
2023-08-02 11:36:50 +00:00
|
|
|
|
export default function DeleteModal() {
|
|
|
|
|
const deleteTariffIds = useTariffStore(state => state.deleteTariffIds);
|
2023-07-12 10:27:21 +00:00
|
|
|
|
|
2023-08-02 11:36:50 +00:00
|
|
|
|
async function handleTariffDeleteClick() {
|
|
|
|
|
if (!deleteTariffIds?.length) return;
|
2023-07-12 10:27:21 +00:00
|
|
|
|
|
2023-08-02 11:36:50 +00:00
|
|
|
|
const results = await deleteManyTariffs(deleteTariffIds);
|
2023-07-03 16:56:30 +00:00
|
|
|
|
|
2023-08-02 11:36:50 +00:00
|
|
|
|
enqueueSnackbar(`Тарифов удалено: ${results.deletedCount}, ошибок: ${results.errorCount}`);
|
|
|
|
|
if (results.errors.length) devlog("Errors deleting tariffs", results.errors);
|
|
|
|
|
closeDeleteTariffDialog();
|
2023-07-03 16:56:30 +00:00
|
|
|
|
|
2023-08-02 11:36:50 +00:00
|
|
|
|
requestTariffs();
|
|
|
|
|
};
|
2023-07-03 16:56:30 +00:00
|
|
|
|
|
2023-08-02 11:36:50 +00:00
|
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
open={Boolean(deleteTariffIds?.length)}
|
|
|
|
|
onClose={closeDeleteTariffDialog}
|
|
|
|
|
aria-labelledby="modal-modal-title"
|
|
|
|
|
aria-describedby="modal-modal-description"
|
2023-06-12 13:48:06 +00:00
|
|
|
|
>
|
2023-08-02 11:36:50 +00:00
|
|
|
|
<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,
|
|
|
|
|
}}
|
2023-07-11 14:42:18 +00:00
|
|
|
|
>
|
2023-08-02 11:36:50 +00:00
|
|
|
|
<Typography id="modal-modal-title" variant="h6" component="h2">
|
|
|
|
|
Вы уверены, что хотите удалить тариф(ы)?
|
|
|
|
|
</Typography>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
mt: "20px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
width: "332px",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={() => handleTariffDeleteClick()}
|
|
|
|
|
sx={{ width: "40px", height: "25px" }}
|
|
|
|
|
>
|
|
|
|
|
Да
|
|
|
|
|
</Button>
|
|
|
|
|
{/* <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-08-02 11:36:50 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
2023-06-12 13:48:06 +00:00
|
|
|
|
}
|