Fix dashboard script

This commit is contained in:
Bruno Rybársky 2024-02-06 20:00:32 +01:00
parent dafe34665c
commit dc6b1589d3
2 changed files with 11 additions and 20 deletions

@ -33,6 +33,10 @@ function handleResponse(data, successMessage, failureMessage) {
}, 3000);
}
async function showDashboardGreeting() {
document.getElementById("welcomeMsg").innerText = `Ahoj, ${UserInfo.FirstName}.`;
}
async function doAction(url, requestData, successMessage, failureMessage, silent = false) {
try {
const params = new URLSearchParams();
@ -63,8 +67,8 @@ async function doAction(url, requestData, successMessage, failureMessage, silent
}
function handlePageResponse(data) {
const navbar = document.getElementById("navbar");
const pageArea = document.getElementById("pagearea");
const navbar = document.getElementById("navbar_container");
const pageArea = document.getElementById("page_container");
if (data.Navigation) {
navbar.innerHTML = data.Navigation;
@ -162,13 +166,16 @@ function onPageLoad(){
let currentPage = localStorage.getItem("currentPage");
if(currentSite === "home" && currentPage === "settings"){
if(document.getElementById("user-settings")){
getUserInfo();
populateUserInfoFields(UserInfo);
}
if(document.getElementById("admin-settings")){
listActivationCodes();
listUsers();
}
}
if(currentSite === "home" && currentPage === "account") {
showDashboardGreeting();
}
}
function navigateTo(site, page){
@ -217,6 +224,7 @@ function login() {
doLogin(email, password);
refreshNavbar();
softReload();
getUserInfo();
}
async function doLogin(email, password) {
@ -320,7 +328,6 @@ function getUserInfo() {
const result = doAction('/account', data, "User info retrieved Successfully!", "User info retrieval failed.", true);
if (result && result.Status === "Success") {
populateUserInfoFields(result.UserInfo);
UserInfo = result.UserInfo;
}
}

@ -1,19 +1,3 @@
<script defer>
async function getUserInfo() {
const data = new URLSearchParams();
data.append("action", "get_user_info");
const result = await doAccountAction(data, null, null, true);
if (result && result.Status === "Success") {
document.getElementById("welcomeMsg").innerText = `Ahoj, ${result.UserInfo.FirstName}.`;
}
}
getUserInfo();
</script>
<div class="dashboard">
<h1 id="welcomeMsg"></h1>
</div>