mirror of
https://github.com/Awesome-Technologies/synapse-admin.git
synced 2024-10-31 06:55:15 +03:00
Simplify DeviceRemoveButton
Change-Id: I23dcb327d2612db7fc132889d623b709dce34f06
This commit is contained in:
parent
9d26a1ce3a
commit
abc677dc16
1 changed files with 16 additions and 43 deletions
|
@ -1,29 +1,21 @@
|
||||||
import React, { useState } from "react";
|
import React from "react";
|
||||||
import {
|
import {
|
||||||
Button,
|
DeleteButton,
|
||||||
useDelete,
|
useDelete,
|
||||||
useNotify,
|
useNotify,
|
||||||
Confirm,
|
|
||||||
useRecordContext,
|
useRecordContext,
|
||||||
useRefresh,
|
useRefresh,
|
||||||
} from "react-admin";
|
} from "react-admin";
|
||||||
import ActionDelete from "@mui/icons-material/Delete";
|
|
||||||
import { alpha, useTheme } from "@mui/material/styles";
|
|
||||||
|
|
||||||
export const DeviceRemoveButton = props => {
|
export const DeviceRemoveButton = props => {
|
||||||
const theme = useTheme();
|
|
||||||
const record = useRecordContext();
|
const record = useRecordContext();
|
||||||
const [open, setOpen] = useState(false);
|
|
||||||
const refresh = useRefresh();
|
const refresh = useRefresh();
|
||||||
const notify = useNotify();
|
const notify = useNotify();
|
||||||
|
|
||||||
const [removeDevice, { isLoading }] = useDelete();
|
const [removeDevice] = useDelete();
|
||||||
|
|
||||||
if (!record) return null;
|
if (!record) return null;
|
||||||
|
|
||||||
const handleClick = () => setOpen(true);
|
|
||||||
const handleDialogClose = () => setOpen(false);
|
|
||||||
|
|
||||||
const handleConfirm = () => {
|
const handleConfirm = () => {
|
||||||
removeDevice(
|
removeDevice(
|
||||||
"devices",
|
"devices",
|
||||||
|
@ -39,40 +31,21 @@ export const DeviceRemoveButton = props => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
setOpen(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<DeleteButton
|
||||||
<Button
|
{...props}
|
||||||
{...props}
|
label="ra.action.remove"
|
||||||
label="ra.action.remove"
|
confirmTitle="resources.devices.action.erase.title"
|
||||||
onClick={handleClick}
|
confirmContent="resources.devices.action.erase.content"
|
||||||
sx={{
|
onConfirm={handleConfirm}
|
||||||
color: theme.palette.error.main,
|
mutationMode="pessimistic"
|
||||||
"&:hover": {
|
redirect={false}
|
||||||
backgroundColor: alpha(theme.palette.error.main, 0.12),
|
translateOptions={{
|
||||||
// Reset on mouse devices
|
id: record.id,
|
||||||
"@media (hover: none)": {
|
name: record.display_name ? record.display_name : record.id,
|
||||||
backgroundColor: "transparent",
|
}}
|
||||||
},
|
/>
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<ActionDelete />
|
|
||||||
</Button>
|
|
||||||
<Confirm
|
|
||||||
isOpen={open}
|
|
||||||
loading={isLoading}
|
|
||||||
onConfirm={handleConfirm}
|
|
||||||
onClose={handleDialogClose}
|
|
||||||
title="resources.devices.action.erase.title"
|
|
||||||
content="resources.devices.action.erase.content"
|
|
||||||
translateOptions={{
|
|
||||||
id: record.id,
|
|
||||||
name: record.display_name ? record.display_name : record.id,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue