// Copyright 2021 The Casdoor 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, InputNumber, Radio, Row, Select, Switch} from "antd";
import * as OrganizationBackend from "./backend/OrganizationBackend";
import * as ApplicationBackend from "./backend/ApplicationBackend";
import * as LdapBackend from "./backend/LdapBackend";
import * as Setting from "./Setting";
import * as Conf from "./Conf";
import i18next from "i18next";
import {LinkOutlined} from "@ant-design/icons";
import LdapTable from "./table/LdapTable";
import AccountTable from "./table/AccountTable";
import ThemeEditor from "./common/theme/ThemeEditor";
import MfaTable from "./table/MfaTable";
const {Option} = Select;
class OrganizationEditPage extends React.Component {
constructor(props) {
super(props);
this.state = {
classes: props,
organizationName: props.match.params.organizationName,
organization: null,
applications: [],
ldaps: null,
mode: props.location.mode !== undefined ? props.location.mode : "edit",
};
}
UNSAFE_componentWillMount() {
this.getOrganization();
this.getApplications();
this.getLdaps();
}
getOrganization() {
OrganizationBackend.getOrganization("admin", this.state.organizationName)
.then((res) => {
if (res.status === "ok") {
const organization = res.data;
if (organization === null) {
this.props.history.push("/404");
return;
}
this.setState({
organization: organization,
});
} else {
Setting.showMessage("error", res.msg);
}
});
}
getApplications() {
ApplicationBackend.getApplicationsByOrganization("admin", this.state.organizationName)
.then((res) => {
if (res.status === "error") {
Setting.showMessage("error", res.msg);
return;
}
this.setState({
applications: res.data || [],
});
});
}
getLdaps() {
LdapBackend.getLdaps(this.state.organizationName)
.then(res => {
let resdata = [];
if (res.status === "ok") {
if (res.data !== null) {
resdata = res.data;
}
}
this.setState({
ldaps: resdata,
});
});
}
parseOrganizationField(key, value) {
// if ([].includes(key)) {
// value = Setting.myParseInt(value);
// }
return value;
}
updateOrganizationField(key, value) {
value = this.parseOrganizationField(key, value);
const organization = this.state.organization;
organization[key] = value;
this.setState({
organization: organization,
});
}
renderOrganization() {
return (
{this.state.mode === "add" ? i18next.t("organization:New Organization") : i18next.t("organization:Edit Organization")}
{this.state.mode === "add" ? : null}
} style={(Setting.isMobile()) ? {margin: "5px"} : {}} type="inner">