// Copyright 2024 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 * as TransactionBackend from "./backend/TransactionBackend"; import * as Setting from "./Setting"; import * as ApplicationBackend from "./backend/ApplicationBackend"; import {Button, Card, Col, Input, Row} from "antd"; import i18next from "i18next"; class TransactionEditPage extends React.Component { constructor(props) { super(props); this.state = { classes: props, organizationName: props.organizationName !== undefined ? props.organizationName : props.match.params.organizationName, transactionName: props.match.params.transactionName, application: null, transaction: null, providers: [], mode: props.location.mode !== undefined ? props.location.mode : "edit", }; } UNSAFE_componentWillMount() { this.getTransaction(); } getTransaction() { TransactionBackend.getTransaction(this.state.organizationName, this.state.transactionName) .then((res) => { if (res.data === null) { this.props.history.push("/404"); return; } this.setState({ transaction: res.data, }); Setting.scrollToDiv("invoice-area"); }); } submitTransactionEdit(exitAfterSave) { const transaction = Setting.deepCopy(this.state.transaction); TransactionBackend.updateTransaction(this.state.transaction.owner, this.state.transactionName, transaction) .then((res) => { if (res.status === "ok") { Setting.showMessage("success", i18next.t("general:Successfully saved")); this.setState({ transactionName: this.state.transaction.name, }); if (exitAfterSave) { this.props.history.push("/transactions"); } else { this.props.history.push(`/transactions/${this.state.organizationName}/${this.state.transaction.name}`); } } else { Setting.showMessage("error", `${i18next.t("general:Failed to save")}: ${res.msg}`); this.updatePaymentField("name", this.state.transactionName); } }) .catch(error => { Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`); }); } deleteTransaction() { TransactionBackend.deleteTransaction(this.state.transaction) .then((res) => { if (res.status === "ok") { this.props.history.push("/transactions"); } else { Setting.showMessage("error", `${i18next.t("general:Failed to delete")}: ${res.msg}`); } }) .catch(error => { Setting.showMessage("error", `${i18next.t("general:Failed to connect to server")}: ${error}`); }); } parseTransactionField(key, value) { if ([""].includes(key)) { value = Setting.myParseInt(value); } return value; } getApplication() { ApplicationBackend.getApplication("admin", this.state.applicationName) .then((res) => { if (res.data === null) { this.props.history.push("/404"); return; } if (res.status === "error") { Setting.showMessage("error", res.msg); return; } const application = res.data; if (application.grantTypes === null || application.grantTypes === undefined || application.grantTypes.length === 0) { application.grantTypes = ["authorization_code"]; } if (application.tags === null || application.tags === undefined) { application.tags = []; } this.setState({ application: application, }); this.getCerts(application.organization); this.getSamlMetadata(application.enableSamlPostBinding); }); } renderTransaction() { return ( {this.state.mode === "add" ? i18next.t("transaction:New Transaction") : i18next.t("transaction:Edit Transaction")}     {this.state.mode === "add" ? : null} } style={(Setting.isMobile()) ? {margin: "5px"} : {}} type="inner"> {Setting.getLabel(i18next.t("general:Organization"), i18next.t("general:Organization - Tooltip"))} : { // this.updatePaymentField('organization', e.target.value); }} /> {Setting.getLabel(i18next.t("general:Name"), i18next.t("general:Name - Tooltip"))} : { // this.updatePaymentField('name', e.target.value); }} /> {Setting.getLabel(i18next.t("general:Display name"), i18next.t("general:Display name - Tooltip"))} : { this.updatePaymentField("displayName", e.target.value); }} /> {Setting.getLabel(i18next.t("general:Provider"), i18next.t("general:Provider - Tooltip"))} : { // this.updatePaymentField('provider', e.target.value); }} /> {Setting.getLabel(i18next.t("provider:Category"), i18next.t("provider:Category - Tooltip"))} : { this.updatePaymentField("displayName", e.target.value); }} /> {Setting.getLabel(i18next.t("provider:Type"), i18next.t("payment:Type - Tooltip"))} : { // this.updatePaymentField('type', e.target.value); }} /> {Setting.getLabel(i18next.t("payment:Product"), i18next.t("payment:Product - Tooltip"))} : { // this.updatePaymentField('productName', e.target.value); }} /> {Setting.getLabel(i18next.t("product:Detail"), i18next.t("product:Detail - Tooltip"))} : { // this.updatePaymentField('currency', e.target.value); }} /> {Setting.getLabel(i18next.t("user:Tag"), i18next.t("transaction:Tag - Tooltip"))} : { // this.updatePaymentField('currency', e.target.value); }} /> {Setting.getLabel(i18next.t("payment:Currency"), i18next.t("payment:Currency - Tooltip"))} : { // this.updatePaymentField('currency', e.target.value); }} /> {Setting.getLabel(i18next.t("transaction:Amount"), i18next.t("transaction:Amount - Tooltip"))} : { // this.updatePaymentField('amount', e.target.value); }} /> {Setting.getLabel(i18next.t("product:Return URL"), i18next.t("product:Return URL - Tooltip"))} : { // this.updatePaymentField('amount', e.target.value); }} /> {Setting.getLabel(i18next.t("general:User"), i18next.t("general:User - Tooltip"))} : { // this.updatePaymentField('amount', e.target.value); }} /> {Setting.getLabel(i18next.t("general:Application"), i18next.t("general:Application - Tooltip"))} : { // this.updatePaymentField('amount', e.target.value); }} /> {Setting.getLabel(i18next.t("general:Payment"), i18next.t("general:Payment - Tooltip"))} : { // this.updatePaymentField('amount', e.target.value); }} /> {Setting.getLabel(i18next.t("general:State"), i18next.t("general:State - Tooltip"))} : { // this.updatePaymentField('state', e.target.value); }} /> ); } render() { return (
{ this.state.transaction !== null ? this.renderTransaction() : null }
{this.state.mode === "add" ? : null}
); } } export default TransactionEditPage;