fix: fail to return after flush the page (#1325)

* fix: fail to return after flush the page 

Old methed just get the url path parameter when click the butten. But when the page flushed, the returnUrl will disappear, so can not return to the specified page.

* Update UserEditPage.js

* Update UserEditPage.js

Co-authored-by: hsluoyz <hsluoyz@qq.com>
This commit is contained in:
Yaodong Yu
2022-11-25 23:08:45 +08:00
committed by GitHub
parent b10fb97c92
commit b7cd598ee8

View File

@ -49,6 +49,7 @@ class UserEditPage extends React.Component {
applications: [],
mode: props.location.mode !== undefined ? props.location.mode : "edit",
loading: true,
returnUrl: null,
};
}
@ -57,6 +58,7 @@ class UserEditPage extends React.Component {
this.getOrganizations();
this.getApplicationsByOrganization(this.state.organizationName);
this.getUserApplication();
this.setReturnUrl();
}
getUser() {
@ -100,9 +102,14 @@ class UserEditPage extends React.Component {
});
}
getReturnUrl() {
setReturnUrl() {
const searchParams = new URLSearchParams(this.props.location.search);
return searchParams.get("returnUrl");
const returnUrl = searchParams.get("returnUrl");
if (returnUrl !== null) {
this.setState({
returnUrl: returnUrl,
});
}
}
parseUserField(key, value) {
@ -619,9 +626,8 @@ class UserEditPage extends React.Component {
}
} else {
if (willExist) {
const returnUrl = this.getReturnUrl();
if (returnUrl) {
window.location.href = returnUrl;
if (this.state.returnUrl) {
window.location.href = this.state.returnUrl;
}
}
}