From d815bf92bd2ce46ec8f6459f984439bbe4addde2 Mon Sep 17 00:00:00 2001 From: Yaodong Yu <2814461814@qq.com> Date: Tue, 29 Nov 2022 20:32:47 +0800 Subject: [PATCH] fix: handle add message in frontend (#1340) --- web/src/AdapterListPage.js | 9 ++++++--- web/src/ApplicationEditPage.js | 2 +- web/src/ApplicationListPage.js | 9 ++++++--- web/src/CertListPage.js | 9 ++++++--- web/src/ModelListPage.js | 9 ++++++--- web/src/OrganizationEditPage.js | 2 +- web/src/OrganizationListPage.js | 9 ++++++--- web/src/PaymentListPage.js | 6 +++++- web/src/PermissionListPage.js | 11 +++++------ web/src/ProductListPage.js | 9 ++++++--- web/src/ProviderEditPage.js | 2 +- web/src/ProviderListPage.js | 9 ++++++--- web/src/RoleListPage.js | 9 ++++++--- web/src/SyncerListPage.js | 9 ++++++--- web/src/TokenListPage.js | 9 ++++++--- web/src/UserEditPage.js | 2 +- web/src/UserListPage.js | 9 ++++++--- web/src/WebhookListPage.js | 9 ++++++--- 18 files changed, 86 insertions(+), 47 deletions(-) diff --git a/web/src/AdapterListPage.js b/web/src/AdapterListPage.js index c86a99b5..7ca8afca 100644 --- a/web/src/AdapterListPage.js +++ b/web/src/AdapterListPage.js @@ -45,9 +45,12 @@ class AdapterListPage extends BaseListPage { const newAdapter = this.newAdapter(); AdapterBackend.addAdapter(newAdapter) .then((res) => { - this.props.history.push({pathname: `/adapters/${newAdapter.organization}/${newAdapter.name}`, mode: "add"}); - } - ) + if (res.status === "ok") { + this.props.history.push({pathname: `/adapters/${newAdapter.organization}/${newAdapter.name}`, mode: "add"}); + } else { + Setting.showMessage("error", `Adapter failed to add: ${res.msg}`); + } + }) .catch(error => { Setting.showMessage("error", `Adapter failed to add: ${error}`); }); diff --git a/web/src/ApplicationEditPage.js b/web/src/ApplicationEditPage.js index 4154b249..01516686 100644 --- a/web/src/ApplicationEditPage.js +++ b/web/src/ApplicationEditPage.js @@ -786,7 +786,7 @@ class ApplicationEditPage extends React.Component { const application = Setting.deepCopy(this.state.application); ApplicationBackend.updateApplication("admin", this.state.applicationName, application) .then((res) => { - if (res.msg === "") { + if (res.status === "ok") { Setting.showMessage("success", "Successfully saved"); this.setState({ applicationName: this.state.application.name, diff --git a/web/src/ApplicationListPage.js b/web/src/ApplicationListPage.js index 9ec3e738..ac34966b 100644 --- a/web/src/ApplicationListPage.js +++ b/web/src/ApplicationListPage.js @@ -78,9 +78,12 @@ class ApplicationListPage extends BaseListPage { const newApplication = this.newApplication(); ApplicationBackend.addApplication(newApplication) .then((res) => { - this.props.history.push({pathname: `/applications/${newApplication.organization}/${newApplication.name}`, mode: "add"}); - } - ) + if (res.status === "ok") { + this.props.history.push({pathname: `/applications/${newApplication.organization}/${newApplication.name}`, mode: "add"}); + } else { + Setting.showMessage("error", `Application failed to add: ${res.msg}`); + } + }) .catch(error => { Setting.showMessage("error", `Application failed to add: ${error}`); }); diff --git a/web/src/CertListPage.js b/web/src/CertListPage.js index e299bfde..71391064 100644 --- a/web/src/CertListPage.js +++ b/web/src/CertListPage.js @@ -43,9 +43,12 @@ class CertListPage extends BaseListPage { const newCert = this.newCert(); CertBackend.addCert(newCert) .then((res) => { - this.props.history.push({pathname: `/certs/${newCert.name}`, mode: "add"}); - } - ) + if (res.status === "ok") { + this.props.history.push({pathname: `/certs/${newCert.name}`, mode: "add"}); + } else { + Setting.showMessage("error", `Cert failed to add: ${res.msg}`); + } + }) .catch(error => { Setting.showMessage("error", `Cert failed to add: ${error}`); }); diff --git a/web/src/ModelListPage.js b/web/src/ModelListPage.js index c00c7cf0..285c72b8 100644 --- a/web/src/ModelListPage.js +++ b/web/src/ModelListPage.js @@ -38,9 +38,12 @@ class ModelListPage extends BaseListPage { const newModel = this.newModel(); ModelBackend.addModel(newModel) .then((res) => { - this.props.history.push({pathname: `/models/${newModel.owner}/${newModel.name}`, mode: "add"}); - } - ) + if (res.status === "ok") { + this.props.history.push({pathname: `/models/${newModel.owner}/${newModel.name}`, mode: "add"}); + } else { + Setting.showMessage("error", `Model failed to add: ${res.msg}`); + } + }) .catch(error => { Setting.showMessage("error", `Model failed to add: ${error}`); }); diff --git a/web/src/OrganizationEditPage.js b/web/src/OrganizationEditPage.js index 00dc3876..d80ff49c 100644 --- a/web/src/OrganizationEditPage.js +++ b/web/src/OrganizationEditPage.js @@ -335,7 +335,7 @@ class OrganizationEditPage extends React.Component { const organization = Setting.deepCopy(this.state.organization); OrganizationBackend.updateOrganization(this.state.organization.owner, this.state.organizationName, organization) .then((res) => { - if (res.msg === "") { + if (res.status === "ok") { Setting.showMessage("success", "Successfully saved"); this.setState({ organizationName: this.state.organization.name, diff --git a/web/src/OrganizationListPage.js b/web/src/OrganizationListPage.js index 523aa002..a9daa26e 100644 --- a/web/src/OrganizationListPage.js +++ b/web/src/OrganizationListPage.js @@ -75,9 +75,12 @@ class OrganizationListPage extends BaseListPage { const newOrganization = this.newOrganization(); OrganizationBackend.addOrganization(newOrganization) .then((res) => { - this.props.history.push({pathname: `/organizations/${newOrganization.name}`, mode: "add"}); - } - ) + if (res.status === "ok") { + this.props.history.push({pathname: `/organizations/${newOrganization.name}`, mode: "add"}); + } else { + Setting.showMessage("error", `Organization failed to add: ${res.msg}`); + } + }) .catch(error => { Setting.showMessage("error", `Organization failed to add: ${error}`); }); diff --git a/web/src/PaymentListPage.js b/web/src/PaymentListPage.js index 451c42d1..09cc0a40 100644 --- a/web/src/PaymentListPage.js +++ b/web/src/PaymentListPage.js @@ -51,7 +51,11 @@ class PaymentListPage extends BaseListPage { const newPayment = this.newPayment(); PaymentBackend.addPayment(newPayment) .then((res) => { - this.props.history.push({pathname: `/payments/${newPayment.name}`, mode: "add"}); + if (res.status === "ok") { + this.props.history.push({pathname: `/payments/${newPayment.name}`, mode: "add"}); + } else { + Setting.showMessage("error", `Payment failed to add: ${res.msg}`); + } } ) .catch(error => { diff --git a/web/src/PermissionListPage.js b/web/src/PermissionListPage.js index 98fd2aca..90c5192f 100644 --- a/web/src/PermissionListPage.js +++ b/web/src/PermissionListPage.js @@ -48,13 +48,12 @@ class PermissionListPage extends BaseListPage { const newPermission = this.newPermission(); PermissionBackend.addPermission(newPermission) .then((res) => { - if (res.msg !== "") { - Setting.showMessage("error", res.msg); - return; + if (res.status === "ok") { + this.props.history.push({pathname: `/permissions/${newPermission.owner}/${newPermission.name}`, mode: "add"}); + } else { + Setting.showMessage("error", `Permission failed to add: ${res.msg}`); } - this.props.history.push({pathname: `/permissions/${newPermission.owner}/${newPermission.name}`, mode: "add"}); - } - ) + }) .catch(error => { Setting.showMessage("error", `Permission failed to add: ${error}`); }); diff --git a/web/src/ProductListPage.js b/web/src/ProductListPage.js index c50029c1..dd54a458 100644 --- a/web/src/ProductListPage.js +++ b/web/src/ProductListPage.js @@ -45,9 +45,12 @@ class ProductListPage extends BaseListPage { const newProduct = this.newProduct(); ProductBackend.addProduct(newProduct) .then((res) => { - this.props.history.push({pathname: `/products/${newProduct.name}`, mode: "add"}); - } - ) + if (res.status === "ok") { + this.props.history.push({pathname: `/products/${newProduct.name}`, mode: "add"}); + } else { + Setting.showMessage("error", `Product failed to add: ${res.msg}`); + } + }) .catch(error => { Setting.showMessage("error", `Product failed to add: ${error}`); }); diff --git a/web/src/ProviderEditPage.js b/web/src/ProviderEditPage.js index f9f842b8..1c95077f 100644 --- a/web/src/ProviderEditPage.js +++ b/web/src/ProviderEditPage.js @@ -789,7 +789,7 @@ class ProviderEditPage extends React.Component { const provider = Setting.deepCopy(this.state.provider); ProviderBackend.updateProvider(this.state.owner, this.state.providerName, provider) .then((res) => { - if (res.msg === "") { + if (res.status === "ok") { Setting.showMessage("success", "Successfully saved"); this.setState({ owner: this.state.provider.owner, diff --git a/web/src/ProviderListPage.js b/web/src/ProviderListPage.js index 6b99778f..d875b13d 100644 --- a/web/src/ProviderListPage.js +++ b/web/src/ProviderListPage.js @@ -61,9 +61,12 @@ class ProviderListPage extends BaseListPage { const newProvider = this.newProvider(); ProviderBackend.addProvider(newProvider) .then((res) => { - this.props.history.push({pathname: `/providers/${newProvider.owner}/${newProvider.name}`, mode: "add"}); - } - ) + if (res.status === "ok") { + this.props.history.push({pathname: `/providers/${newProvider.owner}/${newProvider.name}`, mode: "add"}); + } else { + Setting.showMessage("error", `Provider failed to add: ${res.msg}`); + } + }) .catch(error => { Setting.showMessage("error", `Provider failed to add: ${error}`); }); diff --git a/web/src/RoleListPage.js b/web/src/RoleListPage.js index 838d84ec..c8fa42a2 100644 --- a/web/src/RoleListPage.js +++ b/web/src/RoleListPage.js @@ -40,9 +40,12 @@ class RoleListPage extends BaseListPage { const newRole = this.newRole(); RoleBackend.addRole(newRole) .then((res) => { - this.props.history.push({pathname: `/roles/${newRole.owner}/${newRole.name}`, mode: "add"}); - } - ) + if (res.status === "ok") { + this.props.history.push({pathname: `/roles/${newRole.owner}/${newRole.name}`, mode: "add"}); + } else { + Setting.showMessage("error", `Role failed to add: ${res.msg}`); + } + }) .catch(error => { Setting.showMessage("error", `Role failed to add: ${error}`); }); diff --git a/web/src/SyncerListPage.js b/web/src/SyncerListPage.js index 5b0538a7..b3ee0c55 100644 --- a/web/src/SyncerListPage.js +++ b/web/src/SyncerListPage.js @@ -49,9 +49,12 @@ class SyncerListPage extends BaseListPage { const newSyncer = this.newSyncer(); SyncerBackend.addSyncer(newSyncer) .then((res) => { - this.props.history.push({pathname: `/syncers/${newSyncer.name}`, mode: "add"}); - } - ) + if (res.status === "ok") { + this.props.history.push({pathname: `/syncers/${newSyncer.name}`, mode: "add"}); + } else { + Setting.showMessage("error", `Syncer failed to add: ${res.msg}`); + } + }) .catch(error => { Setting.showMessage("error", `Syncer failed to add: ${error}`); }); diff --git a/web/src/TokenListPage.js b/web/src/TokenListPage.js index 4e1b10fa..65ad70e8 100644 --- a/web/src/TokenListPage.js +++ b/web/src/TokenListPage.js @@ -42,9 +42,12 @@ class TokenListPage extends BaseListPage { const newToken = this.newToken(); TokenBackend.addToken(newToken) .then((res) => { - this.props.history.push({pathname: `/tokens/${newToken.name}`, mode: "add"}); - } - ) + if (res.status === "ok") { + this.props.history.push({pathname: `/tokens/${newToken.name}`, mode: "add"}); + } else { + Setting.showMessage("error", `Token failed to add: ${res.msg}`); + } + }) .catch(error => { Setting.showMessage("error", `Token failed to add: ${error}`); }); diff --git a/web/src/UserEditPage.js b/web/src/UserEditPage.js index 95546e98..a1e02856 100644 --- a/web/src/UserEditPage.js +++ b/web/src/UserEditPage.js @@ -611,7 +611,7 @@ class UserEditPage extends React.Component { const user = Setting.deepCopy(this.state.user); UserBackend.updateUser(this.state.organizationName, this.state.userName, user) .then((res) => { - if (res.msg === "") { + if (res.status === "ok") { Setting.showMessage("success", "Successfully saved"); this.setState({ organizationName: this.state.user.owner, diff --git a/web/src/UserListPage.js b/web/src/UserListPage.js index 8a10771b..2f330473 100644 --- a/web/src/UserListPage.js +++ b/web/src/UserListPage.js @@ -72,9 +72,12 @@ class UserListPage extends BaseListPage { const newUser = this.newUser(); UserBackend.addUser(newUser) .then((res) => { - this.props.history.push({pathname: `/users/${newUser.owner}/${newUser.name}`, mode: "add"}); - } - ) + if (res.status === "ok") { + this.props.history.push({pathname: `/users/${newUser.owner}/${newUser.name}`, mode: "add"}); + } else { + Setting.showMessage("error", `User failed to add: ${res.msg}`); + } + }) .catch(error => { Setting.showMessage("error", `User failed to add: ${error}`); }); diff --git a/web/src/WebhookListPage.js b/web/src/WebhookListPage.js index 5679af98..0c7c54ca 100644 --- a/web/src/WebhookListPage.js +++ b/web/src/WebhookListPage.js @@ -42,9 +42,12 @@ class WebhookListPage extends BaseListPage { const newWebhook = this.newWebhook(); WebhookBackend.addWebhook(newWebhook) .then((res) => { - this.props.history.push({pathname: `/webhooks/${newWebhook.name}`, mode: "add"}); - } - ) + if (res.status === "ok") { + this.props.history.push({pathname: `/webhooks/${newWebhook.name}`, mode: "add"}); + } else { + Setting.showMessage("error", `Webhook failed to add: ${res.msg}`); + } + }) .catch(error => { Setting.showMessage("error", `Webhook failed to add: ${error}`); });