import React, { useState } from "react"; import { Button, useDelete, useNotify, Confirm, useRecordContext, useRefresh, } from "react-admin"; import ActionDelete from "@mui/icons-material/Delete"; import { alpha, useTheme } from "@mui/material/styles"; export const DeviceRemoveButton = props => { const theme = useTheme(); const record = useRecordContext(); const [open, setOpen] = useState(false); const refresh = useRefresh(); const notify = useNotify(); const [removeDevice, { isLoading }] = useDelete(); if (!record) return null; const handleClick = () => setOpen(true); const handleDialogClose = () => setOpen(false); const handleConfirm = () => { removeDevice( "devices", { id: record.id, meta: { user_id: record.user_id } }, { onSuccess: () => { notify("resources.devices.action.erase.success"); refresh(); }, onError: () => { notify("resources.devices.action.erase.failure", { type: "error" }); }, } ); setOpen(false); }; return ( <> ); };