mirror of https://github.com/vector-im/riot-web
Merge pull request #6742 from matrix-org/travis/fix-oidc-dialog
Convert widget OIDC exchange dialog to TS (fixing it)pull/21833/head
commit
78617c01a8
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2019 Travis Ralston
|
Copyright 2019 Travis Ralston
|
||||||
|
Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -15,42 +16,46 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { _t } from "../../../languageHandler";
|
import { _t } from "../../../languageHandler";
|
||||||
import * as sdk from "../../../index";
|
|
||||||
import LabelledToggleSwitch from "../elements/LabelledToggleSwitch";
|
import LabelledToggleSwitch from "../elements/LabelledToggleSwitch";
|
||||||
import { Widget } from "matrix-widget-api";
|
import { Widget, WidgetKind } from "matrix-widget-api";
|
||||||
import { OIDCState, WidgetPermissionStore } from "../../../stores/widgets/WidgetPermissionStore";
|
import { OIDCState, WidgetPermissionStore } from "../../../stores/widgets/WidgetPermissionStore";
|
||||||
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||||
|
import { IDialogProps } from "./IDialogProps";
|
||||||
|
import BaseDialog from "./BaseDialog";
|
||||||
|
import DialogButtons from "../elements/DialogButtons";
|
||||||
|
|
||||||
|
interface IProps extends IDialogProps {
|
||||||
|
widget: Widget;
|
||||||
|
widgetKind: WidgetKind;
|
||||||
|
inRoomId?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IState {
|
||||||
|
rememberSelection: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
@replaceableComponent("views.dialogs.WidgetOpenIDPermissionsDialog")
|
@replaceableComponent("views.dialogs.WidgetOpenIDPermissionsDialog")
|
||||||
export default class WidgetOpenIDPermissionsDialog extends React.Component {
|
export default class WidgetOpenIDPermissionsDialog extends React.PureComponent<IProps, IState> {
|
||||||
static propTypes = {
|
constructor(props: IProps) {
|
||||||
onFinished: PropTypes.func.isRequired,
|
super(props);
|
||||||
widget: PropTypes.objectOf(Widget).isRequired,
|
|
||||||
widgetKind: PropTypes.string.isRequired, // WidgetKind from widget-api
|
|
||||||
inRoomId: PropTypes.string,
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
rememberSelection: false,
|
rememberSelection: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
_onAllow = () => {
|
private onAllow = () => {
|
||||||
this._onPermissionSelection(true);
|
this.onPermissionSelection(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
_onDeny = () => {
|
private onDeny = () => {
|
||||||
this._onPermissionSelection(false);
|
this.onPermissionSelection(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
_onPermissionSelection(allowed) {
|
private onPermissionSelection(allowed: boolean) {
|
||||||
if (this.state.rememberSelection) {
|
if (this.state.rememberSelection) {
|
||||||
console.log(`Remembering ${this.props.widgetId} as allowed=${allowed} for OpenID`);
|
console.log(`Remembering ${this.props.widget.id} as allowed=${allowed} for OpenID`);
|
||||||
|
|
||||||
WidgetPermissionStore.instance.setOIDCState(
|
WidgetPermissionStore.instance.setOIDCState(
|
||||||
this.props.widget, this.props.widgetKind, this.props.inRoomId,
|
this.props.widget, this.props.widgetKind, this.props.inRoomId,
|
||||||
|
@ -61,14 +66,11 @@ export default class WidgetOpenIDPermissionsDialog extends React.Component {
|
||||||
this.props.onFinished(allowed);
|
this.props.onFinished(allowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onRememberSelectionChange = (newVal) => {
|
private onRememberSelectionChange = (newVal: boolean) => {
|
||||||
this.setState({ rememberSelection: newVal });
|
this.setState({ rememberSelection: newVal });
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
public render() {
|
||||||
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
|
|
||||||
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BaseDialog
|
<BaseDialog
|
||||||
className='mx_WidgetOpenIDPermissionsDialog'
|
className='mx_WidgetOpenIDPermissionsDialog'
|
||||||
|
@ -87,13 +89,13 @@ export default class WidgetOpenIDPermissionsDialog extends React.Component {
|
||||||
</div>
|
</div>
|
||||||
<DialogButtons
|
<DialogButtons
|
||||||
primaryButton={_t("Continue")}
|
primaryButton={_t("Continue")}
|
||||||
onPrimaryButtonClick={this._onAllow}
|
onPrimaryButtonClick={this.onAllow}
|
||||||
onCancel={this._onDeny}
|
onCancel={this.onDeny}
|
||||||
additive={
|
additive={
|
||||||
<LabelledToggleSwitch
|
<LabelledToggleSwitch
|
||||||
value={this.state.rememberSelection}
|
value={this.state.rememberSelection}
|
||||||
toggleInFront={true}
|
toggleInFront={true}
|
||||||
onChange={this._onRememberSelectionChange}
|
onChange={this.onRememberSelectionChange}
|
||||||
label={_t("Remember this")} />}
|
label={_t("Remember this")} />}
|
||||||
/>
|
/>
|
||||||
</BaseDialog>
|
</BaseDialog>
|
Loading…
Reference in New Issue