diff --git a/products/ASC.People/Client/src/pages/ProfileAction/Section/Body/updateUserForm.js b/products/ASC.People/Client/src/pages/ProfileAction/Section/Body/updateUserForm.js index ceefeb637fc..0eabd68d4b6 100644 --- a/products/ASC.People/Client/src/pages/ProfileAction/Section/Body/updateUserForm.js +++ b/products/ASC.People/Client/src/pages/ProfileAction/Section/Body/updateUserForm.js @@ -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)); @@ -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) {