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