Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 9fe77a8

Browse files
committed
update: popup the dialog warning at a later stage of registration
1 parent 872d0e0 commit 9fe77a8

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/components/structures/auth/Registration.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,8 @@ export default class Registration extends React.Component<IProps, IState> {
139139

140140
componentDidMount() {
141141
this.replaceClient(this.props.serverConfig);
142-
//triggers a confirmation dialog for data loss before page unloads/refreshes
143-
window.addEventListener("beforeunload", this.unloadCallback);
144142
}
145143

146-
componentWillUnmount() {
147-
window.removeEventListener("beforeunload", this.unloadCallback);
148-
}
149-
150-
private unloadCallback = (event: BeforeUnloadEvent) => {
151-
event.preventDefault();
152-
event.returnValue = "";
153-
return "";
154-
};
155-
156144
// TODO: [REACT-WARNING] Replace with appropriate lifecycle event
157145
// eslint-disable-next-line
158146
UNSAFE_componentWillReceiveProps(newProps) {

src/components/views/auth/CaptchaForm.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,21 @@ export default class CaptchaForm extends React.Component<ICaptchaFormProps, ICap
6565
);
6666
this.recaptchaContainer.current.appendChild(scriptTag);
6767
}
68+
//triggers a confirmation dialog for data loss before page unloads/refreshes
69+
window.addEventListener("beforeunload", this.unloadCallback);
6870
}
6971

7072
componentWillUnmount() {
7173
this.resetRecaptcha();
74+
window.removeEventListener("beforeunload", this.unloadCallback);
7275
}
7376

77+
private unloadCallback = (event: BeforeUnloadEvent) => {
78+
event.preventDefault();
79+
event.returnValue = "";
80+
return "";
81+
};
82+
7483
// Borrowed directly from: https://github.com/codeep/react-recaptcha-google/commit/e118fa5670fa268426969323b2e7fe77698376ba
7584
private isRecaptchaReady(): boolean {
7685
return typeof window !== "undefined" &&

src/components/views/auth/InteractiveAuthEntryComponents.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,20 @@ export class TermsAuthEntry extends React.Component<ITermsAuthEntryProps, ITerms
320320

321321
componentDidMount() {
322322
this.props.onPhaseChange(DEFAULT_PHASE);
323+
//triggers a confirmation dialog for data loss before page unloads/refreshes
324+
window.addEventListener("beforeunload", this.unloadCallback);
323325
}
324326

327+
componentWillUnmount() {
328+
window.removeEventListener("beforeunload", this.unloadCallback);
329+
}
330+
331+
private unloadCallback = (event: BeforeUnloadEvent) => {
332+
event.preventDefault();
333+
event.returnValue = "";
334+
return "";
335+
};
336+
325337
private togglePolicy(policyId: string) {
326338
const newToggles = {};
327339
for (const policy of this.state.policies) {

0 commit comments

Comments
 (0)