application stuff
This commit is contained in:
1 parent
aa7ef06858
commit
e3e291b8cf
4 files changed
+97
-5
No files matched your search
@@ -0,0 +1,33 @@
|
||||
const form = document.querySelector('form[data-join]');
|
||||
|
||||
if (form) {
|
||||
const status = form.querySelector('[data-status]');
|
||||
const button = form.querySelector('button[type="submit"]');
|
||||
|
||||
form.addEventListener('submit', async (event) => {
|
||||
event.preventDefault();
|
||||
status.textContent = 'Sending…';
|
||||
button.disabled = true;
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/join', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(Object.fromEntries(new FormData(form))),
|
||||
});
|
||||
const body = await res.json().catch(() => ({}));
|
||||
|
||||
if (res.ok && body.code) {
|
||||
location.href = `/join-status/#${encodeURIComponent(body.code)}`;
|
||||
return;
|
||||
}
|
||||
status.textContent = body.error ||
|
||||
(res.status === 429
|
||||
? 'Too many attempts. Please wait a few minutes and try again.'
|
||||
: 'Something went wrong. Please try again, or email us instead.');
|
||||
} catch {
|
||||
status.textContent = 'Could not reach the server. Check your connection and try again.';
|
||||
}
|
||||
button.disabled = false;
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user