mirror of
https://github.com/etkecc/synapse-admin.git
synced 2024-11-28 11:29:02 +03:00
Refactor RoomDirectory
Change-Id: Ie3bd606fc91b2673d2a3422f8fd465258d3211b0
This commit is contained in:
parent
4204eb902f
commit
00ecb29d6b
2 changed files with 42 additions and 45 deletions
|
@ -13,6 +13,7 @@ import {
|
|||
TextField,
|
||||
TopToolbar,
|
||||
useCreate,
|
||||
useDataProvider,
|
||||
useListContext,
|
||||
useNotify,
|
||||
useTranslate,
|
||||
|
@ -28,7 +29,7 @@ const RoomDirectoryPagination = () => (
|
|||
<Pagination rowsPerPageOptions={[100, 500, 1000, 2000]} />
|
||||
);
|
||||
|
||||
export const RoomDirectoryDeleteButton = props => {
|
||||
export const RoomDirectoryUnpublishButton = props => {
|
||||
const translate = useTranslate();
|
||||
|
||||
return (
|
||||
|
@ -49,7 +50,7 @@ export const RoomDirectoryDeleteButton = props => {
|
|||
);
|
||||
};
|
||||
|
||||
export const RoomDirectoryBulkDeleteButton = props => (
|
||||
export const RoomDirectoryBulkUnpublishButton = props => (
|
||||
<BulkDeleteButton
|
||||
{...props}
|
||||
label="resources.room_directory.action.erase"
|
||||
|
@ -61,57 +62,59 @@ export const RoomDirectoryBulkDeleteButton = props => (
|
|||
/>
|
||||
);
|
||||
|
||||
export const RoomDirectoryBulkSaveButton = () => {
|
||||
export const RoomDirectoryBulkPublishButton = props => {
|
||||
const { selectedIds } = useListContext();
|
||||
const notify = useNotify();
|
||||
const refresh = useRefresh();
|
||||
const unselectAllRooms = useUnselectAll("rooms");
|
||||
const { createMany, isloading } = useMutation();
|
||||
|
||||
const handleSend = values => {
|
||||
createMany(
|
||||
["room_directory", "createMany", { ids: selectedIds, data: {} }],
|
||||
const dataProvider = useDataProvider();
|
||||
const { mutate, isLoading } = useMutation(
|
||||
() =>
|
||||
dataProvider.createMany("room_directory", {
|
||||
ids: selectedIds,
|
||||
data: {},
|
||||
}),
|
||||
{
|
||||
onSuccess: data => {
|
||||
onSuccess: () => {
|
||||
notify("resources.room_directory.action.send_success");
|
||||
unselectAllRooms();
|
||||
refresh();
|
||||
},
|
||||
onError: error =>
|
||||
onError: () =>
|
||||
notify("resources.room_directory.action.send_failure", {
|
||||
type: "error",
|
||||
}),
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Button
|
||||
{...props}
|
||||
label="resources.room_directory.action.create"
|
||||
onClick={handleSend}
|
||||
disabled={isloading}
|
||||
onClick={mutate}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<RoomDirectoryIcon />
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
export const RoomDirectorySaveButton = () => {
|
||||
export const RoomDirectoryPublishButton = props => {
|
||||
const record = useRecordContext();
|
||||
const notify = useNotify();
|
||||
const refresh = useRefresh();
|
||||
const [create, { isloading }] = useCreate();
|
||||
const [create, { isLoading }] = useCreate();
|
||||
|
||||
const handleSend = () => {
|
||||
create(
|
||||
"room_directory",
|
||||
{ data: { id: record.id } },
|
||||
{
|
||||
onSuccess: _data => {
|
||||
onSuccess: () => {
|
||||
notify("resources.room_directory.action.send_success");
|
||||
refresh();
|
||||
},
|
||||
onError: _error =>
|
||||
onError: () =>
|
||||
notify("resources.room_directory.action.send_failure", {
|
||||
type: "error",
|
||||
}),
|
||||
|
@ -121,17 +124,16 @@ export const RoomDirectorySaveButton = () => {
|
|||
|
||||
return (
|
||||
<Button
|
||||
{...props}
|
||||
label="resources.room_directory.action.create"
|
||||
onClick={handleSend}
|
||||
disabled={isloading}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<RoomDirectoryIcon />
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
const RoomDirectoryBulkActionButtons = () => <RoomDirectoryBulkDeleteButton />;
|
||||
|
||||
const RoomDirectoryListActions = () => (
|
||||
<TopToolbar>
|
||||
<SelectColumnsButton />
|
||||
|
@ -146,8 +148,8 @@ export const RoomDirectoryList = () => (
|
|||
actions={<RoomDirectoryListActions />}
|
||||
>
|
||||
<DatagridConfigurable
|
||||
rowClick={(id, resource, record) => "/rooms/" + id + "/show"}
|
||||
bulkActionButtons={<RoomDirectoryBulkActionButtons />}
|
||||
rowClick={(id, _resource, _record) => "/rooms/" + id + "/show"}
|
||||
bulkActionButtons={<RoomDirectoryBulkUnpublishButton />}
|
||||
omit={["room_id", "canonical_alias", "topic"]}
|
||||
>
|
||||
<AvatarField
|
||||
|
|
|
@ -36,10 +36,10 @@ import VisibilityIcon from "@mui/icons-material/Visibility";
|
|||
import EventIcon from "@mui/icons-material/Event";
|
||||
import RoomIcon from "@mui/icons-material/ViewList";
|
||||
import {
|
||||
RoomDirectoryBulkDeleteButton,
|
||||
RoomDirectoryBulkSaveButton,
|
||||
RoomDirectoryDeleteButton,
|
||||
RoomDirectorySaveButton,
|
||||
RoomDirectoryBulkUnpublishButton,
|
||||
RoomDirectoryBulkPublishButton,
|
||||
RoomDirectoryUnpublishButton,
|
||||
RoomDirectoryPublishButton,
|
||||
} from "./RoomDirectory";
|
||||
|
||||
const date_format = {
|
||||
|
@ -79,14 +79,9 @@ const RoomShowActions = () => {
|
|||
|
||||
return (
|
||||
<TopToolbar>
|
||||
{roomDirectoryStatus === false && (
|
||||
<RoomDirectorySaveButton record={record} />
|
||||
)}
|
||||
{roomDirectoryStatus === true && (
|
||||
<RoomDirectoryDeleteButton record={record} />
|
||||
)}
|
||||
{roomDirectoryStatus === false && <RoomDirectoryPublishButton />}
|
||||
{roomDirectoryStatus === true && <RoomDirectoryUnpublishButton />}
|
||||
<DeleteButton
|
||||
record={record}
|
||||
mutationMode="pessimistic"
|
||||
confirmTitle="resources.rooms.action.erase.title"
|
||||
confirmContent="resources.rooms.action.erase.content"
|
||||
|
@ -280,8 +275,8 @@ export const RoomShow = props => {
|
|||
|
||||
const RoomBulkActionButtons = () => (
|
||||
<>
|
||||
<RoomDirectoryBulkSaveButton />
|
||||
<RoomDirectoryBulkDeleteButton />
|
||||
<RoomDirectoryBulkPublishButton />
|
||||
<RoomDirectoryBulkUnpublishButton />
|
||||
<BulkDeleteButton
|
||||
confirmTitle="resources.rooms.action.erase.title"
|
||||
confirmContent="resources.rooms.action.erase.content"
|
||||
|
|
Loading…
Reference in a new issue