Add client-side timeout on resend confirmation button (#26300)

This commit is contained in:
Eugen Rochko 2023-08-03 01:51:10 +02:00 committed by GitHub
parent 425d77f812
commit 2f932cb2bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -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);
});
});

View File

@ -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'