fix: front-end improvements

makes some fields visible and other hidden depending on the result of
some API calls, e.g. visitor is logged in -> show "Log out" button
This commit is contained in:
2025-05-19 00:43:15 +02:00
parent e0e6fa0573
commit 5536a9ad7f
15 changed files with 465 additions and 22 deletions

View File

@@ -0,0 +1,42 @@
interface EventData {
title: string;
location: string;
description: string;
eventDate: string;
}
interface MyAccount {
userId: number;
email: string;
firstName: string;
lastName: string;
createdAt: string;
isOrganisation: boolean;
}
export async function unhideElementById(document: Document, e: string) {
var element = document.getElementById(e);
if (element) {
element.classList.remove('hidden-before-load');
console.log(element.classList);
}
}
export async function getEvent(id: string): Promise<EventData> {
const res = await fetch("/api/events/" + id);
if (!res.ok) {
throw Error("To wydarzenie nie istnieje");
}
const events = await res.json();
return events;
}
export async function getMyAccount(): Promise<MyAccount> {
const res = await fetch("/api/auth/my_account");
if (!res.ok) {
throw Error("U¿ytkownik niezalogowany!");
}
const data = await res.json();
return data;
}