feat: made these functions universal (will be non-duplicate soon)

pull/239/head
Josh Moore 1 year ago
parent 1a07edf3cf
commit 49bd572d03

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

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

Loading…
Cancel
Save