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 tariffDelete = async (tarifIid: GridSelectionModel) => {
|
||||||
const deleted = [];
|
const deleted = [];
|
||||||
const notDeleted = [];
|
const notDeleted = [];
|
||||||
@ -165,7 +189,7 @@ export default function TariffsDG({ selectedTariffs, handleSelectionChange }: Pr
|
|||||||
return (
|
return (
|
||||||
<IconButton
|
<IconButton
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
tariffDelete(row.id);
|
tariffDeleteDataGrid(row.id);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<BackspaceIcon />
|
<BackspaceIcon />
|
||||||
@ -224,6 +248,7 @@ export default function TariffsDG({ selectedTariffs, handleSelectionChange }: Pr
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DataGrid
|
<DataGrid
|
||||||
|
disableSelectionOnClick={true}
|
||||||
checkboxSelection={true}
|
checkboxSelection={true}
|
||||||
rows={gridData}
|
rows={gridData}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
|
Loading…
Reference in New Issue
Block a user