Skip to content

Commit

Permalink
Add loading and success indicators for backend checks
Browse files Browse the repository at this point in the history
  • Loading branch information
rebecca-shoptaw committed Jul 19, 2024
1 parent 44a46e2 commit f7becfc
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
25 changes: 17 additions & 8 deletions openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,23 @@ msgstr ""
msgid "Toggle Password Visibility"
msgstr ""

#: account/create.html books/custom_carousel.html
#: search/work_search_facets.html
msgid "Loading..."
msgstr ""

#: account/create.html
msgid "Loading spinner"
msgstr ""

#: account/create.html type/author/view.html
msgid "Success!"
msgstr ""

#: account/create.html
msgid "Checkmark"
msgstr ""

#: account/create.html
msgid "Your URL"
msgstr ""
Expand Down Expand Up @@ -3008,10 +3025,6 @@ msgstr ""
msgid "Not in Library"
msgstr ""

#: books/custom_carousel.html search/work_search_facets.html
msgid "Loading..."
msgstr ""

#: books/custom_carousel.html books/mobile_carousel.html
#, python-format
msgid " by %(name)s"
Expand Down Expand Up @@ -5865,10 +5878,6 @@ msgstr ""
msgid "Refresh the page?"
msgstr ""

#: type/author/view.html
msgid "Success!"
msgstr ""

#: type/author/view.html
msgid ""
"OK. The merge is in motion. <i>It will take <u>a few minutes to "
Expand Down
19 changes: 19 additions & 0 deletions openlibrary/plugins/openlibrary/js/realtime_account_validation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export function initRealTimeValidation() {
const signupForm = document.querySelector('form[name=signup]');
const i18nStrings = JSON.parse(signupForm.dataset.i18n);
const emailLoadingIcon = $('.ol-signup-form__input--email .ol-signup-form__icon--loading');
const usernameLoadingIcon = $('.ol-signup-form__input--username .ol-signup-form__icon--loading');
const emailSuccessIcon = $('.ol-signup-form__input--email .ol-signup-form__icon--success');
const usernameSuccessIcon = $('.ol-signup-form__input--username .ol-signup-form__icon--success');

// Keep the same with openlibrary/plugins/upstream/forms.py
const VALID_EMAIL_RE = /^.*@.*\..*$/;
const VALID_USERNAME_RE = /^[a-z0-9-_]{3,20}$/i;
Expand Down Expand Up @@ -57,6 +62,8 @@ export function initRealTimeValidation() {
function validateUsername() {
const value_username = $(this).val();

usernameSuccessIcon.hide();

if (value_username === '') {
clearError('#username', '#usernameMessage');
return;
Expand All @@ -73,14 +80,19 @@ export function initRealTimeValidation() {
}

clearError('#username', '#usernameMessage');
usernameLoadingIcon.show();

$.ajax({
url: '/account/validate',
data: { username: value_username },
type: 'GET',
success: function(errors) {
usernameLoadingIcon.hide();

if (errors.username) {
renderError('#username', '#usernameMessage', errors.username);
} else {
usernameSuccessIcon.show();
}
}
});
Expand All @@ -89,6 +101,8 @@ export function initRealTimeValidation() {
function validateEmail() {
const value_email = $(this).val();

emailSuccessIcon.hide();

if (value_email === '') {
clearError('#emailAddr', '#emailAddrMessage');
return;
Expand All @@ -100,14 +114,19 @@ export function initRealTimeValidation() {
}

clearError('#emailAddr', '#emailAddrMessage');
emailLoadingIcon.show();

$.ajax({
url: '/account/validate',
data: { email: value_email },
type: 'GET',
success: function(errors) {
emailLoadingIcon.hide();

if (errors.email) {
renderError('#emailAddr', '#emailAddrMessage', errors.email);
} else {
emailSuccessIcon.show();
}
}
});
Expand Down
1 change: 1 addition & 0 deletions openlibrary/plugins/upstream/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class RegisterForm(Form):
help=_("Public and cannot be changed later."),
autocapitalize="off",
validators=[vlogin, username_validator],
maxlength="20",
pattern=vlogin.rexp.pattern,
title=vlogin.msg,
required="true",
Expand Down
9 changes: 7 additions & 2 deletions openlibrary/templates/account/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h1 class="ol-signup-hero__title">$_("Sign Up")</h1>
$# :param openlibrary.utils.form.Input input:
$# :param str suffix: HTML to put at bottom of input

<div class="formElement ol-signup-form__input">
<div class="formElement ol-signup-form__input ol-signup-form__input--$(input.id)">
<div class="label">
<label for="$input.id">$input.description</label>
$if input.help:
Expand All @@ -39,9 +39,14 @@ <h1 class="ol-signup-hero__title">$_("Sign Up")</h1>
<div class="input">
$:input.render()
$if input.name == 'password':
<a href="javascript:;" class="password-visibility-toggle">
<a href="javascript:;" class="password-visibility-toggle ol-signup-form__icon-wrap">
<img src="/static/images/icons/icon_eye-closed.svg" title="$_('Toggle Password Visibility')" alt="$_('Toggle Password Visibility')"/>
</a>
$else:
<a href="javascript:;" class="ol-signup-form__icon-wrap">
<img src="/static/images/ajax-loader.gif" class="ol-signup-form__icon ol-signup-form__icon--loading" title="$_('Loading...')" alt="$_('Loading spinner')" style="display:none"/>
<img src="/static/images/icons/icon_check.png" class="ol-signup-form__icon ol-signup-form__icon--success" title="$_('Success!')" alt="$_('Checkmark')" style="display:none" />
</a>
</div>
<div class="ol-signup-form__suffix">$:suffix</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions static/css/page-signup.less
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@
position: relative;
}

.password-visibility-toggle {
.ol-signup-form__icon-wrap {
position: absolute;
right: 5px;
top: 5px;
}

.password-visibility-toggle > img {
.ol-signup-form__icon-wrap > img {
width: 22px;
height: 22px;
}
Expand Down

0 comments on commit f7becfc

Please sign in to comment.