From 2e59190bd0ff760d1c0bb992ae23488926797ead Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Tue, 24 Jan 2023 15:24:14 +0100 Subject: [PATCH] Migrate `useMutation` to `useDelete` in `devices.js` (#225) * Migrate `useMutation` to `useDelete` in `devices.js` * Update deprecated `notify` call --- src/components/devices.js | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/components/devices.js b/src/components/devices.js index 5003987..b4cb701 100644 --- a/src/components/devices.js +++ b/src/components/devices.js @@ -1,11 +1,5 @@ import React, { Fragment, useState } from "react"; -import { - Button, - useMutation, - useNotify, - Confirm, - useRefresh, -} from "react-admin"; +import { Button, useDelete, useNotify, Confirm, useRefresh } from "react-admin"; import ActionDelete from "@material-ui/icons/Delete"; import { makeStyles } from "@material-ui/core/styles"; import { alpha } from "@material-ui/core/styles/colorManipulator"; @@ -34,7 +28,7 @@ export const DeviceRemoveButton = props => { const refresh = useRefresh(); const notify = useNotify(); - const [removeDevice, { loading }] = useMutation(); + const [removeDevice, { isLoading }] = useDelete("devices"); if (!record) return null; @@ -43,21 +37,15 @@ export const DeviceRemoveButton = props => { const handleConfirm = () => { removeDevice( - { - type: "delete", - resource: "devices", - payload: { - id: record.id, - user_id: record.user_id, - }, - }, + { payload: { id: record.id, user_id: record.user_id } }, { onSuccess: () => { notify("resources.devices.action.erase.success"); refresh(); }, - onFailure: () => - notify("resources.devices.action.erase.failure", "error"), + onFailure: () => { + notify("resources.devices.action.erase.failure", { type: "error" }); + }, } ); setOpen(false); @@ -74,7 +62,7 @@ export const DeviceRemoveButton = props => {