11/*
22Copyright 2019 Travis Ralston
3+ Copyright 2021 The Matrix.org Foundation C.I.C.
34
45Licensed under the Apache License, Version 2.0 (the "License");
56you may not use this file except in compliance with the License.
@@ -15,42 +16,46 @@ limitations under the License.
1516*/
1617
1718import React from 'react' ;
18- import PropTypes from 'prop-types' ;
1919import { _t } from "../../../languageHandler" ;
20- import * as sdk from "../../../index" ;
2120import LabelledToggleSwitch from "../elements/LabelledToggleSwitch" ;
22- import { Widget } from "matrix-widget-api" ;
21+ import { Widget , WidgetKind } from "matrix-widget-api" ;
2322import { OIDCState , WidgetPermissionStore } from "../../../stores/widgets/WidgetPermissionStore" ;
2423import { replaceableComponent } from "../../../utils/replaceableComponent" ;
24+ import { IDialogProps } from "./IDialogProps" ;
25+ import BaseDialog from "./BaseDialog" ;
26+ import DialogButtons from "../elements/DialogButtons" ;
2527
26- @replaceableComponent ( "views.dialogs.WidgetOpenIDPermissionsDialog" )
27- export default class WidgetOpenIDPermissionsDialog extends React . Component {
28- static propTypes = {
29- onFinished : PropTypes . func . isRequired ,
30- widget : PropTypes . objectOf ( Widget ) . isRequired ,
31- widgetKind : PropTypes . string . isRequired , // WidgetKind from widget-api
32- inRoomId : PropTypes . string ,
33- } ;
28+ interface IProps extends IDialogProps {
29+ widget : Widget ;
30+ widgetKind : WidgetKind ;
31+ inRoomId ?: string ;
32+ }
3433
35- constructor ( ) {
36- super ( ) ;
34+ interface IState {
35+ rememberSelection : boolean ;
36+ }
37+
38+ @replaceableComponent ( "views.dialogs.WidgetOpenIDPermissionsDialog" )
39+ export default class WidgetOpenIDPermissionsDialog extends React . PureComponent < IProps , IState > {
40+ constructor ( props : IProps ) {
41+ super ( props ) ;
3742
3843 this . state = {
3944 rememberSelection : false ,
4045 } ;
4146 }
4247
43- _onAllow = ( ) => {
44- this . _onPermissionSelection ( true ) ;
48+ private onAllow = ( ) => {
49+ this . onPermissionSelection ( true ) ;
4550 } ;
4651
47- _onDeny = ( ) => {
48- this . _onPermissionSelection ( false ) ;
52+ private onDeny = ( ) => {
53+ this . onPermissionSelection ( false ) ;
4954 } ;
5055
51- _onPermissionSelection ( allowed ) {
56+ private onPermissionSelection ( allowed : boolean ) {
5257 if ( this . state . rememberSelection ) {
53- console . log ( `Remembering ${ this . props . widgetId } as allowed=${ allowed } for OpenID` ) ;
58+ console . log ( `Remembering ${ this . props . widget . id } as allowed=${ allowed } for OpenID` ) ;
5459
5560 WidgetPermissionStore . instance . setOIDCState (
5661 this . props . widget , this . props . widgetKind , this . props . inRoomId ,
@@ -61,14 +66,11 @@ export default class WidgetOpenIDPermissionsDialog extends React.Component {
6166 this . props . onFinished ( allowed ) ;
6267 }
6368
64- _onRememberSelectionChange = ( newVal ) => {
69+ private onRememberSelectionChange = ( newVal : boolean ) => {
6570 this . setState ( { rememberSelection : newVal } ) ;
6671 } ;
6772
68- render ( ) {
69- const BaseDialog = sdk . getComponent ( 'views.dialogs.BaseDialog' ) ;
70- const DialogButtons = sdk . getComponent ( 'views.elements.DialogButtons' ) ;
71-
73+ public render ( ) {
7274 return (
7375 < BaseDialog
7476 className = 'mx_WidgetOpenIDPermissionsDialog'
@@ -87,13 +89,13 @@ export default class WidgetOpenIDPermissionsDialog extends React.Component {
8789 </ div >
8890 < DialogButtons
8991 primaryButton = { _t ( "Continue" ) }
90- onPrimaryButtonClick = { this . _onAllow }
91- onCancel = { this . _onDeny }
92+ onPrimaryButtonClick = { this . onAllow }
93+ onCancel = { this . onDeny }
9294 additive = {
9395 < LabelledToggleSwitch
9496 value = { this . state . rememberSelection }
9597 toggleInFront = { true }
96- onChange = { this . _onRememberSelectionChange }
98+ onChange = { this . onRememberSelectionChange }
9799 label = { _t ( "Remember this" ) } /> }
98100 />
99101 </ BaseDialog >
0 commit comments