2018-06-12 17:22:45 +03:00
|
|
|
/*
|
|
|
|
Copyright 2018 Vector Creations Ltd
|
2019-09-26 16:52:20 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2018-06-12 17:22:45 +03:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from '../../../index';
|
2018-06-12 17:29:05 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2018-06-12 17:22:45 +03:00
|
|
|
import Modal from '../../../Modal';
|
|
|
|
import {Group} from 'matrix-js-sdk';
|
|
|
|
import GroupStore from "../../../stores/GroupStore";
|
2019-12-03 02:21:59 +03:00
|
|
|
import {MenuItem} from "../../structures/ContextMenu";
|
2021-03-09 05:45:39 +03:00
|
|
|
import {replaceableComponent} from "../../../utils/replaceableComponent";
|
2018-06-12 17:22:45 +03:00
|
|
|
|
2021-03-09 05:45:39 +03:00
|
|
|
@replaceableComponent("views.context_menus.GroupInviteTileContextMenu")
|
2018-06-12 17:22:45 +03:00
|
|
|
export default class GroupInviteTileContextMenu extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
group: PropTypes.instanceOf(Group).isRequired,
|
|
|
|
/* callback called when the menu is dismissed */
|
|
|
|
onFinished: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
2019-12-17 20:26:12 +03:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-06-12 17:22:45 +03:00
|
|
|
|
|
|
|
this._onClickReject = this._onClickReject.bind(this);
|
|
|
|
}
|
|
|
|
|
2019-11-11 20:53:17 +03:00
|
|
|
componentDidMount() {
|
2018-06-12 17:22:45 +03:00
|
|
|
this._unmounted = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this._unmounted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_onClickReject() {
|
|
|
|
const QuestionDialog = sdk.getComponent('dialogs.QuestionDialog');
|
|
|
|
Modal.createTrackedDialog('Reject community invite', '', QuestionDialog, {
|
|
|
|
title: _t('Reject invitation'),
|
|
|
|
description: _t('Are you sure you want to reject the invitation?'),
|
2019-01-09 21:10:35 +03:00
|
|
|
onFinished: async (shouldLeave) => {
|
2018-06-12 17:22:45 +03:00
|
|
|
if (!shouldLeave) return;
|
|
|
|
|
|
|
|
// FIXME: controller shouldn't be loading a view :(
|
|
|
|
const Loader = sdk.getComponent("elements.Spinner");
|
|
|
|
const modal = Modal.createDialog(Loader, null, 'mx_Dialog_spinner');
|
|
|
|
|
|
|
|
try {
|
|
|
|
await GroupStore.leaveGroup(this.props.group.groupId);
|
|
|
|
} catch (e) {
|
2018-06-14 15:53:02 +03:00
|
|
|
console.error("Error rejecting community invite: ", e);
|
2018-06-12 17:22:45 +03:00
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createTrackedDialog('Error rejecting invite', '', ErrorDialog, {
|
|
|
|
title: _t("Error"),
|
|
|
|
description: _t("Unable to reject invite"),
|
|
|
|
});
|
2018-06-14 15:53:02 +03:00
|
|
|
} finally {
|
|
|
|
modal.close();
|
2018-06-12 17:22:45 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// Close the context menu
|
|
|
|
if (this.props.onFinished) {
|
|
|
|
this.props.onFinished();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return <div>
|
2019-11-11 20:53:17 +03:00
|
|
|
<MenuItem className="mx_RoomTileContextMenu_leave" onClick={this._onClickReject}>
|
|
|
|
<img className="mx_RoomTileContextMenu_tag_icon" src={require("../../../../res/img/icon_context_delete.svg")} width="15" height="15" alt="" />
|
2018-06-12 17:22:45 +03:00
|
|
|
{ _t('Reject') }
|
2019-11-11 20:53:17 +03:00
|
|
|
</MenuItem>
|
2018-06-12 17:22:45 +03:00
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
}
|