diff --git a/src/components/devices.js b/src/components/devices.js index 196f3d8..4929432 100644 --- a/src/components/devices.js +++ b/src/components/devices.js @@ -1,96 +1,96 @@ -import React, { Fragment, useState } from "react"; -import { - Button, - useMutation, - useNotify, - useTranslate, - Confirm, - useRefresh, -} from "react-admin"; -import ActionDelete from "@material-ui/icons/Delete"; -import { makeStyles } from "@material-ui/core/styles"; -import { fade } from "@material-ui/core/styles/colorManipulator"; -import classnames from "classnames"; - -export const RemoveDeviceButton = props => { - const { record } = props; - const classes = useStyles(props); - const [open, setOpen] = useState(false); - const translate = useTranslate(); - const refresh = useRefresh(); - const notify = useNotify(); - - const [removeDevice, { loading }] = useMutation(); - const handleSend = values => { - removeDevice( - { - type: "removeDevice", - resource: "devices", - payload: { - user_id: record.user_id, - device_id: record.device_id, - }, - }, - { - onSuccess: () => { - notify("resources.devices.action.remove_success"); - refresh(); - }, - onFailure: () => - notify("resources.devices.action.remove_failure", "error"), - } - ); - }; - - const handleClick = () => setOpen(true); - const handleDialogClose = () => setOpen(false); - - const handleConfirm = () => { - handleSend(); - setOpen(false); - }; - - return ( - - - - - ); -}; - -const useStyles = makeStyles( - theme => ({ - deleteButton: { - color: theme.palette.error.main, - "&:hover": { - backgroundColor: fade(theme.palette.error.main, 0.12), - // Reset on mouse devices - "@media (hover: none)": { - backgroundColor: "transparent", - }, - }, - }, - }), - { name: "RaDeleteDeviceButton" } -); +import React, { Fragment, useState } from "react"; +import { + Button, + useMutation, + useNotify, + useTranslate, + Confirm, + useRefresh, +} from "react-admin"; +import ActionDelete from "@material-ui/icons/Delete"; +import { makeStyles } from "@material-ui/core/styles"; +import { fade } from "@material-ui/core/styles/colorManipulator"; +import classnames from "classnames"; + +export const RemoveDeviceButton = props => { + const { record } = props; + const classes = useStyles(props); + const [open, setOpen] = useState(false); + const translate = useTranslate(); + const refresh = useRefresh(); + const notify = useNotify(); + + const [removeDevice, { loading }] = useMutation(); + const handleSend = values => { + removeDevice( + { + type: "removeDevice", + resource: "devices", + payload: { + user_id: record.user_id, + device_id: record.device_id, + }, + }, + { + onSuccess: () => { + notify("resources.devices.action.remove_success"); + refresh(); + }, + onFailure: () => + notify("resources.devices.action.remove_failure", "error"), + } + ); + }; + + const handleClick = () => setOpen(true); + const handleDialogClose = () => setOpen(false); + + const handleConfirm = () => { + handleSend(); + setOpen(false); + }; + + return ( + + + + + ); +}; + +const useStyles = makeStyles( + theme => ({ + deleteButton: { + color: theme.palette.error.main, + "&:hover": { + backgroundColor: fade(theme.palette.error.main, 0.12), + // Reset on mouse devices + "@media (hover: none)": { + backgroundColor: "transparent", + }, + }, + }, + }), + { name: "RaDeleteDeviceButton" } +);