|
|
@ -7,6 +7,7 @@ import {
|
|
|
|
Toolbar,
|
|
|
|
Toolbar,
|
|
|
|
required,
|
|
|
|
required,
|
|
|
|
useCreate,
|
|
|
|
useCreate,
|
|
|
|
|
|
|
|
useDataProvider,
|
|
|
|
useListContext,
|
|
|
|
useListContext,
|
|
|
|
useNotify,
|
|
|
|
useNotify,
|
|
|
|
useRecordContext,
|
|
|
|
useRecordContext,
|
|
|
@ -47,11 +48,7 @@ const ServerNoticeDialog = ({ open, loading, onClose, onSubmit }) => {
|
|
|
|
<DialogContentText>
|
|
|
|
<DialogContentText>
|
|
|
|
{translate("resources.servernotices.helper.send")}
|
|
|
|
{translate("resources.servernotices.helper.send")}
|
|
|
|
</DialogContentText>
|
|
|
|
</DialogContentText>
|
|
|
|
<SimpleForm
|
|
|
|
<SimpleForm toolbar={<ServerNoticeToolbar />} onSubmit={onSubmit}>
|
|
|
|
toolbar={<ServerNoticeToolbar />}
|
|
|
|
|
|
|
|
redirect={false}
|
|
|
|
|
|
|
|
onSubmit={onSubmit}
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<TextInput
|
|
|
|
<TextInput
|
|
|
|
source="body"
|
|
|
|
source="body"
|
|
|
|
label="resources.servernotices.fields.body"
|
|
|
|
label="resources.servernotices.fields.body"
|
|
|
@ -114,43 +111,44 @@ export const ServerNoticeButton = () => {
|
|
|
|
export const ServerNoticeBulkButton = () => {
|
|
|
|
export const ServerNoticeBulkButton = () => {
|
|
|
|
const { selectedIds } = useListContext();
|
|
|
|
const { selectedIds } = useListContext();
|
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
|
|
|
|
const openDialog = () => setOpen(true);
|
|
|
|
|
|
|
|
const closeDialog = () => setOpen(false);
|
|
|
|
const notify = useNotify();
|
|
|
|
const notify = useNotify();
|
|
|
|
const unselectAllUsers = useUnselectAll("users");
|
|
|
|
const unselectAllUsers = useUnselectAll("users");
|
|
|
|
const { createMany, isloading } = useMutation();
|
|
|
|
const dataProvider = useDataProvider();
|
|
|
|
|
|
|
|
|
|
|
|
const handleDialogOpen = () => setOpen(true);
|
|
|
|
|
|
|
|
const handleDialogClose = () => setOpen(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleSend = values => {
|
|
|
|
const { mutate: sendNotices, isLoading } = useMutation(
|
|
|
|
createMany(
|
|
|
|
data =>
|
|
|
|
["servernotices", "createMany", { ids: selectedIds, data: values }],
|
|
|
|
dataProvider.createMany("servernotices", {
|
|
|
|
|
|
|
|
ids: selectedIds,
|
|
|
|
|
|
|
|
data: data,
|
|
|
|
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
{
|
|
|
|
onSuccess: data => {
|
|
|
|
onSuccess: () => {
|
|
|
|
notify("resources.servernotices.action.send_success");
|
|
|
|
notify("resources.servernotices.action.send_success");
|
|
|
|
unselectAllUsers();
|
|
|
|
unselectAllUsers();
|
|
|
|
handleDialogClose();
|
|
|
|
closeDialog();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onError: error =>
|
|
|
|
onError: () =>
|
|
|
|
notify("resources.servernotices.action.send_failure", {
|
|
|
|
notify("resources.servernotices.action.send_failure", {
|
|
|
|
type: "error",
|
|
|
|
type: "error",
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
<Button
|
|
|
|
<Button
|
|
|
|
label="resources.servernotices.send"
|
|
|
|
label="resources.servernotices.send"
|
|
|
|
onClick={handleDialogOpen}
|
|
|
|
onClick={openDialog}
|
|
|
|
disabled={isloading}
|
|
|
|
disabled={isLoading}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
<MessageIcon />
|
|
|
|
<MessageIcon />
|
|
|
|
</Button>
|
|
|
|
</Button>
|
|
|
|
<ServerNoticeDialog
|
|
|
|
<ServerNoticeDialog
|
|
|
|
open={open}
|
|
|
|
open={open}
|
|
|
|
onClose={handleDialogClose}
|
|
|
|
onClose={closeDialog}
|
|
|
|
onSubmit={handleSend}
|
|
|
|
onSubmit={sendNotices}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
);
|
|
|
|