fix: handle add message in frontend (#1340)

This commit is contained in:
Yaodong Yu
2022-11-29 20:32:47 +08:00
committed by GitHub
parent 7867060b71
commit d815bf92bd
18 changed files with 86 additions and 47 deletions

View File

@ -45,9 +45,12 @@ class AdapterListPage extends BaseListPage {
const newAdapter = this.newAdapter();
AdapterBackend.addAdapter(newAdapter)
.then((res) => {
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}`);
});

View File

@ -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,

View File

@ -78,9 +78,12 @@ class ApplicationListPage extends BaseListPage {
const newApplication = this.newApplication();
ApplicationBackend.addApplication(newApplication)
.then((res) => {
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}`);
});

View File

@ -43,9 +43,12 @@ class CertListPage extends BaseListPage {
const newCert = this.newCert();
CertBackend.addCert(newCert)
.then((res) => {
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}`);
});

View File

@ -38,9 +38,12 @@ class ModelListPage extends BaseListPage {
const newModel = this.newModel();
ModelBackend.addModel(newModel)
.then((res) => {
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}`);
});

View File

@ -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,

View File

@ -75,9 +75,12 @@ class OrganizationListPage extends BaseListPage {
const newOrganization = this.newOrganization();
OrganizationBackend.addOrganization(newOrganization)
.then((res) => {
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}`);
});

View File

@ -51,7 +51,11 @@ class PaymentListPage extends BaseListPage {
const newPayment = this.newPayment();
PaymentBackend.addPayment(newPayment)
.then((res) => {
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 => {

View File

@ -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}`);
}
)
})
.catch(error => {
Setting.showMessage("error", `Permission failed to add: ${error}`);
});

View File

@ -45,9 +45,12 @@ class ProductListPage extends BaseListPage {
const newProduct = this.newProduct();
ProductBackend.addProduct(newProduct)
.then((res) => {
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}`);
});

View File

@ -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,

View File

@ -61,9 +61,12 @@ class ProviderListPage extends BaseListPage {
const newProvider = this.newProvider();
ProviderBackend.addProvider(newProvider)
.then((res) => {
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}`);
});

View File

@ -40,9 +40,12 @@ class RoleListPage extends BaseListPage {
const newRole = this.newRole();
RoleBackend.addRole(newRole)
.then((res) => {
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}`);
});

View File

@ -49,9 +49,12 @@ class SyncerListPage extends BaseListPage {
const newSyncer = this.newSyncer();
SyncerBackend.addSyncer(newSyncer)
.then((res) => {
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}`);
});

View File

@ -42,9 +42,12 @@ class TokenListPage extends BaseListPage {
const newToken = this.newToken();
TokenBackend.addToken(newToken)
.then((res) => {
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}`);
});

View File

@ -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,

View File

@ -72,9 +72,12 @@ class UserListPage extends BaseListPage {
const newUser = this.newUser();
UserBackend.addUser(newUser)
.then((res) => {
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}`);
});

View File

@ -42,9 +42,12 @@ class WebhookListPage extends BaseListPage {
const newWebhook = this.newWebhook();
WebhookBackend.addWebhook(newWebhook)
.then((res) => {
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}`);
});