// Copyright 2023 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, Row, Select} from "antd"; import * as InvitationBackend from "./backend/InvitationBackend"; import * as OrganizationBackend from "./backend/OrganizationBackend"; import * as ApplicationBackend from "./backend/ApplicationBackend"; import * as Setting from "./Setting"; import i18next from "i18next"; const {Option} = Select; class InvitationEditPage extends React.Component { constructor(props) { super(props); this.state = { classes: props, organizationName: props.organizationName !== undefined ? props.organizationName : props.match.params.organizationName, invitationName: props.match.params.invitationName, invitation: null, organizations: [], applications: [], mode: props.location.mode !== undefined ? props.location.mode : "edit", }; } UNSAFE_componentWillMount() { this.getInvitation(); this.getOrganizations(); this.getApplicationsByOrganization(this.state.organizationName); } getInvitation() { InvitationBackend.getInvitation(this.state.organizationName, this.state.invitationName) .then((res) => { if (res.data === null) { this.props.history.push("/404"); return; } this.setState({ invitation: res.data, }); }); } getOrganizations() { OrganizationBackend.getOrganizations("admin") .then((res) => { this.setState({ organizations: res.data || [], }); }); } getApplicationsByOrganization(organizationName) { ApplicationBackend.getApplicationsByOrganization("admin", organizationName) .then((res) => { this.setState({ applications: res.data || [], }); }); } parseInvitationField(key, value) { if ([""].includes(key)) { value = Setting.myParseInt(value); } return value; } updateInvitationField(key, value) { value = this.parseInvitationField(key, value); const invitation = this.state.invitation; invitation[key] = value; this.setState({ invitation: invitation, }); } renderInvitation() { const isCreatedByPlan = this.state.invitation.tag === "auto_created_invitation_for_plan"; return ( {this.state.mode === "add" ? i18next.t("invitation:New Invitation") : i18next.t("invitation:Edit Invitation")}     {this.state.mode === "add" ? : null} } style={(Setting.isMobile()) ? {margin: "5px"} : {}} type="inner"> {Setting.getLabel(i18next.t("general:Organization"), i18next.t("general:Organization - Tooltip"))} : {Setting.getLabel(i18next.t("general:Name"), i18next.t("general:Name - Tooltip"))} : { this.updateInvitationField("name", e.target.value); }} /> {Setting.getLabel(i18next.t("general:Display name"), i18next.t("general:Display name - Tooltip"))} : { this.updateInvitationField("displayName", e.target.value); }} /> {Setting.getLabel(i18next.t("invitation:Code"), i18next.t("invitation:Code - Tooltip"))} : { this.updateInvitationField("code", e.target.value); }} /> {Setting.getLabel(i18next.t("invitation:Quota"), i18next.t("invitation:Quota - Tooltip"))} : { this.updateInvitationField("quota", value); }} /> {Setting.getLabel(i18next.t("invitation:Used count"), i18next.t("invitation:Used count - Tooltip"))} : { this.updateInvitationField("usedCount", value); }} /> {Setting.getLabel(i18next.t("general:Application"), i18next.t("general:Application - Tooltip"))} : { this.updateInvitationField("username", e.target.value); }} /> {Setting.getLabel(i18next.t("general:Email"), i18next.t("general:Email - Tooltip"))} : { this.updateInvitationField("email", e.target.value); }} /> {Setting.getLabel(i18next.t("general:Phone"), i18next.t("general:Phone - Tooltip"))} : { this.updateInvitationField("phone", e.target.value); }} /> {Setting.getLabel(i18next.t("general:State"), i18next.t("general:State - Tooltip"))} :