feat: refactor code to use responseOK everywhere (#2111)

* refactor: use responseOK return frontend format json data

* revert handle error

* revert handle error
This commit is contained in:
Yaodong Yu
2023-07-23 09:49:16 +08:00
committed by GitHub
parent fc9528be43
commit a6f803aff1
53 changed files with 178 additions and 218 deletions

View File

@ -75,19 +75,20 @@ class UserEditPage extends React.Component {
getUser() {
UserBackend.getUser(this.state.organizationName, this.state.userName)
.then((data) => {
if (data === null) {
.then((res) => {
if (res.data === null) {
this.props.history.push("/404");
return;
}
if (data.status === null || data.status !== "error") {
this.setState({
user: data,
multiFactorAuths: data?.multiFactorAuths ?? [],
});
if (res.status === "error") {
Setting.showMessage("error", res.msg);
return;
}
this.setState({
user: res.data,
multiFactorAuths: res.data?.multiFactorAuths ?? [],
loading: false,
});
});
@ -108,7 +109,7 @@ class UserEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin")
.then((res) => {
this.setState({
organizations: (res.msg === undefined) ? res : [],
organizations: res.data || [],
});
});
}
@ -117,7 +118,7 @@ class UserEditPage extends React.Component {
ApplicationBackend.getApplicationsByOrganization("admin", organizationName)
.then((res) => {
this.setState({
applications: (res.msg === undefined) ? res : [],
applications: res.data || [],
});
});
}
@ -129,12 +130,10 @@ class UserEditPage extends React.Component {
Setting.showMessage("error", res.msg);
return;
}
this.setState({
application: res,
});
this.setState({
isGroupsVisible: res.organizationObj.accountItems?.some((item) => item.name === "Groups" && item.visible),
application: res.data,
isGroupsVisible: res.data?.organizationObj.accountItems?.some((item) => item.name === "Groups" && item.visible),
});
});
}