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

104 lines
3.6 KiB
TypeScript
Raw Normal View History

/*
Copyright 2019 Travis Ralston
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';
2021-06-29 13:11:58 +01:00
import { _t } from "../../../languageHandler";
import LabelledToggleSwitch from "../elements/LabelledToggleSwitch";
2021-09-05 12:02:43 +02:00
import { Widget, WidgetKind } from "matrix-widget-api";
2021-06-29 13:11:58 +01:00
import { OIDCState, WidgetPermissionStore } from "../../../stores/widgets/WidgetPermissionStore";
import { replaceableComponent } from "../../../utils/replaceableComponent";
2021-09-05 12:02:43 +02:00
import DialogButtons from "../elements/DialogButtons";
import BaseDialog from "./BaseDialog";
interface IProps {
onFinished: (confirmed: boolean) => void;
widget: Widget;
widgetKind: WidgetKind; // WidgetKind from widget-api
inRoomId?: string;
}
interface IState {
rememberSelection: boolean;
}
@replaceableComponent("views.dialogs.WidgetOpenIDPermissionsDialog")
2021-09-05 12:02:43 +02:00
export default class WidgetOpenIDPermissionsDialog extends React.Component<IProps, IState> {
constructor(props: IProps) {
super(props);
this.state = {
rememberSelection: false,
};
}
2021-09-05 12:02:43 +02:00
private onAllow = (): void => {
this.onPermissionSelection(true);
};
2021-09-05 12:02:43 +02:00
private onDeny = (): void => {
this.onPermissionSelection(false);
};
2021-09-05 12:02:43 +02:00
private onPermissionSelection(allowed: boolean): void {
if (this.state.rememberSelection) {
2021-09-05 12:02:43 +02:00
console.log(`Remembering ${this.props.widget.id} as allowed=${allowed} for OpenID`);
WidgetPermissionStore.instance.setOIDCState(
this.props.widget, this.props.widgetKind, this.props.inRoomId,
allowed ? OIDCState.Allowed : OIDCState.Denied,
);
}
this.props.onFinished(allowed);
}
2021-09-05 12:02:43 +02:00
private onRememberSelectionChange = (newVal: boolean): void => {
2021-06-29 13:11:58 +01:00
this.setState({ rememberSelection: newVal });
};
render() {
return (
2021-04-29 19:57:02 +02:00
<BaseDialog
className='mx_WidgetOpenIDPermissionsDialog'
hasCancel={true}
2021-04-27 17:23:27 +02:00
onFinished={this.props.onFinished}
2021-04-29 19:57:02 +02:00
title={_t("Allow this widget to verify your identity")}
>
<div className='mx_WidgetOpenIDPermissionsDialog_content'>
<p>
{ _t("The widget will verify your user ID, but won't be able to perform actions for you:") }
</p>
<p className="text-muted">
{ /* cheap trim to just get the path */ }
{ this.props.widget.templateUrl.split("?")[0].split("#")[0] }
</p>
</div>
<DialogButtons
primaryButton={_t("Continue")}
2021-09-05 12:02:43 +02:00
onPrimaryButtonClick={this.onAllow}
onCancel={this.onDeny}
additive={
<LabelledToggleSwitch
value={this.state.rememberSelection}
toggleInFront={true}
2021-09-05 12:02:43 +02:00
onChange={this.onRememberSelectionChange}
label={_t("Remember this")} />}
/>
</BaseDialog>
);
}
}