diff --git a/src/components/rooms.js b/src/components/rooms.js index d91db05..74e89c8 100644 --- a/src/components/rooms.js +++ b/src/components/rooms.js @@ -1,4 +1,6 @@ -import React, { Fragment } from "react"; +import React, { Fragment, useState } from "react"; +import classnames from "classnames"; +import { fade } from "@material-ui/core/styles/colorManipulator"; import { connect } from "react-redux"; import { BooleanField, @@ -21,6 +23,14 @@ import { TopToolbar, useRecordContext, useTranslate, + useRedirect, + Toolbar, + SaveButton, + Button, + SimpleForm, + BooleanInput, + useDelete, + useNotify, } from "react-admin"; import get from "lodash/get"; import PropTypes from "prop-types"; @@ -33,7 +43,13 @@ import PageviewIcon from "@material-ui/icons/Pageview"; import UserIcon from "@material-ui/icons/Group"; import ViewListIcon from "@material-ui/icons/ViewList"; import VisibilityIcon from "@material-ui/icons/Visibility"; +import IconCancel from "@material-ui/icons/Cancel"; import EventIcon from "@material-ui/icons/Event"; +import Dialog from "@material-ui/core/Dialog"; +import DialogContent from "@material-ui/core/DialogContent"; +import DialogContentText from "@material-ui/core/DialogContentText"; +import DialogTitle from "@material-ui/core/DialogTitle"; +import DeleteIcon from "@material-ui/icons/Delete"; import { RoomDirectoryBulkDeleteButton, RoomDirectoryBulkSaveButton, @@ -46,6 +62,16 @@ const useStyles = makeStyles(theme => ({ fontFamily: "Roboto, Helvetica, Arial, sans-serif", margin: "0.5em", }, + deleteButton: { + color: theme.palette.error.main, + "&:hover": { + backgroundColor: fade(theme.palette.error.main, 0.12), + // Reset on mouse devices + "@media (hover: none)": { + backgroundColor: "transparent", + }, + }, + }, })); const RoomPagination = props => ( @@ -106,14 +132,7 @@ const RoomShowActions = ({ basePath, data, resource }) => { {roomDirectoryStatus === true && ( )} - + ); }; @@ -408,3 +427,92 @@ function mapStateToProps(state) { } export const RoomList = connect(mapStateToProps)(FilterableRoomList); + +const DeleteRoomDialog = ({ open, loading, onClose, onSend }) => { + const translate = useTranslate(); + + const DeleteRoomToolbar = props => { + return ( + + } + /> + + + ); + }; + + return ( + + + {translate("resources.rooms.action.erase.title")} + + + + {translate("resources.rooms.action.erase.content")} + + } + submitOnEnter={false} + redirect={false} + save={onSend} + > + + + + + ); +}; + +export const DeleteRoomButton = props => { + const classes = useStyles(props); + const [open, setOpen] = useState(false); + const notify = useNotify(); + const redirect = useRedirect(); + const [deleteOne, { loading }] = useDelete("rooms"); + const record = useRecordContext(props); + + const handleDialogOpen = () => setOpen(true); + const handleDialogClose = () => setOpen(false); + + const handleSend = values => { + deleteOne( + { payload: { id: record.id, ...values } }, + { + onSuccess: () => { + notify("resources.rooms.action.erase.send_success"); + handleDialogClose(); + redirect('/rooms'); + }, + onFailure: () => + notify("resources.rooms.action.erase.send_failure", "error"), + } + ); + }; + + return ( + + + + + ); +}; diff --git a/src/i18n/de.js b/src/i18n/de.js index 385c479..708c9c2 100644 --- a/src/i18n/de.js +++ b/src/i18n/de.js @@ -180,6 +180,11 @@ const de = { title: "Raum löschen", content: "Sind Sie sicher dass Sie den Raum löschen möchten? Diese Aktion kann nicht rückgängig gemacht werden. Alle Nachrichten und Medien, die der Raum beinhaltet werden vom Server gelöscht!", + fields: { + block: "Raum für erneute Beitritte sperren", + }, + send_success: "Der Raum wurde gelöscht", + send_failure: "Der Raum konnte nicht gelöscht werden", }, }, }, diff --git a/src/i18n/en.js b/src/i18n/en.js index 5f38c8b..5c4a2eb 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -177,6 +177,11 @@ const en = { title: "Delete room", content: "Are you sure you want to delete the room? This cannot be undone. All messages and shared media in the room will be deleted from the server!", + fields: { + block: "Block room from being rejoined", + }, + send_success: "The room has been deleted", + send_failure: "The room could not be deleted", }, }, reports: { diff --git a/src/synapse/dataProvider.js b/src/synapse/dataProvider.js index 3bfa4e7..4b54e09 100644 --- a/src/synapse/dataProvider.js +++ b/src/synapse/dataProvider.js @@ -68,7 +68,7 @@ const resourceMap = { }, delete: params => ({ endpoint: `/_synapse/admin/v1/rooms/${params.id}`, - body: { block: false }, + body: { block: !!params.block }, }), }, reports: {