// Copyright 2021 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} from 'antd'; import * as OrganizationBackend from "./backend/OrganizationBackend"; import * as Setting from "./Setting"; import i18next from "i18next"; import {LinkOutlined} from "@ant-design/icons"; class OrganizationEditPage extends React.Component { constructor(props) { super(props); this.state = { classes: props, organizationName: props.match.params.organizationName, organization: null, }; } UNSAFE_componentWillMount() { this.getOrganization(); } getOrganization() { OrganizationBackend.getOrganization("admin", this.state.organizationName) .then((organization) => { this.setState({ organization: organization, }); }); } parseOrganizationField(key, value) { // if ([].includes(key)) { // value = Setting.myParseInt(value); // } return value; } updateOrganizationField(key, value) { value = this.parseOrganizationField(key, value); let organization = this.state.organization; organization[key] = value; this.setState({ organization: organization, }); } renderOrganization() { return ( {i18next.t("organization:Edit Organization")}     } style={{marginLeft: '5px'}} type="inner"> {i18next.t("general:Name")}: { this.updateOrganizationField('name', e.target.value); }} /> {i18next.t("general:Display name")}: { this.updateOrganizationField('displayName', e.target.value); }} /> Favicon: URL: } value={this.state.organization.favicon} onChange={e => { this.updateOrganizationField('favicon', e.target.value); }} /> {i18next.t("general:Preview")}: {this.state.organization.favicon} {i18next.t("organization:Website URL")}: { this.updateOrganizationField('websiteUrl', e.target.value); }} /> ) } submitOrganizationEdit() { let organization = Setting.deepCopy(this.state.organization); OrganizationBackend.updateOrganization(this.state.organization.owner, this.state.organizationName, organization) .then((res) => { if (res.msg === "") { Setting.showMessage("success", `Successfully saved`); this.setState({ organizationName: this.state.organization.name, }); this.props.history.push(`/organizations/${this.state.organization.name}`); } else { Setting.showMessage("error", res.msg); this.updateOrganizationField('name', this.state.organizationName); } }) .catch(error => { Setting.showMessage("error", `Failed to connect to server: ${error}`); }); } render() { return (
{ this.state.organization !== null ? this.renderOrganization() : null }
); } } export default OrganizationEditPage;