From 7974bfd16e6423b5c7ad23a19750da8d1a42d39a Mon Sep 17 00:00:00 2001
From: dklimpel <5740567+dklimpel@users.noreply.github.com>
Date: Wed, 6 May 2020 07:41:16 +0200
Subject: [PATCH] Add ServerNoticeBulkButton
Seperate ServerNoticeButton and ServerNoticeBulkButton into two button.
ServerNoticeButton for 'create' ServerNotice and ServerNoticeBulkButton
for 'createMany' ServerNotices.
---
src/components/ServerNotices.js | 95 ++++++++++++++++++++-------------
src/components/users.js | 4 +-
2 files changed, 61 insertions(+), 38 deletions(-)
diff --git a/src/components/ServerNotices.js b/src/components/ServerNotices.js
index 39864cf..2a3e8bd 100644
--- a/src/components/ServerNotices.js
+++ b/src/components/ServerNotices.js
@@ -6,6 +6,7 @@ import {
TextInput,
Toolbar,
required,
+ useCreate,
useMutation,
useNotify,
useTranslate,
@@ -60,50 +61,72 @@ const ServerNoticeDialog = ({ open, loading, onClose, onSend }) => {
);
};
-export const ServerNoticeButton = ({ record, selectedIds }) => {
+export const ServerNoticeButton = ({ record }) => {
const [open, setOpen] = useState(false);
const notify = useNotify();
- const unselectAll = useUnselectAll();
- const [create, { loading }] = useMutation();
+ const [create, { loading }] = useCreate("servernotices");
const handleDialogOpen = () => setOpen(true);
const handleDialogClose = () => setOpen(false);
const handleSend = values => {
- if (record) {
- create(
- {
- type: "create",
- resource: "servernotices",
- payload: { data: { id: record.id, ...values } },
+ create(
+ { payload: { data: { id: record.id, ...values } } },
+ {
+ onSuccess: () => {
+ notify("resources.servernotices.action.send_success");
+ handleDialogClose();
},
- {
- onSuccess: () => {
- notify("resources.servernotices.action.send_success");
- handleDialogClose();
- },
- onFailure: () =>
- notify("resources.servernotices.action.send_failure", "error"),
- }
- );
- } else {
- create(
- {
- type: "createMany",
- resource: "servernotices",
- payload: { ids: selectedIds, data: values },
- },
- {
- onSuccess: ({ data }) => {
- notify("resources.servernotices.action.send_success");
- unselectAll("users");
- handleDialogClose();
- },
- onFailure: error =>
- notify("resources.servernotices.action.send_failure", "error"),
- }
- );
- }
+ onFailure: () =>
+ notify("resources.servernotices.action.send_failure", "error"),
+ }
+ );
+ };
+
+ return (
+
+
+
+
+ );
+};
+
+export const ServerNoticeBulkButton = ({ selectedIds }) => {
+ const [open, setOpen] = useState(false);
+ const notify = useNotify();
+ const unselectAll = useUnselectAll();
+ const [createMany, { loading }] = useMutation();
+
+ const handleDialogOpen = () => setOpen(true);
+ const handleDialogClose = () => setOpen(false);
+
+ const handleSend = values => {
+ createMany(
+ {
+ type: "createMany",
+ resource: "servernotices",
+ payload: { ids: selectedIds, data: values },
+ },
+ {
+ onSuccess: ({ data }) => {
+ notify("resources.servernotices.action.send_success");
+ unselectAll("users");
+ handleDialogClose();
+ },
+ onFailure: error =>
+ notify("resources.servernotices.action.send_failure", "error"),
+ }
+ );
};
return (
diff --git a/src/components/users.js b/src/components/users.js
index 616f699..16167a0 100644
--- a/src/components/users.js
+++ b/src/components/users.js
@@ -30,7 +30,7 @@ import {
useTranslate,
Pagination,
} from "react-admin";
-import { ServerNoticeButton } from "./ServerNotices";
+import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices";
const UserPagination = props => (
@@ -51,7 +51,7 @@ const UserBulkActionButtons = props => {
const translate = useTranslate();
return (
-
+