2024-02-07 16:03:51 +01:00
|
|
|
import React from "react";
|
2023-01-24 16:36:08 +01:00
|
|
|
import {
|
2024-02-07 16:03:51 +01:00
|
|
|
DeleteButton,
|
2023-01-24 16:36:08 +01:00
|
|
|
useDelete,
|
|
|
|
|
useNotify,
|
|
|
|
|
useRecordContext,
|
|
|
|
|
useRefresh,
|
|
|
|
|
} from "react-admin";
|
2020-07-08 11:11:24 +02:00
|
|
|
|
|
|
|
|
export const DeviceRemoveButton = props => {
|
2023-01-24 16:36:08 +01:00
|
|
|
const record = useRecordContext();
|
2020-07-08 11:11:24 +02:00
|
|
|
const refresh = useRefresh();
|
|
|
|
|
const notify = useNotify();
|
|
|
|
|
|
2024-02-07 16:03:51 +01:00
|
|
|
const [removeDevice] = useDelete();
|
2020-07-08 11:11:24 +02:00
|
|
|
|
|
|
|
|
if (!record) return null;
|
|
|
|
|
|
|
|
|
|
const handleConfirm = () => {
|
|
|
|
|
removeDevice(
|
2023-02-08 09:24:02 +01:00
|
|
|
"devices",
|
2024-02-06 11:23:38 +01:00
|
|
|
// needs previousData for user_id
|
|
|
|
|
{ id: record.id, previousData: record },
|
2020-07-08 11:11:24 +02:00
|
|
|
{
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
notify("resources.devices.action.erase.success");
|
|
|
|
|
refresh();
|
|
|
|
|
},
|
2024-02-05 21:44:51 +01:00
|
|
|
onError: () => {
|
2023-01-24 15:24:14 +01:00
|
|
|
notify("resources.devices.action.erase.failure", { type: "error" });
|
|
|
|
|
},
|
2020-07-08 11:11:24 +02:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2024-02-07 16:03:51 +01:00
|
|
|
<DeleteButton
|
|
|
|
|
{...props}
|
|
|
|
|
label="ra.action.remove"
|
|
|
|
|
confirmTitle="resources.devices.action.erase.title"
|
|
|
|
|
confirmContent="resources.devices.action.erase.content"
|
|
|
|
|
onConfirm={handleConfirm}
|
|
|
|
|
mutationMode="pessimistic"
|
|
|
|
|
redirect={false}
|
|
|
|
|
translateOptions={{
|
|
|
|
|
id: record.id,
|
|
|
|
|
name: record.display_name ? record.display_name : record.id,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2020-07-08 11:11:24 +02:00
|
|
|
);
|
|
|
|
|
};
|