mirror of
https://github.com/UA-Fediland/synapse-admin.git
synced 2024-11-24 15:31:26 +00:00
Refactor ServerNotices
https://marmelab.com/react-admin/Upgrade.html#usequery-usemutation-and-usequerywithstore-have-been-removed Change-Id: Id12f727d8813f78c3ae300035aeb1333a1272e02
This commit is contained in:
parent
6430aca02b
commit
4204eb902f
1 changed files with 27 additions and 29 deletions
|
@ -7,6 +7,7 @@ import {
|
|||
Toolbar,
|
||||
required,
|
||||
useCreate,
|
||||
useDataProvider,
|
||||
useListContext,
|
||||
useNotify,
|
||||
useRecordContext,
|
||||
|
@ -47,11 +48,7 @@ const ServerNoticeDialog = ({ open, loading, onClose, onSubmit }) => {
|
|||
<DialogContentText>
|
||||
{translate("resources.servernotices.helper.send")}
|
||||
</DialogContentText>
|
||||
<SimpleForm
|
||||
toolbar={<ServerNoticeToolbar />}
|
||||
redirect={false}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
<SimpleForm toolbar={<ServerNoticeToolbar />} onSubmit={onSubmit}>
|
||||
<TextInput
|
||||
source="body"
|
||||
label="resources.servernotices.fields.body"
|
||||
|
@ -114,43 +111,44 @@ export const ServerNoticeButton = () => {
|
|||
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 (
|
||||
<>
|
||||
<Button
|
||||
label="resources.servernotices.send"
|
||||
onClick={handleDialogOpen}
|
||||
disabled={isloading}
|
||||
onClick={openDialog}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<MessageIcon />
|
||||
</Button>
|
||||
<ServerNoticeDialog
|
||||
open={open}
|
||||
onClose={handleDialogClose}
|
||||
onSubmit={handleSend}
|
||||
onClose={closeDialog}
|
||||
onSubmit={sendNotices}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue