Skip to content

Commit

Permalink
Merge pull request #371 from ONLYOFFICE/bugfix/Bug52895
Browse files Browse the repository at this point in the history
Fix bug 52895: warning when leaving a page
  • Loading branch information
ilyaoleshko authored Oct 5, 2021
2 parents 2ae932e + 63dfa0b commit c54b4ed
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,38 @@ class UpdateUserForm extends React.Component {
this.onSelectGroups = this.onSelectGroups.bind(this);
this.onRemoveGroup = this.onRemoveGroup.bind(this);

this.handleWindowBeforeUnload = this.handleWindowBeforeUnload.bind(this);

this.mainFieldsContainerRef = React.createRef();
}

componentDidMount() {
this.props.setIsEditTargetUser(true);

this.unblock = this.props.history.block((targetLocation) => {
if (this.props.isEdit) {
this.props.setIsVisibleDataLossDialog(true);
return false;
}

return true;
});

window.addEventListener("beforeunload", this.handleWindowBeforeUnload);
}

componentWillUnmount() {
this.unblock();
window.removeEventListener("beforeunload", this.handleWindowBeforeUnload);
}

handleWindowBeforeUnload = (e) => {
if (this.props.isEdit) {
e.preventDefault();
e.returnValue = "";
}
};

componentDidUpdate(prevProps, prevState) {
if (this.props.match.params.userId !== prevProps.match.params.userId) {
this.setState(this.mapPropsToState(this.props));
Expand Down Expand Up @@ -318,6 +343,8 @@ class UpdateUserForm extends React.Component {
personal,
} = this.props;

this.unblock();

if (personal) {
history.push(combineUrl(AppServerConfig.proxyURL, "/my"));
} else if (isEditTargetUser || document.referrer) {
Expand Down

0 comments on commit c54b4ed

Please sign in to comment.