Patch: "Reloading the registration page should warn about data loss" (#8377)

t3chguy/dedup-icons-17oct
Yaya Usman 2022-04-29 12:42:40 +03:00 committed by GitHub
parent 6cb29f2b8d
commit b4da870af1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

View File

@ -139,8 +139,21 @@ export default class Registration extends React.Component<IProps, IState> {
componentDidMount() {
this.replaceClient(this.props.serverConfig);
//triggers a confirmation dialog for data loss before page unloads/refreshes
window.addEventListener("beforeunload", this.unloadCallback);
}
componentWillUnmount() {
window.removeEventListener("beforeunload", this.unloadCallback);
}
private unloadCallback = (event: BeforeUnloadEvent) => {
if (this.state.doingUIAuth) {
event.preventDefault();
event.returnValue = "";
return "";
}
};
// TODO: [REACT-WARNING] Replace with appropriate lifecycle event
// eslint-disable-next-line
UNSAFE_componentWillReceiveProps(newProps) {