From 4204eb902fa4ba41f11e042366e4116e98e35531 Mon Sep 17 00:00:00 2001 From: Manuel Stahl Date: Tue, 6 Feb 2024 14:17:00 +0100 Subject: [PATCH] Refactor ServerNotices https://marmelab.com/react-admin/Upgrade.html#usequery-usemutation-and-usequerywithstore-have-been-removed Change-Id: Id12f727d8813f78c3ae300035aeb1333a1272e02 --- src/components/ServerNotices.js | 56 ++++++++++++++++----------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/src/components/ServerNotices.js b/src/components/ServerNotices.js index f2c8fcb..ab15825 100644 --- a/src/components/ServerNotices.js +++ b/src/components/ServerNotices.js @@ -7,6 +7,7 @@ import { Toolbar, required, useCreate, + useDataProvider, useListContext, useNotify, useRecordContext, @@ -47,11 +48,7 @@ const ServerNoticeDialog = ({ open, loading, onClose, onSubmit }) => { {translate("resources.servernotices.helper.send")} - } - redirect={false} - onSubmit={onSubmit} - > + } onSubmit={onSubmit}> { export const ServerNoticeBulkButton = () => { const { selectedIds } = useListContext(); const [open, setOpen] = useState(false); + const openDialog = () => setOpen(true); + const closeDialog = () => setOpen(false); const notify = useNotify(); const unselectAllUsers = useUnselectAll("users"); - const { createMany, isloading } = useMutation(); + const dataProvider = useDataProvider(); - const handleDialogOpen = () => setOpen(true); - const handleDialogClose = () => setOpen(false); - - const handleSend = values => { - createMany( - ["servernotices", "createMany", { ids: selectedIds, data: values }], - { - onSuccess: data => { - notify("resources.servernotices.action.send_success"); - unselectAllUsers(); - handleDialogClose(); - }, - onError: error => - notify("resources.servernotices.action.send_failure", { - type: "error", - }), - } - ); - }; + const { mutate: sendNotices, isLoading } = useMutation( + data => + dataProvider.createMany("servernotices", { + ids: selectedIds, + data: data, + }), + { + onSuccess: () => { + notify("resources.servernotices.action.send_success"); + unselectAllUsers(); + closeDialog(); + }, + onError: () => + notify("resources.servernotices.action.send_failure", { + type: "error", + }), + } + ); return ( <> );