From 701c808f7aa2e1947fd560a07ca0e3adb27aee32 Mon Sep 17 00:00:00 2001 From: Josh Moore Date: Sat, 14 Oct 2023 15:27:07 -0600 Subject: [PATCH] feat: set up initial frontend JS --- frontend/login.mts | 24 +++++++++++++++++++++++- frontend/setup.mts | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/frontend/login.mts b/frontend/login.mts index 9138bed..74e8c3d 100644 --- a/frontend/login.mts +++ b/frontend/login.mts @@ -1,4 +1,26 @@ import { SlInput, SlButton } from '@shoelace-style/shoelace'; // * Wait for the document to be ready -document.addEventListener('DOMContentLoaded', () => console.log('Login page')); \ No newline at end of file +document.addEventListener('DOMContentLoaded', () => { + + const Elements = { + usernameInput: document.querySelector('#login-username') as SlInput, + passwordInput: document.querySelector('#login-password') as SlInput, + submitButton: document.querySelector('#login-submit') as SlButton + }; + + // * Login button click handler + Elements.submitButton.addEventListener('click', async () => { + Elements.submitButton.disabled = true; + + // Make sure fields are filled + const errorReset = (message: string) => (Elements.submitButton.disabled = false, alert(message)); + if (Elements.usernameInput.value == null || Elements.usernameInput.value === '') + return errorReset('Username is required!'); + if (Elements.passwordInput.value == null || Elements.passwordInput.value === '') + return errorReset('Password is required!'); + + alert(`Attempting to login user [${Elements.usernameInput.value}]`); + Elements.submitButton.disabled = false; + }); +}); diff --git a/frontend/setup.mts b/frontend/setup.mts index 0d8b70a..2db940c 100644 --- a/frontend/setup.mts +++ b/frontend/setup.mts @@ -106,7 +106,7 @@ document.addEventListener('DOMContentLoaded', () => { message: string }) => { alert(data.message); - if (data.success) window.location.href = '/admin'; + if (data.success) window.location.href = '/login'; }); }) .catch((err) => errAlert('POST to /setup failed!', err))