Fix yarn test in devices.js
This commit is contained in:
parent
f92173b1cb
commit
6916380c8b
@ -1,96 +1,96 @@
|
|||||||
import React, { Fragment, useState } from "react";
|
import React, { Fragment, useState } from "react";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
useMutation,
|
useMutation,
|
||||||
useNotify,
|
useNotify,
|
||||||
useTranslate,
|
useTranslate,
|
||||||
Confirm,
|
Confirm,
|
||||||
useRefresh,
|
useRefresh,
|
||||||
} from "react-admin";
|
} from "react-admin";
|
||||||
import ActionDelete from "@material-ui/icons/Delete";
|
import ActionDelete from "@material-ui/icons/Delete";
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
import { fade } from "@material-ui/core/styles/colorManipulator";
|
import { fade } from "@material-ui/core/styles/colorManipulator";
|
||||||
import classnames from "classnames";
|
import classnames from "classnames";
|
||||||
|
|
||||||
export const RemoveDeviceButton = props => {
|
export const RemoveDeviceButton = props => {
|
||||||
const { record } = props;
|
const { record } = props;
|
||||||
const classes = useStyles(props);
|
const classes = useStyles(props);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const translate = useTranslate();
|
const translate = useTranslate();
|
||||||
const refresh = useRefresh();
|
const refresh = useRefresh();
|
||||||
const notify = useNotify();
|
const notify = useNotify();
|
||||||
|
|
||||||
const [removeDevice, { loading }] = useMutation();
|
const [removeDevice, { loading }] = useMutation();
|
||||||
const handleSend = values => {
|
const handleSend = values => {
|
||||||
removeDevice(
|
removeDevice(
|
||||||
{
|
{
|
||||||
type: "removeDevice",
|
type: "removeDevice",
|
||||||
resource: "devices",
|
resource: "devices",
|
||||||
payload: {
|
payload: {
|
||||||
user_id: record.user_id,
|
user_id: record.user_id,
|
||||||
device_id: record.device_id,
|
device_id: record.device_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
notify("resources.devices.action.remove_success");
|
notify("resources.devices.action.remove_success");
|
||||||
refresh();
|
refresh();
|
||||||
},
|
},
|
||||||
onFailure: () =>
|
onFailure: () =>
|
||||||
notify("resources.devices.action.remove_failure", "error"),
|
notify("resources.devices.action.remove_failure", "error"),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClick = () => setOpen(true);
|
const handleClick = () => setOpen(true);
|
||||||
const handleDialogClose = () => setOpen(false);
|
const handleDialogClose = () => setOpen(false);
|
||||||
|
|
||||||
const handleConfirm = () => {
|
const handleConfirm = () => {
|
||||||
handleSend();
|
handleSend();
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<Button
|
<Button
|
||||||
label="ra.action.remove"
|
label="ra.action.remove"
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
className={classnames("ra-delete-button", classes.deleteButton)}
|
className={classnames("ra-delete-button", classes.deleteButton)}
|
||||||
>
|
>
|
||||||
<ActionDelete />
|
<ActionDelete />
|
||||||
</Button>
|
</Button>
|
||||||
<Confirm
|
<Confirm
|
||||||
isOpen={open}
|
isOpen={open}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
title="resources.devices.action.remove_title"
|
title="resources.devices.action.remove_title"
|
||||||
content="resources.devices.action.remove_content"
|
content="resources.devices.action.remove_content"
|
||||||
onConfirm={handleConfirm}
|
onConfirm={handleConfirm}
|
||||||
onClose={handleDialogClose}
|
onClose={handleDialogClose}
|
||||||
translateOptions={{
|
translateOptions={{
|
||||||
name: translate(`resources.devices.name`, {
|
name: translate(`resources.devices.name`, {
|
||||||
smart_count: 1,
|
smart_count: 1,
|
||||||
}),
|
}),
|
||||||
display_name: translate(`resources.devices.fields.display_name`),
|
display_name: translate(`resources.devices.fields.display_name`),
|
||||||
id: record.device_id,
|
id: record.device_id,
|
||||||
displayname: record.display_name,
|
displayname: record.display_name,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const useStyles = makeStyles(
|
const useStyles = makeStyles(
|
||||||
theme => ({
|
theme => ({
|
||||||
deleteButton: {
|
deleteButton: {
|
||||||
color: theme.palette.error.main,
|
color: theme.palette.error.main,
|
||||||
"&:hover": {
|
"&:hover": {
|
||||||
backgroundColor: fade(theme.palette.error.main, 0.12),
|
backgroundColor: fade(theme.palette.error.main, 0.12),
|
||||||
// Reset on mouse devices
|
// Reset on mouse devices
|
||||||
"@media (hover: none)": {
|
"@media (hover: none)": {
|
||||||
backgroundColor: "transparent",
|
backgroundColor: "transparent",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
{ name: "RaDeleteDeviceButton" }
|
{ name: "RaDeleteDeviceButton" }
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user