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

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

134 lines
4.4 KiB
TypeScript
Raw Normal View History

2017-02-14 13:40:19 +00:00
/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
2017-02-14 13:40:19 +00:00
Copyright 2017 Vector Creations Ltd
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.
2017-02-14 13:40:19 +00:00
*/
import React, { ChangeEvent, FormEvent, ReactNode } from "react";
import { RoomMember } from "matrix-js-sdk/src/matrix";
import classNames from "classnames";
2017-05-25 11:39:08 +01:00
import { _t } from "../../../languageHandler";
2021-07-03 11:24:33 +02:00
import MemberAvatar from "../avatars/MemberAvatar";
import BaseDialog from "./BaseDialog";
import DialogButtons from "../elements/DialogButtons";
import Field from "../elements/Field";
import UserIdentifierCustomisations from "../../../customisations/UserIdentifier";
interface IProps {
// matrix-js-sdk (room) member object.
member: RoomMember;
action: string; // eg. 'Ban'
title: string; // eg. 'Ban this user?'
// Whether to display a text field for a reason
// If true, the second argument to onFinished will
// be the string entered.
askReason?: boolean;
danger?: boolean;
children?: ReactNode;
className?: string;
roomId?: string;
onFinished: (success?: boolean, reason?: string) => void;
}
2017-02-14 13:40:19 +00:00
interface IState {
reason: string;
}
2017-02-14 13:40:19 +00:00
/*
* A dialog for confirming an operation on another user.
* Takes a user ID and a verb, displays the target user prominently
2017-02-14 16:09:02 +00:00
* such that it should be easy to confirm that the operation is being
2017-02-14 13:40:19 +00:00
* performed on the right person, and displays the operation prominently
* to make it obvious what is going to happen.
* Also tweaks the style for 'dangerous' actions (albeit only with colour)
*/
export default class ConfirmUserActionDialog extends React.Component<IProps, IState> {
public static defaultProps: Partial<IProps> = {
2017-02-14 13:40:19 +00:00
danger: false,
2017-02-17 17:27:46 +00:00
askReason: false,
2020-08-29 12:14:16 +01:00
};
public constructor(props: IProps) {
super(props);
this.state = {
reason: "",
};
}
private onOk = (ev: FormEvent): void => {
ev.preventDefault();
this.props.onFinished(true, this.state.reason);
2020-08-29 12:14:16 +01:00
};
2017-02-14 13:40:19 +00:00
private onCancel = (): void => {
2017-02-14 13:40:19 +00:00
this.props.onFinished(false);
2020-08-29 12:14:16 +01:00
};
2017-02-14 13:40:19 +00:00
private onReasonChange = (ev: ChangeEvent<HTMLInputElement>): void => {
this.setState({
reason: ev.target.value,
});
};
public render(): React.ReactNode {
const confirmButtonClass = this.props.danger ? "danger" : "";
2017-02-17 17:27:46 +00:00
let reasonBox;
if (this.props.askReason) {
reasonBox = (
<form onSubmit={this.onOk}>
<Field
type="text"
onChange={this.onReasonChange}
value={this.state.reason}
className="mx_ConfirmUserActionDialog_reasonField"
label={_t("room_settings|permissions|ban_reason")}
autoFocus={true}
/>
</form>
2017-02-17 17:27:46 +00:00
);
}
const avatar = <MemberAvatar member={this.props.member} size="48px" />;
const name = this.props.member.name;
const userId = this.props.member.userId;
2017-08-04 15:00:34 +01:00
const displayUserIdentifier = UserIdentifierCustomisations.getDisplayUserIdentifier(userId, {
roomId: this.props.roomId,
withDisplayName: true,
});
2017-02-14 13:40:19 +00:00
return (
2021-07-23 10:23:45 +01:00
<BaseDialog
className={classNames("mx_ConfirmUserActionDialog", this.props.className)}
2021-07-23 10:23:45 +01:00
onFinished={this.props.onFinished}
title={this.props.title}
contentId="mx_Dialog_content"
2017-02-14 13:40:19 +00:00
>
<div id="mx_Dialog_content" className="mx_Dialog_content">
<div className="mx_ConfirmUserActionDialog_user">
<div className="mx_ConfirmUserActionDialog_avatar">{avatar}</div>
<div className="mx_ConfirmUserActionDialog_name">{name}</div>
<div className="mx_ConfirmUserActionDialog_userId">{displayUserIdentifier}</div>
2017-02-14 13:40:19 +00:00
</div>
{reasonBox}
{this.props.children}
2017-02-14 13:40:19 +00:00
</div>
<DialogButtons
primaryButton={this.props.action}
onPrimaryButtonClick={this.onOk}
primaryButtonClass={confirmButtonClass}
focus={!this.props.askReason}
onCancel={this.onCancel}
/>
2017-02-14 13:40:19 +00:00
</BaseDialog>
);
2020-08-29 12:14:16 +01:00
}
}