Skip to content

Commit

Permalink
show progress dialog when verifying email address on signup instead o…
Browse files Browse the repository at this point in the history
…f error dialog, close #2642
  • Loading branch information
johnbotris committed Jan 29, 2021
1 parent 96a4675 commit 174e7db
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
26 changes: 18 additions & 8 deletions src/api/main/SignupForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import {isApp, isTutanotaDomain} from "../Env"
import {AccountType, TUTANOTA_MAIL_ADDRESS_DOMAINS} from "../common/TutanotaConstants"
import {PasswordForm} from "../../settings/PasswordForm"
import type {CheckboxAttrs} from "../../gui/base/CheckboxN"
import {neverNull} from "../common/utils/Utils"
import {neverNull, noOp} from "../common/utils/Utils"
import {lang} from "../../misc/LanguageViewModel"
import type {DialogHeaderBarAttrs} from "../../gui/base/DialogHeaderBar"
import {htmlSanitizer} from "../../misc/HtmlSanitizer"
import {showWorkerProgressDialog} from "../../gui/base/ProgressDialog"
import {showProgressDialog, showWorkerProgressDialog} from "../../gui/base/ProgressDialog"
import {worker} from "./WorkerClient"
import {AccessDeactivatedError, AccessExpiredError, InvalidDataError} from "../common/error/RestError"
import {createRegistrationCaptchaServiceGetData} from "../entities/sys/RegistrationCaptchaServiceGetData"
Expand All @@ -32,6 +32,7 @@ import {TextField} from "../../gui/base/TextField"
import {DialogHeaderBar} from "../../gui/base/DialogHeaderBar"
import {uint8ArrayToBase64} from "../common/utils/Encoding"
import {CheckboxN} from "../../gui/base/CheckboxN"
import {CancelledError} from "../common/error/CancelledError"

export type SignupFormAttrs = {
/** Handle a new account signup. if readonly then the argument will always be null */
Expand Down Expand Up @@ -73,7 +74,6 @@ export class SignupForm implements MComponent<SignupFormAttrs> {
checked: this._confirmAge
}


const submit = () => {
if (a.readonly) {
return a.newSignupHandler(null)
Expand All @@ -86,11 +86,21 @@ export class SignupForm implements MComponent<SignupFormAttrs> {
return
}

const ageConfirmPromise = this._confirmAge()
? Promise.resolve(true)
: Dialog.confirm("parentConfirmation_msg", "paymentDataValidation_action")
const awaitVerification = this._mailAddressForm.awaitVerification()
const mailAddressVerificationPromise = awaitVerification
? showProgressDialog("mailAddressBusy_msg", awaitVerification)
: Promise.resolve(true)

mailAddressVerificationPromise.then(verified => {
if (!verified) {
Dialog.error(() => neverNull(this._mailAddressForm.getErrorMessageId()))
return false
}

ageConfirmPromise.then(confirmed => {
return this._confirmAge()
? true
: Dialog.confirm("parentConfirmation_msg", "paymentDataValidation_action")
}).then(confirmed => {
if (confirmed) {
return signup(
this._mailAddressForm.getCleanMailAddress(),
Expand All @@ -103,7 +113,7 @@ export class SignupForm implements MComponent<SignupFormAttrs> {
a.newSignupHandler(newAccountData)
})
}
})
}).catch(CancelledError, noOp)
}

return m("#signup-account-dialog.flex-center", m(".flex-grow-shrink-auto.max-width-m.pt.pb.plr-l", [
Expand Down
22 changes: 20 additions & 2 deletions src/settings/SelectMailAddressForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import {ButtonN, ButtonType} from "../gui/base/ButtonN"
import {attachDropdown} from "../gui/base/DropdownN"
import {AccessDeactivatedError} from "../api/common/error/RestError"
import {neverNull} from "../api/common/utils/Utils.js"
import type {DeferredObject} from "../api/common/utils/Utils"
import {defer} from "../api/common/utils/Utils"
import {CancelledError} from "../api/common/error/CancelledError"


assertMainOrNode()
Expand All @@ -31,6 +34,8 @@ export class SelectMailAddressForm {
_availableDomains: string[];
injectionsRightButtonAttrs: ?ButtonAttrs;

deferredVerification: ?DeferredObject<boolean>

constructor(availableDomains: string[], injectionsRightButtonAttrs: ?ButtonAttrs = null) {
this.injectionsRightButtonAttrs = injectionsRightButtonAttrs
this._messageId = stream("mailAddressNeutral_msg")
Expand Down Expand Up @@ -74,6 +79,8 @@ export class SelectMailAddressForm {

_verifyMailAddress() {
clearTimeout(neverNull(this._checkAddressTimeout))
this.deferredVerification && this.deferredVerification.reject(new CancelledError(""))
this.deferredVerification = null
let cleanMailAddress = this.cleanMailAddress()
let cleanUsername = this._username().trim().toLowerCase()
if (cleanUsername === "") {
Expand All @@ -86,18 +93,29 @@ export class SelectMailAddressForm {
return
}
this._messageId("mailAddressBusy_msg")
this.deferredVerification = defer()
this._checkAddressTimeout = setTimeout(() => {
if (this.cleanMailAddress() !== cleanMailAddress) return
worker.initialized.then(() => worker.isMailAddressAvailable(cleanMailAddress))
.then(available => {
if (this.cleanMailAddress() === cleanMailAddress) {
this._messageId(available ? VALID_MESSAGE_ID : "mailAddressNA_msg")
}
this.deferredVerification && this.deferredVerification.resolve(available)
this.deferredVerification = null
})
.catch(AccessDeactivatedError, () => {
this._messageId("mailAddressDelay_msg")
this.deferredVerification && this.deferredVerification.resolve(false)
this.deferredVerification = null
})
.catch(AccessDeactivatedError, () => this._messageId("mailAddressDelay_msg"))
}, 500)
}

awaitVerification(): ?Promise<boolean> {
return this.deferredVerification && this.deferredVerification.promise
}

getCleanMailAddress(): string {
return this.cleanMailAddress()
}
Expand All @@ -106,7 +124,7 @@ export class SelectMailAddressForm {
* @return null if the entered email address is valid, the corresponding error message otherwise
*/
getErrorMessageId(): ?TranslationKey {
return (this._messageId() === VALID_MESSAGE_ID) ? null : this._messageId()
return (this._messageId() === VALID_MESSAGE_ID || this._messageId() === "mailAddressBusy_msg") ? null : this._messageId()
}
}

0 comments on commit 174e7db

Please sign in to comment.