Deleting a row and sending backend request for tariffs.
This commit is contained in:
parent
c98c078be6
commit
607887bce8
@ -94,6 +94,30 @@ export default function TariffsDG({ selectedTariffs, handleSelectionChange }: Pr
|
||||
}
|
||||
};
|
||||
|
||||
const tariffDeleteDataGrid = async (tarifIid: string) => {
|
||||
if (exampleTariffs.find((tariff) => tariff.id === tarifIid)) {
|
||||
deleteTariffs(tarifIid);
|
||||
enqueueSnackbar("Тариф удалён");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await axios({
|
||||
method: "delete",
|
||||
url: "https://admin.pena.digital/strator/tariff",
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
data: { id: tarifIid },
|
||||
});
|
||||
setDeletedRows((prevDeletedRows) => [...prevDeletedRows, tarifIid]);
|
||||
enqueueSnackbar("Тариф удалён");
|
||||
} catch (error: any) {
|
||||
setErrorDelete(true);
|
||||
enqueueSnackbar("Ошибка удаления :", error.message);
|
||||
}
|
||||
};
|
||||
|
||||
const tariffDelete = async (tarifIid: GridSelectionModel) => {
|
||||
const deleted = [];
|
||||
const notDeleted = [];
|
||||
@ -165,7 +189,7 @@ export default function TariffsDG({ selectedTariffs, handleSelectionChange }: Pr
|
||||
return (
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
tariffDelete(row.id);
|
||||
tariffDeleteDataGrid(row.id);
|
||||
}}
|
||||
>
|
||||
<BackspaceIcon />
|
||||
@ -224,6 +248,7 @@ export default function TariffsDG({ selectedTariffs, handleSelectionChange }: Pr
|
||||
return (
|
||||
<>
|
||||
<DataGrid
|
||||
disableSelectionOnClick={true}
|
||||
checkboxSelection={true}
|
||||
rows={gridData}
|
||||
columns={columns}
|
||||
|
Loading…
Reference in New Issue
Block a user