diff --git a/frontend/login.mts b/frontend/login.mts index 74e8c3d..1c1ffb6 100644 --- a/frontend/login.mts +++ b/frontend/login.mts @@ -1,5 +1,9 @@ import { SlInput, SlButton } from '@shoelace-style/shoelace'; +const genericErrorAlert = () => alert('An error occured, please check the console for details'); +const errAlert = (logTitle: string, err: any, stream: 'error' | 'warn' = 'error') => (console[stream](logTitle, err), genericErrorAlert()); +const errReset = (message: string, element: SlButton) => (element.disabled = false, alert(message)); + // * Wait for the document to be ready document.addEventListener('DOMContentLoaded', () => { @@ -14,11 +18,10 @@ document.addEventListener('DOMContentLoaded', () => { 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!'); + return errReset('Username is required!', Elements.submitButton); if (Elements.passwordInput.value == null || Elements.passwordInput.value === '') - return errorReset('Password is required!'); + return errReset('Password is required!', Elements.submitButton); alert(`Attempting to login user [${Elements.usernameInput.value}]`); Elements.submitButton.disabled = false; diff --git a/frontend/setup.mts b/frontend/setup.mts index f0452c5..15c5511 100644 --- a/frontend/setup.mts +++ b/frontend/setup.mts @@ -3,6 +3,7 @@ import { IdType, UserConfiguration } from 'ass'; const genericErrorAlert = () => alert('An error occured, please check the console for details'); const errAlert = (logTitle: string, err: any, stream: 'error' | 'warn' = 'error') => (console[stream](logTitle, err), genericErrorAlert()); +const errReset = (message: string, element: SlButton) => (element.disabled = false, alert(message)); // * Wait for the document to be ready document.addEventListener('DOMContentLoaded', () => { @@ -72,11 +73,10 @@ document.addEventListener('DOMContentLoaded', () => { } // ! Make sure the admin user fields are set - const adminErrReset = (message: string) => (Elements.submitButton.disabled = false, alert(message)); if (Elements.userUsername.value == null || Elements.userUsername.value === '') - return adminErrReset('Admin username is required!'); + return errReset('Admin username is required!', Elements.submitButton); if (Elements.userPassword.value == null || Elements.userPassword.value === '') - return adminErrReset('Admin password is required!'); + return errReset('Admin password is required!', Elements.submitButton); // Do setup fetch('/api/setup', {