frontend: Workload pages

This commit is contained in:
Frank Agerholm 2026-01-25 19:47:11 +01:00
commit 9eb9be7318
No known key found for this signature in database
8 changed files with 372 additions and 21 deletions

View file

@ -4,6 +4,7 @@ definePageMeta({
requiresAuth: true
})
import { isUnauthorized } from "~/utils/auth"
import { ref, onMounted } from "vue"
const { loadToken } = useAuth()
@ -17,7 +18,12 @@ const error = ref("")
async function loadOwners() {
loading.value = true
try {
owners.value = await apiFetch("/owners")
const result = await apiFetch("/owners")
if (isUnauthorized(result)) {
return result
}
owners.value = result
return result
} catch (e: any) {
error.value = e.message
} finally {
@ -29,23 +35,27 @@ async function createOwner() {
if (!newOwnerName.value.trim()) return
try {
const owner = await apiFetch("/owners", {
const result = await apiFetch("/owners", {
method: "POST",
body: {
name: newOwnerName.value
}
})
if (isUnauthorized(result)) {
return result
}
owners.value.push(owner)
owners.value.push(result)
newOwnerName.value = ""
return result
} catch (e: any) {
error.value = e.message
}
}
onMounted(() => {
onMounted( async () => {
loadToken()
loadOwners()
if (isUnauthorized(await loadOwners())) return
})
</script>