2019-12-02 17:16:18 +01:00
|
|
|
import { delegate, show, hide } from '@utils';
|
2019-12-02 14:20:26 +01:00
|
|
|
import { suggest } from 'email-butler';
|
2019-12-02 13:07:40 +01:00
|
|
|
|
2019-12-02 17:16:18 +01:00
|
|
|
const userNewEmailSelector = '#new_user input#user_email';
|
2019-12-03 10:05:26 +01:00
|
|
|
const passwordFieldSelector = '#new_user input#user_password';
|
2019-12-02 17:16:18 +01:00
|
|
|
const suggestionsSelector = '.suspect-email';
|
2019-12-03 10:04:54 +01:00
|
|
|
const emailSuggestionSelector = '.suspect-email .email-suggestion-address';
|
2019-12-02 13:07:40 +01:00
|
|
|
|
2019-12-02 17:16:18 +01:00
|
|
|
delegate('focusout', userNewEmailSelector, () => {
|
2019-12-02 14:20:26 +01:00
|
|
|
// When the user leaves the email input during account creation, we check if this account looks correct.
|
2019-12-02 17:16:18 +01:00
|
|
|
// If not (e.g if its "bidou@gmail.coo" or "john@yahoo.rf"), we attempt to suggest a fix for the invalid email.
|
|
|
|
const userEmailInput = document.querySelector(userNewEmailSelector);
|
|
|
|
const suggestedEmailSpan = document.querySelector(emailSuggestionSelector);
|
|
|
|
|
|
|
|
const suggestion = suggest(userEmailInput.value);
|
2019-12-19 17:45:14 +01:00
|
|
|
if (suggestion && suggestion.full && suggestedEmailSpan) {
|
2019-12-02 17:16:18 +01:00
|
|
|
suggestedEmailSpan.innerHTML = suggestion.full;
|
|
|
|
show(document.querySelector(suggestionsSelector));
|
2019-12-02 17:16:42 +01:00
|
|
|
} else {
|
|
|
|
hide(document.querySelector(suggestionsSelector));
|
2019-12-02 14:20:26 +01:00
|
|
|
}
|
2019-12-02 13:07:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
export function acceptEmailSuggestion() {
|
2019-12-02 17:16:18 +01:00
|
|
|
const userEmailInput = document.querySelector(userNewEmailSelector);
|
|
|
|
const suggestedEmailSpan = document.querySelector(emailSuggestionSelector);
|
|
|
|
|
|
|
|
userEmailInput.value = suggestedEmailSpan.innerHTML;
|
|
|
|
hide(document.querySelector(suggestionsSelector));
|
2019-12-03 10:05:26 +01:00
|
|
|
document.querySelector(passwordFieldSelector).focus();
|
2019-12-02 13:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function discardEmailSuggestionBox() {
|
2019-12-02 17:16:18 +01:00
|
|
|
hide(document.querySelector(suggestionsSelector));
|
2019-12-02 13:07:40 +01:00
|
|
|
}
|