demarches-normaliennes/app/javascript/new_design/user-sign_up.js

31 lines
1 KiB
JavaScript
Raw Normal View History

import { on, show, hide } from '@utils';
2019-12-02 14:20:26 +01:00
import { suggest } from 'email-butler';
2019-12-02 14:20:26 +01:00
const user_new_email_selector = '#new_user > #user_email';
const suspectSuggestionsBox = document.querySelector('.suspect-email');
2019-12-02 14:20:26 +01:00
const emailSuggestionSpan = document.querySelector(
'.suspect-email .question .suggested-email'
);
2019-12-02 14:20:26 +01:00
on(user_new_email_selector, 'blur', () => {
// When the user leaves the email input during account creation, we check if this account looks correct.
// 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() {
2019-12-02 14:20:26 +01:00
document.querySelector(user_new_email_selector).value =
emailSuggestionSpan.innerHTML;
hide(suspectSuggestionsBox);
}
export function discardEmailSuggestionBox() {
hide(suspectSuggestionsBox);
}