mirror of
https://github.com/UA-Fediland/synapse-admin.git
synced 2024-11-09 16:24:51 +00:00
Add ServerNoticeButton to UserBulkActionButtons (#41)
This adds the button to send "Server Notices" to many users at once.
This commit is contained in:
parent
c41b8ab846
commit
009ce803e2
3 changed files with 73 additions and 1 deletions
|
@ -7,8 +7,10 @@ import {
|
||||||
Toolbar,
|
Toolbar,
|
||||||
required,
|
required,
|
||||||
useCreate,
|
useCreate,
|
||||||
|
useMutation,
|
||||||
useNotify,
|
useNotify,
|
||||||
useTranslate,
|
useTranslate,
|
||||||
|
useUnselectAll,
|
||||||
} from "react-admin";
|
} from "react-admin";
|
||||||
import MessageIcon from "@material-ui/icons/Message";
|
import MessageIcon from "@material-ui/icons/Message";
|
||||||
import IconCancel from "@material-ui/icons/Cancel";
|
import IconCancel from "@material-ui/icons/Cancel";
|
||||||
|
@ -98,3 +100,49 @@ export const ServerNoticeButton = ({ record }) => {
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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 (
|
||||||
|
<Fragment>
|
||||||
|
<Button
|
||||||
|
label="resources.servernotices.send"
|
||||||
|
onClick={handleDialogOpen}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
<MessageIcon />
|
||||||
|
</Button>
|
||||||
|
<ServerNoticeDialog
|
||||||
|
open={open}
|
||||||
|
onClose={handleDialogClose}
|
||||||
|
onSend={handleSend}
|
||||||
|
/>
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -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,6 +51,7 @@ const UserBulkActionButtons = props => {
|
||||||
const translate = useTranslate();
|
const translate = useTranslate();
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
|
<ServerNoticeBulkButton {...props} />
|
||||||
<BulkDeleteButton
|
<BulkDeleteButton
|
||||||
{...props}
|
{...props}
|
||||||
label="resources.users.action.erase"
|
label="resources.users.action.erase"
|
||||||
|
|
|
@ -221,6 +221,29 @@ const dataProvider = {
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
createMany: (resource, params) => {
|
||||||
|
console.log("createMany " + resource);
|
||||||
|
const homeserver = localStorage.getItem("base_url");
|
||||||
|
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||||
|
|
||||||
|
const res = resourceMap[resource];
|
||||||
|
if (!("create" in res)) return Promise.reject();
|
||||||
|
|
||||||
|
return Promise.all(
|
||||||
|
params.ids.map(id => {
|
||||||
|
params.data.id = id;
|
||||||
|
const cre = res["create"](params.data);
|
||||||
|
const endpoint_url = homeserver + cre.endpoint;
|
||||||
|
return jsonClient(endpoint_url, {
|
||||||
|
method: cre.method,
|
||||||
|
body: JSON.stringify(cre.body, filterNullValues),
|
||||||
|
});
|
||||||
|
})
|
||||||
|
).then(responses => ({
|
||||||
|
data: responses.map(({ json }) => json),
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
delete: (resource, params) => {
|
delete: (resource, params) => {
|
||||||
console.log("delete " + resource);
|
console.log("delete " + resource);
|
||||||
const homeserver = localStorage.getItem("base_url");
|
const homeserver = localStorage.getItem("base_url");
|
||||||
|
|
Loading…
Reference in a new issue