// Copyright 2023 The casbin Authors. All Rights Reserved. // // 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"; import {Button, Card, Col, Input, Row, Select} from "antd"; import * as Setting from "./Setting"; import i18next from "i18next"; import * as MessageBackend from "./backend/MessageBackend"; import TextArea from "antd/es/input/TextArea"; import * as ChatBackend from "./backend/ChatBackend"; class MessageEditPage extends React.Component { constructor(props) { super(props); this.state = { classes: props, messageName: props.match.params.messageName, messages: [], message: null, chats: [], // users: [], chat: null, }; } UNSAFE_componentWillMount() { this.getMessage(); this.getMessages(); this.getChats(); } getChats() { ChatBackend.getChats(this.props.account.name) .then((chats) => { if (chats.status === "ok") { this.setState({ chats: chats.data, }); } else { Setting.showMessage("error", `Failed to get chat: ${chats.msg}`); } }); } getChat(chatName) { ChatBackend.getChat(this.props.account.name, chatName) .then((chat) => { if (chat.status === "ok") { this.setState({ chat: chat.data, }); } else { Setting.showMessage("error", `Failed to get chat: ${chat.msg}`); } }); } getMessage() { MessageBackend.getMessage(this.props.account.name, this.state.messageName) .then((message) => { if (message.status === "ok") { this.setState({ message: message.data, }); } else { Setting.showMessage("error", `Failed to get message: ${message.msg}`); } }); } getMessages() { MessageBackend.getMessages(this.props.account.name) .then((messages) => { if (messages.status === "ok") { this.setState({ messages: messages.data, }); } else { Setting.showMessage("error", `Failed to get messages: ${messages.msg}`); } }); } parseMessageField(key, value) { if ([""].includes(key)) { value = Setting.myParseInt(value); } return value; } updateMessageField(key, value) { value = this.parseMessageField(key, value); const message = this.state.message; message[key] = value; this.setState({ message: message, }); } renderMessage() { return ( {i18next.t("message:Edit Chat")}     } style={(Setting.isMobile()) ? {margin: "5px"} : {}} type="inner"> {/* */} {/* */} {/* {Setting.getLabel(i18next.t("general:Organization"), i18next.t("general:Organization - Tooltip"))} :*/} {/* */} {/* */} {/* { this.updateMessageField("name", e.target.value); }} /> {i18next.t("message:Chat")}: { this.updateMessageField("author", value); }} options={ this.state.chat !== null ? this.state.chat.users.map((user) => Setting.getOption(`${user}`, `${user}`) ) : [] } /> {i18next.t("message:replyTo")}: