implement email suggestion
This commit is contained in:
parent
0bfdb2d5da
commit
80b68afab5
4 changed files with 27 additions and 8 deletions
|
@ -1,20 +1,30 @@
|
||||||
import { on, show, hide } from '@utils';
|
import { on, show, hide } from '@utils';
|
||||||
|
import { suggest } from 'email-butler';
|
||||||
|
|
||||||
const USER_NEW_EMAIL_SELECTOR = '#new_user > #user_email';
|
const user_new_email_selector = '#new_user > #user_email';
|
||||||
const suspectSuggestionsBox = document.querySelector('.suspect-email');
|
const suspectSuggestionsBox = document.querySelector('.suspect-email');
|
||||||
const emailSuggestionSpan = document.querySelector(".suspect-email .question .suggested-email");
|
const emailSuggestionSpan = document.querySelector(
|
||||||
|
'.suspect-email .question .suggested-email'
|
||||||
|
);
|
||||||
|
|
||||||
on(USER_NEW_EMAIL_SELECTOR, 'blur', _ => {
|
on(user_new_email_selector, 'blur', () => {
|
||||||
emailSuggestionSpan.innerHTML = 'bidou@plop.com';
|
// When the user leaves the email input during account creation, we check if this account looks correct.
|
||||||
show(suspectSuggestionsBox)
|
// If not (e.g if its "bidou@gmail.coo" or "john@yahoo.rf") we attempt to suggest a fix for the invalid email.
|
||||||
|
const suggestion = suggest(
|
||||||
|
document.querySelector(user_new_email_selector).value
|
||||||
|
);
|
||||||
|
if (suggestion.full) {
|
||||||
|
emailSuggestionSpan.innerHTML = suggestion.full;
|
||||||
|
show(suspectSuggestionsBox);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export function acceptEmailSuggestion() {
|
export function acceptEmailSuggestion() {
|
||||||
document.querySelector(USER_NEW_EMAIL_SELECTOR).value = emailSuggestionSpan.innerHTML;
|
document.querySelector(user_new_email_selector).value =
|
||||||
|
emailSuggestionSpan.innerHTML;
|
||||||
hide(suspectSuggestionsBox);
|
hide(suspectSuggestionsBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function discardEmailSuggestionBox() {
|
export function discardEmailSuggestionBox() {
|
||||||
hide(suspectSuggestionsBox);
|
hide(suspectSuggestionsBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,10 @@ import {
|
||||||
} from '../new_design/state-button';
|
} from '../new_design/state-button';
|
||||||
import { toggleChart } from '../new_design/toggle-chart';
|
import { toggleChart } from '../new_design/toggle-chart';
|
||||||
import { replaceSemicolonByComma } from '../new_design/avis';
|
import { replaceSemicolonByComma } from '../new_design/avis';
|
||||||
import { acceptEmailSuggestion, discardEmailSuggestionBox } from '../new_design/user-sign_up';
|
import {
|
||||||
|
acceptEmailSuggestion,
|
||||||
|
discardEmailSuggestionBox
|
||||||
|
} from '../new_design/user-sign_up';
|
||||||
|
|
||||||
// This is the global application namespace where we expose helpers used from rails views
|
// This is the global application namespace where we expose helpers used from rails views
|
||||||
const DS = {
|
const DS = {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
"core-js": "^2.0.0",
|
"core-js": "^2.0.0",
|
||||||
"debounce": "^1.2.0",
|
"debounce": "^1.2.0",
|
||||||
"dom4": "^2.1.5",
|
"dom4": "^2.1.5",
|
||||||
|
"email-butler": "^1.0.12",
|
||||||
"highcharts": "^6.1.2",
|
"highcharts": "^6.1.2",
|
||||||
"intersection-observer": "^0.7.0",
|
"intersection-observer": "^0.7.0",
|
||||||
"jquery": "^3.4.1",
|
"jquery": "^3.4.1",
|
||||||
|
|
|
@ -3110,6 +3110,11 @@ elliptic@^6.0.0:
|
||||||
minimalistic-assert "^1.0.0"
|
minimalistic-assert "^1.0.0"
|
||||||
minimalistic-crypto-utils "^1.0.0"
|
minimalistic-crypto-utils "^1.0.0"
|
||||||
|
|
||||||
|
email-butler@^1.0.12:
|
||||||
|
version "1.0.12"
|
||||||
|
resolved "https://registry.yarnpkg.com/email-butler/-/email-butler-1.0.12.tgz#f504b45658fea6257dbc0f891be2cf822d29caa6"
|
||||||
|
integrity sha512-JcvRCjCpLp3fIHlP+KgdDadSmhETA/D4KUtIi3VnwEw2bJKilMOcd+xLJUHrD631bToxxxYRnxB3xTvAQeIRCQ==
|
||||||
|
|
||||||
emoji-regex@^7.0.1:
|
emoji-regex@^7.0.1:
|
||||||
version "7.0.3"
|
version "7.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156"
|
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156"
|
||||||
|
|
Loading…
Reference in a new issue