2018-06-12 17:22:45 +03:00
|
|
|
/*
|
|
|
|
Copyright 2018 Vector Creations Ltd
|
|
|
|
|
|
|
|
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';
|
|
|
|
import 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";
|
|
|
|
|
|
|
|
export default class GroupInviteTileContextMenu extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
group: PropTypes.instanceOf(Group).isRequired,
|
|
|
|
/* callback called when the menu is dismissed */
|
|
|
|
onFinished: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this._onClickReject = this._onClickReject.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
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?'),
|
2018-10-27 06:50: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>
|
|
|
|
<div className="mx_RoomTileContextMenu_leave" onClick={this._onClickReject} >
|
|
|
|
<img className="mx_RoomTileContextMenu_tag_icon" src="img/icon_context_delete.svg" width="15" height="15" />
|
|
|
|
{ _t('Reject') }
|
|
|
|
</div>
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
}
|