From e6582c140f370128d27f1ad738310f0683aa0128 Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Fri, 13 Nov 2020 15:23:54 +0200 Subject: [PATCH] Dont' allow HostingSignupDialog to close Except via confirmed cancel action or host setup success postmessage. --- .../structures/HostingSignupAction.tsx | 27 +++++++-- .../structures/HostingSignupDialog.tsx | 58 +++++++++++++++---- .../ConfirmCloseHostingSignupDialog.js | 35 +++++++++++ 3 files changed, 104 insertions(+), 16 deletions(-) create mode 100644 src/components/views/dialogs/ConfirmCloseHostingSignupDialog.js diff --git a/src/components/structures/HostingSignupAction.tsx b/src/components/structures/HostingSignupAction.tsx index 7434abfff8..d0ed9d651e 100644 --- a/src/components/structures/HostingSignupAction.tsx +++ b/src/components/structures/HostingSignupAction.tsx @@ -23,15 +23,34 @@ interface IProps {} interface IState {} export default class HostingSignupAction extends React.PureComponent { - private static openDialog() { - Modal.createDialog( - HostingSignupDialog, {}, "mx_HostingSignupDialog", + closingAllowed = false; + modalRef: any; + + private openDialog = () => { + this.modalRef = Modal.createTrackedDialog( + 'Hosting Signup Open', + '', + HostingSignupDialog, + { + requestClose: this.requestClose, + }, + "mx_HostingSignupDialog", + false, + true, + { + onBeforeClose: async () => this.closingAllowed, + }, ); } + private requestClose = () => { + this.closingAllowed = true; + this.modalRef.close(); + } + public render(): React.ReactNode { return ( -
+
Get your own personal Element!
); diff --git a/src/components/structures/HostingSignupDialog.tsx b/src/components/structures/HostingSignupDialog.tsx index 7cd4e85046..0315504a8d 100644 --- a/src/components/structures/HostingSignupDialog.tsx +++ b/src/components/structures/HostingSignupDialog.tsx @@ -15,10 +15,14 @@ limitations under the License. */ import * as React from "react"; +import * as sdk from '../../index'; +import Modal from "../../Modal"; import SdkConfig from "../../SdkConfig"; import {MatrixClientPeg} from "../../MatrixClientPeg"; -interface IProps {} +interface IProps { + requestClose(): void, +} interface IState { error: string, @@ -49,6 +53,29 @@ export default class HostingSignupDialog extends React.PureComponent { + if (result) { + // We're done, close + this.props.requestClose(); + } else { + const ConfirmDialog = sdk.getComponent('views.dialogs.ConfirmCloseHostingSignupDialog'); + Modal.createDialog( + ConfirmDialog, + { + onFinished: result => { + if (result) { + // TODO call an API endpoint to clean up? + this.props.requestClose(); + } + }, + }, + ) } } @@ -82,18 +109,25 @@ export default class HostingSignupDialog extends React.PureComponent -