Files
ThreadNet-Web/src/components/views/dialogs/RoomUpgradeDialog.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

100 lines
3.2 KiB
TypeScript
Raw Normal View History

2018-08-17 14:54:43 +01:00
/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
Copyright 2018-2021 The Matrix.org Foundation C.I.C.
2018-08-17 14:54:43 +01:00
2024-09-09 14:57:16 +01:00
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
Please see LICENSE files in the repository root for full details.
2018-08-17 14:54:43 +01:00
*/
import React from "react";
import { Room } from "matrix-js-sdk/src/matrix";
2021-07-09 08:47:18 +01:00
2018-08-17 14:54:43 +01:00
import Modal from "../../../Modal";
import { _t } from "../../../languageHandler";
import { upgradeRoom } from "../../../utils/RoomUpgrade";
2021-07-09 08:47:18 +01:00
import BaseDialog from "./BaseDialog";
import ErrorDialog from "./ErrorDialog";
import DialogButtons from "../elements/DialogButtons";
import Spinner from "../elements/Spinner";
interface IProps {
2021-07-09 08:47:18 +01:00
room: Room;
onFinished(upgrade?: boolean): void;
2021-07-09 08:47:18 +01:00
}
interface IState {
busy: boolean;
}
2018-08-17 14:54:43 +01:00
2021-07-09 08:47:18 +01:00
export default class RoomUpgradeDialog extends React.Component<IProps, IState> {
private targetVersion?: string;
2018-08-17 14:54:43 +01:00
public state = {
2020-08-29 12:14:16 +01:00
busy: true,
};
public async componentDidMount(): Promise<void> {
2019-01-28 17:21:33 -07:00
const recommended = await this.props.room.getRecommendedVersion();
2021-07-09 08:47:18 +01:00
this.targetVersion = recommended.version;
2021-06-29 13:11:58 +01:00
this.setState({ busy: false });
2020-08-29 12:14:16 +01:00
}
2018-08-17 14:54:43 +01:00
2021-07-09 08:47:18 +01:00
private onCancelClick = (): void => {
2018-08-17 14:54:43 +01:00
this.props.onFinished(false);
2020-08-29 12:14:16 +01:00
};
2018-08-17 14:54:43 +01:00
2021-07-09 08:47:18 +01:00
private onUpgradeClick = (): void => {
2021-06-29 13:11:58 +01:00
this.setState({ busy: true });
upgradeRoom(this.props.room, this.targetVersion!, false, false)
2021-07-09 08:47:18 +01:00
.then(() => {
this.props.onFinished(true);
})
.catch((err) => {
2022-06-14 17:51:51 +01:00
Modal.createDialog(ErrorDialog, {
title: _t("room_settings|advanced|error_upgrade_title"),
description:
err && err.message ? err.message : _t("room_settings|advanced|error_upgrade_description"),
2022-12-12 12:24:14 +01:00
});
})
2018-08-17 14:54:43 +01:00
.finally(() => {
2021-06-29 13:11:58 +01:00
this.setState({ busy: false });
2018-08-17 14:54:43 +01:00
});
2020-08-29 12:14:16 +01:00
};
2018-08-17 14:54:43 +01:00
public render(): React.ReactNode {
let buttons: JSX.Element;
2018-08-17 14:54:43 +01:00
if (this.state.busy) {
buttons = <Spinner />;
} else {
buttons = (
<DialogButtons
primaryButton={_t("room_settings|advanced|upgrade_button", { version: this.targetVersion })}
2018-08-17 14:54:43 +01:00
primaryButtonClass="danger"
hasCancel={true}
2021-07-09 08:47:18 +01:00
onPrimaryButtonClick={this.onUpgradeClick}
onCancel={this.onCancelClick}
2018-08-17 14:54:43 +01:00
/>
);
}
return (
2021-07-09 08:47:18 +01:00
<BaseDialog
className="mx_RoomUpgradeDialog"
onFinished={this.props.onFinished}
title={_t("room_settings|advanced|upgrade_dialog_title")}
2018-08-17 14:54:43 +01:00
contentId="mx_Dialog_content"
hasCancel={true}
>
<p>{_t("room_settings|advanced|upgrade_dialog_description")}</p>
2018-08-17 14:54:43 +01:00
<ol>
<li>{_t("room_settings|advanced|upgrade_dialog_description_1")}</li>
<li>{_t("room_settings|advanced|upgrade_dialog_description_2")}</li>
<li>{_t("room_settings|advanced|upgrade_dialog_description_3")}</li>
<li>{_t("room_settings|advanced|upgrade_dialog_description_4")}</li>
2018-08-17 14:54:43 +01:00
</ol>
2021-07-09 08:47:18 +01:00
{buttons}
2018-08-17 14:54:43 +01:00
</BaseDialog>
);
2020-08-29 12:14:16 +01:00
}
}