// 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, Modal, Row, Select, Table} from "antd"; import {CopyOutlined} from "@ant-design/icons"; 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"; import copy from "copy-to-clipboard"; import * as GroupBackend from "./backend/GroupBackend"; 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: [], groups: [], mode: props.location.mode !== undefined ? props.location.mode : "edit", sendLoading: false, }; } UNSAFE_componentWillMount() { this.getInvitation(); this.getOrganizations(); this.getApplicationsByOrganization(this.state.organizationName); this.getGroupsByOrganization(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 || [], }); }); } getGroupsByOrganization(organizationName) { GroupBackend.getGroups(organizationName) .then((res) => { if (res.status === "ok") { this.setState({ groups: 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, }); } copySignupLink() { let defaultApplication; if (this.state.invitation.owner === "built-in") { defaultApplication = "app-built-in"; } else { const selectedOrganization = Setting.getArrayItem(this.state.organizations, "name", this.state.invitation.owner); defaultApplication = selectedOrganization.defaultApplication; if (!defaultApplication) { Setting.showMessage("error", i18next.t("invitation:You need to first specify a default application for organization: ") + selectedOrganization.name); return; } } copy(`${window.location.origin}/signup/${defaultApplication}?invitationCode=${this.state.invitation?.defaultCode}`); Setting.showMessage("success", i18next.t("general:Copied to clipboard successfully")); } renderSendEmailModal() { const emailColumns = [ {title: "email", dataIndex: "email"}, ]; const emails = this.state.emails?.split("\n")?.filter(email => Setting.isValidEmail(email)); const emailData = emails?.map((email) => {return {email: email};}); return { this.setState({sendLoading: true}); InvitationBackend.sendInvitation(this.state.invitation, emails).then(() => { this.setState({sendLoading: false}); Setting.showMessage("success", i18next.t("general:Successfully sent")); }).catch(err => Setting.showMessage("success", err.message)); }}>{i18next.t("general:Send")}, ]} onCancel={() => {this.setState({showSendModal: false});}}>

You will send invitation email to:

; } 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"))} : { const regex = /[^a-zA-Z0-9]/; if (!regex.test(e.target.value)) { this.updateInvitationField("defaultCode", e.target.value); } this.updateInvitationField("code", e.target.value); }} /> {Setting.getLabel(i18next.t("invitation:Default code"), i18next.t("invitation:Default code - Tooltip"))} : { this.updateInvitationField("defaultCode", e.target.value); }} /> {i18next.t("general:Send")} { this.setState({emails: value.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("signupGroup", value);})}> { this.state.groups.map((group, index) => ) } {Setting.getLabel(i18next.t("signup:Username"), i18next.t("signup:Username - 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"))} :