Skip to content

Commit

Permalink
Add client-side timeout on re-send confirmation button
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron committed Aug 1, 2023
1 parent ca342d4 commit e03a8b7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions app/javascript/packs/sign_up.js
Expand Up @@ -13,4 +13,30 @@ ready(() => {
console.error(error);
});
}, 5000);

document.querySelectorAll('.timer-button').forEach(button => {
let counter = 30;

const container = document.createElement('span');

const updateCounter = () => {
container.innerText = ` (${counter})`;
};

updateCounter();

const countdown = setInterval(() => {
counter--;

if (counter === 0) {
button.disabled = false;
button.removeChild(container);
clearInterval(countdown);
} else {
updateCounter();
}
}, 1000);

button.appendChild(container);
});
});
2 changes: 1 addition & 1 deletion app/views/auth/setup/show.html.haml
Expand Up @@ -19,6 +19,6 @@
= f.input :email, required: true, hint: false, input_html: { 'aria-label': t('simple_form.labels.defaults.email'), autocomplete: 'off' }

.actions
= f.submit t('auth.resend_confirmation'), class: 'button'
= f.button :button, t('auth.resend_confirmation'), type: :submit, class: 'button timer-button', disabled: true

.form-footer= render 'auth/shared/links'

0 comments on commit e03a8b7

Please sign in to comment.