* chore: add my name to the chaore so that I can search after cleanup * feat: update the forem creator signup template and copy over some stuff from the email_resgistration * feat: update the fields * feat: make sure that it saves * feat: add an eye svg to the password input * feat: update eye and eye-off svg * feat: update the placeholder for the password field * reveak and hide the password when clicking on the icon * eye visiblibility functionality * feat: display the username * feat: show the username row when we click edit * feat: update the interaction design * chore: remove extra line * chore: remove unneeded function * feat: never show the username hint when the user field is not hidden * feat: ensure that the username works * chore: update the existing specs * feat: move to packs * refactor: manage the visibility with a avariable and not with the password type * optimize the way we use password visibility * chore: validate the username field * chore: update the statement * feat: add a background * feat: accessibility changes * feat: set a max length on the username * feat: some more accessibility changes * feat: validate the length of the password * chore: add some margin to the error box * feat: by_email shows the error states and we should cater for the Forem Creator * feat: tackle any errors * WIP/test: first pass of some integration specs * feat: update the Cypress tests * Update app/views/shared/authentication/_forem_creator_signup.html.erb Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Update app/views/shared/authentication/_forem_creator_signup.html.erb Co-authored-by: Michael Kohl <me@citizen428.net> * chore: temporarily disable the background on large screens * chore: remove title * prevent default * feat; update the style of the button * feat: update the tests to use accessibility tags * feat: update icons * chore: oops * little forntend updates * Update app/views/shared/authentication/_forem_creator_signup.html.erb Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Update cypress/integration/creatorOnboardingFlows/creatorSignup.spec.js Co-authored-by: Nick Taylor <nick@iamdeveloper.com> * fea: change the aria label and pressed * feat: change to just John * feat: update cypress tests * test if this is causing the test to fail * feat: add some margin * feat: mostly for Cypress - required is true or false based on whether the field is needed * refactor: use the password label and skip last test * Update app/views/shared/authentication/_forem_creator_signup.html.erb Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Update app/views/shared/authentication/_forem_creator_signup.html.erb Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * fix: do not toggle the label (accessibility) * fix: add a comma Co-authored-by: Suzanne Aitchison <suzanne@forem.com> Co-authored-by: Michael Kohl <me@citizen428.net> Co-authored-by: Paweł Ludwiczak <ludwiczakpawel@gmail.com> Co-authored-by: Nick Taylor <nick@iamdeveloper.com>
104 lines
2.8 KiB
JavaScript
104 lines
2.8 KiB
JavaScript
function setDefaultUsername(event) {
|
|
if (
|
|
document
|
|
.getElementsByClassName('js-creator-signup-username-row')[0]
|
|
.classList.contains('hidden')
|
|
) {
|
|
const name = event.target.value;
|
|
// It's the first user and so we can assume that this username is not taken.
|
|
const usernameHint = createUsernameHint(name);
|
|
setUsernameHint(usernameHint);
|
|
setUsernameField(usernameHint);
|
|
showHintRow();
|
|
}
|
|
}
|
|
|
|
function createUsernameHint(name) {
|
|
return name
|
|
.toLowerCase()
|
|
.replace(/[^a-zA-Z0-9]/g, '_')
|
|
.substr(0, 30);
|
|
}
|
|
|
|
function showHintRow() {
|
|
const hintRow = document.getElementsByClassName(
|
|
'js-creator-signup-username-hint-row',
|
|
)[0];
|
|
hintRow.classList.remove('hidden');
|
|
}
|
|
|
|
function setUsernameHint(usernameHint) {
|
|
const usernameHintDisplay = document.getElementsByClassName(
|
|
'js-creator-signup-username-hint',
|
|
)[0];
|
|
usernameHintDisplay.innerHTML = usernameHint;
|
|
}
|
|
|
|
function setUsernameField(usernameHint) {
|
|
const usernameField = document.getElementsByClassName(
|
|
'js-creator-signup-username',
|
|
)[0];
|
|
usernameField.value = usernameHint;
|
|
}
|
|
|
|
function showUsernameField() {
|
|
const usernameRow = document.getElementsByClassName(
|
|
'js-creator-signup-username-row',
|
|
)[0];
|
|
usernameRow.classList.remove('hidden');
|
|
focusUsernameInput(usernameRow);
|
|
hideHintRow();
|
|
}
|
|
|
|
function focusUsernameInput(usernameRow) {
|
|
// A timer with a count of 0 will run when the thread becomes idle
|
|
window.setTimeout(() => {
|
|
usernameRow.getElementsByTagName('input')[0].focus();
|
|
}, 0);
|
|
}
|
|
|
|
function hideHintRow() {
|
|
const hintRow = document.getElementsByClassName(
|
|
'js-creator-signup-username-hint-row',
|
|
)[0];
|
|
hintRow.classList.add('hidden');
|
|
}
|
|
|
|
function togglePasswordMask(event) {
|
|
event.preventDefault();
|
|
visible = !visible;
|
|
toggleAriaPressed(visible);
|
|
togglePasswordType(visible);
|
|
toggleEyeIcons(visible);
|
|
}
|
|
|
|
function toggleAriaPressed(visible) {
|
|
visibility.setAttribute('aria-pressed', visible);
|
|
}
|
|
|
|
function togglePasswordType(visible) {
|
|
const passwordType = visible ? 'text' : 'password';
|
|
passwordField.type = passwordType;
|
|
}
|
|
|
|
function toggleEyeIcons(visible) {
|
|
eyeOffIcon.classList.toggle('hidden', !visible);
|
|
eyeIcon.classList.toggle('hidden', visible);
|
|
}
|
|
|
|
let visible = false;
|
|
const eyeIcon = document.getElementsByClassName('js-eye')[0];
|
|
const eyeOffIcon = document.getElementsByClassName('js-eye-off')[0];
|
|
const passwordField = document.getElementsByClassName('js-password')[0];
|
|
const visibility = document.getElementsByClassName(
|
|
'js-creator-password-visibility',
|
|
)[0];
|
|
visibility.addEventListener('click', togglePasswordMask);
|
|
|
|
const name = document.getElementsByClassName('js-creator-signup-name')[0];
|
|
name.addEventListener('input', setDefaultUsername);
|
|
|
|
const editUsername = document.getElementsByClassName(
|
|
'js-creator-edit-username',
|
|
)[0];
|
|
editUsername.addEventListener('click', showUsernameField);
|