Add ServerNoticeBulkButton
Seperate ServerNoticeButton and ServerNoticeBulkButton into two button. ServerNoticeButton for 'create' ServerNotice and ServerNoticeBulkButton for 'createMany' ServerNotices.
This commit is contained in:
parent
6bd2c0ff19
commit
7974bfd16e
@ -6,6 +6,7 @@ import {
|
|||||||
TextInput,
|
TextInput,
|
||||||
Toolbar,
|
Toolbar,
|
||||||
required,
|
required,
|
||||||
|
useCreate,
|
||||||
useMutation,
|
useMutation,
|
||||||
useNotify,
|
useNotify,
|
||||||
useTranslate,
|
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 [open, setOpen] = useState(false);
|
||||||
const notify = useNotify();
|
const notify = useNotify();
|
||||||
const unselectAll = useUnselectAll();
|
const [create, { loading }] = useCreate("servernotices");
|
||||||
const [create, { loading }] = useMutation();
|
|
||||||
|
|
||||||
const handleDialogOpen = () => setOpen(true);
|
const handleDialogOpen = () => setOpen(true);
|
||||||
const handleDialogClose = () => setOpen(false);
|
const handleDialogClose = () => setOpen(false);
|
||||||
|
|
||||||
const handleSend = values => {
|
const handleSend = values => {
|
||||||
if (record) {
|
create(
|
||||||
create(
|
{ payload: { data: { id: record.id, ...values } } },
|
||||||
{
|
{
|
||||||
type: "create",
|
onSuccess: () => {
|
||||||
resource: "servernotices",
|
notify("resources.servernotices.action.send_success");
|
||||||
payload: { data: { id: record.id, ...values } },
|
handleDialogClose();
|
||||||
},
|
},
|
||||||
{
|
onFailure: () =>
|
||||||
onSuccess: () => {
|
notify("resources.servernotices.action.send_failure", "error"),
|
||||||
notify("resources.servernotices.action.send_success");
|
}
|
||||||
handleDialogClose();
|
);
|
||||||
},
|
};
|
||||||
onFailure: () =>
|
|
||||||
notify("resources.servernotices.action.send_failure", "error"),
|
return (
|
||||||
}
|
<Fragment>
|
||||||
);
|
<Button
|
||||||
} else {
|
label="resources.servernotices.send"
|
||||||
create(
|
onClick={handleDialogOpen}
|
||||||
{
|
disabled={loading}
|
||||||
type: "createMany",
|
>
|
||||||
resource: "servernotices",
|
<MessageIcon />
|
||||||
payload: { ids: selectedIds, data: values },
|
</Button>
|
||||||
},
|
<ServerNoticeDialog
|
||||||
{
|
open={open}
|
||||||
onSuccess: ({ data }) => {
|
onClose={handleDialogClose}
|
||||||
notify("resources.servernotices.action.send_success");
|
onSend={handleSend}
|
||||||
unselectAll("users");
|
/>
|
||||||
handleDialogClose();
|
</Fragment>
|
||||||
},
|
);
|
||||||
onFailure: error =>
|
};
|
||||||
notify("resources.servernotices.action.send_failure", "error"),
|
|
||||||
}
|
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 (
|
return (
|
||||||
|
@ -30,7 +30,7 @@ import {
|
|||||||
useTranslate,
|
useTranslate,
|
||||||
Pagination,
|
Pagination,
|
||||||
} from "react-admin";
|
} from "react-admin";
|
||||||
import { ServerNoticeButton } from "./ServerNotices";
|
import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices";
|
||||||
|
|
||||||
const UserPagination = props => (
|
const UserPagination = props => (
|
||||||
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
||||||
@ -51,7 +51,7 @@ const UserBulkActionButtons = props => {
|
|||||||
const translate = useTranslate();
|
const translate = useTranslate();
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<ServerNoticeButton {...props} />
|
<ServerNoticeBulkButton {...props} />
|
||||||
<BulkDeleteButton
|
<BulkDeleteButton
|
||||||
{...props}
|
{...props}
|
||||||
label="resources.users.action.erase"
|
label="resources.users.action.erase"
|
||||||
|
Loading…
Reference in New Issue
Block a user